1import { assert } from "@effect/vitest";
2import type { ProviderReplayTranscript } from "@t3tools/contracts";
3
4import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
5import {
6 assertBaseProjection,
7 assertNoExtraAppRunsForProviderChildren,
8 assertSemanticProjectionIntegrity,
9 assertUserMessagesInclude,
10 projectionFor,
11 SUBAGENT_CONTINUE_CHILD_PROMPT,
12 SUBAGENT_CONTINUE_PARENT_PROMPT,
13 SUBAGENT_CONTINUE_PROMPT,
14} from "../shared.ts";
15
16export function assertSubagentContinueOutput(
17 result: OrchestratorV2ScenarioResult,
18 transcript: ProviderReplayTranscript,
19) {
20 assertBaseProjection({
21 result,
22 transcript,
23 runCount: 2,
24 runStatuses: ["completed", "completed"],
25 });
26
27 const projection = projectionFor(result, transcript.scenario);
28 assertSemanticProjectionIntegrity(projection);
29 assertNoExtraAppRunsForProviderChildren({ projection, expectedAppRuns: 2 });
30 assertUserMessagesInclude(projection, [
31 SUBAGENT_CONTINUE_PROMPT,
32 SUBAGENT_CONTINUE_PARENT_PROMPT,
33 ]);
34 assert.lengthOf(projection.subagents, 1);
35
36 const subagent = projection.subagents[0]!;
37 assert.equal(subagent.status, "completed");
38 assert.equal(subagent.result, "continued subagent response");
39 assert.equal(subagent.runId, projection.runs[1]!.id);
40 assert.isNotNull(subagent.childThreadId);
41 if (subagent.childThreadId === null) {
42 throw new Error("Continued subagent is missing its child thread");
43 }
44
45 const childProjection = result.projections.get(subagent.childThreadId);
46 assert.isDefined(childProjection);
47 assert.lengthOf(childProjection.runs, 0);
48 assert.lengthOf(childProjection.providerTurns, 2);
49 assertUserMessagesInclude(childProjection, [subagent.prompt, SUBAGENT_CONTINUE_CHILD_PROMPT]);
50 assert.isTrue(
51 childProjection.turnItems.some(
52 (item) => item.type === "assistant_message" && item.text === "initial subagent response",
53 ),
54 );
55 assert.isTrue(
56 childProjection.turnItems.some(
57 (item) => item.type === "assistant_message" && item.text === "continued subagent response",
58 ),
59 );
60}