Skip to content

feat: Add template tests#9083

Merged
Yukiyukiyeah merged 31 commits into
mainfrom
add-template-test
Jul 28, 2025
Merged

feat: Add template tests#9083
Yukiyukiyeah merged 31 commits into
mainfrom
add-template-test

Conversation

@Yukiyukiyeah
Copy link
Copy Markdown
Contributor

@Yukiyukiyeah Yukiyukiyeah commented Jul 17, 2025

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_code function has been enhanced to include a custom execution context for Langflow-specific imports.

CI Workflow Enhancements:

  • Added a new test-templates job to the CI workflow to test starter project templates. This job validates templates for proper structure, security, and functionality using pytest. [1] [2]
  • Introduced a standalone template-tests.yml workflow triggered by changes to relevant files or via manual dispatch.

Validation Utilities:

  • Created src/backend/base/langflow/utils/template_validation.py to provide functions for validating template structure, flow building, code correctness, and execution.
  • Enhanced the validate_code function to use a custom execution context with Langflow-specific imports, improving its ability to evaluate template-related code. [1] [2]

Testing Improvements:

  • Added src/backend/tests/unit/template/test_starter_projects.py to perform comprehensive tests on all starter project templates, including JSON validity, structure, flow building, and execution.
  • Updated the Makefile with a new template_tests target to run all template tests.

Pre-commit Hook:

  • Introduced a new pre-commit hook to validate starter project templates for structural and security issues.This pull request introduces a comprehensive testing framework for validating starter project templates in the Langflow project. 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 runs pytest on 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 the starter_projects directory for correctness and security.

Makefile Integration:

  • Makefile: Added a template_tests target to run all starter project template tests using pytest.

Unit Test Implementation:

Documentation:

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive validation utilities and tests for starter project templates, ensuring structural integrity, buildability, and runtime execution.
    • Added asynchronous validation against a remote API endpoint for enhanced template checking.
    • Integrated a new Makefile target and pre-commit hook for automated template validation.
    • Set up a dedicated GitHub Actions workflow to run template tests on relevant changes.
  • Tests

    • Added extensive automated tests to verify the correctness and security of starter project templates.

@Yukiyukiyeah Yukiyukiyeah self-assigned this Jul 17, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 17, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This 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

File(s) Change Summary
.github/workflows/template-tests.yml Added a GitHub Actions workflow to run template tests on relevant changes.
.pre-commit-config.yaml Added a pre-commit hook to validate starter project templates on JSON file changes.
Makefile Added template_tests target to run starter project template tests.
src/backend/base/langflow/utils/template_validation.py New module providing layered validation utilities for starter project templates (structure, build, endpoint, execution).
src/backend/base/langflow/utils/validate.py Updated validate_code to use a custom execution context with Langflow and typing imports.
src/backend/tests/unit/template/init.py Added module docstring for the new template test module.
src/backend/tests/unit/template/test_starter_projects.py New test suite for validating, building, and executing starter project templates.

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
Loading

Suggested labels

lgtm

Suggested reviewers

  • erichare
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-template-test

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Yukiyukiyeah Yukiyukiyeah changed the title Add template tests feat: Add template tests Jul 18, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 18, 2025
@Yukiyukiyeah Yukiyukiyeah marked this pull request as ready for review July 18, 2025 01:30
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 18, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d9f3ced and bafdc9a.

📒 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_tests target follows established patterns in the Makefile:

  • Consistent use of uv run pytest command
  • 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-projects hook is properly structured:

  • Targets the correct file pattern for starter project JSON templates
  • Uses consistent uv run python execution pattern
  • pass_filenames: false is appropriate for directory-wide validation
  • The --security-check argument 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_code function 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.asyncio decorator 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.

Comment thread .github/workflows/template-tests.yml Outdated
Comment thread src/backend/base/langflow/utils/template_validation.py Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 18, 2025
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 18, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 18, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 18, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 23, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 23, 2025
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>
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 24, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 24, 2025
@SonicDMG SonicDMG temporarily deployed to add-template-test - langflow-manual-install PR #9083 July 28, 2025 15:58 — with Render Destroyed
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 28, 2025
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants