mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-15 11:12:58 +00:00
fix(scripts): guard codex protocol generation disk headroom
This commit is contained in:
@@ -2,8 +2,12 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildCodexProtocolExportArgs,
|
||||
resolveCodexAppServerProtocolSource,
|
||||
resolveCodexProtocolCargoTargetDir,
|
||||
resolveCodexProtocolMinFreeBytes,
|
||||
resolveCodexProtocolPnpmCommand,
|
||||
validateCodexProtocolGenerationHeadroom,
|
||||
} from "../../scripts/lib/codex-app-server-protocol-source.js";
|
||||
import { createScriptTestHarness } from "./test-helpers.js";
|
||||
|
||||
@@ -19,6 +23,86 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user