feat: Add template tests#9083
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis update introduces comprehensive validation and testing for Langflow starter project templates. It adds a new validation utility module, a dedicated test suite for templates, a Makefile target, a pre-commit hook, and a GitHub Actions workflow. Existing code validation logic is improved with a custom execution context for function definitions. Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer
participant PreCommit as Pre-commit Hook
participant TestRunner as Test Suite
participant Validation as Template Validation Utils
participant API as Langflow API
Dev->>PreCommit: Commit JSON template
PreCommit->>Validation: validate_template_structure
PreCommit->>Validation: validate_flow_can_build
PreCommit->>Validation: validate_template_comprehensive_async
PreCommit->>API: (async) validate_flow_endpoint
PreCommit->>API: (async) validate_flow_execution
PreCommit-->>Dev: Report errors if any
Dev->>GitHub: Push/PR triggers workflow
GitHub->>TestRunner: Run template tests
TestRunner->>Validation: Run structure/build/endpoint/execution validations
TestRunner->>API: (async) validate via API endpoints
TestRunner-->>GitHub: Report test results
Suggested labels
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
src/backend/tests/unit/template/test_starter_projects.py (1)
26-29: Consider making the starter projects path configurable.The hardcoded path could break if the directory structure changes. Consider using environment variables or configuration files for better maintainability.
+import os + def get_starter_projects_path() -> Path: """Get path to starter projects directory.""" - return Path("src/backend/base/langflow/initial_setup/starter_projects") + base_path = os.environ.get( + "LANGFLOW_STARTER_PROJECTS_PATH", + "src/backend/base/langflow/initial_setup/starter_projects" + ) + return Path(base_path)src/backend/base/langflow/utils/template_validation.py (3)
15-49: Consider adding edge validation for completeness.The function thoroughly validates nodes but doesn't validate edge structure. Edges should have source and target fields.
Add edge validation after line 40:
# Check edges have required fields for i, edge in enumerate(data.get("edges", [])): if "source" not in edge: errors.append(f"{filename}: Edge {i} missing 'source'") if "target" not in edge: errors.append(f"{filename}: Edge {i} missing 'target'")
108-168: Well-implemented endpoint validation with thorough error checking!The function properly validates code snippets via API with comprehensive error extraction. Consider using constants for HTTP status codes instead of magic numbers.
227-293: Consider making the event stream timeout configurable.The hardcoded 10-second timeout might be insufficient for complex flows. Consider making it configurable.
-async def _validate_event_stream(response, job_id: str, filename: str, errors: list[str]) -> None: +async def _validate_event_stream( + response, job_id: str, filename: str, errors: list[str], timeout: float = 10.0 +) -> None: """Validate the event stream from flow execution. Args: response: The response object with event stream job_id: The job ID to verify in events filename: Name of the template file for error reporting errors: List to append errors to + timeout: Maximum time to wait for event stream completion """And update the call in
validate_flow_execution:- await _validate_event_stream(events_response, job_id, filename, errors) + await _validate_event_stream(events_response, job_id, filename, errors, timeout=30.0)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
.github/workflows/template-tests.yml(1 hunks).pre-commit-config.yaml(1 hunks)Makefile(1 hunks)src/backend/base/langflow/utils/template_validation.py(1 hunks)src/backend/base/langflow/utils/validate.py(2 hunks)src/backend/tests/unit/template/__init__.py(1 hunks)src/backend/tests/unit/template/test_starter_projects.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/backend/**/*.py
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- .cursor/rules/backend_development.mdc
src/backend/tests/unit/**/*.py
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- .cursor/rules/backend_development.mdc
src/backend/tests/**/*.py
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- .cursor/rules/testing.mdc
{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py}
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- .cursor/rules/testing.mdc
{src/backend/tests/**/*.py,tests/**/*.py}
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- .cursor/rules/testing.mdc
Makefile
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- .cursor/rules/backend_development.mdc
🧠 Learnings (8)
📓 Common learnings
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: ogabrielluiz
PR: langflow-ai/langflow#0
File: :0-0
Timestamp: 2025-06-26T19:43:18.260Z
Learning: In langflow custom components, the `module_name` parameter is now propagated through template building functions to add module metadata and code hashes to frontend nodes for better component tracking and debugging.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Starter project files are auto-formatted after langflow run; these changes can be committed or ignored
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Validate input/output behavior in tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
src/backend/tests/unit/template/__init__.py (14)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to src/backend/tests/**/*.py : Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Create comprehensive unit tests for all new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Expected behaviors should be explicitly stated in test docstrings or comments.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Complex test setups should be commented, and mock usage should be documented within the test code.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/base/langflow/components/**/*.py : Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use 'MockLanguageModel' for testing language model components without external API calls.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
Learnt from: ogabrielluiz
PR: langflow-ai/langflow#0
File: :0-0
Timestamp: 2025-06-26T19:43:18.260Z
Learning: In langflow custom components, the `module_name` parameter is now propagated through template building functions to add module metadata and code hashes to frontend nodes for better component tracking and debugging.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Makefile (11)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to Makefile : Use Makefile targets (make backend, make format_backend, make lint, make unit_tests) for backend development workflows
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.md,tests/**/*.md} : If unit tests are incomplete, create a Markdown file with manual testing steps in the same directory as the unit tests, using the same filename as the component but with a '.md' extension.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to tests/**/*.py : Run make unit_tests to execute backend unit tests
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Create comprehensive unit tests for all new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to src/backend/tests/**/*.py : Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/**/*.py : Run make format_backend to format Python code early and often
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/**/*.py : Run make lint to check for linting issues in backend Python code
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Complex test setups should be commented, and mock usage should be documented within the test code.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Test both sync and async code paths in components.
.github/workflows/template-tests.yml (4)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Starter project files are auto-formatted after langflow run; these changes can be committed or ignored
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
.pre-commit-config.yaml (7)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Starter project files are auto-formatted after langflow run; these changes can be committed or ignored
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Validate input/output behavior in tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/{package*.json,tsconfig.json,tailwind.config.*,vite.config.*} : Frontend configuration files such as 'package.json', 'tsconfig.json', 'tailwind.config.*', and 'vite.config.*' must be present and properly maintained in 'src/frontend/'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to src/frontend/**/*.@(test|spec).{ts,tsx,js,jsx} : Frontend test files should be named with '.test.' or '.spec.' before the extension (e.g., 'Component.test.tsx', 'Component.spec.js').
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/docs_development.mdc:0-0
Timestamp: 2025-06-30T14:40:02.682Z
Learning: Applies to docs/blog/**/*.{md,mdx} : Blog posts must use the provided frontmatter and template, including fields for title, description, authors, date, and tags.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/src/**/__tests__/**/*.test.{ts,tsx} : All frontend components must have associated tests using React Testing Library.
src/backend/base/langflow/utils/validate.py (1)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/base/langflow/components/**/*.py : Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
src/backend/tests/unit/template/test_starter_projects.py (11)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Create comprehensive unit tests for all new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to src/backend/tests/**/*.py : Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Validate input/output behavior in tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test real-time event streaming endpoints by consuming NDJSON event streams and validating event structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
src/backend/base/langflow/utils/template_validation.py (6)
Learnt from: ogabrielluiz
PR: langflow-ai/langflow#0
File: :0-0
Timestamp: 2025-06-26T19:43:18.260Z
Learning: In langflow custom components, the `module_name` parameter is now propagated through template building functions to add module metadata and code hashes to frontend nodes for better component tracking and debugging.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/base/langflow/components/**/*.py : Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
🪛 actionlint (1.7.7)
.github/workflows/template-tests.yml
24-24: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: test-starter-projects
- GitHub Check: Optimize new Python code in this PR
- GitHub Check: test-starter-projects
🔇 Additional comments (15)
src/backend/tests/unit/template/__init__.py (1)
1-1: LGTM! Clean module initialization.The module docstring appropriately describes the purpose of the template testing package for Langflow.
Makefile (1)
164-171: Well-structured Makefile target for template testing.The new
template_teststarget follows established patterns in the Makefile:
- Consistent use of
uv run pytestcommand- Appropriate verbose flag for debugging
- Clear echo statement indicating the test execution
- Properly organized in its own section
This integrates well with the existing testing infrastructure.
.pre-commit-config.yaml (1)
36-42: Well-configured pre-commit hook for template validation.The new
validate-starter-projectshook is properly structured:
- Targets the correct file pattern for starter project JSON templates
- Uses consistent
uv run pythonexecution patternpass_filenames: falseis appropriate for directory-wide validation- The
--security-checkargument indicates additional security validation- Integrates well with the existing CI pipeline and Makefile target
This provides good local validation before commits.
.github/workflows/template-tests.yml (1)
1-39: Well-structured GitHub Actions workflow with efficient path-based triggering.The workflow is properly configured with:
- Appropriate trigger conditions targeting relevant file changes
- Logical job structure using Ubuntu latest
- Consistent dependency management with
uv- Clear step naming and organization
This effectively automates template validation in the CI pipeline.
src/backend/base/langflow/utils/validate.py (2)
52-62: Improved code validation with Langflow-specific execution context.The updated
validate_codefunction now uses a dedicated execution context that includes common Langflow imports, making the validation more realistic and accurate for template code that relies on Langflow-specific types and utilities.
68-133: Well-implemented execution context creation function.The
_create_langflow_execution_context()function is excellently designed:
- Comprehensive coverage of common Langflow types (DataFrame, Message, Data, Component)
- Robust error handling with fallback mocks for failed imports
- Includes essential typing constructs and pandas for broader compatibility
- Proper private function naming convention
- Clean, readable structure with consistent exception handling
This provides a realistic execution environment for validating template code.
src/backend/tests/unit/template/test_starter_projects.py (5)
1-24: Well-structured module with clear documentation!The module docstring clearly outlines the validation objectives, and imports are properly organized following Python conventions.
31-41: Good test coverage for template existence!The test properly validates directory existence and presence of template files with clear error messages.
42-53: Excellent JSON validation with proper error handling!The test correctly validates JSON syntax with appropriate encoding specification and descriptive error messages.
54-87: Excellent error aggregation pattern for comprehensive validation!Both test methods effectively collect all errors before reporting, which helps developers identify and fix multiple issues in a single test run.
88-123: Well-implemented async tests following best practices!The async tests properly use the
@pytest.mark.asynciodecorator and follow the coding guidelines for API testing with the client fixture. The error aggregation pattern is consistently applied.src/backend/base/langflow/utils/template_validation.py (4)
1-13: Clean module setup with appropriate imports!The module docstring clearly states its purpose and imports are minimal and well-organized.
51-85: Robust flow building validation with comprehensive error handling!The function properly validates flow buildability with appropriate exception handling and clear error reporting.
170-225: Excellent async flow execution validation with proper cleanup!The function demonstrates good resource management with the try/finally block ensuring flow cleanup. The event stream validation is properly delegated to a helper function.
295-326: Comprehensive async validation aggregator following established patterns!The function effectively combines all validation types with an optional execution flag, maintaining consistency with the synchronous version.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Added 6 additional test cases to improve coverage of template_validation.py: - test_validate_stream_exception: Tests Graph.validate_stream() exception handling - test_code_validation_other_exceptions: Tests TypeError/KeyError/AttributeError handling - test_vertices_sorted_without_end_vertex_events: Tests variable usage tracking - test_vertex_count_tracking: Tests vertex_count increment paths - test_empty_lines_in_stream: Tests empty line handling in event streams - test_event_stream_validation_exception: Tests exception handling in _validate_event_stream These tests target the remaining 7 uncovered lines to maximize coverage percentage. Total tests: 40 (all passing) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|




This pull request introduces comprehensive testing and validation for starter project templates in the Langflow codebase. The changes include new workflows, validation utilities, and test cases to ensure the integrity and functionality of templates. Additionally, the
validate_codefunction has been enhanced to include a custom execution context for Langflow-specific imports.CI Workflow Enhancements:
test-templatesjob to the CI workflow to test starter project templates. This job validates templates for proper structure, security, and functionality using pytest. [1] [2]template-tests.ymlworkflow triggered by changes to relevant files or via manual dispatch.Validation Utilities:
src/backend/base/langflow/utils/template_validation.pyto provide functions for validating template structure, flow building, code correctness, and execution.validate_codefunction to use a custom execution context with Langflow-specific imports, improving its ability to evaluate template-related code. [1] [2]Testing Improvements:
src/backend/tests/unit/template/test_starter_projects.pyto perform comprehensive tests on all starter project templates, including JSON validity, structure, flow building, and execution.Makefilewith a newtemplate_teststarget to run all template tests.Pre-commit Hook:
Langflowproject. It includes automated workflows, pre-commit hooks, Makefile commands, and unit tests to ensure templates are valid, have the required structure, and are free from basic security issues.Workflow and Automation Enhancements:
.github/workflows/template-tests.yml: Added a new GitHub Actions workflow to automatically test starter project templates on code pushes and pull requests. It sets up Python 3.12, installs dependencies, and runspyteston the template test file.Pre-commit Hook Updates:
.pre-commit-config.yaml: Added a new pre-commit hook (validate-starter-projects) to validate JSON templates in thestarter_projectsdirectory for correctness and security.Makefile Integration:
Makefile: Added atemplate_teststarget to run all starter project template tests usingpytest.Unit Test Implementation:
src/backend/tests/unit/template/test_starter_projects.py: Created a new test suite to validate starter project templates. It checks for valid JSON, required structure (nodes and edges), and basic security issues.Documentation:
src/backend/tests/unit/template/__init__.py: Added a module-level docstring describing the purpose of the template testing module.Summary by CodeRabbit
New Features
Tests