@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 123 lines 4.61 KB
Raw
1 import { assert } from "@effect/vitest";
2 import type { ProviderReplayTranscript } from "@t3tools/contracts";
3
4 import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
5 import {
6 assertBaseProjection,
7 assertExecutionNodeKinds,
8 assertNoExtraAppRunsForProviderChildren,
9 assertRunProviderTurnCardinality,
10 assertSemanticProjectionIntegrity,
11 assertTurnItemTypes,
12 assertUserMessagesInclude,
13 projectionFor,
14 SUBAGENT_PROMPT,
15 } from "../shared.ts";
16
17 export function assertSubagentOutput(
18 result: OrchestratorV2ScenarioResult,
19 transcript: ProviderReplayTranscript,
20 ) {
21 assertBaseProjection({
22 result,
23 transcript,
24 runCount: 1,
25 runStatuses: ["completed"],
26 });
27
28 const projection = projectionFor(result, transcript.scenario);
29 assertSemanticProjectionIntegrity(projection);
30 assertTurnItemTypes(projection, ["user_message", "subagent", "assistant_message"]);
31 assertExecutionNodeKinds(projection, ["root_turn", "subagent"]);
32 assertRunProviderTurnCardinality({ projection, rootRunCount: 1 });
33 assertNoExtraAppRunsForProviderChildren({ projection, expectedAppRuns: 1 });
34 assertUserMessagesInclude(projection, [SUBAGENT_PROMPT]);
35 assert.equal(projection.runs.length, 1, "subagent provider turns must not become app runs");
36 assert.lengthOf(
37 projection.turnItems.filter((item) => item.type === "command_execution"),
38 0,
39 "subagent commands must not be projected into the parent thread",
40 );
41
42 assert.lengthOf(projection.subagents, 2);
43 assert.lengthOf(result.shellSnapshot.threads, 3);
44 assert.deepEqual(
45 projection.subagents.map((subagent) => subagent.status),
46 ["completed", "completed"],
47 );
48 assert.isTrue(
49 projection.subagents.some(
50 (subagent) =>
51 subagent.prompt.includes("package.json") &&
52 !subagent.prompt.includes("tsconfig.json") &&
53 subagent.result?.includes("effect-codex-app-server"),
54 ),
55 );
56 assert.isTrue(
57 projection.subagents.some(
58 (subagent) =>
59 subagent.prompt.includes("tsconfig.json") &&
60 !subagent.prompt.includes("package.json") &&
61 subagent.result?.includes("../../tsconfig.base.json"),
62 ),
63 );
64
65 for (const subagent of projection.subagents) {
66 assert.equal(subagent.origin, "provider_native");
67 assert.equal(subagent.createdBy, "agent");
68 assert.equal(subagent.driver, "codex");
69 assert.isNotNull(subagent.childThreadId);
70 assert.isNotNull(subagent.providerThreadId);
71 assert.isNotNull(subagent.nativeTaskRef);
72 assert.isNotNull(subagent.completedAt);
73 const parentItem = projection.turnItems.find(
74 (item) => item.type === "subagent" && item.subagentId === subagent.id,
75 );
76 assert.isDefined(parentItem);
77 if (parentItem?.type !== "subagent") {
78 throw new Error(`Missing parent lifecycle item for subagent ${subagent.id}`);
79 }
80 assert.equal(parentItem.result, subagent.result);
81 if (subagent.childThreadId === null) {
82 throw new Error(`Subagent ${subagent.id} is missing its child thread`);
83 }
84
85 const providerThread = projection.providerThreads.find(
86 (thread) => thread.id === subagent.providerThreadId,
87 );
88 assert.isDefined(providerThread);
89 assert.equal(providerThread.appThreadId, subagent.childThreadId);
90 assert.isNull(providerThread.ownerNodeId);
91
92 const childProjection = result.projections.get(subagent.childThreadId);
93 assert.isDefined(childProjection);
94 assert.equal(childProjection.thread.lineage.parentThreadId, projection.thread.id);
95 assert.equal(childProjection.thread.lineage.relationshipToParent, "subagent");
96 assert.equal(childProjection.thread.activeProviderThreadId, providerThread.id);
97 assert.lengthOf(childProjection.runs, 0);
98 assert.lengthOf(childProjection.providerThreads, 1);
99 assert.lengthOf(childProjection.providerTurns, 1);
100 assertTurnItemTypes(childProjection, [
101 "user_message",
102 "command_execution",
103 "assistant_message",
104 ]);
105 assertUserMessagesInclude(childProjection, [subagent.prompt]);
106 assert.isTrue(
107 childProjection.turnItems.some(
108 (item) =>
109 item.type === "assistant_message" &&
110 subagent.result !== null &&
111 item.text.includes(subagent.result.slice(0, 40)),
112 ),
113 `child thread ${subagent.childThreadId} must contain the subagent response`,
114 );
115 }
116
117 const rootProviderThread = projection.providerThreads.find(
118 (thread) => thread.ownerNodeId === null && thread.appThreadId === projection.thread.id,
119 );
120 assert.isDefined(rootProviderThread);
121 assert.equal(rootProviderThread.appThreadId, projection.thread.id);
122 assert.equal(projection.thread.activeProviderThreadId, rootProviderThread.id);
123 }