




























@@ -10,23 +10,16 @@ const outputDir = process.env.OPENCLAW_NPM_TELEGRAM_OUTPUT_DIR ?? ".artifacts/rt
1010const telegramApiBaseUrl = (
1111process.env.OPENCLAW_QA_TELEGRAM_API_BASE_URL ?? "https://api.telegram.org"
1212).replace(/\/+$/u, "");
13-const timeoutMs = Number(process.env.OPENCLAW_QA_TELEGRAM_SCENARIO_TIMEOUT_MS ?? "180000");
14-const canaryTimeoutMs = Number(
15-process.env.OPENCLAW_QA_TELEGRAM_CANARY_TIMEOUT_MS ?? String(timeoutMs),
16-);
17-const warmSampleCount = Number(process.env.OPENCLAW_NPM_TELEGRAM_WARM_SAMPLES ?? "20");
18-const sampleTimeoutMs = Number(process.env.OPENCLAW_NPM_TELEGRAM_SAMPLE_TIMEOUT_MS ?? "30000");
19-const botApiTimeoutMs = readPositiveInt(
20-process.env.OPENCLAW_NPM_TELEGRAM_BOT_API_TIMEOUT_MS,
21-30000,
22-);
23-const botApiBodyMaxBytes = readPositiveInt(
24-process.env.OPENCLAW_NPM_TELEGRAM_BOT_API_BODY_MAX_BYTES,
13+const timeoutMs = readPositiveIntEnv("OPENCLAW_QA_TELEGRAM_SCENARIO_TIMEOUT_MS", 180000);
14+const canaryTimeoutMs = readPositiveIntEnv("OPENCLAW_QA_TELEGRAM_CANARY_TIMEOUT_MS", timeoutMs);
15+const warmSampleCount = readPositiveIntEnv("OPENCLAW_NPM_TELEGRAM_WARM_SAMPLES", 20);
16+const sampleTimeoutMs = readPositiveIntEnv("OPENCLAW_NPM_TELEGRAM_SAMPLE_TIMEOUT_MS", 30000);
17+const botApiTimeoutMs = readPositiveIntEnv("OPENCLAW_NPM_TELEGRAM_BOT_API_TIMEOUT_MS", 30000);
18+const botApiBodyMaxBytes = readPositiveIntEnv(
19+"OPENCLAW_NPM_TELEGRAM_BOT_API_BODY_MAX_BYTES",
25201024 * 1024,
2621);
27-const maxWarmFailures = Number(
28-process.env.OPENCLAW_NPM_TELEGRAM_MAX_FAILURES ?? String(warmSampleCount),
29-);
22+const maxWarmFailures = readPositiveIntEnv("OPENCLAW_NPM_TELEGRAM_MAX_FAILURES", warmSampleCount);
3023const successMarker = process.env.OPENCLAW_NPM_TELEGRAM_SUCCESS_MARKER ?? "OPENCLAW_E2E_OK";
3124const scenarioIds = new Set(
3225(process.env.OPENCLAW_NPM_TELEGRAM_SCENARIOS ?? "telegram-mentioned-message-reply")
@@ -40,25 +33,16 @@ if (!groupId || !driverToken || !sutToken) {
4033"missing Telegram env: OPENCLAW_QA_TELEGRAM_GROUP_ID, OPENCLAW_QA_TELEGRAM_DRIVER_BOT_TOKEN, OPENCLAW_QA_TELEGRAM_SUT_BOT_TOKEN",
4134);
4235}
43-if (!Number.isInteger(warmSampleCount) || warmSampleCount < 1) {
44-throw new Error(
45-`OPENCLAW_NPM_TELEGRAM_WARM_SAMPLES must be a positive integer; got: ${warmSampleCount}`,
46-);
47-}
48-if (!Number.isInteger(sampleTimeoutMs) || sampleTimeoutMs < 1) {
49-throw new Error(
50-`OPENCLAW_NPM_TELEGRAM_SAMPLE_TIMEOUT_MS must be a positive integer; got: ${sampleTimeoutMs}`,
51-);
52-}
53-if (!Number.isInteger(maxWarmFailures) || maxWarmFailures < 1) {
54-throw new Error(
55-`OPENCLAW_NPM_TELEGRAM_MAX_FAILURES must be a positive integer; got: ${maxWarmFailures}`,
56-);
57-}
58-59-function readPositiveInt(raw, fallback) {
60-const parsed = Number.parseInt(String(raw || ""), 10);
61-return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
36+function readPositiveIntEnv(name, fallback) {
37+const text = String(process.env[name] ?? fallback).trim();
38+if (!/^\d+$/u.test(text)) {
39+throw new Error(`invalid ${name}: ${text}`);
40+}
41+const value = Number(text);
42+if (!Number.isSafeInteger(value) || value <= 0) {
43+throw new Error(`invalid ${name}: ${text}`);
44+}
45+return value;
6246}
63476448function taggedError(message, code) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。