diff --git a/scripts/dev/gateway-smoke.ts b/scripts/dev/gateway-smoke.ts index ab61d0e1ae1f..c0df403d4fdc 100644 --- a/scripts/dev/gateway-smoke.ts +++ b/scripts/dev/gateway-smoke.ts @@ -49,9 +49,14 @@ function usage(): string { } function validateArgs(argv: readonly string[]): void { + const seen = new Set(); for (let index = 0; index < argv.length; index += 1) { const arg = argv[index] ?? ""; if (BOOLEAN_FLAGS.has(arg)) { + if (seen.has(arg)) { + throw new GatewaySmokeArgError(`${arg} was provided more than once`); + } + seen.add(arg); continue; } if (VALUE_FLAGS.has(arg)) { @@ -59,6 +64,10 @@ function validateArgs(argv: readonly string[]): void { if (!value || value.startsWith("-")) { throw new GatewaySmokeArgError(`${arg} requires a value`); } + if (seen.has(arg)) { + throw new GatewaySmokeArgError(`${arg} was provided more than once`); + } + seen.add(arg); index += 1; continue; } diff --git a/test/e2e/qa-lab/runtime/gateway-smoke.e2e.test.ts b/test/e2e/qa-lab/runtime/gateway-smoke.e2e.test.ts index 56acfd2dff78..86cfe65e1f0b 100644 --- a/test/e2e/qa-lab/runtime/gateway-smoke.e2e.test.ts +++ b/test/e2e/qa-lab/runtime/gateway-smoke.e2e.test.ts @@ -223,6 +223,33 @@ describe("gateway-smoke", () => { } }); + it("rejects duplicate CLI args before connecting", () => { + for (const [flag, args] of [ + [ + "--url", + ["--url", "ws://127.0.0.1:9", "--url", "ws://127.0.0.1:10", "--token", "token"], + ], + [ + "--token", + ["--url", "ws://127.0.0.1:9", "--token", "one", "--token", "two"], + ], + ["--help", ["--help", "--help"]], + ] as const) { + const result = spawnSync( + process.execPath, + ["--import", "tsx", "scripts/dev/gateway-smoke.ts", ...args], + { + cwd: process.cwd(), + encoding: "utf8", + }, + ); + + expect(result.status).toBe(1); + expect(result.stdout).toBe(""); + expect(result.stderr.trim()).toBe(`${flag} was provided more than once`); + } + }); + it("passes against a loopback gateway websocket using the real client", async () => { const stdout: string[] = []; const stderr: string[] = [];