langflow/.github/workflows/python_test.yml
Gabriel Luiz Freitas Almeida 6403a8f564
fix(graph): fixes bug that caused simple flows with Loop to fail (#8809)
* fix: improve predecessors check for loop component

- Enhanced the handling of cycle vertices to prevent infinite loops by ensuring that a vertex can only run if all pending predecessors have completed.
- Updated conditions for the first execution of cycle vertices to allow running only if all pending predecessors are also cycle vertices.
- This refactor improves the robustness of the vertex management system in asynchronous workflows.

* fix: update _mark_branch method to return visited vertices and refine predecessor mapping

* fix: prevent duplicate item dependencies in LoopComponent

* feat: add loop connection handling in Component class

- Introduced methods to process loop feedback connections, allowing components to connect outputs to loop-enabled inputs.
- Implemented checks to validate loop connections and ensure proper handling of callable methods from other components.
- Enhanced the edge creation logic to support special loop feedback edges targeting outputs instead of inputs.

* fix: enhance name overlap validation in FrontendNode

- Updated the validate_name_overlap method to exclude outputs that allow loops from the overlap check.
- Improved error message to include the display name of the component, along with detailed lists of input and output names for better debugging.

* fix: correct condition for executing cycle vertices in RunnableVerticesManager

- Updated the logic to ensure that a cycle vertex can only execute if it is a loop and all pending predecessors are cycle vertices. This change enhances the robustness of the vertex management system in asynchronous workflows.

* feat: implement comprehensive loop flow for URL processing

- Added a new loop flow that processes multiple URLs through a series of components including URLComponent, SplitTextComponent, LoopComponent, ParserComponent, PromptComponent, OpenAIModelComponent, StructuredOutputComponent, and ChatOutput.
- Enhanced the StructuredOutputComponent to include a detailed system prompt and refined output schema to ensure proper JSON formatting.
- Introduced a test case to validate the creation and execution of the loop flow, ensuring all components are correctly integrated and the expected execution order is maintained.

* refactor: enhance loop target handling in Component and Edge classes

- Introduced LoopTargetHandleDict to better manage loop target structures in the Component and Edge classes.
- Updated the Component class to utilize type casting for loop target handles, improving type safety.
- Refactored the Edge class to accommodate the new loop target handling, ensuring compatibility with existing edge structures.
- Removed deprecated message handling methods from the Component class to streamline the codebase and improve maintainability.

* test: skip OpenAI model integration test if API key is not set

- Added a conditional skip to the test_build_model_integration_reasoning method to prevent execution when the OPENAI_API_KEY environment variable is not set, ensuring tests run only in appropriate environments.

* [autofix.ci] apply automated fixes

* chore: add required secrets for OpenAI and Anthropic APIs in CI workflows

* Updated ci.yml to include OPENAI_API_KEY and ANTHROPIC_API_KEY secrets.
* Modified python_test.yml to mark these secrets as required for workflow execution.

* fix: update OPENAI_API_KEY check in test_loop.py to handle dummy values

* Modified the condition in the pytest skipif decorator to also skip tests when OPENAI_API_KEY is set to "dummy", ensuring more robust test execution.

* refactor: streamline component setup in test_loop.py

* Removed redundant comments and improved formatting for component initialization in the loop_flow function.
* Added missing system_prompt to StructuredOutputComponent to resolve "Multiple structured outputs" error.
* Updated test_loop_flow to ensure it tests the graph creation with proper loop feedback connection.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-03 14:39:09 +00:00

164 lines
5.5 KiB
YAML

name: Python tests
on:
workflow_call:
secrets:
OPENAI_API_KEY:
required: true
ANTHROPIC_API_KEY:
required: true
inputs:
python-versions:
description: "(Optional) Python versions to test"
required: true
type: string
default: "['3.10', '3.11', '3.12', '3.13']"
ref:
description: "(Optional) ref to checkout"
required: false
type: string
nightly:
description: "Whether run is from the nightly build"
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
python-versions:
description: "(Optional) Python versions to test"
required: true
type: string
default: "['3.10', '3.11', '3.12', '3.13']"
env:
POETRY_VERSION: "1.8.2"
NODE_VERSION: "21"
PYTEST_RUN_PATH: "src/backend/tests"
jobs:
build:
name: Unit Tests - Python ${{ matrix.python-version }} - Group ${{ matrix.group }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ${{ fromJson(inputs.python-versions || '["3.10", "3.11", "3.12", "3.13"]' ) }}
splitCount: [5]
group: [1, 2, 3, 4, 5]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
id: setup-node
with:
node-version: ${{ env.NODE_VERSION }}
- name: "Setup Environment"
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
python-version: ${{ matrix.python-version }}
prune-cache: false
- name: Install the project
run: uv sync
- name: Run unit tests
uses: nick-fields/retry@v3
with:
timeout_minutes: 12
max_attempts: 2
command: make unit_tests args="-x -vv --splits ${{ matrix.splitCount }} --group ${{ matrix.group }} --reruns 5"
integration-tests:
name: Integration Tests - Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ${{ fromJson(inputs.python-versions || '["3.10", "3.11", "3.12", "3.13"]' ) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- name: "Setup Environment"
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
python-version: ${{ matrix.python-version }}
prune-cache: false
- name: Install the project
run: uv sync
- name: Run integration tests
run: make integration_tests_no_api_keys
env:
PYLEAK_LOG_LEVEL: debug # enable pyleak logging
DO_NOT_TRACK: true # disable telemetry reporting
test-cli:
name: Test CLI - Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ${{ fromJson(inputs.python-versions || '["3.10", "3.11", "3.12", "3.13"]') }}
steps:
- name: Check out the code at a specific ref
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- name: "Setup Environment"
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
python-version: ${{ matrix.python-version }}
prune-cache: false
- name: Check Version
id: check-version
# We need to print $3 because langflow-base is a dependency of langflow
# For langlow we'd use print $2
run: |
version=$(uv tree | grep 'langflow-base' | awk '{print $3}' | sed 's/^v//' | head -n 1)
url="https://pypi.org/pypi/langflow-base/json"
if [ ${{ inputs.nightly }} == true ]; then
url="https://pypi.org/pypi/langflow-base-nightly/json"
fi
last_released_version=$(curl -s $url | jq -r '.releases | keys | .[]' | sort -V | tail -n 1)
if [ "$version" != "$last_released_version" ]; then
echo "Version $version has not been released yet. Skipping the rest of the job."
echo skipped=true >> $GITHUB_OUTPUT
exit 0
else
echo version=$version >> $GITHUB_OUTPUT
echo skipped=false >> $GITHUB_OUTPUT
fi
- name: Build wheel
if: steps.check-version.outputs.skipped == 'false'
run: |
make build main=true
- name: Install wheel and Test CLI
if: steps.check-version.outputs.skipped == 'false'
run: |
uv venv new-venv
source new-venv/bin/activate
uv pip install dist/*.whl
- name: Test CLI
if: steps.check-version.outputs.skipped == 'false'
run: |
source new-venv/bin/activate
python -m langflow run --host localhost --port 7860 --backend-only &
SERVER_PID=$!
# Wait for the server to start
timeout 120 bash -c 'until curl -f http://localhost:7860/api/v1/auto_login; do sleep 5; done' || (echo "Server did not start in time" && kill $SERVER_PID && exit 1)
# Terminate the server
kill $SERVER_PID || (echo "Failed to terminate the server" && exit 1)
sleep 20 # give the server some time to terminate
# Check if the server is still running
if kill -0 $SERVER_PID 2>/dev/null; then
echo "Failed to terminate the server"
exit 0
else
echo "Server terminated successfully"
fi