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

DevinSubagentSupport.test.ts

231 lines7.8 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3const MAX_SUMMARY_CHARS = 160;
4const SAFE_ID_PATTERN = /^[A-Za-z0-9._:-]{1,96}$/;
5const ORDINARY_TOOL_UPDATE_TYPES = new Set(["tool_call", "tool_call_update"]);
6​
7export type DevinSubagentEventClassification =
8 | "stable child-agent stream"
9 | "event stream without stable identity"
10 | "no child-agent event support";
11​
12export interface DevinSanitizedSubagentObservation {
13 readonly method: "session/update";
14 readonly updateType: string;
15 readonly toolCallId?: string;
16 readonly summary?: string;
18​
19export const DEVIN_SUBAGENT_UNSUPPORTED_FIXTURE = {
20 status: "unsupported",
21 classification: "no child-agent event support",
22 reason: "not-emitted-by-installed-devin-cli",
23} as const;
24​
25interface DevinSubagentClassification {
26 readonly classification: DevinSubagentEventClassification;
27 readonly observations: ReadonlyArray<DevinSanitizedSubagentObservation>;
28 readonly taskEvents: readonly [];
30​
31function isRecord(value: unknown): value is Record<string, unknown> {
32 return typeof value === "object" && value !== null && !Array.isArray(value);
34​
35function boundedSummary(value: unknown): string | undefined {
36 if (typeof value !== "string") return undefined;
37 const summary = value.trim();
38 return summary.length > 0 ? summary.slice(0, MAX_SUMMARY_CHARS) : undefined;
40​
41function safeId(value: unknown): string | undefined {
42 return typeof value === "string" && SAFE_ID_PATTERN.test(value) ? value : undefined;
44​
45/**
46 * Test-local capture for the negative-evidence path. It records only bounded,
47 * non-sensitive fields and never turns an ordinary ACP tool update into a task.
48 */
49export function captureDevinSubagentObservation(
50 event: unknown,
51): DevinSanitizedSubagentObservation | undefined {
52 if (!isRecord(event) || event.direction !== "incoming" || event.stage !== "decoded") {
53 return undefined;
54 }
55​
56 const messages = Array.isArray(event.payload) ? event.payload : [event.payload];
57 const message = messages.find(isRecord);
58 if (message?.tag !== "session/update") return undefined;
59​
60 const payload = isRecord(message.payload) ? message.payload : undefined;
61 const update = payload && isRecord(payload.update) ? payload.update : undefined;
62 if (update === undefined) return undefined;
63 const updateType = typeof update?.sessionUpdate === "string" ? update.sessionUpdate : undefined;
64 if (updateType === undefined || updateType.length > 64) return undefined;
65​
66 const toolCallId = safeId(update.toolCallId);
67 const summary = boundedSummary(update.title);
68 return {
69 method: "session/update",
70 updateType,
71 ...(toolCallId ? { toolCallId } : {}),
72 ...(summary ? { summary } : {}),
73 };
75​
76/**
77 * Classify what the installed Devin ACP stream demonstrated. A future unknown
78 * update is kept as an unclassified stream; it is never promoted to a stable
79 * child-agent stream without observed identity, lifecycle, and parent linkage.
80 */
81export function classifyDevinSubagentEvents(
82 events: ReadonlyArray<unknown>,
83): DevinSubagentClassification {
84 const observations = events.flatMap((event) => {
85 const observation = captureDevinSubagentObservation(event);
86 return observation ? [observation] : [];
87 });
88​
89 const onlyOrdinaryToolUpdates =
90 observations.length > 0 &&
91 observations.every((observation) => ORDINARY_TOOL_UPDATE_TYPES.has(observation.updateType));
92​
93 return {
94 classification:
95 observations.length === 0 || onlyOrdinaryToolUpdates
96 ? DEVIN_SUBAGENT_UNSUPPORTED_FIXTURE.classification
97 : "event stream without stable identity",
98 observations,
99 taskEvents: [],
100 };
102​
103const decodedUpdate = (update: Record<string, unknown>) => ({
104 direction: "incoming",
105 stage: "decoded",
106 payload: [{ tag: "session/update", payload: { update } }],
107});
108​
109describe("Devin ACP child-agent evidence", () => {
110 it("records the explicit unsupported/no-stream result", () => {
111 expect(DEVIN_SUBAGENT_UNSUPPORTED_FIXTURE).toEqual({
112 status: "unsupported",
113 classification: "no child-agent event support",
114 reason: "not-emitted-by-installed-devin-cli",
115 });
116 expect(classifyDevinSubagentEvents([])).toMatchObject({
117 classification: "no child-agent event support",
118 taskEvents: [],
119 });
120 });
121​
122 it("does not synthesize a child agent from ordinary tool calls", () => {
123 const result = classifyDevinSubagentEvents([
124 decodedUpdate({
125 sessionUpdate: "tool_call",
126 toolCallId: "tool-1",
127 title: "Delegate-like tool title",
128 }),
129 decodedUpdate({
130 sessionUpdate: "tool_call_update",
131 toolCallId: "tool-1",
132 title: "Delegate-like tool title",
133 }),
134 ]);
135​
136 expect(result.classification).toBe("no child-agent event support");
137 expect(result.taskEvents).toEqual([]);
138 });
139​
140 it("keeps duplicate ordinary updates out of task events", () => {
141 const update = decodedUpdate({
142 sessionUpdate: "tool_call_update",
143 toolCallId: "tool-duplicate",
144 title: "bounded tool update",
145 });
146 const result = classifyDevinSubagentEvents([update, update]);
147​
148 expect(result.observations).toHaveLength(2);
149 expect(result.classification).toBe("no child-agent event support");
150 expect(result.taskEvents).toEqual([]);
151 });
152​
153 it("keeps out-of-order ordinary updates out of task events", () => {
154 const result = classifyDevinSubagentEvents([
155 decodedUpdate({
156 sessionUpdate: "tool_call_update",
157 toolCallId: "tool-out-of-order",
158 status: "completed",
159 }),
160 decodedUpdate({
161 sessionUpdate: "tool_call",
162 toolCallId: "tool-out-of-order",
163 status: "pending",
164 }),
165 ]);
166​
167 expect(result.classification).toBe("no child-agent event support");
168 expect(result.taskEvents).toEqual([]);
169 });
170​
171 it("does not treat an ordinary update without parent linkage as a child agent", () => {
172 const result = classifyDevinSubagentEvents([
173 decodedUpdate({
174 sessionUpdate: "tool_call",
175 toolCallId: "tool-no-parent",
176 title: "ordinary tool",
177 }),
178 ]);
179​
180 expect(result.observations[0]).not.toHaveProperty("parentAgentId");
181 expect(result.classification).toBe("no child-agent event support");
182 expect(result.taskEvents).toEqual([]);
183 });
184​
185 it("keeps a future unknown update as an event stream without stable identity", () => {
186 const result = classifyDevinSubagentEvents([
187 decodedUpdate({
188 sessionUpdate: "future_update",
189 title: "unrecognized update",
190 }),
191 ]);
192​
193 expect(result.classification).toBe("event stream without stable identity");
194 expect(result.taskEvents).toEqual([]);
195 });
196​
197 it("ignores malformed notifications without creating task events", () => {
198 const result = classifyDevinSubagentEvents([
199 undefined,
200 { direction: "incoming", stage: "decoded", payload: [{ tag: "session/update" }] },
201 decodedUpdate({ sessionUpdate: 42 }),
202 decodedUpdate({ sessionUpdate: "tool_call", toolCallId: "bad id" }),
203 ]);
204​
205 expect(result.observations).toEqual([{ method: "session/update", updateType: "tool_call" }]);
206 expect(result.classification).toBe("no child-agent event support");
207 expect(result.taskEvents).toEqual([]);
208 });
209​
210 it("bounds sanitized summaries and omits raw payload fields", () => {
211 const secretLikeText = "redacted-summary-" + "x".repeat(500);
212 const result = classifyDevinSubagentEvents([
213 decodedUpdate({
214 sessionUpdate: "tool_call",
215 toolCallId: "tool-bounded",
216 title: secretLikeText,
217 prompt: "must not be retained",
218 credentials: "must not be retained",
219 }),
220 ]);
221​
222 expect(result.observations[0]).toEqual({
223 method: "session/update",
224 updateType: "tool_call",
225 toolCallId: "tool-bounded",
226 summary: secretLikeText.slice(0, MAX_SUMMARY_CHARS),
227 });
228 expect(JSON.stringify(result)).not.toContain("must not be retained");
229 expect(JSON.stringify(result)).not.toContain("credentials");
230 });
231});