Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

subagentRuntime.test.ts

188 lines5.3 KB

1import { describe, expect, it } from "vite-plus/test";
2import {
3 NodeId,
4 ProviderDriverKind,
5 ProviderInstanceId,
6 RunId,
7 ThreadId,
8 type OrchestrationV2Subagent,
9} from "@t3tools/contracts";
10import * as DateTime from "effect/DateTime";
11​
12import { projectedSubagentsToRuntime } from "./subagentRuntime.ts";
13import { deriveAgentPanelModel } from "./workflowGroups.ts";
14​
15const at = (iso: string) => DateTime.makeUnsafe(iso);
16​
17function subagent(
18 overrides: Omit<Partial<OrchestrationV2Subagent>, "id"> & { readonly id: string },
19): OrchestrationV2Subagent {
20 const { id, ...rest } = overrides;
21 return {
22 id: NodeId.make(id),
23 threadId: ThreadId.make("thread-1"),
24 runId: RunId.make("run-1"),
25 parentNodeId: NodeId.make("node-root"),
26 origin: "provider_native",
27 createdBy: "agent",
28 driver: ProviderDriverKind.make("pi"),
29 providerInstanceId: ProviderInstanceId.make("pi"),
30 providerThreadId: null,
31 childThreadId: null,
32 nativeTaskRef: null,
33 prompt: "Do the thing",
34 title: "Worker",
35 model: "claude-sonnet-5",
36 status: "running",
37 result: null,
38 startedAt: at("2026-09-17T14:46:00.000Z"),
39 completedAt: null,
40 updatedAt: at("2026-09-17T14:46:01.000Z"),
41 ...rest,
42 };
44​
45describe("projectedSubagentsToRuntime", () => {
46 it("projects a plain subagent without workflow fields", () => {
47 const [projected] = projectedSubagentsToRuntime([subagent({ id: "plain" })]);
48 expect(projected).toMatchObject({
49 id: "plain",
50 kind: "subagent",
51 workflowName: null,
52 phases: [],
53 parentAgentId: null,
54 agentIndex: null,
55 phaseIndex: null,
56 phaseTitle: null,
57 runHandles: null,
58 });
59 });
60​
61 it("projects a workflow coordinator with its full phase list and run id", () => {
62 const [projected] = projectedSubagentsToRuntime([
63 subagent({
64 id: "run-a",
65 title: "audit_auth_flow",
66 workflow: {
67 kind: "workflow",
68 workflowName: "audit_auth_flow",
69 phases: [
70 { index: 0, title: "Recon" },
71 { index: 1, title: "Design" },
72 ],
73 phaseIndex: null,
74 phaseTitle: null,
75 agentIndex: null,
76 runId: "audit-auth-flow-mu5n6tcx-i253rw",
77 },
78 }),
79 ]);
80​
81 expect(projected).toMatchObject({
82 id: "run-a",
83 kind: "workflow",
84 workflowName: "audit_auth_flow",
85 phases: [
86 { index: 0, title: "Recon" },
87 { index: 1, title: "Design" },
88 ],
89 parentAgentId: null,
90 runHandles: { runId: "audit-auth-flow-mu5n6tcx-i253rw" },
91 });
92 });
93​
94 it("projects a workflow member linked to its coordinator phase", () => {
95 const [projected] = projectedSubagentsToRuntime([
96 subagent({
97 id: "run-a:wf:1",
98 title: "recon-store",
99 parentNodeId: NodeId.make("run-a"),
100 workflow: {
101 kind: "workflow_agent",
102 workflowName: "audit_auth_flow",
103 phases: [],
104 phaseIndex: 0,
105 phaseTitle: "Recon",
106 agentIndex: 1,
107 runId: "audit-auth-flow-mu5n6tcx-i253rw",
108 },
109 }),
110 ]);
111​
112 expect(projected).toMatchObject({
113 id: "run-a:wf:1",
114 kind: "workflow_agent",
115 workflowName: "audit_auth_flow",
116 phases: [],
117 parentAgentId: "run-a",
118 agentIndex: 1,
119 phaseIndex: 0,
120 phaseTitle: "Recon",
121 runHandles: { runId: "audit-auth-flow-mu5n6tcx-i253rw" },
122 });
123 });
124​
125 it("leaves a legacy subagent without a workflow block untouched", () => {
126 const [projected] = projectedSubagentsToRuntime([
127 subagent({ id: "legacy", parentNodeId: NodeId.make("some-parent") }),
128 ]);
129 expect(projected).toMatchObject({
130 kind: "subagent",
131 parentAgentId: null,
132 phases: [],
133 runHandles: null,
134 });
135 });
136​
137 it("carries a failed status into the error field", () => {
138 const [projected] = projectedSubagentsToRuntime([
139 subagent({ id: "boom", status: "failed", result: "it broke" }),
140 ]);
141 expect(projected?.status).toBe("failed");
142 expect(projected?.error).toBe("it broke");
143 });
144​
145 it("feeds the workflow grouping helper end to end", () => {
146 const projected = projectedSubagentsToRuntime([
147 subagent({
148 id: "run-a",
149 title: "audit_auth_flow",
150 status: "completed",
151 workflow: {
152 kind: "workflow",
153 workflowName: "audit_auth_flow",
154 phases: [
155 { index: 0, title: "Recon" },
156 { index: 1, title: "Design" },
157 ],
158 phaseIndex: null,
159 phaseTitle: null,
160 agentIndex: null,
161 runId: "audit-auth-flow-mu5n6tcx-i253rw",
162 },
163 }),
164 subagent({
165 id: "run-a:wf:0",
166 parentNodeId: NodeId.make("run-a"),
167 status: "completed",
168 workflow: {
169 kind: "workflow_agent",
170 workflowName: "audit_auth_flow",
171 phases: [],
172 phaseIndex: 0,
173 phaseTitle: "Recon",
174 agentIndex: 0,
175 runId: "audit-auth-flow-mu5n6tcx-i253rw",
176 },
177 }),
178 ]);
179​
180 const model = deriveAgentPanelModel(projected);
181 expect(model.workflows).toHaveLength(1);
182 expect(model.workflows[0]!.label).toBe("audit_auth_flow · mu5n6tcx-i253rw");
183 expect(model.workflows[0]!.phases.map((phase) => `${phase.title}:${phase.state}`)).toEqual([
184 "Recon:done",
185 "Design:skipped",
186 ]);
187 });
188});