mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 04:53:40 +00:00
* refactor: extract agent core package Introduce packages/agent-core as the OpenClaw-owned home for reusable agent loop, harness, session, prompt, and runtime dependency contracts. * refactor: extract shared llm runtime Move provider model registries, stream wrappers, OAuth helpers, and LLM utilities into src/llm with plugin-sdk barrels instead of depending on the old embedded runtime layout. * refactor: remove pi runtime internals Rename remaining Pi-shaped agent surfaces to OpenClaw agent runtime names, delete obsolete Pi docs and package graph checks, and add the third-party notice for incorporated code. * refactor: tighten agent session runtime Make agent-core/runtime dependencies explicit, consolidate compaction and session transcript helpers, and move model/session helpers behind OpenClaw-owned contracts. * refactor: remove static model and pi auth paths Drop static model catalogs and Pi auth bridges, move model/provider facts to manifest-owned runtime contracts, and harden internal embedded-agent utilities. * refactor: remove legacy provider compat paths * docs: remove agent parity notes * fix: skip provider wildcard metadata parsing * refactor: share session extension sdk loading * refactor: inline acpx proxy error formatter * refactor: fold edit recovery into edit tool * fix: accept extension batch separator * test: align startup provider plugin expectations * fix: restore provider-scoped release discovery * test: align static asset packaging expectations * fix: run static provider catalogs during scoped discovery * fix: add provider entry catalogs for scoped live discovery * fix: load lightweight provider catalog entries * fix: refresh provider-scoped plugin metadata * fix: keep provider catalog entries on release live path * fix: keep static manifest models in release live checks * fix: harden release model discovery * fix: reduce OpenAI live cache probe reasoning * fix: disable OpenAI cache probe reasoning * ci: extend OpenAI gateway live timeout * fix: extend live gateway model budget * fix: stabilize release validation regressions * fix: honor provider aliases in model rows * fix: stabilize release validation lanes * fix: stabilize release memory qa * ci: stabilize release validation lanes * ci: prefer ipv4 for live docker node calls * fix: restore shared tool-call stream wrapper * ci: remove legacy pi test shard alias * fix: clean up embedded agent test drift * fix: stabilize runtime alias status * fix: clean up embedded agent ci drift * fix: restore release ci invariants * fix: clean up post-rebase runtime drift * fix: restore release ci checks * fix: restore release ci after rebase * fix: remove stale pi runtime path * test: align compaction runtime expectations * test: update plugin prerelease expectations * fix: handle claude live tool approvals * fix: stabilize release validation gates * fix: finish agent runtime import * test: finish post-rebase agent runtime mocks * fix: keep codex compaction native * fix: stabilize codex app-server hook tests * test: isolate codex diagnostic active run * test: remove codex diagnostic completion race # Conflicts: # extensions/codex/src/app-server/run-attempt.test.ts * ci: fix full release manifest performance run id * refactor: narrow llm plugin sdk boundary * chore: drop generated google boundary stamps * fix: repair rebase fallout * fix: clean up rebased runtime references * fix: decode codex jwt payloads as base64url * fix: preserve shipped pi runtime alias * fix: add scoped sdk virtual modules * fix: decode llm codex oauth jwt as base64url * fix: avoid stale vertex adc negative cache * fix: harden tool arg decoding and codeql path * fix: keep vertex adc negative checks live * refactor: consolidate codex jwt and edit helpers * fix: await codex oauth node runtime imports * fix: preserve sdk tool and notice contracts * fix: preserve shipped compat config boundaries * fix: align codex oauth callback host * fix: terminate agent-core loop streams on failure * fix: keep codex oauth callback alive during fallback * ci: include session tools in critical codeql scans * fix: keep Cloudflare Anthropic provider auth header * docs: redirect legacy pi runtime pages * fix: honor bundled web provider compat discovery * fix: protect session output spill files * fix: keep legacy agent dir env blocked * fix: contain auto-discovered skill symlinks * fix: harden agent core sdk proxy surfaces * fix: restore approval reaction sdk compat * fix: keep live docker runs bounded * fix: keep codex oauth redirect host aligned * fix: resolve post-rebase agent runtime drift * fix: redact anthropic oauth parse failures * fix: preserve responses strict tool shaping * fix: repair agent runtime rebase cleanup * docs: redirect retired parity pages * fix: bound auto-discovered resources to roots * fix: repair post-rebase agent test drift * fix: preserve bundled provider allowlist migration * fix: preserve manifest-owned provider aliases * fix: declare photon image dependency * fix: keep provider headers out of proxy body * fix: preserve shipped env aliases * fix: refresh control ui i18n generated state * fix: quote read fallback paths * fix: preview edits through configured backend * test: satisfy core test typecheck * fix: preserve ZAI usage auth fallback * test: repair codex diagnostic test * fix: repair agent runtime rebase drift * test: finish embedded runner import rename * fix: repair agent runtime rebase integrations * test: align compaction oauth fallback expectations * fix: allow sdk-auth session models * fix: update doctor tool schema import * fix: preserve bedrock plugin region * fix: stream harmony-like prose immediately * ci: include session runtime in codeql shards * fix: repair latest rebase integrations * fix: honor explicit codex websocket transport * fix: keep openai-compatible credentials provider-scoped * fix: refresh sdk api baseline after rebase * fix: route cli runtime aliases through openclaw harness * test: rename stale harness mock expectation * test: rename embedded agent overflow calls * test: clean embedded auth test wording * test: use openclaw stream types in deepinfra cache test * fix: refresh sdk api baseline on latest main * fix: honor bundled discovery compat allowlists * fix: refresh sdk api baseline after latest rebase * fix: remove stale rebase imports * test: rename stale model catalog mock * test: mock renamed doctor runtime modules * fix: map canonical kimi env auth * fix: use internal model registry in bench script * fix: migrate deepinfra provider catalog entry * fix: enforce builtin tool suppression * fix: route compaction auth and proxy payloads safely * refactor: prune unused llm registry leftovers * test: update codex hooks session import * test: fix model picker ci coverage * test: align model picker auth mock types
971 lines
31 KiB
TypeScript
971 lines
31 KiB
TypeScript
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const refreshOpenAICodexTokenMock = vi.hoisted(() => vi.fn());
|
|
const loginOpenAICodexDeviceCodeMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("./openai-codex-provider.runtime.js", () => ({
|
|
refreshOpenAICodexToken: refreshOpenAICodexTokenMock,
|
|
}));
|
|
|
|
vi.mock("./openai-codex-device-code.js", () => ({
|
|
loginOpenAICodexDeviceCode: loginOpenAICodexDeviceCodeMock,
|
|
}));
|
|
|
|
let buildOpenAICodexProviderPlugin: typeof import("./openai-codex-provider.js").buildOpenAICodexProviderPlugin;
|
|
|
|
function createCodexTemplate(overrides: {
|
|
id?: string;
|
|
name?: string;
|
|
cost?: { input: number; output: number; cacheRead: number; cacheWrite: number };
|
|
contextWindow?: number;
|
|
contextTokens?: number;
|
|
}) {
|
|
return {
|
|
id: overrides.id ?? "gpt-5.3-codex",
|
|
name: overrides.name ?? overrides.id ?? "gpt-5.3-codex",
|
|
provider: "openai-codex",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api",
|
|
reasoning: true,
|
|
input: ["text", "image"] as const,
|
|
cost: overrides.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: overrides.contextWindow ?? 272_000,
|
|
...(overrides.contextTokens === undefined ? {} : { contextTokens: overrides.contextTokens }),
|
|
maxTokens: 128_000,
|
|
};
|
|
}
|
|
|
|
function createSingleModelRegistry(
|
|
template: ReturnType<typeof createCodexTemplate>,
|
|
missValue?: null,
|
|
) {
|
|
return {
|
|
find: (providerId: string, modelId: string) =>
|
|
providerId === "openai-codex" && modelId === template.id ? template : missValue,
|
|
};
|
|
}
|
|
|
|
type CodexProvider = ReturnType<typeof buildOpenAICodexProviderPlugin>;
|
|
type CodexAuthMethod = NonNullable<CodexProvider["auth"]>[number];
|
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
}
|
|
|
|
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
|
if (!isRecord(value)) {
|
|
throw new Error(`expected ${label} to be an object`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function requireArray(value: unknown, label: string): unknown[] {
|
|
if (!Array.isArray(value)) {
|
|
throw new Error(`expected ${label} to be an array`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function requireAuthMethod(provider: CodexProvider, id: string): CodexAuthMethod {
|
|
const method = provider.auth?.find((candidate) => candidate.id === id);
|
|
if (!method) {
|
|
throw new Error(`expected OpenAI Codex auth method ${id}`);
|
|
}
|
|
return method;
|
|
}
|
|
|
|
function expectRecordFields(value: unknown, label: string, expected: Record<string, unknown>) {
|
|
const record = requireRecord(value, label);
|
|
for (const [key, expectedValue] of Object.entries(expected)) {
|
|
expect(record[key]).toEqual(expectedValue);
|
|
}
|
|
}
|
|
|
|
function expectModelFields(model: unknown, expected: Record<string, unknown>) {
|
|
expectRecordFields(model, "model", expected);
|
|
}
|
|
|
|
function requireEntryById(entries: unknown, id: string): Record<string, unknown> {
|
|
const entry = requireArray(entries, "model catalog entries")
|
|
.filter(isRecord)
|
|
.find((candidate) => candidate.id === id);
|
|
if (!entry) {
|
|
throw new Error(`expected model catalog entry ${id}`);
|
|
}
|
|
return entry;
|
|
}
|
|
|
|
describe("openai codex provider", () => {
|
|
beforeAll(async () => {
|
|
({ buildOpenAICodexProviderPlugin } = await import("./openai-codex-provider.js"));
|
|
});
|
|
|
|
beforeEach(() => {
|
|
refreshOpenAICodexTokenMock.mockReset();
|
|
loginOpenAICodexDeviceCodeMock.mockReset();
|
|
});
|
|
|
|
it("falls back to the cached credential when accountId extraction fails", async () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const credential = {
|
|
type: "oauth" as const,
|
|
provider: "openai-codex",
|
|
access: "cached-access-token",
|
|
refresh: "refresh-token",
|
|
expires: Date.now() - 60_000,
|
|
};
|
|
refreshOpenAICodexTokenMock.mockRejectedValueOnce(
|
|
new Error("Failed to extract accountId from token"),
|
|
);
|
|
|
|
await expect(provider.refreshOAuth?.(credential)).resolves.toEqual(credential);
|
|
});
|
|
|
|
it("rethrows unrelated refresh failures", async () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const credential = {
|
|
type: "oauth" as const,
|
|
provider: "openai-codex",
|
|
access: "cached-access-token",
|
|
refresh: "refresh-token",
|
|
expires: Date.now() - 60_000,
|
|
};
|
|
refreshOpenAICodexTokenMock.mockRejectedValueOnce(new Error("invalid_grant"));
|
|
|
|
await expect(provider.refreshOAuth?.(credential)).rejects.toThrow("invalid_grant");
|
|
});
|
|
|
|
it("merges refreshed oauth credentials", async () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const credential = {
|
|
type: "oauth" as const,
|
|
provider: "openai-codex",
|
|
access: "cached-access-token",
|
|
refresh: "refresh-token",
|
|
expires: Date.now() - 60_000,
|
|
email: "user@example.com",
|
|
displayName: "User",
|
|
};
|
|
refreshOpenAICodexTokenMock.mockResolvedValueOnce({
|
|
access: "next-access",
|
|
refresh: "next-refresh",
|
|
expires: Date.now() + 60_000,
|
|
});
|
|
|
|
const refreshed = await provider.refreshOAuth?.(credential);
|
|
|
|
expect(refreshed?.expires).toBeTypeOf("number");
|
|
expect(refreshed).toEqual({
|
|
...credential,
|
|
access: "next-access",
|
|
refresh: "next-refresh",
|
|
expires: refreshed?.expires,
|
|
});
|
|
});
|
|
|
|
it("exposes grouped model/auth picker labels for Codex auth methods", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const oauth = requireAuthMethod(provider, "oauth");
|
|
const deviceCode = requireAuthMethod(provider, "device-code");
|
|
const apiKey = requireAuthMethod(provider, "api-key");
|
|
|
|
expectRecordFields(oauth.wizard, "oauth wizard", {
|
|
choiceLabel: "ChatGPT/Codex Browser Login",
|
|
groupId: "openai",
|
|
groupLabel: "OpenAI",
|
|
groupHint: "ChatGPT/Codex sign-in or API key",
|
|
});
|
|
expectRecordFields(deviceCode.wizard, "device-code wizard", {
|
|
choiceLabel: "ChatGPT/Codex Device Pairing",
|
|
groupId: "openai",
|
|
groupLabel: "OpenAI",
|
|
groupHint: "ChatGPT/Codex sign-in or API key",
|
|
});
|
|
expectRecordFields(apiKey.wizard, "api-key wizard", {
|
|
choiceLabel: "OpenAI API Key Backup",
|
|
choiceHint: "Use an OpenAI API key when your Codex subscription is unavailable",
|
|
groupId: "openai",
|
|
groupLabel: "OpenAI",
|
|
groupHint: "ChatGPT/Codex sign-in or API key",
|
|
});
|
|
});
|
|
|
|
it("returns deprecated-profile doctor guidance for legacy Codex CLI ids", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
expect(
|
|
provider.buildAuthDoctorHint?.({
|
|
provider: "openai-codex",
|
|
profileId: "openai-codex:codex-cli",
|
|
config: undefined,
|
|
store: { version: 1, profiles: {} },
|
|
}),
|
|
).toBe(
|
|
"Deprecated profile. Run `openclaw models auth login --provider openai-codex` or `openclaw configure`.",
|
|
);
|
|
});
|
|
|
|
it("declares the legacy default OAuth profile repair", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
expect(provider.oauthProfileIdRepairs).toEqual([
|
|
{
|
|
legacyProfileId: "openai-codex:default",
|
|
promptLabel: "OpenAI Codex",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("offers OpenAI menu auth methods for browser login and device pairing", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const oauth = requireAuthMethod(provider, "oauth");
|
|
const deviceCode = requireAuthMethod(provider, "device-code");
|
|
|
|
expect(provider.auth?.map((method) => method.id)).toEqual(["oauth", "device-code", "api-key"]);
|
|
expect(oauth.label).toBe("ChatGPT/Codex Browser Login");
|
|
expect(oauth.hint).toBe("Sign in with OpenAI in your browser");
|
|
expectRecordFields(oauth.wizard, "oauth wizard", {
|
|
choiceId: "openai-codex",
|
|
choiceLabel: "ChatGPT/Codex Browser Login",
|
|
assistantPriority: -30,
|
|
onboardingFeatured: true,
|
|
});
|
|
expect(deviceCode.label).toBe("ChatGPT/Codex Device Pairing");
|
|
expect(deviceCode.hint).toBe("Pair in browser with a device code");
|
|
expect(deviceCode.kind).toBe("device_code");
|
|
expectRecordFields(deviceCode.wizard, "device-code wizard", {
|
|
choiceId: "openai-codex-device-code",
|
|
choiceLabel: "ChatGPT/Codex Device Pairing",
|
|
assistantPriority: -10,
|
|
});
|
|
});
|
|
|
|
it("stores device-code logins as OpenAI Codex oauth profiles", async () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const deviceCodeMethod = requireAuthMethod(provider, "device-code");
|
|
const note = vi.fn(async () => {});
|
|
const progress = { update: vi.fn(), stop: vi.fn() };
|
|
const runtime = {
|
|
log: vi.fn(),
|
|
error: vi.fn(),
|
|
exit: vi.fn(),
|
|
};
|
|
loginOpenAICodexDeviceCodeMock.mockResolvedValueOnce({
|
|
access:
|
|
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF9hY2NvdW50X2lkIjoiYWNjdC1kZXZpY2UtMTIzIn19.signature",
|
|
refresh: "device-refresh-token",
|
|
expires: Date.now() + 60_000,
|
|
});
|
|
|
|
const result = await deviceCodeMethod.run({
|
|
config: {},
|
|
env: process.env,
|
|
prompter: {
|
|
note,
|
|
progress: vi.fn(() => progress),
|
|
} as never,
|
|
runtime: runtime as never,
|
|
isRemote: false,
|
|
openUrl: async () => {},
|
|
oauth: { createVpsAwareHandlers: (() => ({})) as never },
|
|
});
|
|
|
|
expect(loginOpenAICodexDeviceCodeMock).toHaveBeenCalledOnce();
|
|
expect(runtime.error).not.toHaveBeenCalled();
|
|
expect(note).not.toHaveBeenCalledWith(
|
|
"Trouble with device code login? See https://docs.openclaw.ai/start/faq",
|
|
"OAuth help",
|
|
);
|
|
const profiles = requireArray(result?.profiles, "device-code profiles");
|
|
expect(profiles).toHaveLength(1);
|
|
const profile = requireRecord(profiles[0], "device-code profile");
|
|
const credential = requireRecord(profile.credential, "device-code credential");
|
|
expect(profile.profileId).toBe("openai-codex:default");
|
|
expect(credential).toEqual({
|
|
type: "oauth",
|
|
provider: "openai-codex",
|
|
access:
|
|
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF9hY2NvdW50X2lkIjoiYWNjdC1kZXZpY2UtMTIzIn19.signature",
|
|
refresh: "device-refresh-token",
|
|
expires: credential.expires,
|
|
accountId: "acct-device-123",
|
|
});
|
|
expect(credential.expires).toBeTypeOf("number");
|
|
expect(result?.defaultModel).toBe("openai/gpt-5.5");
|
|
expect(result?.configPatch).toEqual({
|
|
agents: {
|
|
defaults: {
|
|
models: {
|
|
"openai/gpt-5.5": {},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
expect(result?.profiles[0]?.credential).not.toHaveProperty("idToken");
|
|
});
|
|
|
|
async function runRemoteDeviceCodeAuthFlow() {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const deviceCodeMethod = requireAuthMethod(provider, "device-code");
|
|
const note = vi.fn(async () => {});
|
|
const progress = { update: vi.fn(), stop: vi.fn() };
|
|
const runtime = {
|
|
log: vi.fn(),
|
|
error: vi.fn(),
|
|
exit: vi.fn(),
|
|
};
|
|
loginOpenAICodexDeviceCodeMock.mockImplementationOnce(async ({ onVerification }) => {
|
|
await onVerification({
|
|
verificationUrl: "https://auth.openai.com/codex/device",
|
|
userCode: "CODE-12345",
|
|
expiresInMs: 900_000,
|
|
});
|
|
return {
|
|
access:
|
|
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF9hY2NvdW50X2lkIjoiYWNjdC1kZXZpY2UtMTIzIn19.signature",
|
|
refresh: "device-refresh-token",
|
|
expires: Date.now() + 60_000,
|
|
};
|
|
});
|
|
|
|
const result = await deviceCodeMethod.run({
|
|
config: {},
|
|
env: process.env,
|
|
prompter: {
|
|
note,
|
|
progress: vi.fn(() => progress),
|
|
} as never,
|
|
runtime: runtime as never,
|
|
isRemote: true,
|
|
openUrl: async () => {},
|
|
oauth: { createVpsAwareHandlers: (() => ({})) as never },
|
|
});
|
|
|
|
expect(
|
|
requireArray(result.profiles, "remote device-code profiles").map(
|
|
(profile) => requireRecord(profile, "remote device-code profile").profileId,
|
|
),
|
|
).toContain("openai-codex:default");
|
|
|
|
return { note, runtime };
|
|
}
|
|
|
|
it("surfaces the device pairing code via the prompter note in remote (SSH) mode (#74212)", async () => {
|
|
const { note } = await runRemoteDeviceCodeAuthFlow();
|
|
|
|
expect(note).toHaveBeenCalledWith(
|
|
[
|
|
"Open this URL in your LOCAL browser and enter the code below.",
|
|
"URL: https://auth.openai.com/codex/device",
|
|
"Code: CODE-12345",
|
|
"Code expires in 15 minutes. Never share it.",
|
|
].join("\n"),
|
|
"OpenAI Codex device code",
|
|
);
|
|
expect(note).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("does not write the device pairing code to the runtime log in remote mode", async () => {
|
|
const { runtime } = await runRemoteDeviceCodeAuthFlow();
|
|
|
|
const logOutput = runtime.log.mock.calls.flat().join("\n");
|
|
expect(logOutput).toContain("https://auth.openai.com/codex/device");
|
|
expect(logOutput).not.toContain("CODE-12345");
|
|
});
|
|
|
|
it("owns native reasoning output mode for Codex responses", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
expect(
|
|
provider.resolveReasoningOutputMode?.({
|
|
provider: "openai-codex",
|
|
modelApi: "openai-codex-responses",
|
|
modelId: "gpt-5.4",
|
|
} as never),
|
|
).toBe("native");
|
|
});
|
|
|
|
it("resolves gpt-5.4 with native contextWindow plus default contextTokens cap", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.4",
|
|
modelRegistry: createSingleModelRegistry(createCodexTemplate({})) as never,
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.4",
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
});
|
|
});
|
|
|
|
it("resolves gpt-5.4-pro with pro pricing and codex-sized limits", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.4-pro",
|
|
modelRegistry: createSingleModelRegistry(createCodexTemplate({})) as never,
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.4-pro",
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
cost: { input: 30, output: 180, cacheRead: 0, cacheWrite: 0 },
|
|
});
|
|
});
|
|
|
|
it("keeps OpenClaw cost metadata but applies Codex context metadata for gpt-5.5", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.5",
|
|
modelRegistry: createSingleModelRegistry(
|
|
createCodexTemplate({
|
|
id: "gpt-5.5",
|
|
cost: { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 0 },
|
|
contextWindow: 272_000,
|
|
}),
|
|
) as never,
|
|
});
|
|
const pro = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.5-pro",
|
|
modelRegistry: createSingleModelRegistry(createCodexTemplate({ id: "gpt-5.4-pro" })) as never,
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.5",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api",
|
|
input: ["text", "image"],
|
|
contextWindow: 400_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
cost: { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 0 },
|
|
});
|
|
expectModelFields(pro, {
|
|
id: "gpt-5.5-pro",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api",
|
|
contextWindow: 1_000_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
cost: { input: 30, output: 180, cacheRead: 0, cacheWrite: 0 },
|
|
});
|
|
});
|
|
|
|
it("repairs sparse configured gpt-5.5 catalog rows to remain image-capable", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const sparseConfiguredModel = {
|
|
id: "gpt-5.5",
|
|
name: "gpt-5.5",
|
|
provider: "openai-codex",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
reasoning: false,
|
|
input: ["text"] as const,
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 8_192,
|
|
};
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.5",
|
|
modelRegistry: {
|
|
find: (providerId: string, modelId: string) =>
|
|
providerId === "openai-codex" && modelId === "gpt-5.5" ? sparseConfiguredModel : null,
|
|
} as never,
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.5",
|
|
api: "openai-codex-responses",
|
|
input: ["text", "image"],
|
|
contextWindow: 400_000,
|
|
contextTokens: 200_000,
|
|
maxTokens: 8_192,
|
|
});
|
|
});
|
|
|
|
it("synthesizes gpt-5.5 when the Codex catalog omits the OAuth row", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.5",
|
|
modelRegistry: createSingleModelRegistry(createCodexTemplate({}), null) as never,
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.5",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
contextWindow: 400_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
});
|
|
});
|
|
|
|
it("honors providerConfig.baseUrl in the gpt-5.5 synthesis fallback", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.5",
|
|
modelRegistry: createSingleModelRegistry(createCodexTemplate({}), null) as never,
|
|
providerConfig: { baseUrl: "http://proxy.local:30400" },
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.5",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "http://proxy.local:30400",
|
|
});
|
|
});
|
|
|
|
it("honors providerConfig.baseUrl in the gpt-5.4 synthesis fallback", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
const emptyRegistry = { find: () => null };
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.4",
|
|
modelRegistry: emptyRegistry as never,
|
|
providerConfig: { baseUrl: "http://proxy.local:30400" },
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.4",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "http://proxy.local:30400",
|
|
contextWindow: 1_050_000,
|
|
maxTokens: 128_000,
|
|
});
|
|
});
|
|
|
|
it("resolves gpt-5.4-pro from a gpt-5.4 runtime template when legacy codex rows are absent", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.4-pro",
|
|
modelRegistry: createSingleModelRegistry(
|
|
createCodexTemplate({
|
|
id: "gpt-5.4",
|
|
cost: { input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
}),
|
|
) as never,
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.4-pro",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api",
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
cost: { input: 30, output: 180, cacheRead: 0, cacheWrite: 0 },
|
|
});
|
|
});
|
|
|
|
it("resolves the legacy gpt-5.4-codex alias to canonical gpt-5.4", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.4-codex",
|
|
modelRegistry: createSingleModelRegistry(createCodexTemplate({})) as never,
|
|
});
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.4",
|
|
name: "gpt-5.4",
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
});
|
|
});
|
|
|
|
it("resolves gpt-5.4-mini through the Codex OAuth route", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.4-mini",
|
|
modelRegistry: createSingleModelRegistry(
|
|
createCodexTemplate({
|
|
id: "gpt-5.4",
|
|
cost: { input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
}),
|
|
null,
|
|
) as never,
|
|
} as never);
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.4-mini",
|
|
name: "gpt-5.4-mini",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api",
|
|
contextWindow: 400_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
cost: { input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0 },
|
|
});
|
|
});
|
|
|
|
it("augments catalog with gpt-5.5-pro and gpt-5.4 native metadata", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const entries = provider.augmentModelCatalog?.({
|
|
env: process.env,
|
|
entries: [
|
|
{
|
|
id: "gpt-5.3-codex",
|
|
name: "gpt-5.3-codex",
|
|
provider: "openai-codex",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
contextWindow: 272_000,
|
|
},
|
|
],
|
|
} as never);
|
|
|
|
expect(
|
|
requireArray(entries, "model catalog entries").some(
|
|
(entry) => isRecord(entry) && entry.id === "gpt-5.5",
|
|
),
|
|
).toBe(false);
|
|
expectRecordFields(requireEntryById(entries, "gpt-5.5-pro"), "gpt-5.5-pro entry", {
|
|
contextWindow: 1_000_000,
|
|
contextTokens: 272_000,
|
|
cost: { input: 30, output: 180, cacheRead: 0, cacheWrite: 0 },
|
|
});
|
|
expectRecordFields(requireEntryById(entries, "gpt-5.4"), "gpt-5.4 entry", {
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
cost: { input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 0 },
|
|
});
|
|
expectRecordFields(requireEntryById(entries, "gpt-5.4-pro"), "gpt-5.4-pro entry", {
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
cost: { input: 30, output: 180, cacheRead: 0, cacheWrite: 0 },
|
|
});
|
|
expectRecordFields(requireEntryById(entries, "gpt-5.4-mini"), "gpt-5.4-mini entry", {
|
|
contextWindow: 400_000,
|
|
contextTokens: 272_000,
|
|
cost: { input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0 },
|
|
});
|
|
});
|
|
|
|
it("augments gpt-5.4-pro from catalog gpt-5.4 when legacy codex rows are absent", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const entries = provider.augmentModelCatalog?.({
|
|
env: process.env,
|
|
entries: [
|
|
{
|
|
id: "gpt-5.4",
|
|
name: "gpt-5.4",
|
|
provider: "openai-codex",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
contextWindow: 272_000,
|
|
},
|
|
],
|
|
} as never);
|
|
|
|
expectRecordFields(requireEntryById(entries, "gpt-5.4-pro"), "gpt-5.4-pro entry", {
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
cost: { input: 30, output: 180, cacheRead: 0, cacheWrite: 0 },
|
|
});
|
|
});
|
|
|
|
it("canonicalizes legacy gpt-5.4-codex models during resolved-model normalization", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.normalizeResolvedModel?.({
|
|
provider: "openai-codex",
|
|
model: {
|
|
id: "gpt-5.4-codex",
|
|
name: "gpt-5.4-codex",
|
|
provider: "openai-codex",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
},
|
|
} as never);
|
|
|
|
expectModelFields(model, {
|
|
id: "gpt-5.4",
|
|
name: "gpt-5.4",
|
|
});
|
|
});
|
|
|
|
it("defaults missing codex api metadata to openai-codex-responses", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.normalizeResolvedModel?.({
|
|
provider: "openai-codex",
|
|
model: {
|
|
id: "gpt-5.4",
|
|
name: "gpt-5.4",
|
|
provider: "openai-codex",
|
|
baseUrl: "https://chatgpt.com/backend-api",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
},
|
|
} as never);
|
|
|
|
expectModelFields(model, {
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("normalizes stale /backend-api/v1 codex metadata to the canonical base url", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.normalizeResolvedModel?.({
|
|
provider: "openai-codex",
|
|
model: {
|
|
id: "gpt-5.4",
|
|
name: "gpt-5.4",
|
|
provider: "openai-codex",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/v1",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
},
|
|
} as never);
|
|
|
|
expectModelFields(model, {
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("normalizes legacy completions metadata to the codex transport", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.normalizeResolvedModel?.({
|
|
provider: "openai-codex",
|
|
model: {
|
|
id: "gpt-5.4",
|
|
name: "gpt-5.4",
|
|
provider: "openai-codex",
|
|
api: "openai-completions",
|
|
baseUrl: "https://api.openai.com/v1",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
},
|
|
} as never);
|
|
|
|
expectModelFields(model, {
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("normalizes legacy GitHub Copilot Codex metadata to the codex transport", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.normalizeResolvedModel?.({
|
|
provider: "openai-codex",
|
|
model: {
|
|
id: "gpt-5.4",
|
|
name: "gpt-5.4",
|
|
provider: "openai-codex",
|
|
api: "openai-completions",
|
|
baseUrl: "https://api.githubcopilot.com",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
},
|
|
} as never);
|
|
|
|
expectModelFields(model, {
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("restores [text,image] input on stale gpt-5.5 rows that omit the input field", () => {
|
|
// Regression: persisted/configured catalog rows can omit the `input` field
|
|
// for openai-codex models. When that row wins the catalog merge,
|
|
// `modelSupportsInput(entry, "image")` returns false and the gateway routes
|
|
// inbound images down the claim-check offload path (`media://inbound/<id>`)
|
|
// instead of inlining them. Mirror of the Anthropic precedent set by
|
|
// upstream #83756.
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.normalizeResolvedModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.5",
|
|
model: {
|
|
id: "gpt-5.5",
|
|
name: "gpt-5.5",
|
|
provider: "openai-codex",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
reasoning: true,
|
|
// No `input` field at all — the stale persisted/configured row shape.
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
},
|
|
} as never);
|
|
|
|
expect(model?.input).toEqual(["text", "image"]);
|
|
});
|
|
|
|
it("preserves [text,image] input on rows that already declare image capability", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.normalizeResolvedModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.5",
|
|
model: {
|
|
id: "gpt-5.5",
|
|
name: "gpt-5.5",
|
|
provider: "openai-codex",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1_050_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
},
|
|
} as never);
|
|
|
|
// Existing image capability untouched; transport is already canonical so
|
|
// normalizeResolvedModel may return undefined (no-op).
|
|
if (model) {
|
|
expect(model.input).toEqual(["text", "image"]);
|
|
}
|
|
});
|
|
|
|
it("leaves codex-suffix and legacy model rows text-only (not vision-capable)", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
const model = provider.normalizeResolvedModel?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.3-codex",
|
|
model: {
|
|
id: "gpt-5.3-codex",
|
|
name: "gpt-5.3-codex",
|
|
provider: "openai-codex",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
reasoning: true,
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 400_000,
|
|
contextTokens: 272_000,
|
|
maxTokens: 128_000,
|
|
},
|
|
} as never);
|
|
|
|
// No image capability should be added — gpt-5.X-codex models are
|
|
// Codex CLI / agent-mode only and not in the documented vision list.
|
|
// normalizeResolvedModel may return undefined (no transport change) or a
|
|
// model with the existing input array; either way `image` must not appear.
|
|
if (model?.input) {
|
|
expect(model.input).not.toContain("image");
|
|
}
|
|
});
|
|
|
|
it("normalizes transport metadata for stale /backend-api/v1 codex routes", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
expect(
|
|
provider.normalizeTransport?.({
|
|
provider: "openai-codex",
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/v1",
|
|
} as never),
|
|
).toEqual({
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("normalizes transport metadata for legacy completions codex routes", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
expect(
|
|
provider.normalizeTransport?.({
|
|
provider: "openai-codex",
|
|
api: "openai-completions",
|
|
baseUrl: "https://api.openai.com/v1",
|
|
} as never),
|
|
).toEqual({
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("normalizes transport metadata for legacy GitHub Copilot Codex routes", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
expect(
|
|
provider.normalizeTransport?.({
|
|
provider: "openai-codex",
|
|
api: "openai-completions",
|
|
baseUrl: "https://api.githubcopilot.com/v1",
|
|
} as never),
|
|
).toEqual({
|
|
api: "openai-codex-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("leaves custom proxy completions transport metadata unchanged", () => {
|
|
const provider = buildOpenAICodexProviderPlugin();
|
|
|
|
expect(
|
|
provider.normalizeTransport?.({
|
|
provider: "openai-codex",
|
|
api: "openai-completions",
|
|
baseUrl: "https://proxy.example.com/v1",
|
|
} as never),
|
|
).toBeUndefined();
|
|
});
|
|
});
|