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