-
-
Notifications
You must be signed in to change notification settings - Fork 23.6k
Fix: Add regex comparison support to Condition Agentflow #5657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shazee257
wants to merge
8
commits into
FlowiseAI:main
Choose a base branch
from
shazee257:fix/regex-comparison-support-agentflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9753302
Initial plan
Copilot fa33826
fix: add regex support to condition node
Copilot 538b8c9
test: clarify condition regex assertions
Copilot b7dab95
fix: guard condition regex evaluation
Copilot a18a703
Update packages/components/nodes/agentflow/Condition/Condition.ts
shazee257 44e9425
Update packages/components/nodes/agentflow/Condition/Condition.ts
shazee257 6419c19
Update packages/components/nodes/agentflow/Condition/Condition.test.ts
shazee257 f040c4a
Update packages/components/nodes/agentflow/Condition/Condition.test.ts
shazee257 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
packages/components/nodes/agentflow/Condition/Condition.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { nodeClass as Condition_Agentflow } from './Condition' | ||
| import { INodeData, INode, ICondition } from '../../../src/Interface' | ||
|
|
||
| function createNodeData(inputs: any): INodeData { | ||
| return { | ||
| id: 'condition-node', | ||
| label: 'Condition', | ||
| name: 'conditionAgentflow', | ||
| type: 'Condition', | ||
| icon: 'condition.svg', | ||
| version: 1.0, | ||
| category: 'Agent Flows', | ||
| baseClasses: ['Condition'], | ||
| inputs | ||
| } | ||
| } | ||
|
|
||
| describe('Condition Agentflow', () => { | ||
| let nodeClass: any | ||
|
|
||
| beforeEach(() => { | ||
| nodeClass = new Condition_Agentflow() | ||
| }) | ||
|
|
||
| it('should match regex operation for string conditions', async () => { | ||
| const nodeData = createNodeData({ | ||
| conditions: [ | ||
| { | ||
| type: 'string', | ||
| value1: 'Hello123', | ||
| operation: 'regex', | ||
| value2: '^Hello\\d+$' | ||
| } | ||
| ] | ||
| }) | ||
|
|
||
| const result = await nodeClass.run(nodeData, '', { agentflowRuntime: { state: {} } }) | ||
| const matchedCondition = result.output.conditions.find( | ||
| (condition: any) => condition.operation === 'regex' && condition.value1 === 'Hello123' && condition.value2 === '^Hello\\d+$' | ||
| ) | ||
| const elseCondition = result.output.conditions.find( | ||
| (condition: any) => condition.operation === 'equal' && condition.value1 === '' && condition.value2 === '' | ||
| ) | ||
| expect(matchedCondition?.isFulfilled).toBe(true) | ||
| expect(elseCondition?.isFulfilled).toBe(false) | ||
| }) | ||
|
|
||
| it('should return false for invalid regex patterns', async () => { | ||
| const nodeData = createNodeData({ | ||
| conditions: [ | ||
| { | ||
| type: 'string', | ||
| value1: 'Hello123', | ||
| operation: 'regex', | ||
| value2: '[invalid' | ||
| } | ||
| ] | ||
| }) | ||
|
|
||
| const result = await nodeClass.run(nodeData, '', { agentflowRuntime: { state: {} } }) | ||
| const matchedCondition = result.output.conditions.find( | ||
| (condition: any) => condition.operation === 'regex' && condition.value1 === 'Hello123' && condition.value2 === '[invalid' | ||
| ) | ||
| const elseCondition = result.output.conditions.find( | ||
| (condition: any) => condition.operation === 'equal' && condition.value1 === '' && condition.value2 === '' | ||
| ) | ||
| expect(matchedCondition?.isFulfilled).toBe(false) | ||
| expect(elseCondition?.isFulfilled).toBe(true) | ||
| }) | ||
|
|
||
| it('should return false when regex exceeds safety limits', async () => { | ||
| const nodeData = createNodeData({ | ||
| conditions: [ | ||
| { | ||
| type: 'string', | ||
| value1: 'Hello123', | ||
| operation: 'regex', | ||
| value2: 'a'.repeat(300) | ||
| } | ||
| ] | ||
| }) | ||
|
|
||
| const result = await nodeClass.run(nodeData, '', { agentflowRuntime: { state: {} } }) | ||
| const matchedCondition = result.output.conditions.find( | ||
| (condition: any) => condition.operation === 'regex' && condition.value2 === 'a'.repeat(300) | ||
| ) | ||
| const elseCondition = result.output.conditions.find( | ||
| (condition: any) => condition.operation === 'equal' && condition.value1 === '' && condition.value2 === '' | ||
| ) | ||
| expect(matchedCondition?.isFulfilled).toBeFalsy() | ||
| expect(elseCondition?.isFulfilled).toBe(true) | ||
| }) | ||
| }) | ||
shazee257 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.