build: refresh deps and route testbox through crabbox

This commit is contained in:
Peter Steinberger
2026-05-11 03:35:00 +01:00
parent 8ccd3e9236
commit 15cf49222f
531 changed files with 1096 additions and 2487 deletions

View File

@@ -1,160 +0,0 @@
import { EventEmitter } from "node:events";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
buildBlacksmithRunArgs,
resolveTestboxSyncTimeoutMs,
runBlacksmithTestboxRunner,
splitRunnerArgs,
} from "../../scripts/blacksmith-testbox-runner.mjs";
describe("blacksmith testbox runner", () => {
const tempDirs: string[] = [];
afterEach(() => {
for (const dir of tempDirs.splice(0)) {
fs.rmSync(dir, { recursive: true, force: true });
}
});
it("splits runner args from the remote command", () => {
expect(
splitRunnerArgs(["--id", "tbx_abc123", "--", "OPENCLAW_TESTBOX=1", "pnpm", "check:changed"]),
).toEqual({
runnerArgs: ["--id", "tbx_abc123"],
commandArgs: ["OPENCLAW_TESTBOX=1", "pnpm", "check:changed"],
});
});
it("builds blacksmith run arguments", () => {
expect(
buildBlacksmithRunArgs({
commandArgs: ["OPENCLAW_TESTBOX=1", "pnpm", "check:changed"],
testboxId: "tbx_abc123",
}),
).toEqual(["testbox", "run", "--id", "tbx_abc123", "OPENCLAW_TESTBOX=1 pnpm check:changed"]);
});
it("refuses to run a remote-visible id without a local private key", async () => {
let spawned = false;
const stderr = { write: (value: string) => value.length };
const code = await runBlacksmithTestboxRunner({
argv: ["--id", "tbx_01kqap50t9fqggzw1akg5dtmmq", "--", "pnpm", "check:changed"],
env: { OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: "/state/testboxes" },
spawn: () => {
spawned = true;
return { status: 0 };
},
stderr,
});
expect(code).toBe(2);
expect(spawned).toBe(false);
});
it("refuses to run a keyed id that was not claimed by this checkout", async () => {
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-testbox-runner-"));
tempDirs.push(stateDir);
const testboxDir = path.join(stateDir, "tbx_01kqap50t9fqggzw1akg5dtmmq");
fs.mkdirSync(testboxDir, { recursive: true });
fs.writeFileSync(path.join(testboxDir, "id_ed25519"), "test-key\n");
let spawned = false;
let stderrText = "";
const code = await runBlacksmithTestboxRunner({
argv: ["--id", "tbx_01kqap50t9fqggzw1akg5dtmmq", "--", "pnpm", "check:changed"],
env: { ...process.env, OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: stateDir },
spawn: () => {
spawned = true;
return { status: 0 };
},
stderr: { write: (value: string) => (stderrText += value) },
});
expect(code).toBe(2);
expect(spawned).toBe(false);
expect(stderrText).toContain("OpenClaw Testbox claim missing");
});
it("claims a keyed id without spawning when no remote command is supplied", async () => {
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-testbox-runner-"));
tempDirs.push(stateDir);
const testboxDir = path.join(stateDir, "tbx_01kqap50t9fqggzw1akg5dtmmq");
const claimPath = path.join(testboxDir, "openclaw-runner.json");
fs.mkdirSync(testboxDir, { recursive: true });
fs.writeFileSync(path.join(testboxDir, "id_ed25519"), "test-key\n");
let spawned = false;
let stdoutText = "";
const code = await runBlacksmithTestboxRunner({
argv: ["--claim", "--id", "tbx_01kqap50t9fqggzw1akg5dtmmq"],
env: { ...process.env, OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: stateDir },
spawn: () => {
spawned = true;
return { status: 0 };
},
stdout: { write: (value: string) => (stdoutText += value) },
});
expect(code).toBe(0);
expect(spawned).toBe(false);
expect(stdoutText).toContain("OpenClaw Testbox claim written");
expect(JSON.parse(fs.readFileSync(claimPath, "utf8")).repoRoot).toBe(process.cwd());
});
it("defaults the Testbox sync timeout and accepts disable override", () => {
expect(resolveTestboxSyncTimeoutMs({})).toBe(300000);
expect(resolveTestboxSyncTimeoutMs({ OPENCLAW_TESTBOX_SYNC_TIMEOUT_MS: "0" })).toBe(0);
expect(resolveTestboxSyncTimeoutMs({ OPENCLAW_TESTBOX_SYNC_TIMEOUT_MS: "2500" })).toBe(2500);
});
it("terminates a Testbox run that stalls in sync", async () => {
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-testbox-runner-"));
tempDirs.push(stateDir);
const testboxId = "tbx_01kqap50t9fqggzw1akg5dtmmq";
const testboxDir = path.join(stateDir, testboxId);
fs.mkdirSync(testboxDir, { recursive: true });
fs.writeFileSync(path.join(testboxDir, "id_ed25519"), "test-key\n");
await runBlacksmithTestboxRunner({
argv: ["--claim", "--id", testboxId],
env: { ...process.env, OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: stateDir },
stdout: { write: () => 0 },
});
let killed = false;
let stderrText = "";
const fakeSpawn = () => {
const child = new EventEmitter() as EventEmitter & {
stdout: EventEmitter;
stderr: EventEmitter;
kill: () => void;
};
child.stdout = new EventEmitter();
child.stderr = new EventEmitter();
child.kill = () => {
killed = true;
child.emit("close", 143);
};
queueMicrotask(() => child.stdout.emit("data", "Syncing... (still in progress)"));
return child;
};
const code = await runBlacksmithTestboxRunner({
argv: ["--id", testboxId, "--", "pnpm", "check:changed"],
env: {
...process.env,
OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: stateDir,
OPENCLAW_TESTBOX_SYNC_TIMEOUT_MS: "1",
},
spawn: fakeSpawn,
stderr: { write: (value: string) => (stderrText += value) },
stdout: { write: () => 0 },
});
expect(code).toBe(124);
expect(killed).toBe(true);
expect(stderrText).toContain("Blacksmith Testbox sync produced no post-sync output");
});
});

View File

@@ -1,119 +0,0 @@
import { describe, expect, it } from "vitest";
import {
evaluateLocalTestboxKey,
evaluateOpenClawTestboxClaim,
parseTestboxIdArg,
resolveTestboxId,
writeOpenClawTestboxClaim,
} from "../../scripts/blacksmith-testbox-state.mjs";
describe("blacksmith testbox state", () => {
it("parses Testbox ids from args and env", () => {
expect(parseTestboxIdArg(["--id", "tbx_abc123"])).toBe("tbx_abc123");
expect(parseTestboxIdArg(["--testbox-id=tbx_def456"])).toBe("tbx_def456");
expect(resolveTestboxId({ argv: [], env: { OPENCLAW_TESTBOX_ID: "tbx_env123" } })).toBe(
"tbx_env123",
);
});
it("fails when a remote-visible Testbox id has no local private key", () => {
const result = evaluateLocalTestboxKey({
env: { OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: "/state/testboxes" },
exists: () => false,
testboxId: "tbx_01kqap50t9fqggzw1akg5dtmmq",
});
expect(result.ok).toBe(false);
expect(result.keyPath).toBe("/state/testboxes/tbx_01kqap50t9fqggzw1akg5dtmmq/id_ed25519");
expect(result.problems[0]).toContain("local Testbox SSH key missing");
});
it("accepts a Testbox id with a local private key", () => {
const result = evaluateLocalTestboxKey({
env: { OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: "/state/testboxes" },
exists: (file) => file.endsWith("/tbx_01kqap50t9fqggzw1akg5dtmmq/id_ed25519"),
testboxId: "tbx_01kqap50t9fqggzw1akg5dtmmq",
});
expect(result.ok).toBe(true);
expect(result.checked).toBe(true);
});
it("fails when a keyed Testbox id has no OpenClaw claim", () => {
const result = evaluateOpenClawTestboxClaim({
cwd: "/repo",
env: { OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: "/state/testboxes" },
exists: () => false,
testboxId: "tbx_01kqap50t9fqggzw1akg5dtmmq",
});
expect(result.ok).toBe(false);
expect(result.claimPath).toBe(
"/state/testboxes/tbx_01kqap50t9fqggzw1akg5dtmmq/openclaw-runner.json",
);
expect(result.problems[0]).toContain("OpenClaw Testbox claim missing");
});
it("fails when an OpenClaw claim belongs to a different checkout", () => {
const result = evaluateOpenClawTestboxClaim({
cwd: "/repo/current",
env: { OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: "/state/testboxes" },
exists: () => true,
now: () => new Date("2026-04-29T12:00:00.000Z"),
readFile: () => JSON.stringify({ repoRoot: "/repo/other" }),
testboxId: "tbx_01kqap50t9fqggzw1akg5dtmmq",
});
expect(result.ok).toBe(false);
expect(result.problems[0]).toContain("claim repo mismatch");
});
it("fails when an OpenClaw claim is stale after a crash or long pause", () => {
const result = evaluateOpenClawTestboxClaim({
cwd: "/repo/current",
env: {
OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: "/state/testboxes",
OPENCLAW_TESTBOX_CLAIM_TTL_MINUTES: "90",
},
exists: () => true,
now: () => new Date("2026-04-29T14:00:00.000Z"),
readFile: () =>
JSON.stringify({
claimedAt: "2026-04-29T12:00:00.000Z",
repoRoot: "/repo/current",
}),
testboxId: "tbx_01kqap50t9fqggzw1akg5dtmmq",
});
expect(result.ok).toBe(false);
expect(result.problems[0]).toContain("claim is stale");
});
it("writes and accepts an OpenClaw Testbox claim for the current checkout", () => {
const writes = new Map<string, string>();
const claim = writeOpenClawTestboxClaim({
cwd: "/repo/current",
env: { OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: "/state/testboxes" },
mkdir: () => undefined,
now: () => new Date("2026-04-29T12:00:00.000Z"),
testboxId: "tbx_01kqap50t9fqggzw1akg5dtmmq",
writeFile: (file, value) => writes.set(file, value),
});
expect(claim.payload).toEqual({
claimedAt: "2026-04-29T12:00:00.000Z",
repoRoot: "/repo/current",
runnerVersion: 1,
});
expect(
evaluateOpenClawTestboxClaim({
cwd: "/repo/current",
env: { OPENCLAW_BLACKSMITH_TESTBOX_STATE_DIR: "/state/testboxes" },
exists: (file) => writes.has(file),
now: () => new Date("2026-04-29T12:30:00.000Z"),
readFile: (file) => writes.get(file) ?? "",
testboxId: "tbx_01kqap50t9fqggzw1akg5dtmmq",
}).ok,
).toBe(true);
});
});

View File

@@ -9,10 +9,10 @@ import {
isPackageScriptOnlyChange,
} from "../../scripts/changed-lanes.mjs";
import {
buildChangedCheckTestboxArgs,
buildChangedCheckCrabboxArgs,
createChangedCheckChildEnv,
createChangedCheckPlan,
shouldDelegateChangedCheckToTestbox,
shouldDelegateChangedCheckToCrabbox,
} from "../../scripts/check-changed.mjs";
import { cleanupTempDirs, makeTempRepoRoot } from "../helpers/temp-repo.js";
@@ -243,15 +243,36 @@ describe("scripts/changed-lanes", () => {
it("delegates local Testbox-mode changed gates before running locally", () => {
expect(
shouldDelegateChangedCheckToTestbox(["--base", "origin/main"], {
shouldDelegateChangedCheckToCrabbox(["--base", "origin/main"], {
OPENCLAW_TESTBOX: "1",
PATH: "/usr/bin",
}),
).toBe(true);
expect(buildChangedCheckTestboxArgs(["--base", "origin/main", "--head", "HEAD"])).toEqual([
"testbox:run",
expect(buildChangedCheckCrabboxArgs(["--base", "origin/main", "--head", "HEAD"])).toEqual([
"crabbox:run",
"--",
"--provider",
"blacksmith-testbox",
"--blacksmith-org",
"openclaw",
"--blacksmith-workflow",
".github/workflows/ci-check-testbox.yml",
"--blacksmith-job",
"check",
"--blacksmith-ref",
"main",
"--idle-timeout",
"90m",
"--ttl",
"240m",
"--timing-json",
"--",
"CI=1",
"NODE_OPTIONS=--max-old-space-size=4096",
"OPENCLAW_TEST_PROJECTS_PARALLEL=6",
"OPENCLAW_VITEST_MAX_WORKERS=1",
"OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=900000",
"OPENCLAW_TESTBOX=1",
"OPENCLAW_TESTBOX_REMOTE_RUN=1",
"pnpm",
@@ -264,15 +285,15 @@ describe("scripts/changed-lanes", () => {
});
it("does not delegate dry-run, CI, or already-remote changed gates", () => {
expect(shouldDelegateChangedCheckToTestbox(["--dry-run"], { OPENCLAW_TESTBOX: "1" })).toBe(
expect(shouldDelegateChangedCheckToCrabbox(["--dry-run"], { OPENCLAW_TESTBOX: "1" })).toBe(
false,
);
expect(
shouldDelegateChangedCheckToTestbox([], { OPENCLAW_TESTBOX: "1", GITHUB_ACTIONS: "true" }),
shouldDelegateChangedCheckToCrabbox([], { OPENCLAW_TESTBOX: "1", GITHUB_ACTIONS: "true" }),
).toBe(false);
expect(shouldDelegateChangedCheckToTestbox([], { OPENCLAW_TESTBOX: "1", CI: "1" })).toBe(false);
expect(shouldDelegateChangedCheckToCrabbox([], { OPENCLAW_TESTBOX: "1", CI: "1" })).toBe(false);
expect(
shouldDelegateChangedCheckToTestbox([], {
shouldDelegateChangedCheckToCrabbox([], {
OPENCLAW_TESTBOX: "1",
OPENCLAW_TESTBOX_REMOTE_RUN: "1",
}),

View File

@@ -1,76 +0,0 @@
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
evaluateTestboxSyncSanity,
parseGitShortStatus,
} from "../../scripts/testbox-sync-sanity.mjs";
describe("testbox sync sanity", () => {
it("parses tracked deletions from git short status", () => {
expect(
parseGitShortStatus(
" D pnpm-lock.yaml\nD package.json\n?? scratch.txt\nR old.ts -> new.ts\n",
),
).toEqual([
{
line: " D pnpm-lock.yaml",
path: "pnpm-lock.yaml",
status: " D",
trackedDeletion: true,
},
{
line: "D package.json",
path: "package.json",
status: "D ",
trackedDeletion: true,
},
{
line: "?? scratch.txt",
path: "scratch.txt",
status: "??",
trackedDeletion: false,
},
{
line: "R old.ts -> new.ts",
path: "new.ts",
status: "R ",
trackedDeletion: false,
},
]);
});
it("fails before a gate when critical repo files disappeared", () => {
const result = evaluateTestboxSyncSanity({
cwd: "/repo",
statusRaw: "",
exists: (file) => path.basename(file) !== "pnpm-lock.yaml",
});
expect(result.ok).toBe(false);
expect(result.problems).toContain("missing required root files: pnpm-lock.yaml");
});
it("fails on mass tracked deletions unless explicitly allowed", () => {
const statusRaw = Array.from({ length: 3 }, (_, index) => ` D file-${index}.ts`).join("\n");
const result = evaluateTestboxSyncSanity({
cwd: "/repo",
statusRaw,
deletionThreshold: 3,
exists: () => true,
});
expect(result.ok).toBe(false);
expect(result.trackedDeletionCount).toBe(3);
expect(result.problems[0]).toContain("remote git status has 3 tracked deletions");
expect(
evaluateTestboxSyncSanity({
cwd: "/repo",
statusRaw,
deletionThreshold: 3,
allowMassDeletions: true,
exists: () => true,
}).ok,
).toBe(true);
});
});