




























@@ -17,11 +17,37 @@ function option(name, fallback) {
1717return value;
1818}
191920+function optionValue(name, envName, fallback) {
21+const index = args.indexOf(name);
22+if (index !== -1) {
23+return {
24+label: name,
25+value: option(name),
26+};
27+}
28+return {
29+label: envName,
30+value: process.env[envName] ?? fallback,
31+};
32+}
33+2034function writeJson(file, value) {
2135fs.mkdirSync(path.dirname(file), { recursive: true });
2236fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
2337}
243839+function readStrictInteger({ allowZero = false, label, value }) {
40+const text = String(value ?? "").trim();
41+if (!/^\d+$/u.test(text)) {
42+throw new Error(`invalid ${label}: ${text}`);
43+}
44+const parsed = Number(text);
45+if (!Number.isSafeInteger(parsed) || (allowZero ? parsed < 0 : parsed <= 0)) {
46+throw new Error(`invalid ${label}: ${text}`);
47+}
48+return parsed;
49+}
50+2551const baseUrl = option("--base-url");
2652const probePath = option("--path");
2753const expectKind = option("--expect");
@@ -32,35 +58,25 @@ const allowFailing = new Set(
3258.map((entry) => entry.trim())
3359.filter(Boolean),
3460);
35-const timeoutMs = Number.parseInt(
36-option("--timeout-ms", process.env.OPENCLAW_UPGRADE_SURVIVOR_PROBE_TIMEOUT_MS || "60000"),
37-10,
61+const timeoutOption = optionValue(
62+"--timeout-ms",
63+"OPENCLAW_UPGRADE_SURVIVOR_PROBE_TIMEOUT_MS",
64+"60000",
3865);
39-const attemptTimeoutMs = Number.parseInt(
40-option(
41-"--attempt-timeout-ms",
42-process.env.OPENCLAW_UPGRADE_SURVIVOR_PROBE_ATTEMPT_TIMEOUT_MS || "5000",
43-),
44-10,
66+const attemptTimeoutOption = optionValue(
67+"--attempt-timeout-ms",
68+"OPENCLAW_UPGRADE_SURVIVOR_PROBE_ATTEMPT_TIMEOUT_MS",
69+"5000",
4570);
46-const maxBodyBytes = Number.parseInt(
47-option(
48-"--max-body-bytes",
49-process.env.OPENCLAW_UPGRADE_SURVIVOR_PROBE_MAX_BODY_BYTES || "1048576",
50-),
51-10,
71+const maxBodyOption = optionValue(
72+"--max-body-bytes",
73+"OPENCLAW_UPGRADE_SURVIVOR_PROBE_MAX_BODY_BYTES",
74+"1048576",
5275);
76+const timeoutMs = readStrictInteger({ ...timeoutOption, allowZero: true });
77+const attemptTimeoutMs = readStrictInteger(attemptTimeoutOption);
78+const maxBodyBytes = readStrictInteger(maxBodyOption);
5379const url = new URL(probePath, baseUrl).toString();
54-55-if (!Number.isFinite(timeoutMs) || timeoutMs < 0) {
56-throw new Error(`invalid --timeout-ms: ${String(timeoutMs)}`);
57-}
58-if (!Number.isFinite(attemptTimeoutMs) || attemptTimeoutMs <= 0) {
59-throw new Error(`invalid --attempt-timeout-ms: ${String(attemptTimeoutMs)}`);
60-}
61-if (!Number.isFinite(maxBodyBytes) || maxBodyBytes <= 0) {
62-throw new Error(`invalid --max-body-bytes: ${String(maxBodyBytes)}`);
63-}
6480if (expectKind !== "live" && expectKind !== "ready") {
6581throw new Error(`unknown probe expectation: ${expectKind}`);
6682}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。