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

agentAwareness.test.ts

128 lines3.2 KB

1import { describe, expect, it } from "@effect/vitest";
2​
3import type {
4 EnvironmentId,
5 OrchestrationProjectShell,
6 OrchestrationThreadShell,
7 ThreadId,
8 TurnId,
9} from "@t3tools/contracts";
10import { ProviderInstanceId } from "@t3tools/contracts";
11​
12import { projectThreadAwareness } from "./agentAwareness.ts";
13​
14const NOW = "2026-05-22T12:00:00.000Z";
15​
16const project = {
17 title: "t3code",
18} satisfies Pick<OrchestrationProjectShell, "title">;
19​
20function thread(
21 overrides: Partial<OrchestrationThreadShell> = {},
22): Pick<
23 OrchestrationThreadShell,
24 | "id"
25 | "title"
26 | "modelSelection"
27 | "session"
28 | "latestTurn"
29 | "updatedAt"
30 | "hasPendingApprovals"
31 | "hasPendingUserInput"
32> {
33 return {
34 id: "thread-1" as ThreadId,
35 title: "Fix failing CI",
36 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
37 session: null,
38 latestTurn: null,
39 updatedAt: NOW,
40 hasPendingApprovals: false,
41 hasPendingUserInput: false,
42 ...overrides,
43 };
45​
46describe("projectThreadAwareness", () => {
47 it("returns null for idle threads without an active awareness state", () => {
48 expect(
49 projectThreadAwareness({
50 environmentId: "env-1" as EnvironmentId,
51 project,
52 thread: thread(),
53 }),
54 ).toBeNull();
55 });
56​
57 it("prioritizes approval requests over running state", () => {
58 const state = projectThreadAwareness({
59 environmentId: "env-1" as EnvironmentId,
60 project,
61 thread: thread({
62 hasPendingApprovals: true,
63 session: {
64 threadId: "thread-1" as ThreadId,
65 status: "running",
66 providerName: "Codex",
67 runtimeMode: "full-access",
68 activeTurnId: "turn-1" as TurnId,
69 lastError: null,
70 updatedAt: NOW,
71 },
72 }),
73 });
74​
75 expect(state?.phase).toBe("waiting_for_approval");
76 expect(state?.headline).toBe("Approval needed");
77 });
78​
79 it("projects running provider sessions", () => {
80 const state = projectThreadAwareness({
81 environmentId: "env-1" as EnvironmentId,
82 project,
83 thread: thread({
84 session: {
85 threadId: "thread-1" as ThreadId,
86 status: "running",
87 providerName: "Codex",
88 runtimeMode: "full-access",
89 activeTurnId: "turn-1" as TurnId,
90 lastError: null,
91 updatedAt: NOW,
92 },
93 }),
94 });
95​
96 expect(state).toMatchObject({
97 phase: "running",
98 headline: "Agent is working",
99 detail: "Codex is active.",
100 modelTitle: "gpt-5.4",
101 deepLink: "/threads/env-1/thread-1",
102 });
103 });
104​
105 it("projects failures with the session error detail", () => {
106 const state = projectThreadAwareness({
107 environmentId: "env-1" as EnvironmentId,
108 project,
109 thread: thread({
110 session: {
111 threadId: "thread-1" as ThreadId,
112 status: "error",
113 providerName: "Codex",
114 runtimeMode: "full-access",
115 activeTurnId: null,
116 lastError: "Provider process exited.",
117 updatedAt: NOW,
118 },
119 }),
120 });
121​
122 expect(state).toMatchObject({
123 phase: "failed",
124 headline: "Agent failed",
125 detail: "Provider process exited.",
126 });
127 });
128});