|
2 | 2 | * @vitest-environment node |
3 | 3 | */ |
4 | 4 | import { describe, expect, it } from 'vitest' |
| 5 | +import { |
| 6 | + buildCanonicalIndex, |
| 7 | + getCanonicalSubBlocksForSurface, |
| 8 | + resolveDependencyValue, |
| 9 | + scopeCanonicalModesForTool, |
| 10 | +} from '@/lib/workflows/subblocks/visibility' |
5 | 11 | import type { StoredTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/types' |
6 | 12 | import { |
7 | 13 | isCustomToolAlreadySelected, |
8 | 14 | isMcpToolAlreadySelected, |
9 | 15 | isWorkflowAlreadySelected, |
10 | 16 | } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/utils' |
| 17 | +import { getDependencyCanonicalModeOverrides } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-dependency-block-type' |
| 18 | +import { TableBlock } from '@/blocks/blocks/table' |
| 19 | + |
| 20 | +describe('nested tool dependency modes', () => { |
| 21 | + const tableCanonicalIndex = buildCanonicalIndex( |
| 22 | + getCanonicalSubBlocksForSurface(TableBlock.subBlocks, false) |
| 23 | + ) |
| 24 | + |
| 25 | + it.each([ |
| 26 | + [0, 'advanced', 'dormant-basic', '', ''], |
| 27 | + [1, 'basic', '', 'dormant-advanced', ''], |
| 28 | + ] as const)( |
| 29 | + 'honors the explicit mode for same-type tool instance %s', |
| 30 | + (toolIndex, mode, basicValue, advancedValue, expected) => { |
| 31 | + const hostOverrides = { |
| 32 | + '0:tableId': 'advanced' as const, |
| 33 | + '1:tableId': 'basic' as const, |
| 34 | + } |
| 35 | + const scopedOverrides = scopeCanonicalModesForTool(hostOverrides, toolIndex, 'table') |
| 36 | + const dependencyOverrides = getDependencyCanonicalModeOverrides( |
| 37 | + { blockType: 'table', canonicalModeOverrides: scopedOverrides }, |
| 38 | + hostOverrides |
| 39 | + ) |
| 40 | + |
| 41 | + expect(dependencyOverrides?.tableId).toBe(mode) |
| 42 | + expect( |
| 43 | + resolveDependencyValue( |
| 44 | + 'tableId', |
| 45 | + { tableSelector: basicValue, manualTableId: advancedValue }, |
| 46 | + tableCanonicalIndex, |
| 47 | + dependencyOverrides |
| 48 | + ) |
| 49 | + ).toBe(expected) |
| 50 | + } |
| 51 | + ) |
| 52 | + |
| 53 | + it('preserves legacy type-scoped modes and missing-mode inference', () => { |
| 54 | + const values = { tableSelector: 'legacy-basic', manualTableId: '' } |
| 55 | + const legacyScoped = scopeCanonicalModesForTool({ 'table:tableId': 'advanced' }, 3, 'table') |
| 56 | + |
| 57 | + expect( |
| 58 | + resolveDependencyValue( |
| 59 | + 'tableId', |
| 60 | + values, |
| 61 | + tableCanonicalIndex, |
| 62 | + getDependencyCanonicalModeOverrides( |
| 63 | + { blockType: 'table', canonicalModeOverrides: legacyScoped }, |
| 64 | + undefined |
| 65 | + ) |
| 66 | + ) |
| 67 | + ).toBe('') |
| 68 | + expect( |
| 69 | + resolveDependencyValue( |
| 70 | + 'tableId', |
| 71 | + values, |
| 72 | + tableCanonicalIndex, |
| 73 | + getDependencyCanonicalModeOverrides( |
| 74 | + { blockType: 'table', canonicalModeOverrides: undefined }, |
| 75 | + { '0:tableId': 'advanced' } |
| 76 | + ) |
| 77 | + ) |
| 78 | + ).toBe('legacy-basic') |
| 79 | + }) |
| 80 | +}) |
11 | 81 |
|
12 | 82 | describe('isMcpToolAlreadySelected', () => { |
13 | 83 | describe('basic functionality', () => { |
|
0 commit comments