|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { BlockType } from '@/executor/consts' |
| 3 | +import { Routing } from '@/executor/routing/routing' |
| 4 | + |
| 5 | +describe('Parallel Activation Integration - shouldSkipConnection behavior', () => { |
| 6 | + describe('Regular blocks can activate parallel/loop blocks', () => { |
| 7 | + it('should allow Agent → Parallel connections', () => { |
| 8 | + // This was the original bug - agent couldn't activate parallel |
| 9 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 10 | + expect(Routing.shouldSkipConnection('source', BlockType.PARALLEL)).toBe(false) |
| 11 | + }) |
| 12 | + |
| 13 | + it('should allow Function → Parallel connections', () => { |
| 14 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 15 | + expect(Routing.shouldSkipConnection('source', BlockType.PARALLEL)).toBe(false) |
| 16 | + }) |
| 17 | + |
| 18 | + it('should allow API → Loop connections', () => { |
| 19 | + expect(Routing.shouldSkipConnection(undefined, BlockType.LOOP)).toBe(false) |
| 20 | + expect(Routing.shouldSkipConnection('source', BlockType.LOOP)).toBe(false) |
| 21 | + }) |
| 22 | + |
| 23 | + it('should allow all regular blocks to activate parallel/loop', () => { |
| 24 | + const regularBlocks = [ |
| 25 | + BlockType.FUNCTION, |
| 26 | + BlockType.AGENT, |
| 27 | + BlockType.API, |
| 28 | + BlockType.EVALUATOR, |
| 29 | + BlockType.RESPONSE, |
| 30 | + BlockType.WORKFLOW, |
| 31 | + ] |
| 32 | + |
| 33 | + regularBlocks.forEach((sourceBlockType) => { |
| 34 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 35 | + expect(Routing.shouldSkipConnection(undefined, BlockType.LOOP)).toBe(false) |
| 36 | + }) |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + describe('✅ Still works: Router and Condition blocks can activate parallel/loop', () => { |
| 41 | + it('should allow Router → Parallel connections', () => { |
| 42 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 43 | + }) |
| 44 | + |
| 45 | + it('should allow Condition → Parallel connections', () => { |
| 46 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + describe('✅ Still blocked: Internal flow control connections', () => { |
| 51 | + it('should block parallel-start-source connections during selective activation', () => { |
| 52 | + expect(Routing.shouldSkipConnection('parallel-start-source', BlockType.FUNCTION)).toBe(true) |
| 53 | + expect(Routing.shouldSkipConnection('parallel-start-source', BlockType.AGENT)).toBe(true) |
| 54 | + }) |
| 55 | + |
| 56 | + it('should block parallel-end-source connections during selective activation', () => { |
| 57 | + expect(Routing.shouldSkipConnection('parallel-end-source', BlockType.FUNCTION)).toBe(true) |
| 58 | + expect(Routing.shouldSkipConnection('parallel-end-source', BlockType.AGENT)).toBe(true) |
| 59 | + }) |
| 60 | + |
| 61 | + it('should block loop-start-source connections during selective activation', () => { |
| 62 | + expect(Routing.shouldSkipConnection('loop-start-source', BlockType.FUNCTION)).toBe(true) |
| 63 | + expect(Routing.shouldSkipConnection('loop-start-source', BlockType.AGENT)).toBe(true) |
| 64 | + }) |
| 65 | + |
| 66 | + it('should block loop-end-source connections during selective activation', () => { |
| 67 | + expect(Routing.shouldSkipConnection('loop-end-source', BlockType.FUNCTION)).toBe(true) |
| 68 | + expect(Routing.shouldSkipConnection('loop-end-source', BlockType.AGENT)).toBe(true) |
| 69 | + }) |
| 70 | + }) |
| 71 | + |
| 72 | + describe('✅ Still blocked: Condition-specific connections during selective activation', () => { |
| 73 | + it('should block condition-specific connections during selective activation', () => { |
| 74 | + expect(Routing.shouldSkipConnection('condition-test-if', BlockType.FUNCTION)).toBe(true) |
| 75 | + expect(Routing.shouldSkipConnection('condition-test-else', BlockType.AGENT)).toBe(true) |
| 76 | + expect(Routing.shouldSkipConnection('condition-some-id', BlockType.PARALLEL)).toBe(true) |
| 77 | + }) |
| 78 | + }) |
| 79 | + |
| 80 | + describe('✅ Still works: Regular connections', () => { |
| 81 | + it('should allow regular connections between regular blocks', () => { |
| 82 | + expect(Routing.shouldSkipConnection(undefined, BlockType.FUNCTION)).toBe(false) |
| 83 | + expect(Routing.shouldSkipConnection('source', BlockType.AGENT)).toBe(false) |
| 84 | + expect(Routing.shouldSkipConnection('output', BlockType.API)).toBe(false) |
| 85 | + }) |
| 86 | + |
| 87 | + it('should allow regular connections with any source handle (except blocked ones)', () => { |
| 88 | + expect(Routing.shouldSkipConnection('result', BlockType.FUNCTION)).toBe(false) |
| 89 | + expect(Routing.shouldSkipConnection('output', BlockType.AGENT)).toBe(false) |
| 90 | + expect(Routing.shouldSkipConnection('data', BlockType.PARALLEL)).toBe(false) |
| 91 | + }) |
| 92 | + }) |
| 93 | +}) |
| 94 | + |
| 95 | +describe('Real-world workflow scenarios', () => { |
| 96 | + describe('✅ Working: User workflows', () => { |
| 97 | + it('should support: Start → Agent → Parallel → Agent pattern', () => { |
| 98 | + // This is the user's exact workflow pattern that was broken |
| 99 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 100 | + }) |
| 101 | + |
| 102 | + it('should support: Start → Function → Loop → Function pattern', () => { |
| 103 | + expect(Routing.shouldSkipConnection(undefined, BlockType.LOOP)).toBe(false) |
| 104 | + }) |
| 105 | + |
| 106 | + it('should support: Start → API → Parallel → Multiple Agents pattern', () => { |
| 107 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 108 | + }) |
| 109 | + |
| 110 | + it('should support: Start → Evaluator → Parallel → Response pattern', () => { |
| 111 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 112 | + }) |
| 113 | + }) |
| 114 | + |
| 115 | + describe('✅ Working: Complex routing patterns', () => { |
| 116 | + it('should support: Start → Router → Parallel → Function (existing working pattern)', () => { |
| 117 | + // This already worked before the fix |
| 118 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 119 | + }) |
| 120 | + |
| 121 | + it('should support: Start → Condition → Parallel → Agent (existing working pattern)', () => { |
| 122 | + // This already worked before the fix |
| 123 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 124 | + }) |
| 125 | + |
| 126 | + it('should support: Start → Router → Function → Parallel → Agent (new working pattern)', () => { |
| 127 | + // Router selects function, function activates parallel |
| 128 | + expect(Routing.shouldSkipConnection(undefined, BlockType.PARALLEL)).toBe(false) |
| 129 | + }) |
| 130 | + }) |
| 131 | +}) |
0 commit comments