mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 19:12:22 +00:00
fix(test): guard kitchen sink rpc cli args
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user