|
3 | 3 | * PostgreSQL, while workflow source is applied to the draft. The apply renames the paused block; |
4 | 4 | * the run then resumes from its execution snapshot. Source apply writes the draft only, so the |
5 | 5 | * 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`. |
7 | 8 | */ |
8 | 9 | import { mkdir, writeFile } from 'node:fs/promises' |
9 | 10 | import { dirname, resolve } from 'node:path' |
@@ -50,6 +51,7 @@ const workspaceId = generateId() |
50 | 51 | const workflowId = generateId() |
51 | 52 | const startId = generateId() |
52 | 53 | const approvalId = generateId() |
| 54 | +const signoffId = generateId() |
53 | 55 | const owner = createSessionPrincipal({ userId: ownerId, sessionId: generateId() }) |
54 | 56 | const ownerKey = createPersonalApiKeyPrincipal({ userId: ownerId, keyId: generateId() }) |
55 | 57 |
|
@@ -168,8 +170,24 @@ beforeAll(async () => { |
168 | 170 | }, |
169 | 171 | }, |
170 | 172 | }), |
| 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 | + }), |
171 | 186 | }, |
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 | + ], |
173 | 191 | loops: {}, |
174 | 192 | parallels: {}, |
175 | 193 | }) |
@@ -266,7 +284,40 @@ check( |
266 | 284 | }, |
267 | 285 | }) |
268 | 286 |
|
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 }) |
271 | 322 | } |
272 | 323 | ) |
0 commit comments