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

schema.test.ts

165 lines4.6 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 isThreadRollbackResponse = Schema.is(CodexSchema.V2ThreadRollbackResponse);
10​
11it("keeps async questions in live notifications and thread history", () => {
12 const item = {
13 type: "agentMessage",
14 id: "question-1",
15 text: "Which package?\n- pnpm\n- npm\n\nWhat should it be named?",
16 phase: "final_answer",
17 delivery: "async",
18 questions: [
19 { title: "Which package manager?", options: ["pnpm", "npm"] },
20 { title: "What should it be named?" },
21 ],
22 } as const;
23 for (const schema of [
24 CodexSchema.ServerNotification__ThreadItem,
25 CodexSchema.V2ItemStartedNotification__ThreadItem,
26 CodexSchema.V2ItemCompletedNotification__ThreadItem,
27 CodexSchema.V2ThreadReadResponse__ThreadItem,
28 CodexSchema.V2ThreadResumeResponse__ThreadItem,
29 ]) {
30 assert.deepEqual(Schema.decodeUnknownSync(schema)(item), item);
31 }
32});
33​
34it("accepts Codex 0.150 multi-agent values", () => {
35 const schemas = [
36 CodexSchema.ServerNotification__SubAgentActivityKind,
37 CodexSchema.V2ItemStartedNotification__SubAgentActivityKind,
38 CodexSchema.V2ItemCompletedNotification__SubAgentActivityKind,
39 CodexSchema.V2ThreadReadResponse__SubAgentActivityKind,
40 CodexSchema.V2ThreadResumeResponse__SubAgentActivityKind,
41 ];
42​
43 for (const schema of schemas) {
44 assert.equal(Schema.is(schema)("completed"), true);
45 }
46​
47 for (const tool of ["sendMessage", "followupTask", "interruptAgent", "listAgents"]) {
48 assert.equal(Schema.is(CodexSchema.ServerNotification__CollabAgentTool)(tool), true);
49 assert.equal(Schema.is(CodexSchema.V2ThreadResumeResponse__CollabAgentTool)(tool), true);
50 }
51​
52 assert.equal(
53 Schema.is(CodexSchema.ServerNotification__CollabAgentToolCallStatus)("interrupted"),
54 true,
55 );
56 assert.equal(
57 Schema.is(CodexSchema.V2ThreadResumeResponse__CollabAgentToolCallStatus)("interrupted"),
58 true,
59 );
60​
61 const resumeResponse = {
62 approvalPolicy: "never",
63 approvalsReviewer: "user",
64 cwd: "/tmp/project",
65 model: "gpt-5.6-sol",
66 modelProvider: "openai",
67 sandbox: { type: "dangerFullAccess" },
68 thread: {
69 cliVersion: "0.150.0",
70 createdAt: 0,
71 cwd: "/tmp/project",
72 ephemeral: false,
73 id: "root-thread",
74 modelProvider: "openai",
75 preview: "",
76 sessionId: "session-1",
77 source: "cli",
78 status: { type: "idle" },
79 turns: [
80 {
81 id: "turn-1",
82 status: "completed",
83 items: [
84 {
85 agentsStates: {},
86 id: "item-1",
87 receiverThreadIds: ["child-thread"],
88 senderThreadId: "root-thread",
89 status: "interrupted",
90 tool: "followupTask",
91 type: "collabAgentToolCall",
92 },
93 ],
94 },
95 ],
96 updatedAt: 0,
97 },
98 };
99​
100 assert.equal(Schema.is(CodexSchema.V2ThreadResumeResponse)(resumeResponse), true);
101});
102​
103it("accepts Codex rate limit errors for thread responses", () => {
104 const failedThread = {
105 cliVersion: "0.150.0",
106 createdAt: 0,
107 cwd: "/tmp/project",
108 ephemeral: false,
109 id: "thread-1",
110 modelProvider: "openai",
111 preview: "",
112 sessionId: "session-1",
113 source: "cli",
114 status: { type: "idle" },
115 turns: [
116 {
117 error: {
118 codexErrorInfo: "rateLimitExceeded",
119 message: "Rate limit exceeded",
120 },
121 id: "turn-1",
122 items: [],
123 status: "failed",
124 },
125 ],
126 updatedAt: 0,
127 };
128 assert.equal(isThreadReadResponse({ thread: failedThread }), true);
129 assert.equal(
130 isThreadResumeResponse({
131 approvalPolicy: "never",
132 approvalsReviewer: "user",
133 cwd: "/tmp/project",
134 model: "gpt-5.6-sol",
135 modelProvider: "openai",
136 sandbox: { type: "dangerFullAccess" },
137 thread: failedThread,
138 }),
139 true,
140 );
141 assert.equal(isThreadRollbackResponse({ thread: failedThread }), true);
142});
143​
144it("accepts Codex 0.150 account plan values", () => {
145 const planTypes = [
146 "self_serve_business_prolite",
147 "ent26",
148 "enterprise_cbp_automation",
149 "edu_plus",
150 "edu_pro",
151 ];
152​
153 for (const planType of planTypes) {
154 const accountResponse = {
155 account: {
156 email: "user@example.com",
157 planType,
158 type: "chatgpt",
159 },
160 requiresOpenaiAuth: true,
161 };
162​
163 assert.equal(isGetAccountResponse(accountResponse), true);
164 }
165});