Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions packages/effect-codex-app-server/src/_internal/shared.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,35 @@ it.effect("passes request errors through without adding a wrapper", () =>
}),
);

it.effect("normalizes unrecognized plan types to unknown before decoding", () =>
it.effect("normalizes unrecognized account plan types to unknown before decoding", () =>
Effect.gen(function* () {
const account = yield* Shared.decodeOptionalPayload(
"account/read",
CodexSchema.V2GetAccountResponse,
{
account: {
type: "chatgpt",
email: "edu@example.com",
planType: "edu_plus",
const plansAddedAfterThePinnedSchema = [
"self_serve_business_prolite",
"ent26",
"enterprise_cbp_automation",
"edu_plus",
"edu_pro",
];
for (const planType of plansAddedAfterThePinnedSchema) {
const account = yield* Shared.decodeOptionalPayload(
"account/read",
CodexSchema.V2GetAccountResponse,
{
account: {
type: "chatgpt",
email: "new-plan@example.com",
planType,
},
requiresOpenaiAuth: false,
},
requiresOpenaiAuth: false,
},
);
);

assert.deepEqual(account.account, {
type: "chatgpt",
email: "edu@example.com",
planType: "unknown",
});
assert.deepEqual(account.account, {
type: "chatgpt",
email: "new-plan@example.com",
planType: "unknown",
});
}

const knownPlan = yield* Shared.decodeOptionalPayload(
"account/read",
Expand Down
8 changes: 4 additions & 4 deletions packages/effect-codex-app-server/src/_internal/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const JsonRpcResponseEnvelope = Schema.Struct({
});

// Plan types emitted by the running codex binary can be newer than the pinned
// protocol schema (e.g. "edu_plus"). Upstream maps unrecognized plans to
// "unknown" via #[serde(other)]; mirror that so account payloads still decode.
const KNOWN_PLAN_TYPES = new Set([
// protocol schema. Upstream maps unrecognized plans to "unknown" via
// #[serde(other)]; mirror that so account payloads still decode.
const PINNED_PLAN_TYPES = new Set([
"free",
"go",
"plus",
Expand All @@ -46,7 +46,7 @@ export const normalizeUnknownPlanTypes = (value: unknown): unknown => {
return Object.fromEntries(
Object.entries(value).map(([key, child]) => [
key,
key === "planType" && typeof child === "string" && !KNOWN_PLAN_TYPES.has(child)
key === "planType" && typeof child === "string" && !PINNED_PLAN_TYPES.has(child)
? "unknown"
: normalizeUnknownPlanTypes(child),
]),
Expand Down