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

agentAwareness.test.ts

115 lines3.2 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" | "status" | "pendingRuntimeRequest" | "lineage"
27 >
28 > = {},
29 ) => ({
30 id: "thread-2" as ThreadId,
31 lineage: {
32 rootThreadId: "thread-2" as ThreadId,
33 parentThreadId: null,
34 relationshipToParent: null,
35 },
36 title: "Integrate orchestration",
37 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
38 status: "running" as const,
39 pendingRuntimeRequest: null,
40 updatedAt,
41 ...overrides,
42 });
43​
44 it("projects V2 run state", () => {
45 expect(
46 projectThreadAwarenessV2({
47 environmentId: "env-1" as EnvironmentId,
48 project,
49 thread: v2Thread(),
50 }),
51 ).toMatchObject({ phase: "running", headline: "Agent is working" });
52 });
53​
54 it.each(["running", "completed", "failed"] as const)(
55 "does not publish %s subagent activity",
56 (status) => {
57 expect(
58 projectThreadAwarenessV2({
59 environmentId: "env-1" as EnvironmentId,
60 project,
61 thread: v2Thread({
62 status,
63 lineage: {
64 rootThreadId: "parent" as ThreadId,
65 parentThreadId: "parent" as ThreadId,
66 relationshipToParent: "subagent",
67 },
68 }),
69 }),
70 ).toBeNull();
71 },
72 );
73​
74 it("keeps an older activity run visible over a newer cancelled run", () => {
75 expect(
76 projectThreadAwarenessV2({
77 environmentId: "env-1" as EnvironmentId,
78 project,
79 thread: v2Thread({ status: "cancelled", activityRunStatus: "running" }),
80 }),
81 ).toMatchObject({ phase: "running", headline: "Agent is working" });
82 });
83​
84 it("prioritizes V2 user-input requests", () => {
85 expect(
86 projectThreadAwarenessV2({
87 environmentId: "env-1" as EnvironmentId,
88 project,
89 thread: v2Thread({
90 pendingRuntimeRequest: {
91 id: RuntimeRequestId.make("request-1"),
92 kind: "user_input",
93 createdAt: updatedAt,
94 },
95 }),
96 }),
97 ).toMatchObject({ phase: "waiting_for_input", headline: "Waiting for input" });
98 });
99​
100 it("does not present authentication refreshes as user approvals", () => {
101 expect(
102 projectThreadAwarenessV2({
103 environmentId: "env-1" as EnvironmentId,
104 project,
105 thread: v2Thread({
106 pendingRuntimeRequest: {
107 id: RuntimeRequestId.make("request-auth-refresh"),
108 kind: "auth_refresh",
109 createdAt: updatedAt,
110 },
111 }),
112 }),
113 ).toMatchObject({ phase: "running", headline: "Agent is working" });
114 });
115});