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
277 lines
7.9 KiB
TypeScript
277 lines
7.9 KiB
TypeScript
// Codex App Server Protocol Source tests cover codex app server protocol source script behavior.
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import {
|
|
buildCodexProtocolExportArgs,
|
|
canonicalizeCodexAppServerProtocolJson,
|
|
formatCodexAppServerProtocolJsonText,
|
|
resolveCodexAppServerProtocolSource,
|
|
resolveCodexProtocolCargoTargetDir,
|
|
resolveCodexProtocolMinFreeBytes,
|
|
resolveCodexProtocolPnpmCommand,
|
|
validateCodexProtocolGenerationHeadroom,
|
|
} from "../../scripts/lib/codex-app-server-protocol-source.js";
|
|
import { createScriptTestHarness } from "./test-helpers.js";
|
|
|
|
const { createTempDir } = createScriptTestHarness();
|
|
const originalOpenClawCodexRepo = process.env.OPENCLAW_CODEX_REPO;
|
|
|
|
afterEach(() => {
|
|
if (originalOpenClawCodexRepo === undefined) {
|
|
delete process.env.OPENCLAW_CODEX_REPO;
|
|
} else {
|
|
process.env.OPENCLAW_CODEX_REPO = originalOpenClawCodexRepo;
|
|
}
|
|
});
|
|
|
|
describe("codex app-server protocol source resolver", () => {
|
|
it("uses the app-server protocol export binary instead of compiling the full codex cli", () => {
|
|
expect(buildCodexProtocolExportArgs("/codex/codex-rs/Cargo.toml", "/tmp/protocol")).toEqual([
|
|
"run",
|
|
"--manifest-path",
|
|
"/codex/codex-rs/Cargo.toml",
|
|
"-p",
|
|
"codex-app-server-protocol",
|
|
"--bin",
|
|
"export",
|
|
"--",
|
|
"--out",
|
|
"/tmp/protocol",
|
|
"--experimental",
|
|
]);
|
|
});
|
|
|
|
it("fails before cargo protocol generation when local disk headroom is too low", () => {
|
|
expect(() =>
|
|
validateCodexProtocolGenerationHeadroom({
|
|
freeBytes: 6 * 1024 * 1024 * 1024,
|
|
minFreeBytes: 10 * 1024 * 1024 * 1024,
|
|
pathLabel: "/repo",
|
|
}),
|
|
).toThrow(/Run this check on Crabbox\/Testbox/);
|
|
});
|
|
|
|
it("allows an explicit local disk headroom override", () => {
|
|
expect(resolveCodexProtocolMinFreeBytes({ OPENCLAW_CODEX_PROTOCOL_MIN_FREE_BYTES: "0" })).toBe(
|
|
0,
|
|
);
|
|
expect(() =>
|
|
validateCodexProtocolGenerationHeadroom({
|
|
freeBytes: 1,
|
|
minFreeBytes: 0,
|
|
pathLabel: "/repo",
|
|
}),
|
|
).not.toThrow();
|
|
});
|
|
|
|
it("rejects malformed local disk headroom overrides", () => {
|
|
expect(() =>
|
|
resolveCodexProtocolMinFreeBytes({ OPENCLAW_CODEX_PROTOCOL_MIN_FREE_BYTES: "nope" }),
|
|
).toThrow(/non-negative byte count/);
|
|
});
|
|
|
|
it("checks the Codex workspace target dir by default", () => {
|
|
expect(resolveCodexProtocolCargoTargetDir("/codex", {})).toBe(
|
|
path.join("/codex", "codex-rs", "target"),
|
|
);
|
|
});
|
|
|
|
it("checks an explicit Cargo target dir override", () => {
|
|
expect(
|
|
resolveCodexProtocolCargoTargetDir("/codex", { CARGO_TARGET_DIR: "/cache/target" }),
|
|
).toBe(path.resolve("/cache/target"));
|
|
});
|
|
|
|
it("resolves relative Cargo target dir overrides from the Codex checkout", () => {
|
|
expect(resolveCodexProtocolCargoTargetDir("/codex", { CARGO_TARGET_DIR: "target-cache" })).toBe(
|
|
path.join("/codex", "target-cache"),
|
|
);
|
|
});
|
|
|
|
it("checks Cargo's build target dir override", () => {
|
|
expect(
|
|
resolveCodexProtocolCargoTargetDir("/codex", {
|
|
CARGO_BUILD_TARGET_DIR: "/cache/build-target",
|
|
}),
|
|
).toBe(path.resolve("/cache/build-target"));
|
|
});
|
|
|
|
it("prefers Cargo's target dir override over the build config env override", () => {
|
|
expect(
|
|
resolveCodexProtocolCargoTargetDir("/codex", {
|
|
CARGO_BUILD_TARGET_DIR: "/cache/build-target",
|
|
CARGO_TARGET_DIR: "/cache/target",
|
|
}),
|
|
).toBe(path.resolve("/cache/target"));
|
|
});
|
|
|
|
it("wraps Windows pnpm formatting through cmd.exe without shell mode", () => {
|
|
expect(
|
|
resolveCodexProtocolPnpmCommand(
|
|
["exec", "oxfmt", "--write", "--threads=1", String.raw`C:\tmp\generated types`],
|
|
{
|
|
comSpec: String.raw`C:\Windows\System32\cmd.exe`,
|
|
npmExecPath: String.raw`C:\Program Files\nodejs\pnpm.cmd`,
|
|
platform: "win32",
|
|
},
|
|
),
|
|
).toEqual({
|
|
args: [
|
|
"/d",
|
|
"/s",
|
|
"/c",
|
|
String.raw`""C:\Program Files\nodejs\pnpm.cmd" exec oxfmt --write --threads=1 "C:\tmp\generated types""`,
|
|
],
|
|
command: String.raw`C:\Windows\System32\cmd.exe`,
|
|
shell: false,
|
|
windowsVerbatimArguments: true,
|
|
});
|
|
});
|
|
|
|
it("uses OPENCLAW_CODEX_REPO when provided", async () => {
|
|
const root = createTempDir("openclaw-protocol-source-root-");
|
|
const codexRepo = createTempDir("openclaw-protocol-source-codex-");
|
|
createProtocolSchema(codexRepo);
|
|
process.env.OPENCLAW_CODEX_REPO = codexRepo;
|
|
|
|
await expect(resolveCodexAppServerProtocolSource(root)).resolves.toEqual({
|
|
codexRepo,
|
|
sourceRoot: path.join(codexRepo, "codex-rs/app-server-protocol/schema"),
|
|
});
|
|
});
|
|
|
|
it("finds the primary checkout sibling from a git worktree", async () => {
|
|
const parentDir = createTempDir("openclaw-protocol-source-parent-");
|
|
const primaryOpenClaw = path.join(parentDir, "openclaw");
|
|
const codexRepo = path.join(parentDir, "codex");
|
|
const worktreeRoot = createTempDir("openclaw-protocol-source-worktree-");
|
|
fs.mkdirSync(path.join(primaryOpenClaw, ".git", "worktrees", "codex-harness"), {
|
|
recursive: true,
|
|
});
|
|
fs.mkdirSync(worktreeRoot, { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(worktreeRoot, ".git"),
|
|
`gitdir: ${path.join(primaryOpenClaw, ".git", "worktrees", "codex-harness")}\n`,
|
|
);
|
|
createProtocolSchema(codexRepo);
|
|
delete process.env.OPENCLAW_CODEX_REPO;
|
|
|
|
await expect(resolveCodexAppServerProtocolSource(worktreeRoot)).resolves.toEqual({
|
|
codexRepo,
|
|
sourceRoot: path.join(codexRepo, "codex-rs/app-server-protocol/schema"),
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("Codex app-server protocol JSON canonicalizer", () => {
|
|
it("sorts object keys recursively before formatting", () => {
|
|
const source = JSON.stringify({
|
|
z: {
|
|
d: 1,
|
|
b: {
|
|
y: 2,
|
|
x: 3,
|
|
},
|
|
},
|
|
a: [
|
|
{
|
|
z: 4,
|
|
a: {
|
|
c: 5,
|
|
b: 6,
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(formatCodexAppServerProtocolJsonText(source)).toBe(`{
|
|
"a": [
|
|
{
|
|
"a": {
|
|
"b": 6,
|
|
"c": 5
|
|
},
|
|
"z": 4
|
|
}
|
|
],
|
|
"z": {
|
|
"b": {
|
|
"x": 3,
|
|
"y": 2
|
|
},
|
|
"d": 1
|
|
}
|
|
}
|
|
`);
|
|
});
|
|
|
|
it("sorts typed-object arrays only for order-insensitive schema keywords", () => {
|
|
expect(
|
|
canonicalizeCodexAppServerProtocolJson({
|
|
anyOf: [
|
|
{ z: 1, type: "string" },
|
|
{ type: "integer", a: 2 },
|
|
],
|
|
enum: [
|
|
{ z: 1, type: "z" },
|
|
{ type: "a", a: 2 },
|
|
],
|
|
mixed: [{ type: "b" }, "item", { type: "a" }],
|
|
oneOf: [
|
|
{ type: "object", z: true },
|
|
{ a: true, type: "array" },
|
|
{ type: "object", z: false },
|
|
],
|
|
prefixItems: [
|
|
{ z: 1, type: "string" },
|
|
{ type: "number", a: 2 },
|
|
],
|
|
required: [
|
|
{ z: 1, type: "z" },
|
|
{ type: "a", a: 2 },
|
|
],
|
|
typed: [
|
|
{ type: "beta", z: 1 },
|
|
{ type: "alpha", z: 2 },
|
|
{ type: "beta", z: 3 },
|
|
],
|
|
}),
|
|
).toEqual({
|
|
anyOf: [
|
|
{ a: 2, type: "integer" },
|
|
{ type: "string", z: 1 },
|
|
],
|
|
enum: [
|
|
{ a: 2, type: "a" },
|
|
{ type: "z", z: 1 },
|
|
],
|
|
mixed: [{ type: "b" }, "item", { type: "a" }],
|
|
oneOf: [
|
|
{ a: true, type: "array" },
|
|
{ type: "object", z: true },
|
|
{ type: "object", z: false },
|
|
],
|
|
prefixItems: [
|
|
{ type: "string", z: 1 },
|
|
{ a: 2, type: "number" },
|
|
],
|
|
required: [
|
|
{ a: 2, type: "a" },
|
|
{ type: "z", z: 1 },
|
|
],
|
|
typed: [
|
|
{ type: "beta", z: 1 },
|
|
{ type: "alpha", z: 2 },
|
|
{ type: "beta", z: 3 },
|
|
],
|
|
});
|
|
});
|
|
});
|
|
|
|
function createProtocolSchema(codexRepo: string): void {
|
|
fs.mkdirSync(path.join(codexRepo, "codex-rs/app-server-protocol/schema/typescript"), {
|
|
recursive: true,
|
|
});
|
|
}
|