mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-16 06:20:44 +00:00
* fix(scripts): find codex protocol source from worktrees * fix(test): keep codex harness docker caches writable * fix(test): relax live codex cache mount permissions * test(codex): add live docker harness debug output * fix(test): detect numeric ci env in codex docker harness * fix(codex): skip duplicate agent-command telemetry * fix(tooling): skip sparse-missing oxlint tsconfig * fix(tooling): route changed checks through testbox * fix(qa): keep coverage json source-clean * fix(test): preflight codex docker auth * fix(codex): validate bind option values * fix(codex): parse quoted command arguments * fix(codex): reject extra control args * fix(codex): use content for blank bound prompts * fix(codex): decode local image file urls * fix(codex): treat local media urls as images * fix(codex): keep windows media paths local * fix(codex): reject malformed diagnostics confirmations * fix(codex): reject malformed resume commands * fix(codex): reject malformed thread actions * fix(codex): reject malformed turn controls * fix(codex): reject malformed model controls * fix(codex): resolve empty user input prompts * fix(codex): enforce user input options * fix(codex): reject ambiguous computer-use actions * fix(codex): ignore stale bound turn notifications * test(gateway): close task registries in gateway harness * test(gateway): route cleanup through task seams * fix(codex): describe current permission approvals * fix(codex): disclose command approval amendments * fix(codex): preserve approval detail under truncation * fix(codex): propagate dynamic tool failures * test(codex): align dynamic tool block contract * fix(codex): reject extra read-only command operands * fix(codex): escape command readout fields * fix(codex): escape status probe errors * fix(codex): narrow formatted thread details * fix(codex): escape successful status summaries * fix(codex): escape bound control replies * fix(codex): escape user input prompts * fix(codex): escape control failure replies * fix(codex): escape approval prompt text * test(codex): narrow escaped reply assertions * test(codex): complete strict reply fixtures * test(codex): preserve account fixture literals * test(codex): align status probe fixtures * fix(codex): satisfy sanitizer regex lint * fix(codex): harden command readouts * fix(codex): harden bound image inputs * fix(codex): sanitize command failure replies * test(codex): complete rate limit fixture * test(tooling): isolate postinstall compile cache fixture * fix(codex): keep app-server event ownership explicit --------- Co-authored-by: pashpashpash <nik@vault77.ai>
127 lines
4.1 KiB
TypeScript
127 lines
4.1 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { clearRuntimeAuthProfileStoreSnapshots } from "openclaw/plugin-sdk/agent-runtime";
|
|
import { upsertAuthProfile } from "openclaw/plugin-sdk/provider-auth";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
readCodexAppServerBinding,
|
|
writeCodexAppServerBinding,
|
|
} from "./app-server/session-binding.js";
|
|
import {
|
|
setCodexConversationFastMode,
|
|
setCodexConversationModel,
|
|
setCodexConversationPermissions,
|
|
} from "./conversation-control.js";
|
|
|
|
let tempDir: string;
|
|
|
|
const sharedClientMocks = vi.hoisted(() => ({
|
|
getSharedCodexAppServerClient: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("./app-server/shared-client.js", () => sharedClientMocks);
|
|
|
|
describe("codex conversation controls", () => {
|
|
beforeEach(async () => {
|
|
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-control-"));
|
|
vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
|
|
sharedClientMocks.getSharedCodexAppServerClient.mockReset();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
vi.unstubAllEnvs();
|
|
clearRuntimeAuthProfileStoreSnapshots();
|
|
await fs.rm(tempDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it("persists fast mode and permissions for later bound turns", async () => {
|
|
const sessionFile = path.join(tempDir, "session.jsonl");
|
|
await writeCodexAppServerBinding(sessionFile, {
|
|
threadId: "thread-1",
|
|
cwd: tempDir,
|
|
model: "gpt-5.4",
|
|
modelProvider: "openai",
|
|
approvalPolicy: "never",
|
|
sandbox: "danger-full-access",
|
|
});
|
|
|
|
await expect(setCodexConversationFastMode({ sessionFile, enabled: true })).resolves.toBe(
|
|
"Codex fast mode enabled.",
|
|
);
|
|
await expect(setCodexConversationPermissions({ sessionFile, mode: "default" })).resolves.toBe(
|
|
"Codex permissions set to default.",
|
|
);
|
|
|
|
await expect(readCodexAppServerBinding(sessionFile)).resolves.toMatchObject({
|
|
threadId: "thread-1",
|
|
serviceTier: "fast",
|
|
approvalPolicy: "on-request",
|
|
sandbox: "workspace-write",
|
|
});
|
|
});
|
|
|
|
it("does not persist public OpenAI provider after model changes on native auth bindings", async () => {
|
|
const sessionFile = path.join(tempDir, "session.jsonl");
|
|
upsertAuthProfile({
|
|
profileId: "work",
|
|
credential: {
|
|
type: "oauth",
|
|
provider: "openai-codex",
|
|
access: "access-token",
|
|
refresh: "refresh-token",
|
|
expires: Date.now() + 60_000,
|
|
},
|
|
});
|
|
await writeCodexAppServerBinding(sessionFile, {
|
|
threadId: "thread-1",
|
|
cwd: tempDir,
|
|
authProfileId: "work",
|
|
model: "gpt-5.4",
|
|
modelProvider: "openai",
|
|
});
|
|
sharedClientMocks.getSharedCodexAppServerClient.mockResolvedValue({
|
|
request: vi.fn(async () => ({
|
|
thread: { id: "thread-1", cwd: tempDir },
|
|
model: "gpt-5.5",
|
|
modelProvider: "openai",
|
|
})),
|
|
});
|
|
|
|
await expect(setCodexConversationModel({ sessionFile, model: "gpt-5.5" })).resolves.toBe(
|
|
"Codex model set to gpt-5.5.",
|
|
);
|
|
|
|
const raw = await fs.readFile(`${sessionFile}.codex-app-server.json`, "utf8");
|
|
const binding = await readCodexAppServerBinding(sessionFile);
|
|
expect(raw).not.toContain('"modelProvider": "openai"');
|
|
expect(binding).toMatchObject({
|
|
threadId: "thread-1",
|
|
authProfileId: "work",
|
|
model: "gpt-5.5",
|
|
});
|
|
expect(binding?.modelProvider).toBeUndefined();
|
|
});
|
|
|
|
it("escapes model names returned from Codex before chat display", async () => {
|
|
const sessionFile = path.join(tempDir, "session.jsonl");
|
|
await writeCodexAppServerBinding(sessionFile, {
|
|
threadId: "thread-1",
|
|
cwd: tempDir,
|
|
model: "gpt-5.4",
|
|
modelProvider: "openai",
|
|
});
|
|
sharedClientMocks.getSharedCodexAppServerClient.mockResolvedValue({
|
|
request: vi.fn(async () => ({
|
|
thread: { id: "thread-1", cwd: tempDir },
|
|
model: "gpt-5.5 <@U123> [trusted](https://evil)",
|
|
modelProvider: "openai",
|
|
})),
|
|
});
|
|
|
|
await expect(setCodexConversationModel({ sessionFile, model: "gpt-5.5" })).resolves.toBe(
|
|
"Codex model set to gpt-5.5 <\uff20U123> \uff3btrusted\uff3d\uff08https://evil\uff09.",
|
|
);
|
|
});
|
|
});
|