Skip to content

Conversation

@jocelynlin-wd
Copy link
Contributor

Add Jest test suite with coverage enforcement for @flowise/agentflow. Includes 119 tests across core logic, API layer, search, and state management. Fixes trailing-slash bug in getNodeIconUrl and extracts reducer to its own module for cleaner separation.

Add Jest test suite with coverage enforcement for @flowise/agentflow.
Includes 119 tests across core logic, API layer, search, and state
management. Fixes trailing-slash bug in getNodeIconUrl and extracts
reducer to its own module for cleaner separation.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jocelynlin-wd, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the @flowise/agentflow package by introducing a robust testing framework. The primary goal is to ensure the reliability and stability of the agentflow canvas by adding extensive unit tests for its core functionalities, API interactions, and state management. This foundational work will enable more confident development and refactoring in the future, while also improving code quality through coverage enforcement and clearer module separation.

Highlights

  • Test Infrastructure Added: A comprehensive Jest test suite has been integrated into the @flowise/agentflow package, including configuration for unit and component tests.
  • Extensive Unit Test Coverage: 119 new unit tests have been added, covering critical areas such as core logic, API interactions, node search functionality, and state management.
  • Coverage Enforcement Implemented: Jest is configured to enforce an 80% code coverage threshold for branches, functions, lines, and statements in core and API modules, with a new test:coverage script.
  • Reducer Logic Refactored: The agentflowReducer and related node normalization logic have been extracted into a dedicated module for improved separation of concerns and maintainability.
  • API Bug Fix: A trailing-slash bug in the getNodeIconUrl utility within the API client has been resolved, ensuring correct URL construction regardless of the provided instance URL.
  • Documentation Updated: A new TESTS.md file has been added, detailing the test plan, coverage tiers, and configuration, and the main README.md has been updated to link to it.
Changelog
  • package.json
    • Added test:coverage script to the root package.json.
  • packages/agentflow/.eslintignore
    • Added coverage directory to the ESLint ignore list.
  • packages/agentflow/.prettierignore
    • Added coverage directory to the Prettier ignore list.
  • packages/agentflow/README.md
    • Updated documentation to include instructions for running tests.
    • Added a link to the new TESTS.md file in the documentation section.
  • packages/agentflow/TESTS.md
    • Added a new file outlining the test plan, coverage tiers, and Jest configuration for the @flowise/agentflow package.
  • packages/agentflow/jest.config.js
    • Added a new file to configure Jest, defining two projects for unit and component tests, coverage thresholds, and module mapping.
  • packages/agentflow/package.json
    • Added test, test:watch, and test:coverage scripts for Jest.
    • Included new development dependencies for testing, such as @testing-library/jest-dom, @testing-library/react, @testing-library/user-event, @types/jest, jest, jest-environment-jsdom, and ts-jest.
  • packages/agentflow/src/mocks/styleMock.js
    • Added a new mock file for handling CSS/SASS imports in Jest tests.
  • packages/agentflow/src/atoms/ConfirmDialog.tsx
    • Added a TODO comment regarding integration with destructive actions.
  • packages/agentflow/src/atoms/Input.tsx
    • Added a TODO comment regarding the necessity of the component.
  • packages/agentflow/src/core/node-catalog/nodeFilters.test.ts
    • Added unit tests for filterNodesByComponents, isAgentflowNode, and groupNodesByCategory functions.
  • packages/agentflow/src/core/node-config/nodeIconUtils.test.ts
    • Added unit tests for getAgentflowIcon and getNodeColor utilities.
  • packages/agentflow/src/core/utils/connectionValidation.test.ts
    • Added unit tests for isValidConnectionAgentflowV2, covering self-connections, valid connections, and cycle detection.
  • packages/agentflow/src/core/utils/flowExport.test.ts
    • Added unit tests for generateExportFlowData, verifying deselection of nodes/edges and stripping of credential data.
  • packages/agentflow/src/core/utils/flowExport.ts
    • Added a TODO comment regarding integration with save/export flow.
  • packages/agentflow/src/core/utils/nodeFactory.test.ts
    • Added unit tests for getUniqueNodeId, getUniqueNodeLabel, initializeDefaultNodeData, and initNode functions.
  • packages/agentflow/src/core/utils/nodeFactory.ts
    • Added TODO comments for integrating unique node label and default input value initialization.
  • packages/agentflow/src/core/validation/flowValidation.test.ts
    • Added unit tests for validateFlow and validateNode, covering empty flows, start node validation, disconnections, cycles, and required inputs.
  • packages/agentflow/src/core/validation/flowValidation.ts
    • Added a TODO comment regarding integration with per-node inline validation.
  • packages/agentflow/src/features/node-editor/EditNodeDialog.tsx
    • Added a TODO comment regarding integration with canvas node interaction.
  • packages/agentflow/src/features/node-palette/search.test.ts
    • Added unit tests for fuzzyScore, searchNodes, and debounce utilities.
  • packages/agentflow/src/infrastructure/api/chatflows.test.ts
    • Added unit tests for the createChatflowsApi client, covering CRUD operations, flow data serialization, and agentflow generation.
  • packages/agentflow/src/infrastructure/api/client.test.ts
    • Added unit tests for createApiClient, verifying base URL, headers, and interceptor behavior, including 401 error handling.
  • packages/agentflow/src/infrastructure/api/hooks/useApi.ts
    • Added a TODO comment regarding the necessity of the useApi hook.
  • packages/agentflow/src/infrastructure/api/nodes.test.ts
    • Added unit tests for the createNodesApi client, covering node retrieval and getNodeIconUrl functionality.
  • packages/agentflow/src/infrastructure/api/nodes.ts
    • Fixed getNodeIconUrl to correctly handle trailing slashes in the instance URL.
  • packages/agentflow/src/infrastructure/store/AgentflowContext.tsx
    • Refactored by importing agentflowReducer and initialState from a new dedicated module.
  • packages/agentflow/src/infrastructure/store/agentflowReducer.test.ts
    • Added unit tests for agentflowReducer and normalizeNodes, verifying state updates and node property normalization.
  • packages/agentflow/src/infrastructure/store/agentflowReducer.ts
    • Added a new file containing the agentflowReducer logic, initialState, and normalizeNodes utility.
  • turbo.json
    • Added test:coverage to the Turbo repository pipeline configuration.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/main.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that significantly improves the test coverage and infrastructure for the agentflow package. The addition of Jest with coverage enforcement, the detailed test plan in TESTS.md, and the comprehensive unit tests for core logic are all fantastic contributions. The bug fix for getNodeIconUrl and the refactoring of the reducer into its own module are also great improvements for code quality and maintainability. The suggestion regarding centralizing test helpers to reduce duplication remains valid, and overall, this is a very high-quality submission.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant