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

agentAwareness.test.ts

164 lines4.7 KB

1import { describe, expect, it } from "@effect/vitest";
2​
3import type {
4 EnvironmentId,
5 OrchestrationV2ThreadShell,
6 Project,
7 ThreadId,
8} from "@t3tools/contracts";
9import { ProviderInstanceId, RuntimeRequestId } from "@t3tools/contracts";
10import * as DateTime from "effect/DateTime";
11​
12import { projectThreadAwarenessV2 } from "./agentAwareness.ts";
13​
14const NOW = "2026-05-22T12:00:00.000Z";
15​
16const project = {
17 title: "t3code",
18} satisfies Pick<Project, "title">;
19​
20describe("projectThreadAwarenessV2", () => {
21 const updatedAt = DateTime.makeUnsafe(NOW);
22 const v2Thread = (
23 overrides: Partial<
24 Pick<
25 OrchestrationV2ThreadShell,
26 | "activityRunStatus"
27 | "status"
28 | "pendingBackgroundTasks"
29 | "pendingRuntimeRequest"
30 | "lineage"
31 | "settledOverride"
32 >
33 > = {},
34 ) => ({
35 id: "thread-2" as ThreadId,
36 lineage: {
37 rootThreadId: "thread-2" as ThreadId,
38 parentThreadId: null,
39 relationshipToParent: null,
40 },
41 title: "Integrate orchestration",
42 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
43 status: "running" as const,
44 pendingRuntimeRequest: null,
45 settledOverride: null,
46 updatedAt,
47 ...overrides,
48 });
49​
50 it("projects V2 run state", () => {
51 expect(
52 projectThreadAwarenessV2({
53 environmentId: "env-1" as EnvironmentId,
54 project,
55 thread: v2Thread(),
56 }),
57 ).toMatchObject({ phase: "running", headline: "Agent is working" });
58 });
59​
60 it.each(["running", "completed", "failed"] as const)(
61 "does not publish %s subagent activity",
62 (status) => {
63 expect(
64 projectThreadAwarenessV2({
65 environmentId: "env-1" as EnvironmentId,
66 project,
67 thread: v2Thread({
68 status,
69 lineage: {
70 rootThreadId: "parent" as ThreadId,
71 parentThreadId: "parent" as ThreadId,
72 relationshipToParent: "subagent",
73 },
74 }),
75 }),
76 ).toBeNull();
77 },
78 );
79​
80 it("keeps an older activity run visible over a newer cancelled run", () => {
81 expect(
82 projectThreadAwarenessV2({
83 environmentId: "env-1" as EnvironmentId,
84 project,
85 thread: v2Thread({ status: "cancelled", activityRunStatus: "running" }),
86 }),
87 ).toMatchObject({ phase: "running", headline: "Agent is working" });
88 });
89​
90 it.each([
91 ["only a dev server", "completed", [{ taskId: "dev", kind: "command" }]],
92 ["a monitor", "running", [{ taskId: "watch", kind: "monitor" }]],
93 [
94 "a dev server and a subagent",
95 "running",
96 [
97 { taskId: "dev", kind: "command" },
98 { taskId: "review", kind: "subagent" },
99 ],
100 ],
101 ] as const)("reports a completed run waiting on %s as %s", (_case, phase, tasks) => {
102 expect(
103 projectThreadAwarenessV2({
104 environmentId: "env-1" as EnvironmentId,
105 project,
106 thread: v2Thread({ status: "completed", pendingBackgroundTasks: tasks }),
107 }),
108 ).toMatchObject({ phase });
109 });
110​
111 it("prioritizes V2 user-input requests", () => {
112 expect(
113 projectThreadAwarenessV2({
114 environmentId: "env-1" as EnvironmentId,
115 project,
116 thread: v2Thread({
117 pendingRuntimeRequest: {
118 id: RuntimeRequestId.make("request-1"),
119 kind: "user_input",
120 createdAt: updatedAt,
121 },
122 }),
123 }),
124 ).toMatchObject({ phase: "waiting_for_input", headline: "Waiting for input" });
125 });
126​
127 it("reports an async question as input only after the working run completes", () => {
128 const input = {
129 environmentId: "env-1" as EnvironmentId,
130 project,
131 thread: v2Thread({
132 pendingRuntimeRequest: {
133 id: RuntimeRequestId.make("request-async"),
134 kind: "user_input",
135 createdAt: updatedAt,
136 blocking: false,
137 },
138 }),
139 };
140 expect(projectThreadAwarenessV2(input)).toMatchObject({
141 phase: "running",
142 headline: "Agent is working",
143 });
144 expect(
145 projectThreadAwarenessV2({ ...input, thread: { ...input.thread, status: "completed" } }),
146 ).toMatchObject({ phase: "waiting_for_input", headline: "Waiting for input" });
147 });
148​
149 it("does not present authentication refreshes as user approvals", () => {
150 expect(
151 projectThreadAwarenessV2({
152 environmentId: "env-1" as EnvironmentId,
153 project,
154 thread: v2Thread({
155 pendingRuntimeRequest: {
156 id: RuntimeRequestId.make("request-auth-refresh"),
157 kind: "auth_refresh",
158 createdAt: updatedAt,
159 },
160 }),
161 }),
162 ).toMatchObject({ phase: "running", headline: "Agent is working" });
163 });
164});