Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
238 lines
7.4 KiB
TypeScript
238 lines
7.4 KiB
TypeScript
// Openai tests cover openai chatgpt provider plugin behavior.
|
|
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const refreshOpenAICodexTokenMock = vi.hoisted(() => vi.fn());
|
|
const loginOpenAICodexDeviceCodeMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("./openai-chatgpt-provider.runtime.js", () => ({
|
|
refreshOpenAICodexToken: refreshOpenAICodexTokenMock,
|
|
}));
|
|
|
|
vi.mock("./openai-chatgpt-device-code.js", () => ({
|
|
loginOpenAICodexDeviceCode: loginOpenAICodexDeviceCodeMock,
|
|
}));
|
|
|
|
let buildOpenAIProvider: typeof import("./openai-provider.js").buildOpenAIProvider;
|
|
|
|
describe("OpenAI provider Codex transport hooks", () => {
|
|
beforeAll(async () => {
|
|
({ buildOpenAIProvider } = await import("./openai-provider.js"));
|
|
});
|
|
|
|
beforeEach(() => {
|
|
refreshOpenAICodexTokenMock.mockReset();
|
|
loginOpenAICodexDeviceCodeMock.mockReset();
|
|
});
|
|
|
|
it("exposes ChatGPT OAuth on the canonical OpenAI provider", () => {
|
|
const provider = buildOpenAIProvider();
|
|
|
|
expect(provider.id).toBe("openai");
|
|
expect(provider.aliases).toBeUndefined();
|
|
expect(provider.hookAliases).toEqual(["azure-openai", "azure-openai-responses"]);
|
|
expect(provider.auth?.map((method) => method.id)).toEqual(["oauth", "device-code", "api-key"]);
|
|
expect(provider.auth?.map((method) => method.wizard?.choiceId)).toEqual([
|
|
"openai",
|
|
"openai-device-code",
|
|
"openai-api-key",
|
|
]);
|
|
expect(provider.oauthProfileIdRepairs).toBeUndefined();
|
|
});
|
|
|
|
it("stores device-code logins as OpenAI OAuth profiles", async () => {
|
|
const provider = buildOpenAIProvider();
|
|
const deviceCodeMethod = provider.auth?.find((method) => method.id === "device-code");
|
|
loginOpenAICodexDeviceCodeMock.mockResolvedValueOnce({
|
|
access: "access-token",
|
|
refresh: "refresh-token",
|
|
expires: 1_700_000_000_000,
|
|
});
|
|
|
|
const result = await deviceCodeMethod?.run({
|
|
isRemote: false,
|
|
openUrl: vi.fn(async () => {}),
|
|
prompter: {
|
|
note: vi.fn(async () => {}),
|
|
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
|
},
|
|
runtime: { log: vi.fn(), error: vi.fn() },
|
|
config: {},
|
|
oauth: {},
|
|
} as never);
|
|
|
|
expect(result?.profiles?.[0]).toMatchObject({
|
|
profileId: "openai:default",
|
|
credential: {
|
|
type: "oauth",
|
|
provider: "openai",
|
|
access: "access-token",
|
|
refresh: "refresh-token",
|
|
},
|
|
});
|
|
});
|
|
|
|
it("routes Codex-backed OpenAI models through the Codex Responses transport", () => {
|
|
const provider = buildOpenAIProvider();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai",
|
|
modelId: "gpt-5.4",
|
|
providerConfig: { api: "openai-chatgpt-responses" },
|
|
modelRegistry: { find: () => null },
|
|
} as never);
|
|
|
|
expect(model).toMatchObject({
|
|
provider: "openai",
|
|
id: "gpt-5.4",
|
|
api: "openai-chatgpt-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it.each(["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"])(
|
|
"resolves %s through the Codex Responses transport without live catalog metadata",
|
|
(modelId) => {
|
|
const provider = buildOpenAIProvider();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai",
|
|
modelId,
|
|
authProfileMode: "oauth",
|
|
modelRegistry: { find: () => null },
|
|
} as never);
|
|
|
|
expect(model).toMatchObject({
|
|
provider: "openai",
|
|
id: modelId,
|
|
api: "openai-chatgpt-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
input: ["text", "image"],
|
|
contextWindow: 372_000,
|
|
contextTokens: 372_000,
|
|
maxTokens: 128_000,
|
|
thinkingLevelMap: { off: null, xhigh: "xhigh", max: "max" },
|
|
});
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
{ name: "fills a missing map", thinkingLevelMap: undefined, expectedOff: null },
|
|
{ name: "preserves explicit overrides", thinkingLevelMap: { off: "low" }, expectedOff: "low" },
|
|
])("$name on registry-backed GPT-5.6 models", ({ thinkingLevelMap, expectedOff }) => {
|
|
const provider = buildOpenAIProvider();
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai",
|
|
modelId: "gpt-5.6-luna",
|
|
authProfileMode: "oauth",
|
|
modelRegistry: {
|
|
find: () => ({
|
|
id: "gpt-5.6-luna",
|
|
name: "GPT-5.6 Luna",
|
|
provider: "openai",
|
|
api: "openai-responses",
|
|
baseUrl: "https://api.openai.com/v1",
|
|
reasoning: true,
|
|
input: ["text"],
|
|
cost: { input: 1, output: 6, cacheRead: 0.1, cacheWrite: 1.25 },
|
|
contextWindow: 372_000,
|
|
maxTokens: 128_000,
|
|
...(thinkingLevelMap ? { thinkingLevelMap } : {}),
|
|
}),
|
|
},
|
|
} as never);
|
|
|
|
expect(model).toMatchObject({
|
|
api: "openai-chatgpt-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
input: ["text", "image"],
|
|
thinkingLevelMap: { off: expectedOff, xhigh: "xhigh", max: "max" },
|
|
});
|
|
});
|
|
|
|
it("keeps default Codex-backed OpenAI catalog models on the Codex Responses transport", () => {
|
|
const provider = buildOpenAIProvider();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai",
|
|
modelId: "gpt-5.5",
|
|
providerConfig: { api: "openai-chatgpt-responses" },
|
|
modelRegistry: {
|
|
find: () => ({
|
|
provider: "openai",
|
|
id: "gpt-5.5",
|
|
name: "gpt-5.5",
|
|
api: "openai-responses",
|
|
baseUrl: "https://api.openai.com/v1",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 1, output: 1, cacheRead: 1, cacheWrite: 1 },
|
|
contextWindow: 400_000,
|
|
maxTokens: 128_000,
|
|
}),
|
|
},
|
|
} as never);
|
|
|
|
expect(model).toMatchObject({
|
|
provider: "openai",
|
|
id: "gpt-5.5",
|
|
api: "openai-chatgpt-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("keeps cloned Codex-backed OpenAI models on the Codex Responses transport", () => {
|
|
const provider = buildOpenAIProvider();
|
|
|
|
const model = provider.resolveDynamicModel?.({
|
|
provider: "openai",
|
|
modelId: "gpt-5.4",
|
|
providerConfig: { api: "openai-chatgpt-responses" },
|
|
modelRegistry: {
|
|
find: () => ({
|
|
provider: "openai",
|
|
id: "gpt-5.4",
|
|
name: "gpt-5.4",
|
|
api: "openai-responses",
|
|
baseUrl: "https://api.openai.com/v1",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 1, output: 1, cacheRead: 1, cacheWrite: 1 },
|
|
contextWindow: 128_000,
|
|
maxTokens: 16_384,
|
|
}),
|
|
},
|
|
} as never);
|
|
|
|
expect(model).toMatchObject({
|
|
provider: "openai",
|
|
id: "gpt-5.4",
|
|
api: "openai-chatgpt-responses",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
});
|
|
});
|
|
|
|
it("refreshes ChatGPT OAuth credentials under the OpenAI provider", async () => {
|
|
const provider = buildOpenAIProvider();
|
|
refreshOpenAICodexTokenMock.mockResolvedValueOnce({
|
|
access: "new-access",
|
|
refresh: "new-refresh",
|
|
expires: 1_700_000_000_000,
|
|
});
|
|
|
|
await expect(
|
|
provider.refreshOAuth?.({
|
|
type: "oauth",
|
|
provider: "openai",
|
|
access: "old-access",
|
|
refresh: "old-refresh",
|
|
expires: Date.now() - 60_000,
|
|
}),
|
|
).resolves.toMatchObject({
|
|
type: "oauth",
|
|
provider: "openai",
|
|
access: "new-access",
|
|
refresh: "new-refresh",
|
|
});
|
|
});
|
|
});
|