Files
openclaw/src/commands/codex-runtime-plugin-install.test.ts
Peter Steinberger a789b92b39 fix(macos): harden fresh AI onboarding (#102637)
* fix(macos): bootstrap Codex before onboarding test

* fix(plugins): activate deferred runtimes on demand

* fix(macos): stage Codex runtime for onboarding probe

* fix(macos): expose sanitized onboarding errors

* fix(codex): reuse native CLI auth during onboarding

* fix(macos): hide Crestodian without inference

* fix(codex): honor explicit runtime policy during setup

* fix(onboarding): redact verification errors

* fix(macos): reset onboarding state with gateway route

* fix(onboarding): persist Codex plugin install metadata

* chore: refresh onboarding inventories

* fix(macos): restart AI setup after gateway change

* chore: refresh native onboarding inventory

* fix(onboarding): defer gateway restart until setup persists

* fix(macos): reset Crestodian on gateway changes

* chore(macos): refresh native i18n inventory

* fix(onboarding): harden inference setup state

* docs(skills): reuse pristine Parallels snapshots

* chore(macos): refresh onboarding i18n inventory

* fix(onboarding): prevent stale gateway and install state

* docs(skills): preserve saved Parallels sessions

* fix(macos): balance AI onboarding layout

* fix(parallels): parse npm workspace pack output

* chore(macos): refresh onboarding i18n inventory

* fix(parallels): bundle workspace runtime in package artifact

* fix(parallels): isolate canonical package helper

* fix(parallels): pack self-contained workspace artifact

* fix(packaging): exclude macOS app bundle

* fix(macos): restart inference checks after route changes

* docs(changelog): defer onboarding note to release

* fix(onboarding): enforce inference-first gateway setup
2026-07-10 04:59:15 +01:00

164 lines
5.0 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/types.openclaw.js";
const mocks = vi.hoisted(() => ({
loadInstalledPluginIndexInstallRecords: vi.fn(),
repairMissingPluginInstallsForIds: vi.fn(),
}));
type MissingPluginInstallRepairCall = {
pluginIds: string[];
env?: NodeJS.ProcessEnv;
};
function readOnlyMissingPluginInstallRepairCall(): MissingPluginInstallRepairCall {
expect(mocks.repairMissingPluginInstallsForIds).toHaveBeenCalledOnce();
const calls = mocks.repairMissingPluginInstallsForIds.mock.calls as unknown as Array<
[MissingPluginInstallRepairCall]
>;
const call = calls[0]?.[0];
if (!call) {
throw new Error("Expected missing plugin install repair call");
}
return call;
}
vi.mock("./doctor/shared/missing-configured-plugin-install.js", () => ({
repairMissingPluginInstallsForIds: mocks.repairMissingPluginInstallsForIds,
}));
vi.mock("../plugins/installed-plugin-index-records.js", () => ({
loadInstalledPluginIndexInstallRecords: mocks.loadInstalledPluginIndexInstallRecords,
}));
describe("Codex runtime plugin install repair", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.loadInstalledPluginIndexInstallRecords.mockResolvedValue({});
mocks.repairMissingPluginInstallsForIds.mockResolvedValue({
changes: [],
warnings: [],
});
});
it("surfaces non-fatal ClawHub repair notices to warning-only callers", async () => {
const reviewNotice = "REVIEW RECOMMENDED - ClawHub has not completed a fresh clean check";
mocks.repairMissingPluginInstallsForIds.mockResolvedValue({
changes: ['Repaired missing configured plugin "codex".'],
warnings: [],
notices: [reviewNotice],
});
const { repairCodexRuntimePluginInstallForModelSelection } =
await import("./codex-runtime-plugin-install.js");
const result = await repairCodexRuntimePluginInstallForModelSelection({
cfg: {},
model: "openai/gpt-5.5",
env: {},
});
const repairCall = readOnlyMissingPluginInstallRepairCall();
expect(repairCall.pluginIds).toStrictEqual(["codex"]);
expect(repairCall.env).toStrictEqual({});
expect(result).toStrictEqual({
required: true,
changes: ['Repaired missing configured plugin "codex".'],
warnings: [reviewNotice],
});
});
it.each([
["plugins disabled", { plugins: { enabled: false } }],
["denylisted", { plugins: { deny: ["codex"] } }],
["not allowlisted", { plugins: { allow: ["other"] } }],
])("does not report an existing Codex install as usable when %s", async (_label, cfg) => {
mocks.loadInstalledPluginIndexInstallRecords.mockResolvedValue({
codex: { source: "npm", installPath: process.cwd() },
});
const { ensureCodexRuntimePluginForModelSelection } =
await import("./codex-runtime-plugin-install.js");
const result = await ensureCodexRuntimePluginForModelSelection({
cfg,
model: "openai/gpt-5.5",
prompter: {} as never,
runtime: {} as never,
});
expect(result).toMatchObject({
cfg,
required: true,
installed: false,
status: "failed",
});
expect(result.reason).toBeTruthy();
});
it("enables an allowed existing Codex install", async () => {
mocks.loadInstalledPluginIndexInstallRecords.mockResolvedValue({
codex: { source: "npm", installPath: process.cwd() },
});
const cfg: OpenClawConfig = {
plugins: {
allow: ["codex"],
entries: { codex: { enabled: false } },
},
};
const { ensureCodexRuntimePluginForModelSelection } =
await import("./codex-runtime-plugin-install.js");
const result = await ensureCodexRuntimePluginForModelSelection({
cfg,
model: "openai/gpt-5.5",
prompter: {} as never,
runtime: {} as never,
});
expect(result).toMatchObject({
required: true,
installed: true,
status: "installed",
cfg: { plugins: { entries: { codex: { enabled: true } } } },
});
});
it("sees an agent-scoped Codex runtime pin behind a custom OpenAI route", async () => {
mocks.loadInstalledPluginIndexInstallRecords.mockResolvedValue({
codex: { source: "npm", installPath: process.cwd() },
});
const cfg = {
agents: {
list: [
{
id: "ops",
default: true,
model: { primary: "openai/gpt-5.5" },
models: { "openai/gpt-5.5": { agentRuntime: { id: "codex" } } },
},
],
},
models: {
providers: {
openai: { baseUrl: "https://proxy.example.test/v1", models: [] },
},
},
};
const { ensureCodexRuntimePluginForModelSelection } =
await import("./codex-runtime-plugin-install.js");
const result = await ensureCodexRuntimePluginForModelSelection({
cfg,
model: "openai/gpt-5.5",
agentId: "ops",
prompter: {} as never,
runtime: {} as never,
});
expect(result).toMatchObject({
required: true,
installed: true,
status: "installed",
});
});
});