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
255 lines
9.1 KiB
TypeScript
255 lines
9.1 KiB
TypeScript
// Codex tests cover index plugin behavior.
|
|
import fs from "node:fs";
|
|
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { createCodexAppServerAgentHarness } from "./harness.js";
|
|
import plugin from "./index.js";
|
|
|
|
const runCodexAppServerAttemptMock = vi.hoisted(() => vi.fn());
|
|
const runCodexAppServerSideQuestionMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("./src/app-server/run-attempt.js", () => ({
|
|
runCodexAppServerAttempt: runCodexAppServerAttemptMock,
|
|
}));
|
|
vi.mock("./src/app-server/side-question.js", () => ({
|
|
runCodexAppServerSideQuestion: runCodexAppServerSideQuestionMock,
|
|
}));
|
|
|
|
function mockCall(mock: { mock: { calls: unknown[][] } }, index = 0) {
|
|
return mock.mock.calls.at(index);
|
|
}
|
|
|
|
function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0, argIndex = 0) {
|
|
return mockCall(mock, index)?.at(argIndex);
|
|
}
|
|
|
|
describe("codex plugin", () => {
|
|
it("is opt-in by default", () => {
|
|
const manifest = JSON.parse(
|
|
fs.readFileSync(new URL("./openclaw.plugin.json", import.meta.url), "utf8"),
|
|
) as { enabledByDefault?: unknown };
|
|
|
|
expect(manifest.enabledByDefault).toBeUndefined();
|
|
});
|
|
|
|
it("registers the codex provider, agent harness, native thread tool, and hosted web search", () => {
|
|
const registerAgentHarness = vi.fn();
|
|
const registerCommand = vi.fn();
|
|
const registerMediaUnderstandingProvider = vi.fn();
|
|
const registerMigrationProvider = vi.fn();
|
|
const registerProvider = vi.fn();
|
|
const registerTool = vi.fn();
|
|
const registerToolMetadata = vi.fn();
|
|
const registerWebSearchProvider = vi.fn();
|
|
const on = vi.fn();
|
|
const onConversationBindingResolved = vi.fn();
|
|
|
|
plugin.register(
|
|
createTestPluginApi({
|
|
id: "codex",
|
|
name: "Codex",
|
|
source: "test",
|
|
config: {},
|
|
pluginConfig: {},
|
|
runtime: {} as never,
|
|
registerAgentHarness,
|
|
registerCommand,
|
|
registerMediaUnderstandingProvider,
|
|
registerMigrationProvider,
|
|
registerProvider,
|
|
registerTool,
|
|
registerToolMetadata,
|
|
registerWebSearchProvider,
|
|
on,
|
|
onConversationBindingResolved,
|
|
}),
|
|
);
|
|
|
|
const providerRegistration = mockCallArg(registerProvider) as Record<string, unknown>;
|
|
const agentHarnessRegistration = mockCallArg(registerAgentHarness) as Record<string, unknown>;
|
|
const mediaProviderRegistration = mockCallArg(registerMediaUnderstandingProvider) as
|
|
| Record<string, unknown>
|
|
| undefined;
|
|
const inboundClaimRegistration = mockCall(on) as [unknown, unknown] | undefined;
|
|
const bindingResolvedRegistration = mockCall(onConversationBindingResolved) as
|
|
| [unknown]
|
|
| undefined;
|
|
|
|
expect(providerRegistration.id).toBe("codex");
|
|
expect(providerRegistration.label).toBe("Codex");
|
|
expect(agentHarnessRegistration.id).toBe("codex");
|
|
expect(agentHarnessRegistration.label).toBe("Codex agent harness");
|
|
expect(agentHarnessRegistration.deliveryDefaults).toEqual({
|
|
sourceVisibleReplies: "message_tool",
|
|
});
|
|
expect(typeof agentHarnessRegistration.dispose).toBe("function");
|
|
expect(mediaProviderRegistration?.id).toBe("codex");
|
|
expect(mediaProviderRegistration?.capabilities).toEqual(["image"]);
|
|
expect(mediaProviderRegistration?.defaultModels).toEqual({ image: "gpt-5.5" });
|
|
expect(typeof mediaProviderRegistration?.describeImage).toBe("function");
|
|
expect(typeof mediaProviderRegistration?.describeImages).toBe("function");
|
|
const webSearchRegistration = mockCallArg(registerWebSearchProvider) as
|
|
| Record<string, unknown>
|
|
| undefined;
|
|
expect(webSearchRegistration?.id).toBe("codex");
|
|
expect(webSearchRegistration?.label).toBe("Codex Hosted Search");
|
|
expect(webSearchRegistration?.requiresCredential).toBe(false);
|
|
expect(typeof webSearchRegistration?.createTool).toBe("function");
|
|
const commandRegistration = mockCallArg(registerCommand) as Record<string, unknown> | undefined;
|
|
expect(commandRegistration?.name).toBe("codex");
|
|
expect(commandRegistration?.description).toBe(
|
|
"Inspect and control the Codex app-server harness",
|
|
);
|
|
const migrationRegistration = mockCallArg(registerMigrationProvider) as
|
|
| Record<string, unknown>
|
|
| undefined;
|
|
expect(migrationRegistration?.id).toBe("codex");
|
|
expect(migrationRegistration?.label).toBe("Codex");
|
|
expect(registerTool).toHaveBeenCalledWith(expect.any(Function), { name: "codex_threads" });
|
|
expect(registerToolMetadata).toHaveBeenCalledWith(
|
|
expect.objectContaining({ toolName: "codex_threads", risk: "high" }),
|
|
);
|
|
expect(inboundClaimRegistration?.[0]).toBe("inbound_claim");
|
|
expect(typeof inboundClaimRegistration?.[1]).toBe("function");
|
|
expect(typeof bindingResolvedRegistration?.[0]).toBe("function");
|
|
});
|
|
|
|
it("registers with capture APIs that do not expose conversation binding hooks yet", () => {
|
|
const registerProvider = vi.fn();
|
|
const api = createTestPluginApi({
|
|
id: "codex",
|
|
name: "Codex",
|
|
source: "test",
|
|
config: {},
|
|
pluginConfig: {},
|
|
runtime: {} as never,
|
|
registerAgentHarness: vi.fn(),
|
|
registerCommand: vi.fn(),
|
|
registerMediaUnderstandingProvider: vi.fn(),
|
|
registerProvider,
|
|
on: vi.fn(),
|
|
});
|
|
delete (api as { onConversationBindingResolved?: unknown }).onConversationBindingResolved;
|
|
|
|
plugin.register(api);
|
|
expect(registerProvider).toHaveBeenCalledTimes(1);
|
|
expect((mockCallArg(registerProvider) as { id?: string } | undefined)?.id).toBe("codex");
|
|
});
|
|
|
|
it("claims the Codex routing providers by default", () => {
|
|
const harness = createCodexAppServerAgentHarness();
|
|
|
|
expect(harness.deliveryDefaults?.sourceVisibleReplies).toBe("message_tool");
|
|
expect(
|
|
harness.supports({ provider: "codex", modelId: "gpt-5.4", requestedRuntime: "auto" })
|
|
.supported,
|
|
).toBe(true);
|
|
const openAiCodex = harness.supports({
|
|
provider: "openai",
|
|
modelId: "gpt-5.4",
|
|
requestedRuntime: "auto",
|
|
});
|
|
expect(openAiCodex.supported).toBe(true);
|
|
const unsupported = harness.supports({
|
|
provider: "9router",
|
|
modelId: "gpt-5.4",
|
|
requestedRuntime: "auto",
|
|
});
|
|
expect(unsupported.supported).toBe(false);
|
|
});
|
|
|
|
it("enables the native hook relay for public Codex app-server attempts", async () => {
|
|
const harness = createCodexAppServerAgentHarness({ pluginConfig: { appServer: {} } });
|
|
const result = { success: true };
|
|
runCodexAppServerAttemptMock.mockResolvedValueOnce(result);
|
|
|
|
await expect(harness.runAttempt({ prompt: "hello" } as never)).resolves.toBe(result);
|
|
|
|
expect(runCodexAppServerAttemptMock).toHaveBeenCalledWith(
|
|
{ prompt: "hello" },
|
|
{
|
|
pluginConfig: { appServer: {} },
|
|
nativeHookRelay: { enabled: true },
|
|
},
|
|
);
|
|
});
|
|
|
|
it("passes live Codex plugin config into public Codex app-server attempts", async () => {
|
|
const registerAgentHarness = vi.fn();
|
|
const liveConfig = {
|
|
plugins: {
|
|
entries: {
|
|
codex: {
|
|
config: {
|
|
codexPlugins: {
|
|
enabled: true,
|
|
plugins: {
|
|
"google-calendar": {
|
|
marketplaceName: "openai-curated",
|
|
pluginName: "google-calendar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
plugin.register(
|
|
createTestPluginApi({
|
|
id: "codex",
|
|
name: "Codex",
|
|
source: "test",
|
|
config: {},
|
|
pluginConfig: { codexPlugins: { enabled: false } },
|
|
runtime: {
|
|
config: {
|
|
current: () => liveConfig,
|
|
},
|
|
} as never,
|
|
registerAgentHarness,
|
|
registerCommand: vi.fn(),
|
|
registerMediaUnderstandingProvider: vi.fn(),
|
|
registerMigrationProvider: vi.fn(),
|
|
registerProvider: vi.fn(),
|
|
on: vi.fn(),
|
|
}),
|
|
);
|
|
const harness = mockCallArg(registerAgentHarness) as ReturnType<
|
|
typeof createCodexAppServerAgentHarness
|
|
>;
|
|
const result = { success: true };
|
|
runCodexAppServerAttemptMock.mockResolvedValueOnce(result);
|
|
|
|
await expect(harness.runAttempt({ prompt: "calendar" } as never)).resolves.toBe(result);
|
|
|
|
expect(runCodexAppServerAttemptMock).toHaveBeenCalledWith(
|
|
{ prompt: "calendar" },
|
|
{
|
|
pluginConfig: liveConfig.plugins.entries.codex.config,
|
|
nativeHookRelay: { enabled: true },
|
|
},
|
|
);
|
|
});
|
|
|
|
it("enables the native hook relay for public Codex side questions", async () => {
|
|
const harness = createCodexAppServerAgentHarness({ pluginConfig: { appServer: {} } });
|
|
const runSideQuestion = harness["runSideQuestion"];
|
|
const result = { text: "ok" };
|
|
runCodexAppServerSideQuestionMock.mockResolvedValueOnce(result);
|
|
|
|
if (!runSideQuestion) {
|
|
throw new Error("Expected Codex harness to expose side questions");
|
|
}
|
|
await expect(runSideQuestion({ question: "btw" } as never)).resolves.toBe(result);
|
|
|
|
expect(runCodexAppServerSideQuestionMock).toHaveBeenCalledWith(
|
|
{ question: "btw" },
|
|
{
|
|
pluginConfig: { appServer: {} },
|
|
nativeHookRelay: { enabled: true },
|
|
},
|
|
);
|
|
});
|
|
});
|