test: add timeout on freeze test to prevent errors on ci (#7227)
This commit is contained in:
parent
ff3c364916
commit
603efe7911
3 changed files with 20 additions and 70 deletions
|
|
@ -26,7 +26,9 @@ from langflow.io import (
|
||||||
StrInput,
|
StrInput,
|
||||||
TableInput,
|
TableInput,
|
||||||
)
|
)
|
||||||
from langflow.schema import Data, DataFrame, Message, dotdict
|
from langflow.schema import Data
|
||||||
|
from langflow.schema.dataframe import DataFrame
|
||||||
|
from langflow.schema.dotdict import dotdict
|
||||||
|
|
||||||
|
|
||||||
class APIRequestComponent(Component):
|
class APIRequestComponent(Component):
|
||||||
|
|
@ -154,9 +156,8 @@ class APIRequestComponent(Component):
|
||||||
]
|
]
|
||||||
|
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(display_name="Data", name="data", method="as_data"),
|
Output(display_name="Data", name="data", method="make_requests"),
|
||||||
Output(display_name="DataFrame", name="dataframe", method="as_dataframe"),
|
Output(display_name="DataFrame", name="dataframe", method="as_dataframe"),
|
||||||
Output(display_name="Message", name="message", method="as_message"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def _parse_json_value(self, value: Any) -> Any:
|
def _parse_json_value(self, value: Any) -> Any:
|
||||||
|
|
@ -224,30 +225,6 @@ class APIRequestComponent(Component):
|
||||||
"""Check if an item is a valid key-value dictionary."""
|
"""Check if an item is a valid key-value dictionary."""
|
||||||
return isinstance(item, dict) and "key" in item and "value" in item
|
return isinstance(item, dict) and "key" in item and "value" in item
|
||||||
|
|
||||||
def _unescape_curl(self, curl: str) -> str:
|
|
||||||
"""Unescape a cURL command that might have escaped characters.
|
|
||||||
|
|
||||||
This method handles various forms of escaped cURL commands:
|
|
||||||
1. JSON string encoded curl commands
|
|
||||||
2. Double escaped quotes
|
|
||||||
3. Single escaped quotes
|
|
||||||
"""
|
|
||||||
if not curl:
|
|
||||||
return curl
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Handle escaped quotes if present
|
|
||||||
if '\\"' in curl or "\\'" in curl:
|
|
||||||
curl = curl.replace('\\"', '"').replace("\\'", "'")
|
|
||||||
try:
|
|
||||||
return json.loads(curl)
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
# If JSON decoding fails, try to handle escaped quotes
|
|
||||||
return curl.strip('"')
|
|
||||||
except (ValueError, AttributeError) as e:
|
|
||||||
self.log(f"Error unescaping curl command: {e}")
|
|
||||||
return curl # Return original if unescaping fails
|
|
||||||
|
|
||||||
def parse_curl(self, curl: str, build_config: dotdict) -> dotdict:
|
def parse_curl(self, curl: str, build_config: dotdict) -> dotdict:
|
||||||
"""Parse a cURL command and update build configuration.
|
"""Parse a cURL command and update build configuration.
|
||||||
|
|
||||||
|
|
@ -258,9 +235,6 @@ class APIRequestComponent(Component):
|
||||||
Updated build configuration
|
Updated build configuration
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Unescape the curl command if it contains escaped characters
|
|
||||||
curl = self._unescape_curl(curl)
|
|
||||||
self.log(f"Unescaped curl command: {curl}") # Log for debugging
|
|
||||||
parsed = parse_context(curl)
|
parsed = parse_context(curl)
|
||||||
|
|
||||||
# Update basic configuration
|
# Update basic configuration
|
||||||
|
|
@ -480,12 +454,7 @@ class APIRequestComponent(Component):
|
||||||
self.log("Failed to decode JSON response")
|
self.log("Failed to decode JSON response")
|
||||||
result = response.text.encode("utf-8")
|
result = response.text.encode("utf-8")
|
||||||
|
|
||||||
# If result is a dictionary, merge it with metadata
|
metadata.update({"result": result})
|
||||||
if isinstance(result, dict):
|
|
||||||
metadata.update(result)
|
|
||||||
else:
|
|
||||||
# If result is not a dict, store it as 'data'
|
|
||||||
metadata["data"] = result
|
|
||||||
|
|
||||||
if include_httpx_metadata:
|
if include_httpx_metadata:
|
||||||
metadata.update(
|
metadata.update(
|
||||||
|
|
@ -559,7 +528,7 @@ class APIRequestComponent(Component):
|
||||||
urls = [self.add_query_params(url, query_params) for url in urls]
|
urls = [self.add_query_params(url, query_params) for url in urls]
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
return await asyncio.gather(
|
results = await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
self.make_request(
|
self.make_request(
|
||||||
client,
|
client,
|
||||||
|
|
@ -575,6 +544,8 @@ class APIRequestComponent(Component):
|
||||||
for u, rec in zip(urls, bodies, strict=False)
|
for u, rec in zip(urls, bodies, strict=False)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
self.status = results
|
||||||
|
return results
|
||||||
|
|
||||||
async def _response_info(
|
async def _response_info(
|
||||||
self, response: httpx.Response, *, with_file_path: bool = False
|
self, response: httpx.Response, *, with_file_path: bool = False
|
||||||
|
|
@ -673,16 +644,6 @@ class APIRequestComponent(Component):
|
||||||
return processed_headers
|
return processed_headers
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
async def as_data(self) -> Data:
|
|
||||||
"""Convert the API response data into a DataFrame.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
DataFrame: A DataFrame containing the API response data.
|
|
||||||
"""
|
|
||||||
data = await self.make_requests()
|
|
||||||
dicts = {"output": [d.data for d in data]}
|
|
||||||
return Data(**dicts)
|
|
||||||
|
|
||||||
async def as_dataframe(self) -> DataFrame:
|
async def as_dataframe(self) -> DataFrame:
|
||||||
"""Convert the API response data into a DataFrame.
|
"""Convert the API response data into a DataFrame.
|
||||||
|
|
||||||
|
|
@ -691,12 +652,3 @@ class APIRequestComponent(Component):
|
||||||
"""
|
"""
|
||||||
data = await self.make_requests()
|
data = await self.make_requests()
|
||||||
return DataFrame(data)
|
return DataFrame(data)
|
||||||
|
|
||||||
async def as_message(self) -> Message:
|
|
||||||
"""Convert the API response data into a DataFrame.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
DataFrame: A DataFrame containing the API response data.
|
|
||||||
"""
|
|
||||||
data = await self.as_data()
|
|
||||||
return Message(text=str(data))
|
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,8 @@ test(
|
||||||
|
|
||||||
await page.getByTestId("icon-FreezeAll").last().click();
|
await page.getByTestId("icon-FreezeAll").last().click();
|
||||||
|
|
||||||
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
await page.keyboard.press("Escape");
|
await page.keyboard.press("Escape");
|
||||||
|
|
||||||
await page.locator('//*[@id="react-flow-id"]').click();
|
await page.locator('//*[@id="react-flow-id"]').click();
|
||||||
|
|
@ -232,6 +234,8 @@ test(
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
await page.getByTestId("button_run_chat output").click();
|
await page.getByTestId("button_run_chat output").click();
|
||||||
|
|
||||||
await page.waitForSelector("text=built successfully", { timeout: 30000 });
|
await page.waitForSelector("text=built successfully", { timeout: 30000 });
|
||||||
|
|
@ -270,12 +274,10 @@ test(
|
||||||
|
|
||||||
await page.getByText("Freeze", { exact: true }).click();
|
await page.getByText("Freeze", { exact: true }).click();
|
||||||
|
|
||||||
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
await page.keyboard.press("Escape");
|
await page.keyboard.press("Escape");
|
||||||
|
|
||||||
await page.locator('//*[@id="react-flow-id"]').click();
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000);
|
|
||||||
|
|
||||||
await page.getByTestId("button_run_chat output").click();
|
await page.getByTestId("button_run_chat output").click();
|
||||||
|
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
|
|
@ -304,15 +306,11 @@ test(
|
||||||
.getByPlaceholder("Empty")
|
.getByPlaceholder("Empty")
|
||||||
.textContent();
|
.textContent();
|
||||||
|
|
||||||
expect(firstTextFreezed).toContain("Lorem Ipsum");
|
expect(firstTextFreezed).toBe(secondRunWithoutFreezing);
|
||||||
expect(secondRunWithoutFreezing).not.toBe(firstTextFreezed);
|
|
||||||
|
expect(firstTextFreezed).not.toBe(firstRunWithoutFreezing);
|
||||||
|
expect(firstTextFreezed).not.toBe(thirdTextWithoutFreezing);
|
||||||
expect(firstRunWithoutFreezing).not.toBe(secondRunWithoutFreezing);
|
expect(firstRunWithoutFreezing).not.toBe(secondRunWithoutFreezing);
|
||||||
|
expect(thirdTextWithoutFreezing).not.toBe(secondRunWithoutFreezing);
|
||||||
expect(thirdTextWithoutFreezing).toContain("Lorem Ipsum");
|
|
||||||
|
|
||||||
const lengthDifference = Math.abs(
|
|
||||||
thirdTextWithoutFreezing?.length! - firstTextFreezed?.length!,
|
|
||||||
);
|
|
||||||
expect(lengthDifference).toBeLessThan(100);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ declare const __dirname: string;
|
||||||
|
|
||||||
withEventDeliveryModes(
|
withEventDeliveryModes(
|
||||||
"Vector Store RAG",
|
"Vector Store RAG",
|
||||||
{ tag: ["@release", "@starter-projects", "@development"] },
|
{ tag: ["@release", "@starter-projects"] },
|
||||||
async ({ page }) => {
|
async ({ page }) => {
|
||||||
test.skip(
|
test.skip(
|
||||||
!process?.env?.OPENAI_API_KEY,
|
!process?.env?.OPENAI_API_KEY,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue