From 7e8d42d12251340266e9ffe90ee3e5604521ca22 Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Mon, 14 Sep 2026 16:17:59 +0800 Subject: [PATCH] test(workflow): await host child starts before cancellation --- .../workflow/workflow-ptc/tests/workflow-ptc.spec.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/workflow/workflow-ptc/tests/workflow-ptc.spec.ts b/packages/workflow/workflow-ptc/tests/workflow-ptc.spec.ts index a65d693141..f48762f3b8 100644 --- a/packages/workflow/workflow-ptc/tests/workflow-ptc.spec.ts +++ b/packages/workflow/workflow-ptc/tests/workflow-ptc.spec.ts @@ -582,12 +582,15 @@ describe('dsh-workflow-ptc', { timeout: 120_000 }, () => { it('cancel() aborts in-flight children and settles after their cleanup', async () => { const { ctx, parent, provider } = await setup({ manual: true }) + const starts: number[] = [] + ctx.on('workflow/agent-start', (_info, agent) => { starts.push(agent.seq) }) const ends: unknown[] = [] ctx.on('workflow/agent-end', (_info, agent) => { ends.push(agent) }) const runEnds: WorkflowResultInfo[] = [] ctx.on('workflow/end', (_info, result) => { runEnds.push(result) }) const handle = ctx.workflowEngine.start({ ...scripted("return await agent('long job')"), parent }) - await waitFor(() => { expect(provider.runs.length).toBe(1) }) + // Cancellation emits child ends only for starts already observed by the host. + await waitFor(() => { expect(starts).toHaveLength(1) }) handle.cancel('user stopped it') const result = await handle.result expect(result.stopReason).toBe('cancelled') @@ -851,7 +854,9 @@ describe('dsh-workflow-ptc', { timeout: 120_000 }, () => { }) it('cancellation emits exactly one agent-end per observed start before workflow/end', async () => { - const { ctx, parent, provider } = await setup({ manual: true }) + const { ctx, parent } = await setup({ manual: true }) + const starts: number[] = [] + ctx.on('workflow/agent-start', (_info, agent) => { starts.push(agent.seq) }) const ends: { seq: number; outcome: string }[] = [] const order: string[] = [] ctx.on('workflow/agent-end', (_info, agent) => { @@ -863,7 +868,7 @@ describe('dsh-workflow-ptc', { timeout: 120_000 }, () => { ...scripted("await parallel([() => agent('a'), () => agent('b')])\nreturn 'unreachable'"), parent, }) - await waitFor(() => { expect(provider.runs.length).toBe(2) }) + await waitFor(() => { expect(starts).toHaveLength(2) }) handle.cancel('user stop') const result = await handle.result expect(result.stopReason).toBe('cancelled')