Open History to see the last commit
1import { assert } from "@effect/vitest";
2import type { ProviderReplayTranscript } from "@t3tools/contracts";
3
4import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
5import {
6 assertAssistantTextIncludes,
7 assertBaseProjection,
8 assertNoExtraAppRunsForProviderChildren,
9 assertProviderNativeSubagentRootTurns,
10 assertSemanticProjectionIntegrity,
11 assertUserMessagesInclude,
12 OPENCODE2_SUBAGENT_PROMPT,
13 projectionFor,
14} from "../shared.ts";
15
16const CHILD_PROMPT = "List the files in the current directory and report their names.";
17
18export function assertOpenCode2SubagentOutput(
19 result: OrchestratorV2ScenarioResult,
20 transcript: ProviderReplayTranscript,
21) {
22 assertBaseProjection({ result, transcript, runCount: 1, runStatuses: ["completed"] });
23 const projection = projectionFor(result, transcript.scenario);
24 assertSemanticProjectionIntegrity(projection);
25 assertNoExtraAppRunsForProviderChildren({ projection, expectedAppRuns: 1 });
26 assertProviderNativeSubagentRootTurns(result);
27 assertUserMessagesInclude(projection, [OPENCODE2_SUBAGENT_PROMPT]);
28 assertAssistantTextIncludes(projection, "hello.txt");
29
30 assert.lengthOf(projection.subagents, 1);
31 const subagent = projection.subagents[0]!;
32 assert.deepInclude(subagent, {
33 origin: "provider_native",
34 status: "completed",
35 prompt: CHILD_PROMPT,
36 title: "List files in current directory",
37 runId: projection.runs[0]!.id,
38 });
39 assert.include(subagent.result ?? "", "hello.txt");
40 assert.notInclude(subagent.result ?? "", "<subagent", "the result is the answer, not the tag");
41 assert.deepEqual(
42 projection.turnItems.flatMap((item) => (item.type === "subagent" ? [item.status] : [])),
43 ["completed"],
44 );
45 assert.isFalse(
46 projection.turnItems.some(
47 (item) => item.type === "dynamic_tool" || item.type === "file_search",
48 ),
49 "the child's read and glob calls must not land on the parent",
50 );
51
52 const child = result.projections.get(subagent.childThreadId!);
53 assert.isDefined(child);
54 assert.equal(child.thread.lineage.relationshipToParent, "subagent");
55 assert.deepEqual(
56 child.providerTurns.map((turn) => turn.status),
57 ["completed"],
58 );
59 assertUserMessagesInclude(child, [CHILD_PROMPT]);
60 assert.isAtLeast(
61 child.turnItems.filter((item) => item.type === "dynamic_tool" || item.type === "file_search")
62 .length,
63 2,
64 );
65 assertAssistantTextIncludes(child, "hello.txt");
66 assert.equal(projection.providerTurns[0]?.turnTokenUsage?.hasSubagents, true);
67}