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 assertBaseProjection,
7 assertExecutionNodeKinds,
8 assertNoExtraAppRunsForProviderChildren,
9 assertSemanticProjectionIntegrity,
10 assertTurnItemTypes,
11 assertUserMessagesInclude,
12 projectionFor,
13 SUBAGENT_PROMPT,
14} from "../shared.ts";
15
16/**
17 * Kiro sends a sub-agent's frames on the parent session, tagged with its
18 * `agentSubtaskId`. They belong in the sub-agent's thread, not the parent's.
19 */
20export function assertKiroSubagentOutput(
21 result: OrchestratorV2ScenarioResult,
22 transcript: ProviderReplayTranscript,
23) {
24 assertBaseProjection({ result, transcript, runCount: 1, runStatuses: ["completed"] });
25
26 const projection = projectionFor(result, transcript.scenario);
27 assertSemanticProjectionIntegrity(projection);
28 assertExecutionNodeKinds(projection, ["root_turn", "subagent"]);
29 assertNoExtraAppRunsForProviderChildren({ projection, expectedAppRuns: 1 });
30 assertUserMessagesInclude(projection, [SUBAGENT_PROMPT]);
31 assertTurnItemTypes(projection, ["user_message", "subagent", "assistant_message"]);
32 assert.notInclude(
33 projection.turnItems.map((item) => item.type),
34 "dynamic_tool",
35 "the sub-agents' tool calls must not land in the parent thread",
36 );
37
38 assert.lengthOf(projection.subagents, 2);
39 assert.lengthOf(result.shellSnapshot.threads, 3);
40 const parentText = projection.turnItems
41 .flatMap((item) => (item.type === "assistant_message" ? [item.text] : []))
42 .join("\n");
43 for (const subagent of projection.subagents) {
44 assert.equal(subagent.status, "completed");
45 assert.equal(subagent.origin, "provider_native");
46 assert.equal(subagent.driver, "kiro");
47 assert.isNotNull(subagent.nativeTaskRef);
48 assert.isNotNull(subagent.title);
49 assert.isNotNull(subagent.result);
50 if (subagent.childThreadId === null) {
51 throw new Error(`Subagent ${subagent.id} is missing its child thread`);
52 }
53
54 const child = result.projections.get(subagent.childThreadId);
55 assert.isDefined(child);
56 assert.equal(child.thread.lineage.parentThreadId, projection.thread.id);
57 assert.equal(child.thread.lineage.relationshipToParent, "subagent");
58 assert.lengthOf(child.runs, 0);
59 assertTurnItemTypes(child, ["user_message", "dynamic_tool", "assistant_message"]);
60 assertUserMessagesInclude(child, [subagent.prompt]);
61 for (const item of child.turnItems) {
62 if (item.type !== "assistant_message") continue;
63 assert.notInclude(parentText, item.text.trim().slice(0, 40));
64 }
65 }
66}