Skip to content

add test - #1168

Merged
isamu merged 3 commits into
receptron:mainfrom
isamu:test_graph_if_flow
Jul 10, 2025
Merged

isamu merged 3 commits into
receptron:mainfrom
isamu:test_graph_if_flow

Conversation

@isamu

@isamu isamu commented Jul 9, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Tests
    • Added a new unit test to verify conditional flow logic within the GraphAI framework.
  • New Features
    • Introduced verbose logging to provide detailed status of graph nodes upon execution completion.

@isamu
isamu requested a review from snakajima July 9, 2025 06:07
@coderabbitai

coderabbitai Bot commented Jul 9, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A new unit test file was added to evaluate conditional flow logic in the GraphAI framework. The test defines a graph with nodes that execute based on conditional expressions, instantiates GraphAI with this graph and agents, runs it asynchronously with a flag, and logs the result without assertions. Additionally, verbose logging was added to the GraphAI class to report non-running nodes and their states when execution completes.

Changes

File(s) Change Summary
packages/graphai/tests/units/test_graph_if_flow.ts Added a unit test for GraphAI, defining and running a graph with conditional node flows and logging output.
packages/graphai/src/graphai.ts Enhanced onExecutionComplete method to log IDs and states of non-running nodes when verbose mode is enabled.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant GraphAI
    participant Agents
    TestRunner->>GraphAI: Instantiate with graph and agents
    TestRunner->>GraphAI: Run graph asynchronously with flag
    GraphAI->>Agents: Invoke agents as per node logic
    GraphAI->>GraphAI: Evaluate conditional nodes (if expressions)
    GraphAI->>TestRunner: Return result (logged)
    GraphAI->>Console: If verbose, log non-running node IDs and states
Loading

Poem

In a warren of logic, the graph does flow,
With ifs and thens where data might go.
Nodes hop along, agents join in,
Testing new pathways for results to begin.
The rabbit logs all, with a twitch of delight—
Conditional magic, running just right!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/graphai/src/graphai.ts

Oops! Something went wrong! :(

ESLint: 9.30.1

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

packages/graphai/tests/units/test_graph_if_flow.ts

Oops! Something went wrong! :(

ESLint: 9.30.1

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@isamu
isamu marked this pull request as draft July 9, 2025 06:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
packages/graphai/tests/units/test_graph_if_flow.ts (1)

47-53: Clarify the merge node behavior with mixed conditional inputs

The merge node depends on both :flowA3.data and :flowB.data. Given the current setup:

  • :flowA3.data will be {} (defaultValue)
  • :flowB.data will be "Hello World"

The commented anyInput: true suggests this might be intentional, but it's unclear if this is the expected test scenario.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b487329 and 835b422.

📒 Files selected for processing (1)
  • packages/graphai/tests/units/test_graph_if_flow.ts (1 hunks)
⏰ 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). (2)
  • GitHub Check: build (24.x)
  • GitHub Check: build (22.x)
🔇 Additional comments (1)
packages/graphai/tests/units/test_graph_if_flow.ts (1)

1-7: LGTM: Imports are correctly structured

The imports are properly organized with framework imports, test utilities, and Node.js test modules.

Comment on lines +12 to +17
message: {
value: {
// valueA: "Hello World",
valueB: "Hello World",
},
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the conditional flow logic by uncommenting or removing valueA

The message node has valueA commented out, which will cause the dependent flowA → flowA2 → flowA3 chain to never execute since flowA depends on :message.valueA. This breaks the conditional flow test logic.

Either uncomment valueA to test the full conditional flow:

       value: {
-        // valueA: "Hello World",
+        valueA: "Hello World",
         valueB: "Hello World",
       },

Or remove the unused flowA chain if testing only the flowB path is intended.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
message: {
value: {
// valueA: "Hello World",
valueB: "Hello World",
},
},
message: {
value: {
valueA: "Hello World",
valueB: "Hello World",
},
},
🤖 Prompt for AI Agents
In packages/graphai/tests/units/test_graph_if_flow.ts around lines 12 to 17, the
property valueA in the message node is commented out, which prevents the flowA →
flowA2 → flowA3 chain from executing because flowA depends on message.valueA. To
fix this, either uncomment valueA to enable testing of the full conditional flow
or remove the flowA chain entirely if only the flowB path should be tested.

Comment on lines +57 to +62
test("test graph", async () => {
const graph = new GraphAI(graph_data, agents);
const result = await graph.run(true);
console.log(result);
// assert.deepStrictEqual(result, {});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Complete the test by adding assertions

The test is incomplete - it runs the graph and logs results but doesn't assert any expected behavior. This makes it impossible to verify if the conditional flow logic works correctly.

Add assertions to verify the expected behavior:

 test("test graph", async () => {
   const graph = new GraphAI(graph_data, agents);
   const result = await graph.run(true);
   console.log(result);
-  // assert.deepStrictEqual(result, {});
+  
+  // Verify the conditional flow results
+  assert.deepStrictEqual(result, {
+    message: { valueB: "Hello World" },
+    flowA3: {}, // defaultValue since flowA chain doesn't execute
+    flowB: { data: "Hello World" },
+    merge: { data: [{}, "Hello World"] }
+  });
 });

Do you want me to help generate more comprehensive test assertions based on the expected conditional flow behavior?

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test("test graph", async () => {
const graph = new GraphAI(graph_data, agents);
const result = await graph.run(true);
console.log(result);
// assert.deepStrictEqual(result, {});
});
test("test graph", async () => {
const graph = new GraphAI(graph_data, agents);
const result = await graph.run(true);
console.log(result);
// Verify the conditional flow results
assert.deepStrictEqual(result, {
message: { valueB: "Hello World" },
flowA3: {}, // defaultValue since flowA chain doesn't execute
flowB: { data: "Hello World" },
merge: { data: [{}, "Hello World"] }
});
});
🤖 Prompt for AI Agents
In packages/graphai/tests/units/test_graph_if_flow.ts around lines 57 to 62, the
test runs the graph and logs the result but lacks assertions to verify expected
behavior. To fix this, replace or supplement the console.log with assert
statements that check the output matches the expected conditional flow results.
Use assert.deepStrictEqual or similar to compare the actual result with the
expected output object that reflects correct conditional logic execution.

Comment on lines +18 to +39
flowA: {
if: ":message.valueA",
agent: "copyAgent",
inputs: {
data: ":message.valueA",
},
},
flowA2: {
if: ":flowA.data",
agent: "copyAgent",
inputs: {
data: ":flowA.data",
},
},
flowA3: {
if: ":flowA2.data",
agent: "copyAgent",
inputs: {
data: ":flowA2.data",
},
defaultValue: {},
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider the impact of the broken conditional chain

The flowA → flowA2 → flowA3 conditional chain will never execute because flowA depends on the commented-out :message.valueA. This means:

  • flowA won't execute (no valueA in message)
  • flowA2 won't execute (depends on flowA.data)
  • flowA3 will use its defaultValue: {} since it won't receive data from flowA2

This may not be the intended test behavior for conditional flow logic.


🏁 Script executed:

#!/bin/bash
set -e
# Locate and print the beginning of the test file to verify the message fixture
FILE=$(find . -type f -name test_graph_if_flow.ts)
sed -n '1,300p' "$FILE"

Length of output: 1528


Fix the broken conditional chain in the test fixture

The test’s graph_data omits message.valueA (it’s commented out), so:

  • flowA.if never passes
  • flowA2 never runs
  • flowA3 always falls back to its defaultValue
  • The merge step only receives flowA3.data (an empty object) and flowB.data

To restore the intended flow logic, either:

  • Uncomment or supply valueA in the message node:
      message: {
        value: {
          valueA: "Hello World",
          valueB: "Hello World",
        },
      },
  • Or remove/adjust the flowA* nodes if they’re not needed, and update the assertion to match the expected output.

Additionally, add a proper assert.deepStrictEqual(result, expected) at the end of the test to verify both branches.

🤖 Prompt for AI Agents
In packages/graphai/tests/units/test_graph_if_flow.ts around lines 18 to 39, the
test fixture's conditional chain is broken because message.valueA is missing,
causing flowA.if to fail and subsequent flows not to run. Fix this by
uncommenting or adding valueA in the message node with appropriate test data, or
alternatively remove or adjust the flowA* nodes if they are unnecessary and
update the test assertions accordingly. Also, add a proper
assert.deepStrictEqual call at the end of the test to verify the result matches
the expected output for both branches.

@isamu
isamu marked this pull request as ready for review July 10, 2025 04:07
if (this.verbose) {
const notExecutedNodes = Object.values(this.nodes).filter((node) => node.isComputedNode && node.state !== "completed");
if (notExecutedNodes.length > 0) {
console.log("Those nodes are not running. " + notExecutedNodes.map((node) => `${node.nodeId}: ${node.state}`).join(", "));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Those nodes are not running. flowA: skipped, flowA2: waiting, flowA3: waiting, merge: waiting

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 835b422 and 722a98d.

📒 Files selected for processing (2)
  • packages/graphai/src/graphai.ts (1 hunks)
  • packages/graphai/tests/units/test_graph_if_flow.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/graphai/tests/units/test_graph_if_flow.ts
⏰ 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). (2)
  • GitHub Check: build (22.x)
  • GitHub Check: build (24.x)

Comment on lines +328 to +333
if (this.verbose) {
const notExecutedNodes = Object.values(this.nodes).filter((node) => node.isComputedNode && node.state !== "completed");
if (notExecutedNodes.length > 0) {
console.log("Those nodes are not running. " + notExecutedNodes.map((node) => `${node.nodeId}: ${node.state}`).join(", "));
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use consistent logging approach and improve message clarity.

The verbose logging implementation has a couple of issues:

  1. Inconsistent logging: The code uses console.log directly, but the class already imports and uses GraphAILogger for other logging purposes (e.g., lines 142, 146, 278).

  2. Confusing message: The message "Those nodes are not running" is misleading since the filter checks for nodes that are not in "completed" state, which could include nodes in other states like "waiting", "ready", or "executing".

Apply this diff to improve consistency and clarity:

    if (this.verbose) {
      const notExecutedNodes = Object.values(this.nodes).filter((node) => node.isComputedNode && node.state !== "completed");
      if (notExecutedNodes.length > 0) {
-        console.log("Those nodes are not running. " + notExecutedNodes.map((node) => `${node.nodeId}: ${node.state}`).join(", "));
+        GraphAILogger.debug("Nodes not completed: " + notExecutedNodes.map((node) => `${node.nodeId}: ${node.state}`).join(", "));
      }
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (this.verbose) {
const notExecutedNodes = Object.values(this.nodes).filter((node) => node.isComputedNode && node.state !== "completed");
if (notExecutedNodes.length > 0) {
console.log("Those nodes are not running. " + notExecutedNodes.map((node) => `${node.nodeId}: ${node.state}`).join(", "));
}
}
if (this.verbose) {
const notExecutedNodes = Object.values(this.nodes).filter((node) => node.isComputedNode && node.state !== "completed");
if (notExecutedNodes.length > 0) {
GraphAILogger.debug("Nodes not completed: " + notExecutedNodes.map((node) => `${node.nodeId}: ${node.state}`).join(", "));
}
}
🤖 Prompt for AI Agents
In packages/graphai/src/graphai.ts around lines 328 to 333, replace the direct
use of console.log with the existing GraphAILogger instance to maintain
consistent logging. Also, update the log message to clearly reflect that the
nodes listed are not completed, rather than saying they are "not running," to
avoid confusion about their actual states.

@isamu
isamu merged commit 32e21a0 into receptron:main Jul 10, 2025
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.

2 participants