Vendor OpenClaw source as Adolf fork baseline
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
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
This commit is contained in:
601
extensions/openai/index.test.ts
Normal file
601
extensions/openai/index.test.ts
Normal file
@@ -0,0 +1,601 @@
|
||||
// Openai tests cover index plugin behavior.
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
||||
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
||||
import { requireRegisteredProvider } from "openclaw/plugin-sdk/plugin-test-runtime";
|
||||
import * as providerAuth from "openclaw/plugin-sdk/provider-auth-runtime";
|
||||
import * as providerHttp from "openclaw/plugin-sdk/provider-http";
|
||||
import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { buildOpenAIImageGenerationProvider } from "./image-generation-provider.js";
|
||||
import plugin from "./index.js";
|
||||
import {
|
||||
OPENAI_FRIENDLY_PROMPT_OVERLAY,
|
||||
OPENAI_GPT5_BEHAVIOR_CONTRACT,
|
||||
OPENAI_HEARTBEAT_PROMPT_OVERLAY,
|
||||
shouldApplyOpenAIPromptOverlay,
|
||||
} from "./prompt-overlay.js";
|
||||
|
||||
const runtimeMocks = vi.hoisted(() => ({
|
||||
ensureGlobalUndiciEnvProxyDispatcher: vi.fn(),
|
||||
refreshOpenAICodexToken: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/runtime-env", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/runtime-env")>(
|
||||
"openclaw/plugin-sdk/runtime-env",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
ensureGlobalUndiciEnvProxyDispatcher: runtimeMocks.ensureGlobalUndiciEnvProxyDispatcher,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./openai-chatgpt-oauth-flow.runtime.js", () => ({
|
||||
refreshOpenAICodexToken: runtimeMocks.refreshOpenAICodexToken,
|
||||
}));
|
||||
|
||||
import { createOpenAICodexProviderRuntime } from "./openai-chatgpt-provider.runtime.js";
|
||||
async function registerOpenAIPluginWithHook(params?: { pluginConfig?: Record<string, unknown> }) {
|
||||
const on = vi.fn();
|
||||
const providers: ProviderPlugin[] = [];
|
||||
plugin.register(
|
||||
createTestPluginApi({
|
||||
id: "openai",
|
||||
name: "OpenAI Provider",
|
||||
source: "test",
|
||||
config: {},
|
||||
runtime: {} as never,
|
||||
pluginConfig: params?.pluginConfig,
|
||||
on,
|
||||
registerProvider: (provider) => {
|
||||
providers.push(provider);
|
||||
},
|
||||
}),
|
||||
);
|
||||
return { on, providers };
|
||||
}
|
||||
|
||||
function expectOpenAIPromptContribution(
|
||||
provider: ProviderPlugin,
|
||||
sectionOverrides: Record<string, unknown>,
|
||||
contextOverrides: Partial<
|
||||
Parameters<NonNullable<ProviderPlugin["resolveSystemPromptContribution"]>>[0]
|
||||
> = {},
|
||||
) {
|
||||
expect(
|
||||
provider.resolveSystemPromptContribution?.({
|
||||
config: undefined,
|
||||
agentDir: undefined,
|
||||
workspaceDir: undefined,
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
promptMode: "full",
|
||||
runtimeChannel: undefined,
|
||||
runtimeCapabilities: undefined,
|
||||
agentId: undefined,
|
||||
...contextOverrides,
|
||||
}),
|
||||
).toEqual({
|
||||
stablePrefix: OPENAI_GPT5_BEHAVIOR_CONTRACT,
|
||||
sectionOverrides,
|
||||
});
|
||||
}
|
||||
|
||||
function mockOpenAIImageApiResponse(params: {
|
||||
finalUrl: string;
|
||||
imageData: string;
|
||||
revisedPrompt?: string;
|
||||
}) {
|
||||
const response = () =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: [
|
||||
{
|
||||
b64_json: Buffer.from(params.imageData).toString("base64"),
|
||||
...(params.revisedPrompt ? { revised_prompt: params.revisedPrompt } : {}),
|
||||
},
|
||||
],
|
||||
}),
|
||||
{ status: 200, headers: { "Content-Type": "application/json" } },
|
||||
);
|
||||
const resolveApiKeySpy = vi.spyOn(providerAuth, "resolveApiKeyForProvider").mockResolvedValue({
|
||||
apiKey: "sk-test",
|
||||
source: "env",
|
||||
mode: "api-key",
|
||||
});
|
||||
const postJsonRequestSpy = vi.spyOn(providerHttp, "postJsonRequest").mockResolvedValue({
|
||||
finalUrl: params.finalUrl,
|
||||
response: response(),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
const postMultipartRequestSpy = vi.spyOn(providerHttp, "postMultipartRequest").mockResolvedValue({
|
||||
finalUrl: params.finalUrl,
|
||||
response: response(),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
vi.spyOn(providerHttp, "assertOkOrThrowHttpError").mockResolvedValue(undefined);
|
||||
return { resolveApiKeySpy, postJsonRequestSpy, postMultipartRequestSpy };
|
||||
}
|
||||
|
||||
function firstMockArg(mocked: unknown): Record<string, unknown> {
|
||||
const arg = (mocked as { mock?: { calls?: unknown[][] } }).mock?.calls?.[0]?.[0];
|
||||
if (!arg || typeof arg !== "object") {
|
||||
throw new Error("Expected first mock argument");
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function mockCalls(mocked: unknown): unknown[][] {
|
||||
return (mocked as { mock?: { calls?: unknown[][] } }).mock?.calls ?? [];
|
||||
}
|
||||
|
||||
function expectNoBeforePromptBuildHook(on: unknown): void {
|
||||
const hasBeforePromptBuild = mockCalls(on).some((call) => call[0] === "before_prompt_build");
|
||||
expect(hasBeforePromptBuild).toBe(false);
|
||||
}
|
||||
|
||||
function expectNoRequestUrl(mocked: unknown, url: string): void {
|
||||
const hasUrl = mockCalls(mocked).some((call) => {
|
||||
const arg = call[0] as { url?: unknown } | undefined;
|
||||
return arg?.url === url;
|
||||
});
|
||||
expect(hasUrl).toBe(false);
|
||||
}
|
||||
|
||||
describe("openai plugin", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("generates PNG buffers from the OpenAI Images API", async () => {
|
||||
const { resolveApiKeySpy, postJsonRequestSpy } = mockOpenAIImageApiResponse({
|
||||
finalUrl: "https://api.openai.com/v1/images/generations",
|
||||
imageData: "png-data",
|
||||
revisedPrompt: "revised",
|
||||
});
|
||||
|
||||
const provider = buildOpenAIImageGenerationProvider();
|
||||
const authStore = { version: 1, profiles: {} };
|
||||
const result = await provider.generateImage({
|
||||
provider: "openai",
|
||||
model: "gpt-image-2",
|
||||
prompt: "draw a cat",
|
||||
cfg: {},
|
||||
authStore,
|
||||
count: 2,
|
||||
size: "2048x2048",
|
||||
});
|
||||
|
||||
const authArgs = firstMockArg(resolveApiKeySpy);
|
||||
expect(authArgs.provider).toBe("openai");
|
||||
expect(authArgs.store).toBe(authStore);
|
||||
const requestArgs = firstMockArg(postJsonRequestSpy);
|
||||
expect(requestArgs.url).toBe("https://api.openai.com/v1/images/generations");
|
||||
expect(requestArgs.body).toEqual({
|
||||
model: "gpt-image-2",
|
||||
prompt: "draw a cat",
|
||||
n: 2,
|
||||
size: "2048x2048",
|
||||
});
|
||||
expectNoRequestUrl(postJsonRequestSpy, "https://api.openai.com/v1/images/edits");
|
||||
expect(result).toEqual({
|
||||
images: [
|
||||
{
|
||||
buffer: Buffer.from("png-data"),
|
||||
mimeType: "image/png",
|
||||
fileName: "image-1.png",
|
||||
revisedPrompt: "revised",
|
||||
},
|
||||
],
|
||||
model: "gpt-image-2",
|
||||
});
|
||||
});
|
||||
|
||||
it("submits reference-image edits to the OpenAI Images edits endpoint", async () => {
|
||||
const { resolveApiKeySpy, postJsonRequestSpy, postMultipartRequestSpy } =
|
||||
mockOpenAIImageApiResponse({
|
||||
finalUrl: "https://api.openai.com/v1/images/edits",
|
||||
imageData: "edited-image",
|
||||
});
|
||||
|
||||
const provider = buildOpenAIImageGenerationProvider();
|
||||
const authStore = { version: 1, profiles: {} };
|
||||
|
||||
const result = await provider.generateImage({
|
||||
provider: "openai",
|
||||
model: "gpt-image-2",
|
||||
prompt: "Edit this image",
|
||||
cfg: {},
|
||||
authStore,
|
||||
count: 2,
|
||||
size: "1536x1024",
|
||||
inputImages: [
|
||||
{ buffer: Buffer.from("x"), mimeType: "image/png" },
|
||||
{ buffer: Buffer.from("y"), mimeType: "image/jpeg", fileName: "ref.jpg" },
|
||||
],
|
||||
});
|
||||
|
||||
const authArgs = firstMockArg(resolveApiKeySpy);
|
||||
expect(authArgs.provider).toBe("openai");
|
||||
expect(authArgs.store).toBe(authStore);
|
||||
const multipartArgs = firstMockArg(postMultipartRequestSpy);
|
||||
expect(multipartArgs.url).toBe("https://api.openai.com/v1/images/edits");
|
||||
expect(multipartArgs.body).toBeInstanceOf(FormData);
|
||||
expect(multipartArgs.allowPrivateNetwork).toBe(false);
|
||||
expect(multipartArgs.dispatcherPolicy).toBeUndefined();
|
||||
expect(multipartArgs.fetchFn).toBe(fetch);
|
||||
const editCallArgs = multipartArgs as unknown as {
|
||||
headers: Headers;
|
||||
body: FormData;
|
||||
};
|
||||
expect(editCallArgs.headers.has("Content-Type")).toBe(false);
|
||||
const form = editCallArgs.body;
|
||||
expect(form.get("model")).toBe("gpt-image-2");
|
||||
expect(form.get("prompt")).toBe("Edit this image");
|
||||
expect(form.get("n")).toBe("2");
|
||||
expect(form.get("size")).toBe("1536x1024");
|
||||
const images = form.getAll("image[]") as File[];
|
||||
expect(images).toHaveLength(2);
|
||||
expect(images[0]?.name).toBe("image-1.png");
|
||||
expect(images[0]?.type).toBe("image/png");
|
||||
expect(images[1]?.name).toBe("ref.jpg");
|
||||
expect(images[1]?.type).toBe("image/jpeg");
|
||||
expectNoRequestUrl(postJsonRequestSpy, "https://api.openai.com/v1/images/edits");
|
||||
expect(result).toEqual({
|
||||
images: [
|
||||
{
|
||||
buffer: Buffer.from("edited-image"),
|
||||
mimeType: "image/png",
|
||||
fileName: "image-1.png",
|
||||
},
|
||||
],
|
||||
model: "gpt-image-2",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not allow private-network routing just because a custom base URL is configured", async () => {
|
||||
vi.spyOn(providerAuth, "resolveApiKeyForProvider").mockResolvedValue({
|
||||
apiKey: "sk-test",
|
||||
source: "env",
|
||||
mode: "api-key",
|
||||
});
|
||||
const fetchMock = vi.fn();
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
const provider = buildOpenAIImageGenerationProvider();
|
||||
await expect(
|
||||
provider.generateImage({
|
||||
provider: "openai",
|
||||
model: "gpt-image-2",
|
||||
prompt: "draw a cat",
|
||||
cfg: {
|
||||
models: {
|
||||
providers: {
|
||||
openai: {
|
||||
baseUrl: "http://127.0.0.1:8080/v1",
|
||||
models: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies OpenClawConfig,
|
||||
}),
|
||||
).rejects.toThrow("Blocked hostname or private/internal/special-use IP address");
|
||||
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("bootstraps the env proxy dispatcher before refreshing codex oauth credentials", async () => {
|
||||
const refreshed = {
|
||||
access: "next-access",
|
||||
refresh: "next-refresh",
|
||||
expires: Date.now() + 60_000,
|
||||
};
|
||||
runtimeMocks.refreshOpenAICodexToken.mockResolvedValue(refreshed);
|
||||
const runtime = createOpenAICodexProviderRuntime({
|
||||
ensureGlobalUndiciEnvProxyDispatcher: runtimeMocks.ensureGlobalUndiciEnvProxyDispatcher,
|
||||
getOAuthApiKey: vi.fn(),
|
||||
refreshOpenAICodexToken: runtimeMocks.refreshOpenAICodexToken,
|
||||
});
|
||||
|
||||
await expect(runtime.refreshOpenAICodexToken("refresh-token")).resolves.toBe(refreshed);
|
||||
|
||||
expect(runtimeMocks.ensureGlobalUndiciEnvProxyDispatcher).toHaveBeenCalledOnce();
|
||||
expect(runtimeMocks.refreshOpenAICodexToken).toHaveBeenCalledOnce();
|
||||
expect(
|
||||
runtimeMocks.ensureGlobalUndiciEnvProxyDispatcher.mock.invocationCallOrder[0],
|
||||
).toBeLessThan(runtimeMocks.refreshOpenAICodexToken.mock.invocationCallOrder[0]);
|
||||
});
|
||||
|
||||
it("registers provider-owned OpenAI tool compat hooks for API and Codex transports", async () => {
|
||||
const { providers } = await registerOpenAIPluginWithHook();
|
||||
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
||||
const noParamsTool = {
|
||||
name: "ping",
|
||||
description: "",
|
||||
parameters: {},
|
||||
execute: vi.fn(),
|
||||
} as never;
|
||||
|
||||
const normalizedOpenAI = openaiProvider.normalizeToolSchemas?.({
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
modelApi: "openai-responses",
|
||||
model: {
|
||||
provider: "openai",
|
||||
api: "openai-responses",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
id: "gpt-5.4",
|
||||
} as never,
|
||||
tools: [noParamsTool],
|
||||
} as never);
|
||||
const normalizedCodex = openaiProvider.normalizeToolSchemas?.({
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
modelApi: "openai-chatgpt-responses",
|
||||
model: {
|
||||
provider: "openai",
|
||||
api: "openai-chatgpt-responses",
|
||||
baseUrl: "https://chatgpt.com/backend-api",
|
||||
id: "gpt-5.4",
|
||||
} as never,
|
||||
tools: [noParamsTool],
|
||||
} as never);
|
||||
|
||||
expect(normalizedOpenAI?.[0]?.parameters).toEqual({
|
||||
type: "object",
|
||||
properties: {},
|
||||
required: [],
|
||||
additionalProperties: false,
|
||||
});
|
||||
expect(normalizedCodex?.[0]?.parameters).toEqual({
|
||||
type: "object",
|
||||
properties: {},
|
||||
required: [],
|
||||
additionalProperties: false,
|
||||
});
|
||||
expect(
|
||||
openaiProvider.inspectToolSchemas?.({
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
modelApi: "openai-responses",
|
||||
model: {
|
||||
provider: "openai",
|
||||
api: "openai-responses",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
id: "gpt-5.4",
|
||||
} as never,
|
||||
tools: [noParamsTool],
|
||||
} as never),
|
||||
).toStrictEqual([]);
|
||||
expect(
|
||||
openaiProvider.inspectToolSchemas?.({
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
modelApi: "openai-chatgpt-responses",
|
||||
model: {
|
||||
provider: "openai",
|
||||
api: "openai-chatgpt-responses",
|
||||
baseUrl: "https://chatgpt.com/backend-api",
|
||||
id: "gpt-5.4",
|
||||
} as never,
|
||||
tools: [noParamsTool],
|
||||
} as never),
|
||||
).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("registers GPT-5 system prompt contributions when the friendly overlay is enabled", async () => {
|
||||
const { on, providers } = await registerOpenAIPluginWithHook({
|
||||
pluginConfig: { personality: "friendly" },
|
||||
});
|
||||
|
||||
expectNoBeforePromptBuildHook(on);
|
||||
|
||||
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
||||
const contributionContext: Parameters<
|
||||
NonNullable<ProviderPlugin["resolveSystemPromptContribution"]>
|
||||
>[0] = {
|
||||
config: undefined,
|
||||
agentDir: undefined,
|
||||
workspaceDir: undefined,
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
promptMode: "full",
|
||||
runtimeChannel: undefined,
|
||||
runtimeCapabilities: undefined,
|
||||
agentId: undefined,
|
||||
};
|
||||
|
||||
expect(openaiProvider.resolveSystemPromptContribution?.(contributionContext)).toEqual({
|
||||
stablePrefix: OPENAI_GPT5_BEHAVIOR_CONTRACT,
|
||||
sectionOverrides: {
|
||||
interaction_style: OPENAI_FRIENDLY_PROMPT_OVERLAY,
|
||||
},
|
||||
});
|
||||
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain("Live chat tone: short, natural, human.");
|
||||
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
|
||||
"Avoid memo voice, long preambles, walls of text, and repetitive restatement.",
|
||||
);
|
||||
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain("Show grounded emotional range when it fits");
|
||||
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
|
||||
"Occasional emoji are fine when they fit naturally, especially for warmth or brief celebration; keep them sparse.",
|
||||
);
|
||||
expect(
|
||||
openaiProvider.resolveSystemPromptContribution?.({
|
||||
...contributionContext,
|
||||
trigger: "heartbeat",
|
||||
}),
|
||||
).toEqual({
|
||||
stablePrefix: OPENAI_GPT5_BEHAVIOR_CONTRACT,
|
||||
sectionOverrides: {
|
||||
interaction_style: `${OPENAI_FRIENDLY_PROMPT_OVERLAY}\n\n${OPENAI_HEARTBEAT_PROMPT_OVERLAY}`,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
openaiProvider.resolveSystemPromptContribution?.({
|
||||
...contributionContext,
|
||||
modelId: "openai/gpt-5.4-mini",
|
||||
}),
|
||||
).toEqual({
|
||||
stablePrefix: OPENAI_GPT5_BEHAVIOR_CONTRACT,
|
||||
sectionOverrides: {
|
||||
interaction_style: OPENAI_FRIENDLY_PROMPT_OVERLAY,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
openaiProvider.resolveSystemPromptContribution?.({
|
||||
...contributionContext,
|
||||
modelId: "gpt-image-1",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
expect(shouldApplyOpenAIPromptOverlay({ modelProviderId: "openai", modelId: "gpt-4.1" })).toBe(
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
shouldApplyOpenAIPromptOverlay({ modelProviderId: "anthropic", modelId: "gpt-5.4" }),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("includes the tagged GPT-5 behavior contract in the OpenAI prompt overlay", () => {
|
||||
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain("Keep progress updates concrete.");
|
||||
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
|
||||
'Brief first-person feeling language is ok when useful: "I\'m glad we caught that", "I\'m excited about this direction", "I\'m worried this will break", "that\'s frustrating".',
|
||||
);
|
||||
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).not.toContain(
|
||||
"Use heartbeats to create useful proactive progress",
|
||||
);
|
||||
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
|
||||
"Use heartbeats to create useful proactive progress, not chatter.",
|
||||
);
|
||||
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
|
||||
"Treat a heartbeat as a wake-up: orient, read HEARTBEAT.md when present, then do what is actually useful now.",
|
||||
);
|
||||
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
|
||||
"If HEARTBEAT.md assigns concrete or ongoing work, execute its spirit with judgment.",
|
||||
);
|
||||
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
|
||||
"Prefer meaningful action over commentary. A good heartbeat often looks like silent progress.",
|
||||
);
|
||||
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
|
||||
'Do not send "same state", "no change", "still", or repetitive summaries because a problem continues.',
|
||||
);
|
||||
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
|
||||
"Notify only for something worth interrupting the user",
|
||||
);
|
||||
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
|
||||
"Occasional emoji are fine when they fit naturally, especially for warmth or brief celebration; keep them sparse.",
|
||||
);
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain("<persona_latch>");
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain("<execution_policy>");
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain("<tool_discipline>");
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain("<output_contract>");
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain("<completion_contract>");
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain(
|
||||
"For irreversible, external, destructive, or privacy-sensitive actions: ask first.",
|
||||
);
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain(
|
||||
"Prefer tool evidence over recall when action, state, or mutable facts matter.",
|
||||
);
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain(
|
||||
"If more tool work would likely change the answer, do it before replying.",
|
||||
);
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain("Return requested sections/order only.");
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).toContain(
|
||||
"Treat the task as incomplete until every requested item is handled",
|
||||
);
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).not.toContain("/approve");
|
||||
expect(OPENAI_GPT5_BEHAVIOR_CONTRACT).not.toContain("GPT-5 Output Contract");
|
||||
});
|
||||
|
||||
it("defaults to the friendly OpenAI interaction-style overlay", async () => {
|
||||
const { on, providers } = await registerOpenAIPluginWithHook();
|
||||
|
||||
expectNoBeforePromptBuildHook(on);
|
||||
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
||||
expectOpenAIPromptContribution(openaiProvider, {
|
||||
interaction_style: OPENAI_FRIENDLY_PROMPT_OVERLAY,
|
||||
});
|
||||
});
|
||||
|
||||
it("supports opting out of the friendly prompt overlay via plugin config", async () => {
|
||||
const { on, providers } = await registerOpenAIPluginWithHook({
|
||||
pluginConfig: { personality: "off" },
|
||||
});
|
||||
|
||||
expectNoBeforePromptBuildHook(on);
|
||||
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
||||
expectOpenAIPromptContribution(openaiProvider, {});
|
||||
});
|
||||
|
||||
it("treats mixed-case off values as disabling the friendly prompt overlay", async () => {
|
||||
const { providers } = await registerOpenAIPluginWithHook({
|
||||
pluginConfig: { personality: "Off" },
|
||||
});
|
||||
|
||||
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
||||
expectOpenAIPromptContribution(openaiProvider, {});
|
||||
});
|
||||
|
||||
it("supports explicitly configuring the friendly prompt overlay", async () => {
|
||||
const { on, providers } = await registerOpenAIPluginWithHook({
|
||||
pluginConfig: { personality: "friendly" },
|
||||
});
|
||||
|
||||
expectNoBeforePromptBuildHook(on);
|
||||
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
||||
expectOpenAIPromptContribution(openaiProvider, {
|
||||
interaction_style: OPENAI_FRIENDLY_PROMPT_OVERLAY,
|
||||
});
|
||||
});
|
||||
|
||||
it("uses live plugin config for GPT-5 prompt overlay mode", async () => {
|
||||
const { providers } = await registerOpenAIPluginWithHook({
|
||||
pluginConfig: { personality: "off" },
|
||||
});
|
||||
|
||||
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
||||
expect(
|
||||
openaiProvider.resolveSystemPromptContribution?.({
|
||||
config: {
|
||||
plugins: {
|
||||
entries: {
|
||||
openai: {
|
||||
config: {
|
||||
personality: "friendly",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
agentDir: undefined,
|
||||
workspaceDir: undefined,
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
promptMode: "full",
|
||||
runtimeChannel: undefined,
|
||||
runtimeCapabilities: undefined,
|
||||
agentId: undefined,
|
||||
}),
|
||||
).toEqual({
|
||||
stablePrefix: OPENAI_GPT5_BEHAVIOR_CONTRACT,
|
||||
sectionOverrides: {
|
||||
interaction_style: OPENAI_FRIENDLY_PROMPT_OVERLAY,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("treats on as an alias for the friendly prompt overlay", async () => {
|
||||
const { providers } = await registerOpenAIPluginWithHook({
|
||||
pluginConfig: { personality: "on" },
|
||||
});
|
||||
|
||||
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
||||
expectOpenAIPromptContribution(openaiProvider, {
|
||||
interaction_style: OPENAI_FRIENDLY_PROMPT_OVERLAY,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user