test: add timeout on freeze test to prevent errors on ci (#7227)

This commit is contained in:
Cristhian Zanforlin Lousa 2025-03-22 08:10:23 -03:00 committed by GitHub
commit 603efe7911
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 70 deletions

View file

@ -26,7 +26,9 @@ from langflow.io import (
StrInput,
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):
@ -154,9 +156,8 @@ class APIRequestComponent(Component):
]
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="Message", name="message", method="as_message"),
]
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."""
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:
"""Parse a cURL command and update build configuration.
@ -258,9 +235,6 @@ class APIRequestComponent(Component):
Updated build configuration
"""
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)
# Update basic configuration
@ -480,12 +454,7 @@ class APIRequestComponent(Component):
self.log("Failed to decode JSON response")
result = response.text.encode("utf-8")
# If result is a dictionary, merge it with metadata
if isinstance(result, dict):
metadata.update(result)
else:
# If result is not a dict, store it as 'data'
metadata["data"] = result
metadata.update({"result": result})
if include_httpx_metadata:
metadata.update(
@ -559,7 +528,7 @@ class APIRequestComponent(Component):
urls = [self.add_query_params(url, query_params) for url in urls]
async with httpx.AsyncClient() as client:
return await asyncio.gather(
results = await asyncio.gather(
*[
self.make_request(
client,
@ -575,6 +544,8 @@ class APIRequestComponent(Component):
for u, rec in zip(urls, bodies, strict=False)
]
)
self.status = results
return results
async def _response_info(
self, response: httpx.Response, *, with_file_path: bool = False
@ -673,16 +644,6 @@ class APIRequestComponent(Component):
return processed_headers
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:
"""Convert the API response data into a DataFrame.
@ -691,12 +652,3 @@ class APIRequestComponent(Component):
"""
data = await self.make_requests()
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))

View file

@ -219,6 +219,8 @@ test(
await page.getByTestId("icon-FreezeAll").last().click();
await page.waitForTimeout(3000);
await page.keyboard.press("Escape");
await page.locator('//*[@id="react-flow-id"]').click();
@ -232,6 +234,8 @@ test(
timeout: 1000,
});
await page.waitForTimeout(2000);
await page.getByTestId("button_run_chat output").click();
await page.waitForSelector("text=built successfully", { timeout: 30000 });
@ -270,12 +274,10 @@ test(
await page.getByText("Freeze", { exact: true }).click();
await page.waitForTimeout(3000);
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.waitForTimeout(1000);
@ -304,15 +306,11 @@ test(
.getByPlaceholder("Empty")
.textContent();
expect(firstTextFreezed).toContain("Lorem Ipsum");
expect(secondRunWithoutFreezing).not.toBe(firstTextFreezed);
expect(firstTextFreezed).toBe(secondRunWithoutFreezing);
expect(firstTextFreezed).not.toBe(firstRunWithoutFreezing);
expect(firstTextFreezed).not.toBe(thirdTextWithoutFreezing);
expect(firstRunWithoutFreezing).not.toBe(secondRunWithoutFreezing);
expect(thirdTextWithoutFreezing).toContain("Lorem Ipsum");
const lengthDifference = Math.abs(
thirdTextWithoutFreezing?.length! - firstTextFreezed?.length!,
);
expect(lengthDifference).toBeLessThan(100);
expect(thirdTextWithoutFreezing).not.toBe(secondRunWithoutFreezing);
},
);

View file

@ -11,7 +11,7 @@ declare const __dirname: string;
withEventDeliveryModes(
"Vector Store RAG",
{ tag: ["@release", "@starter-projects", "@development"] },
{ tag: ["@release", "@starter-projects"] },
async ({ page }) => {
test.skip(
!process?.env?.OPENAI_API_KEY,