fix(test): guard kitchen sink rpc cli args

This commit is contained in:
Vincent Koc
2026-06-20 02:36:52 +02:00
parent 4575734f59
commit 49b0487e5b
2 changed files with 35 additions and 1 deletions

View File

@@ -85,6 +85,15 @@ export function shouldPrintHelp(argv) {
return argv.some((arg) => arg === "--help" || arg === "-h");
}
export function validateCliArgs(argv) {
for (const arg of argv) {
if (arg === "--help" || arg === "-h") {
continue;
}
throw new Error(`Unknown argument: ${arg}`);
}
}
export function readPositiveInt(raw, fallback, label = "value") {
const text = String(raw || "").trim();
if (!text) {
@@ -2597,9 +2606,16 @@ export async function main() {
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
if (shouldPrintHelp(process.argv.slice(2))) {
const argv = process.argv.slice(2);
if (shouldPrintHelp(argv)) {
process.stdout.write(usage());
} else {
try {
validateCliArgs(argv);
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exit(1);
}
await main();
}
}

View File

@@ -55,6 +55,7 @@ import {
tailFile,
unwrapRpcPayload,
usesBuiltOpenClawEntry,
validateCliArgs,
waitForGatewayReady,
} from "../../scripts/e2e/kitchen-sink-rpc-walk.mjs";
import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
@@ -116,6 +117,23 @@ describe("kitchen-sink RPC isolated state", () => {
expect(shouldPrintHelp([])).toBe(false);
});
it("rejects unknown CLI args before creating temp state", async () => {
expect(() => validateCliArgs(["--wat"])).toThrow("Unknown argument: --wat");
const error = await runCommand(process.execPath, [
"scripts/e2e/kitchen-sink-rpc-walk.mjs",
"--wat",
]).then(
() => undefined,
(caught: unknown) => caught as Error & { stderr?: string; stdout?: string },
);
expect(error).toBeDefined();
expect(error?.stdout).toBe("");
expect(error?.stderr?.trim()).toBe("Unknown argument: --wat");
expect(error?.stderr).not.toContain("temp root preserved");
});
it("rejects loose numeric env values before they bypass runtime guardrails", () => {
expect(readPositiveInt(undefined, 60_000)).toBe(60_000);
expect(readPositiveInt("", 60_000)).toBe(60_000);