mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-29 15:15:17 +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
628 lines
22 KiB
TypeScript
628 lines
22 KiB
TypeScript
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
|
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
|
import {
|
|
registerProviderPlugin,
|
|
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-codex-oauth-flow.runtime.js", () => ({
|
|
refreshOpenAICodexToken: runtimeMocks.refreshOpenAICodexToken,
|
|
}));
|
|
|
|
import { createOpenAICodexProviderRuntime } from "./openai-codex-provider.runtime.js";
|
|
|
|
const registerOpenAIPluginForTest = async () =>
|
|
registerProviderPlugin({
|
|
plugin,
|
|
id: "openai",
|
|
name: "OpenAI Provider",
|
|
});
|
|
|
|
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 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: {
|
|
ok: true,
|
|
json: async () => ({
|
|
data: [
|
|
{
|
|
b64_json: Buffer.from(params.imageData).toString("base64"),
|
|
...(params.revisedPrompt ? { revised_prompt: params.revisedPrompt } : {}),
|
|
},
|
|
],
|
|
}),
|
|
} as Response,
|
|
release: vi.fn(async () => {}),
|
|
});
|
|
const postMultipartRequestSpy = vi.spyOn(providerHttp, "postMultipartRequest").mockResolvedValue({
|
|
finalUrl: params.finalUrl,
|
|
response: {
|
|
ok: true,
|
|
json: async () => ({
|
|
data: [
|
|
{
|
|
b64_json: Buffer.from(params.imageData).toString("base64"),
|
|
...(params.revisedPrompt ? { revised_prompt: params.revisedPrompt } : {}),
|
|
},
|
|
],
|
|
}),
|
|
} as 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 openai and codex", async () => {
|
|
const { providers } = await registerOpenAIPluginWithHook();
|
|
const openaiProvider = requireRegisteredProvider(providers, "openai");
|
|
const codexProvider = requireRegisteredProvider(providers, "openai-codex");
|
|
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 = codexProvider.normalizeToolSchemas?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.4",
|
|
modelApi: "openai-codex-responses",
|
|
model: {
|
|
provider: "openai-codex",
|
|
api: "openai-codex-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(
|
|
codexProvider.inspectToolSchemas?.({
|
|
provider: "openai-codex",
|
|
modelId: "gpt-5.4",
|
|
modelApi: "openai-codex-responses",
|
|
model: {
|
|
provider: "openai-codex",
|
|
api: "openai-codex-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 codexProvider = requireRegisteredProvider(providers, "openai-codex");
|
|
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(codexProvider.resolveSystemPromptContribution?.(contributionContext)).toEqual({
|
|
stablePrefix: OPENAI_GPT5_BEHAVIOR_CONTRACT,
|
|
sectionOverrides: {
|
|
interaction_style: OPENAI_FRIENDLY_PROMPT_OVERLAY,
|
|
},
|
|
});
|
|
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,
|
|
});
|
|
});
|
|
});
|