Skip to content

Commit 81f62a6

Browse files
committed
fix(scripts): add docker e2e scheduler help
1 parent 083377a commit 81f62a6

2 files changed

Lines changed: 86 additions & 6 deletions

File tree

scripts/test-docker-all.mjs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,51 @@ const DEFAULT_GITHUB_WORKFLOW = "openclaw-live-and-e2e-checks-reusable.yml";
4141
const IS_MAIN = process.argv[1]
4242
? path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
4343
: false;
44-
const cliArgs = new Set(IS_MAIN ? process.argv.slice(2) : []);
45-
if (IS_MAIN) {
46-
for (const arg of cliArgs) {
47-
if (arg !== "--plan-json") {
48-
throw new Error(`unknown argument: ${arg}`);
44+
45+
export function dockerAllUsage() {
46+
return [
47+
"Usage: node scripts/test-docker-all.mjs [--plan-json]",
48+
"",
49+
"Options:",
50+
" --plan-json Print the resolved Docker E2E plan as JSON and exit.",
51+
" -h, --help Show this help.",
52+
"",
53+
"Lane selection and scheduler settings are configured with OPENCLAW_DOCKER_ALL_* env vars.",
54+
].join("\n");
55+
}
56+
57+
export function parseDockerAllCliArgs(argv) {
58+
const options = {
59+
help: false,
60+
planJson: false,
61+
};
62+
for (const arg of argv) {
63+
if (arg === "--plan-json") {
64+
options.planJson = true;
65+
} else if (arg === "--help" || arg === "-h") {
66+
options.help = true;
67+
} else {
68+
throw new Error(`unknown argument: ${arg}\n\n${dockerAllUsage()}`);
4969
}
5070
}
71+
return options;
72+
}
73+
74+
let cliOptions = {
75+
help: false,
76+
planJson: false,
77+
};
78+
if (IS_MAIN) {
79+
try {
80+
cliOptions = parseDockerAllCliArgs(process.argv.slice(2));
81+
} catch (error) {
82+
console.error(error instanceof Error ? error.message : String(error));
83+
process.exit(1);
84+
}
85+
if (cliOptions.help) {
86+
console.log(dockerAllUsage());
87+
process.exit(0);
88+
}
5189
}
5290

5391
function parsePositiveInt(raw, fallback, label) {
@@ -1107,7 +1145,7 @@ async function main() {
11071145
const timingsEnabled = parseBool(process.env.OPENCLAW_DOCKER_ALL_TIMINGS, true);
11081146
const buildEnabled = parseBool(process.env.OPENCLAW_DOCKER_ALL_BUILD, true);
11091147
const planJson =
1110-
cliArgs.has("--plan-json") || parseBool(process.env.OPENCLAW_DOCKER_ALL_PLAN_JSON, false);
1148+
cliOptions.planJson || parseBool(process.env.OPENCLAW_DOCKER_ALL_PLAN_JSON, false);
11111149
const planReleaseAll = parseBool(process.env.OPENCLAW_DOCKER_ALL_PLAN_RELEASE_ALL, false);
11121150
const profile = parseProfile(process.env.OPENCLAW_DOCKER_ALL_PROFILE);
11131151
const releaseProfile = normalizeReleaseProfile(

test/scripts/docker-all-scheduler.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { spawnSync } from "node:child_process";
12
import { describe, expect, it } from "vitest";
23
import { DEFAULT_RESOURCE_LIMITS } from "../../scripts/lib/docker-e2e-plan.mjs";
34
import {
45
canStartSchedulerLane,
56
describeDockerSchedulerLimits,
7+
parseDockerAllCliArgs,
68
} from "../../scripts/test-docker-all.mjs";
79

810
const limits = {
@@ -30,6 +32,46 @@ function activePool({
3032
}
3133

3234
describe("scripts/test-docker-all scheduler", () => {
35+
it("parses the supported CLI options", () => {
36+
expect(parseDockerAllCliArgs([])).toEqual({
37+
help: false,
38+
planJson: false,
39+
});
40+
expect(parseDockerAllCliArgs(["--plan-json"])).toEqual({
41+
help: false,
42+
planJson: true,
43+
});
44+
expect(parseDockerAllCliArgs(["--help"])).toEqual({
45+
help: true,
46+
planJson: false,
47+
});
48+
});
49+
50+
it("prints CLI help without a stack trace", () => {
51+
const result = spawnSync(process.execPath, ["scripts/test-docker-all.mjs", "--help"], {
52+
cwd: process.cwd(),
53+
encoding: "utf8",
54+
});
55+
56+
expect(result.status).toBe(0);
57+
expect(result.stderr).toBe("");
58+
expect(result.stdout).toContain("Usage: node scripts/test-docker-all.mjs [--plan-json]");
59+
expect(result.stdout).toContain("OPENCLAW_DOCKER_ALL_* env vars");
60+
});
61+
62+
it("rejects unknown CLI options without a stack trace", () => {
63+
const result = spawnSync(process.execPath, ["scripts/test-docker-all.mjs", "--bogus"], {
64+
cwd: process.cwd(),
65+
encoding: "utf8",
66+
});
67+
68+
expect(result.status).toBe(1);
69+
expect(result.stdout).toBe("");
70+
expect(result.stderr).toContain("unknown argument: --bogus");
71+
expect(result.stderr).toContain("Usage: node scripts/test-docker-all.mjs [--plan-json]");
72+
expect(result.stderr).not.toContain("at ");
73+
});
74+
3375
it("allows an overweight lane to start alone under low parallelism", () => {
3476
expect(
3577
canStartSchedulerLane(

0 commit comments

Comments
 (0)