Skip to content

Commit fa9099f

Browse files
committed
test(workflow-code): prove a resumed run that pauses again names the run it resumed
Extend the runtime integration with a second human block, and tighten the cleanup-audited tests so each can fail.
1 parent d5ad786 commit fa9099f

8 files changed

Lines changed: 62 additions & 30 deletions

File tree

‎apps/sim/app/api/v2/workflows/[workflowId]/execute/route.test.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,6 @@ describe('POST /api/v2/workflows/[workflowId]/execute', () => {
359359
})
360360
})
361361

362-
it('reports no pause for a run that finished', async () => {
363-
const body = await (await callExecute({ input: {} })).json()
364-
365-
expect(body.data.paused).toBeNull()
366-
})
367-
368362
it('streams an immediate heartbeat and the same sync result when NDJSON is accepted', async () => {
369363
vi.useFakeTimers()
370364
try {

‎apps/sim/app/api/v2/workflows/[workflowId]/runs/[runId]/resume/route.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe('POST /api/v2/workflows/[workflowId]/runs/[runId]/resume', () => {
137137
expect(v2ResumeWorkflowContract.response.schema.parse(body)).toEqual(body)
138138
})
139139

140-
it('names the run a resume that paused again waits under, which is the run it resumed', async () => {
140+
it("presents the pause the resume reports, not the resume attempt's own run id", async () => {
141141
mocks.resume.mockResolvedValueOnce({
142142
kind: 'sync',
143143
success: true,

‎apps/sim/lib/workflows/application/apply-workflow-source.runtime.integration.ts‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* PostgreSQL, while workflow source is applied to the draft. The apply renames the paused block;
44
* the run then resumes from its execution snapshot. Source apply writes the draft only, so the
55
* snapshot and the deployed version must come through it byte-identical, and the renamed block
6-
* must keep its id so the pause point still names a block the draft holds.
6+
* must keep its id so the pause point still names a block the draft holds. The resumed run then
7+
* pauses at a second block under the run it resumed, which the resume names in `paused.runId`.
78
*/
89
import { mkdir, writeFile } from 'node:fs/promises'
910
import { dirname, resolve } from 'node:path'
@@ -50,6 +51,7 @@ const workspaceId = generateId()
5051
const workflowId = generateId()
5152
const startId = generateId()
5253
const approvalId = generateId()
54+
const signoffId = generateId()
5355
const owner = createSessionPrincipal({ userId: ownerId, sessionId: generateId() })
5456
const ownerKey = createPersonalApiKeyPrincipal({ userId: ownerId, keyId: generateId() })
5557

@@ -168,8 +170,24 @@ beforeAll(async () => {
168170
},
169171
},
170172
}),
173+
[signoffId]: createBlock({
174+
id: signoffId,
175+
type: 'human_in_the_loop',
176+
name: 'Signoff',
177+
position: { x: 600, y: 0 },
178+
subBlocks: {
179+
inputFormat: {
180+
id: 'inputFormat',
181+
type: 'input-format',
182+
value: [{ id: 'signed', name: 'signed', type: 'boolean', required: true }],
183+
},
184+
},
185+
}),
171186
},
172-
edges: [{ id: generateId(), source: startId, target: approvalId }],
187+
edges: [
188+
{ id: generateId(), source: startId, target: approvalId },
189+
{ id: generateId(), source: approvalId, target: signoffId },
190+
],
173191
loops: {},
174192
parallels: {},
175193
})
@@ -266,7 +284,40 @@ check(
266284
},
267285
})
268286

269-
expect(resumed).toMatchObject({ kind: 'sync', success: true })
270-
expect(resumed).not.toMatchObject({ status: 'failed' })
287+
expect(resumed).toMatchObject({ kind: 'sync', success: true, status: 'paused' })
288+
if (resumed.kind !== 'sync' || !resumed.paused)
289+
throw new Error('Expected the run to pause again')
290+
// The resume attempt runs under its own id, but the pause it reaches is recorded under the run
291+
// it resumed, and that is the run the next resume names.
292+
expect(resumed.executionId).not.toBe(runId)
293+
expect(resumed.paused.runId).toBe(runId)
294+
const [waiting] = resumed.paused.points.filter((point) => point.resumeStatus === 'paused')
295+
if (!waiting) throw new Error('Expected a waiting pause point')
296+
expect(waiting.blockId).toBe(signoffId)
297+
await vi.waitFor(
298+
async () => {
299+
const row = await pausedRow(runId)
300+
const points = Object.values(
301+
(row?.pausePoints ?? {}) as Record<string, { contextId: string }>
302+
)
303+
if (!points.some((point) => point.contextId === waiting.contextId)) {
304+
throw new Error('Second pause not yet published')
305+
}
306+
},
307+
{ timeout: 20_000, interval: 250 }
308+
)
309+
310+
const signed = await resumeWorkflowRun.execute({
311+
principal: ownerKey,
312+
input: {
313+
workflowId,
314+
runId: resumed.paused.runId,
315+
contextId: waiting.contextId,
316+
resumeInput: { signed: true },
317+
surface: 'v2',
318+
},
319+
})
320+
321+
expect(signed).toMatchObject({ kind: 'sync', success: true, status: 'completed', paused: null })
271322
}
272323
)

‎packages/sim-cli/src/commands/protocol/source-tree.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ function writeCachedCatalog(catalog: BlockCatalog): void {
176176
writeJsonFile(catalogCachePath(catalog.hash), catalog)
177177
}
178178

179-
/** Records `hash` as the workspace's catalog. */
180179
function writeWorkspaceCatalogPointer(workspaceId: string, hash: string): void {
181180
if (embedStore.getStore() || !CACHE_KEY.test(workspaceId)) return
182181
writeJsonFile(workspaceCatalogPointerPath(workspaceId), { hash })

‎packages/sim-cli/src/commands/protocol/workflow-source-status.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ describe('workflows source status', () => {
541541

542542
await run(folder, 'status', '--offline')
543543

544+
expect(printed()).toMatchObject({ server: 'offline' })
544545
const local = (printed().local ?? []) as Array<{ files: unknown[] }>
545546
expect(local.flatMap((entry) => entry.files)).toEqual([])
546547
})

‎packages/sim-cli/src/commands/protocol/workspace-source-apply.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,14 +1525,17 @@ describe('workspaces source apply', () => {
15251525
request.mockResolvedValue(
15261526
answer({
15271527
dryRun: true,
1528-
plan: [{ kind: 'table', key: 'leads', action: 'create', held: true }],
1528+
plan: [
1529+
{ kind: 'table', key: 'leads', action: 'create', held: true },
1530+
{ kind: 'table', key: 'other', action: 'create' },
1531+
],
15291532
diagnostics: [{ code: 'E_APPLY_LOCKED', severity: 'error', message: 'locked' }],
15301533
})
15311534
)
15321535

15331536
await apply('--dry-run')
15341537

1535-
expect(process.exitCode).toBe(1)
1538+
expect(process.exitCode).toBe(15)
15361539
})
15371540

15381541
it('refuses a local blob over the size limit before reading it, and exits 7', async () => {

‎packages/sim-cli/src/runtime/paused-run.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function shellArgument(value: string): string {
1717
return SAFE_ARGUMENT.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`
1818
}
1919

20-
/** The command that resumes one pause of a paused run. */
2120
function resumeCommand(runId: string, workflowId: string, contextId: string): string {
2221
return `sim workflows runs resume ${shellArgument(runId)} --workflow ${shellArgument(workflowId)} --context ${shellArgument(contextId)}`
2322
}

‎packages/workspace-code/src/kinds/workflow.test.ts‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,4 @@ describe('workflowCodec', () => {
3232
expect(parsed.decl).toBeUndefined()
3333
expect(parsed.diagnostics.map((finding) => finding.code)).toEqual(['E_DECL_SHAPE'])
3434
})
35-
36-
it('refuses a base with no version', () => {
37-
const base = { workflowId: 'wf_1', workspaceId: 'ws', fingerprint: 'sf1:a', catalogHash: 'c' }
38-
const parsed = workflowCodec.parse(
39-
'ingest',
40-
{
41-
'workflows/ingest/workflow.ts': 'export default 1\n',
42-
'workflows/ingest/.sim/base.json': JSON.stringify(base),
43-
},
44-
[]
45-
)
46-
47-
expect(parsed.decl?.base).toBeUndefined()
48-
expect(parsed.diagnostics.map((finding) => finding.code)).toEqual(['E_DECL_SHAPE'])
49-
})
5035
})

0 commit comments

Comments
 (0)