Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions apps/sim/lib/workflows/sanitization/json-sanitizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,58 @@ describe('sanitizeForCopilot product-gated block inputs', () => {
})
})

describe('sanitizeForCopilot subflow config', () => {
/**
* The model's read view has to use the same field names as the write contract it is
* given, or an echoed-back edit is silently dropped. `components/blocks/parallel.json`
* declares `count`; `components/blocks/loop.json` declares `iterations`.
*/
it("names a count-parallel's branch count `count`, matching the parallel write contract", () => {
const state = makeSingleBlockWorkflow('parallel-1', {
type: 'parallel',
name: 'Parallel 1',
enabled: true,
subBlocks: {},
data: { parallelType: 'count', count: 5 },
})

expect(sanitizeForCopilot(state).blocks['parallel-1'].inputs).toEqual({
parallelType: 'count',
count: 5,
})
})

it("names a for-loop's trip count `iterations`, matching the loop write contract", () => {
const state = makeSingleBlockWorkflow('loop-1', {
type: 'loop',
name: 'Loop 1',
enabled: true,
subBlocks: {},
data: { loopType: 'for', count: 3 },
})

expect(sanitizeForCopilot(state).blocks['loop-1'].inputs).toEqual({
loopType: 'for',
iterations: 3,
})
})

it('exports a collection parallel without a branch count', () => {
const state = makeSingleBlockWorkflow('parallel-2', {
type: 'parallel',
name: 'Parallel 2',
enabled: true,
subBlocks: {},
data: { parallelType: 'collection', collection: '<start.items>' },
})

expect(sanitizeForCopilot(state).blocks['parallel-2'].inputs).toEqual({
parallelType: 'collection',
collection: '<start.items>',
})
})
})

/** Builds a one-block workflow for webhook-URL synthesis tests. */
function makeSingleBlockWorkflow(blockId: string, block: Record<string, unknown>): WorkflowState {
return {
Expand Down
6 changes: 5 additions & 1 deletion apps/sim/lib/workflows/sanitization/json-sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,11 @@ export function sanitizeForCopilot(
loopInputs.parallelType = parallelType
// Only export fields relevant to the current parallelType
if (parallelType === 'count' && block.data?.count !== undefined) {
loopInputs.iterations = block.data.count
// `count`, not `iterations`: the parallel schema the model is given names this
// field `count` and the edit path reads it back under that name. A loop's
// equivalent field really is called `iterations` on both sides — copying that
// line here made the model's read view disagree with its own write contract.
loopInputs.count = block.data.count
}
if (parallelType === 'collection' && block.data?.collection !== undefined) {
loopInputs.collection = block.data.collection
Expand Down
Loading