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

schema.test.ts

195 lines5.9 KB

1import { assert, it } from "@effect/vitest";
2import * as Schema from "effect/Schema";
3​
4import * as CodexSchema from "./schema.ts";
5​
6const isGetAccountResponse = Schema.is(CodexSchema.V2GetAccountResponse);
7const isThreadReadResponse = Schema.is(CodexSchema.V2ThreadReadResponse);
8const isThreadResumeResponse = Schema.is(CodexSchema.V2ThreadResumeResponse);
9const isThreadForkResponse = Schema.is(CodexSchema.V2ThreadForkResponse);
10const isTurnCompletedNotification = Schema.is(CodexSchema.V2TurnCompletedNotification);
11const decodeThreadResumeResponse = Schema.decodeUnknownSync(CodexSchema.V2ThreadResumeResponse);
12​
13it("keeps async questions in live notifications and thread history", () => {
14 const item = {
15 type: "agentMessage",
16 id: "question-1",
17 text: "Which package?\n- pnpm\n- npm\n\nWhat should it be named?",
18 phase: "final_answer",
19 delivery: "async",
20 questions: [
21 { title: "Which package manager?", options: ["pnpm", "npm"] },
22 { title: "What should it be named?" },
23 ],
24 } as const;
25 for (const schema of [
26 CodexSchema.ServerNotification__ThreadItem,
27 CodexSchema.V2ItemStartedNotification__ThreadItem,
28 CodexSchema.V2ItemCompletedNotification__ThreadItem,
29 CodexSchema.V2ThreadReadResponse__ThreadItem,
30 CodexSchema.V2ThreadResumeResponse__ThreadItem,
31 ]) {
32 assert.deepEqual(Schema.decodeSync(schema)(item), item);
33 }
34});
35​
36it("accepts Codex 0.150 multi-agent values", () => {
37 const schemas = [
38 CodexSchema.ServerNotification__SubAgentActivityKind,
39 CodexSchema.V2ItemStartedNotification__SubAgentActivityKind,
40 CodexSchema.V2ItemCompletedNotification__SubAgentActivityKind,
41 CodexSchema.V2ThreadReadResponse__SubAgentActivityKind,
42 CodexSchema.V2ThreadResumeResponse__SubAgentActivityKind,
43 ];
44​
45 for (const schema of schemas) {
46 assert.equal(Schema.is(schema)("completed"), true);
47 }
48 const isServerNotificationCollabAgentTool = Schema.is(
49 CodexSchema.ServerNotification__CollabAgentTool,
50 );
51​
52 const isV2ThreadResumeResponseCollabAgentTool = Schema.is(
53 CodexSchema.V2ThreadResumeResponse__CollabAgentTool,
54 );
55​
56 for (const tool of ["sendMessage", "followupTask", "interruptAgent", "listAgents"]) {
57 assert.equal(isServerNotificationCollabAgentTool(tool), true);
58 assert.equal(isV2ThreadResumeResponseCollabAgentTool(tool), true);
59 }
60 const isServerNotificationCollabAgentToolCallStatus = Schema.is(
61 CodexSchema.ServerNotification__CollabAgentToolCallStatus,
62 );
63​
64 assert.equal(isServerNotificationCollabAgentToolCallStatus("interrupted"), true);
65 const isV2ThreadResumeResponseCollabAgentToolCallStatus = Schema.is(
66 CodexSchema.V2ThreadResumeResponse__CollabAgentToolCallStatus,
67 );
68​
69 assert.equal(isV2ThreadResumeResponseCollabAgentToolCallStatus("interrupted"), true);
70​
71 const resumeResponse = {
72 approvalPolicy: "never",
73 approvalsReviewer: "user",
74 cwd: "/tmp/project",
75 model: "gpt-5.6-sol",
76 modelProvider: "openai",
77 sandbox: { type: "dangerFullAccess" },
78 thread: {
79 cliVersion: "0.150.0",
80 createdAt: 0,
81 cwd: "/tmp/project",
82 ephemeral: false,
83 id: "root-thread",
84 modelProvider: "openai",
85 preview: "",
86 projectId: null,
87 sessionId: "session-1",
88 source: "cli",
89 status: { type: "idle" },
90 turns: [
91 {
92 id: "turn-1",
93 status: "completed",
94 items: [
95 {
96 agentsStates: {},
97 id: "item-1",
98 receiverThreadIds: ["child-thread"],
99 senderThreadId: "root-thread",
100 status: "interrupted",
101 tool: "followupTask",
102 type: "collabAgentToolCall",
103 },
104 ],
105 },
106 ],
107 updatedAt: 0,
108 },
109 };
110 const isV2ThreadResumeResponse = Schema.is(CodexSchema.V2ThreadResumeResponse);
111​
112 assert.equal(isV2ThreadResumeResponse(resumeResponse), true);
113});
114​
115it("accepts Codex misalignment policy errors for thread responses", () => {
116 const failedThread = {
117 cliVersion: "0.150.0",
118 createdAt: 0,
119 cwd: "/tmp/project",
120 ephemeral: false,
121 id: "thread-1",
122 modelProvider: "openai",
123 preview: "",
124 projectId: null,
125 sessionId: "session-1",
126 source: "cli",
127 status: { type: "idle" },
128 turns: [
129 {
130 error: {
131 codexErrorInfo: "misalignmentPolicyViolation",
132 message: "Misalignment policy violation",
133 },
134 id: "turn-1",
135 items: [],
136 status: "failed",
137 },
138 ],
139 updatedAt: 0,
140 };
141 const resumeLikeResponse = {
142 approvalPolicy: "never",
143 approvalsReviewer: "user",
144 cwd: "/tmp/project",
145 model: "gpt-5.6-sol",
146 modelProvider: "openai",
147 sandbox: { type: "dangerFullAccess" },
148 thread: failedThread,
149 };
150 assert.equal(isThreadReadResponse({ thread: failedThread }), true);
151 assert.equal(isThreadResumeResponse(resumeLikeResponse), true);
152 assert.equal(isThreadForkResponse(resumeLikeResponse), true);
153 const decodedResume = decodeThreadResumeResponse(resumeLikeResponse);
154 assert.equal(decodedResume.thread.turns[0]?.error?.codexErrorInfo, "misalignmentPolicyViolation");
155 assert.equal(
156 isTurnCompletedNotification({
157 threadId: "thread-1",
158 turn: {
159 error: {
160 codexErrorInfo: "misalignmentPolicyViolation",
161 message: "Misalignment policy violation",
162 },
163 id: "turn-1",
164 items: [],
165 status: "failed",
166 },
167 }),
168 true,
169 );
170});
171​
172it("accepts account plan slugs newer than the pinned protocol", () => {
173 const planTypes = [
174 "self_serve_business_prolite",
175 "ent26",
176 "enterprise_cbp_automation",
177 "edu_plus",
178 "edu_pro",
179 "promax",
180 "some_future_plan",
181 ];
182​
183 for (const planType of planTypes) {
184 const accountResponse = {
185 account: {
186 email: "user@example.com",
187 planType,
188 type: "chatgpt",
189 },
190 requiresOpenaiAuth: true,
191 };
192​
193 assert.equal(isGetAccountResponse(accountResponse), true);
194 }
195});