Skip to content

Commit 3ad3796

Browse files
committed
fix(sim-cli): select the stop block of a --stop-after run that --follow streams
1 parent 79ab6f4 commit 3ad3796

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

‎packages/sim-cli/src/commands/protocol/workflow-run-follow.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function sse(...frames: unknown[]): ReadableStream<Uint8Array> {
5454
return bodyOf(frames.map((frame) => `data: ${JSON.stringify(frame)}\n\n`))
5555
}
5656

57-
function _streamResponse(body: ReadableStream<Uint8Array>): Response {
57+
function streamResponse(body: ReadableStream<Uint8Array>): Response {
5858
return {
5959
body,
6060
status: 200,
@@ -386,6 +386,21 @@ describe('sim workflows run --follow', () => {
386386
expect(requestRaw.mock.calls[1][1].body.selectedOutputs).toEqual([blockId])
387387
})
388388

389+
it('selects the stop block of a --stop-after run it follows, so the final frame holds its output', async () => {
390+
vi.spyOn(console, 'log').mockImplementation(() => {})
391+
requestRaw.mockResolvedValue(
392+
streamResponse(sse({ event: 'final', data: { success: true, output: {} } }))
393+
)
394+
395+
await run(WORKFLOW_ID, '--stop-after', 'agent-1', '--follow')
396+
397+
expect(requestRaw.mock.calls[0][1].body).toMatchObject({
398+
run: { stopAfterBlockId: 'agent-1' },
399+
selectedOutputs: ['agent-1'],
400+
stream: true,
401+
})
402+
})
403+
389404
it('keeps the outputs a --stop-after run selects itself', async () => {
390405
vi.spyOn(console, 'log').mockImplementation(() => {})
391406

‎packages/sim-cli/src/commands/protocol/workflow-run-follow.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ async function followRun(workflowId: string, command: Command): Promise<void> {
491491

492492
/**
493493
* The selection a `--stop-after` run sends when the caller selected nothing: the stop block's
494-
* whole output, so `blockOutputs` names the block the run stopped after and holds what it
495-
* produced (the run's `output` stays empty: no Response block ran). The block is sent as the
496-
* executor compares names ({@link normalizeBlockName}), so a display name with a dot is not read
494+
* whole output, so `blockOutputs` (with `--follow`, the final frame's `output`) names the block
495+
* the run stopped after and holds what it produced (no Response block ran). The block is sent as
496+
* the executor compares names ({@link normalizeBlockName}), so a display name with a dot is not read
497497
* as a path; an id is sent as it is.
498498
*/
499499
function stopBlockSelection(
@@ -541,6 +541,8 @@ function followOrDelegate(previous: ((args: unknown[]) => unknown) | null) {
541541
const selection = resolveWorkflowRunSelection(initialFlags)
542542
if (selection) command.setOptionValue('run', selection)
543543
const flags = command.optsWithGlobals() as Record<string, unknown>
544+
const stopBlock = stopBlockSelection(selection, flags)
545+
if (stopBlock) command.setOptionValue('selectOutput', stopBlock)
544546

545547
if (flags.follow !== true) {
546548
// A queued run has produced nothing to select from, so the server would
@@ -563,8 +565,6 @@ function followOrDelegate(previous: ((args: unknown[]) => unknown) | null) {
563565
)
564566
}
565567
if (flags.async !== true) {
566-
const stopBlock = stopBlockSelection(selection, flags)
567-
if (stopBlock) command.setOptionValue('selectOutput', stopBlock)
568568
await runWithResultStream(workflowId, command, waitTimeoutSeconds)
569569
return
570570
}

0 commit comments

Comments
 (0)