mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-22 11:48:11 +00:00
fix(qa): reject invalid qa lab ports
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { parseArgs } from "node:util";
|
||||
import { parseStrictPositiveInteger } from "../src/infra/parse-finite-number.js";
|
||||
|
||||
const options = {
|
||||
help: { type: "boolean", short: "h" },
|
||||
@@ -64,23 +65,26 @@ async function runQaLabUp(argv: readonly string[], deps: QaLabUpDeps = {}): Prom
|
||||
return 0;
|
||||
}
|
||||
|
||||
const parsePort = (value: string | undefined) => {
|
||||
const parsePort = (value: string | undefined, flag: string) => {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
const parsed = Number(value);
|
||||
if (!Number.isFinite(parsed)) {
|
||||
throw new Error(`Invalid port: ${value}`);
|
||||
const parsed = parseStrictPositiveInteger(value);
|
||||
if (parsed === undefined) {
|
||||
throw new Error(`${flag} must be a positive integer.`);
|
||||
}
|
||||
return parsed;
|
||||
};
|
||||
|
||||
const gatewayPort = parsePort(values["gateway-port"], "--gateway-port");
|
||||
const qaLabPort = parsePort(values["qa-lab-port"], "--qa-lab-port");
|
||||
|
||||
const { runQaDockerUpCommand } = await (deps.loadRuntime ?? loadQaLabRuntime)();
|
||||
|
||||
await runQaDockerUpCommand({
|
||||
outputDir: values["output-dir"],
|
||||
gatewayPort: parsePort(values["gateway-port"]),
|
||||
qaLabPort: parsePort(values["qa-lab-port"]),
|
||||
gatewayPort,
|
||||
qaLabPort,
|
||||
providerBaseUrl: values["provider-base-url"],
|
||||
image: values.image,
|
||||
usePrebuiltImage: values["use-prebuilt-image"],
|
||||
|
||||
@@ -33,4 +33,17 @@ describe("scripts/qa-lab-up", () => {
|
||||
expect.objectContaining({ gatewayPort: 4100 }),
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[["--gateway-port", "1.5"], "--gateway-port must be a positive integer."],
|
||||
[["--gateway-port", "0x1000"], "--gateway-port must be a positive integer."],
|
||||
[["--gateway-port", "0"], "--gateway-port must be a positive integer."],
|
||||
[["--qa-lab-port", "1e4"], "--qa-lab-port must be a positive integer."],
|
||||
])("rejects non-decimal positive integer ports: %j", async (args, errorMessage) => {
|
||||
const loadRuntime = vi.fn(async () => ({ runQaDockerUpCommand: vi.fn(async () => {}) }));
|
||||
|
||||
await expect(qaLabUpTesting.runQaLabUp(args, { loadRuntime })).rejects.toThrow(errorMessage);
|
||||
|
||||
expect(loadRuntime).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user