






















11import fs from "node:fs";
22import os from "node:os";
33import path from "node:path";
4+import { readPositiveIntEnv } from "../env-limits.mjs";
4556const command = process.argv[2];
67const scratchRoot = process.env.OPENCLAW_PLUGINS_TMP_DIR || os.tmpdir();
7-const CLAWHUB_PREFLIGHT_TIMEOUT_MS = readPositiveInt(
8-process.env.OPENCLAW_PLUGINS_E2E_CLAWHUB_PREFLIGHT_TIMEOUT_MS,
9-30_000,
10-);
11-const CLAWHUB_PREFLIGHT_BODY_MAX_BYTES = readPositiveInt(
12-process.env.OPENCLAW_PLUGINS_E2E_CLAWHUB_PREFLIGHT_BODY_MAX_BYTES,
13-1024 * 1024,
14-);
158const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
169const scratchFile = (name) => path.join(scratchRoot, name);
171018-function readPositiveInt(raw, fallback) {
19-const parsed = Number.parseInt(String(raw || ""), 10);
20-return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
11+function readClawHubPreflightLimits() {
12+return {
13+bodyMaxBytes: readPositiveIntEnv(
14+"OPENCLAW_PLUGINS_E2E_CLAWHUB_PREFLIGHT_BODY_MAX_BYTES",
15+1024 * 1024,
16+),
17+timeoutMs: readPositiveIntEnv(
18+"OPENCLAW_PLUGINS_E2E_CLAWHUB_PREFLIGHT_TIMEOUT_MS",
19+30_000,
20+),
21+};
2122}
22232324function createTimeoutError(label, timeoutMs) {
@@ -826,6 +827,7 @@ async function assertClawHubPreflight() {
826827throw new Error(`expected clawhub: spec, got ${spec}`);
827828}
828829830+const limits = readClawHubPreflightLimits();
829831const packageName = parseClawHubPackageName(spec);
830832const baseUrl = (
831833process.env.OPENCLAW_CLAWHUB_URL ||
@@ -840,7 +842,7 @@ async function assertClawHubPreflight() {
840842const preflightUrl = `${baseUrl}/api/v1/packages/${encodeURIComponent(packageName)}`;
841843const response = await withTimeout(
842844`ClawHub package preflight for ${packageName}`,
843-CLAWHUB_PREFLIGHT_TIMEOUT_MS,
845+limits.timeoutMs,
844846(signal) =>
845847fetch(preflightUrl, {
846848headers: token ? { Authorization: `Bearer ${token}` } : undefined,
@@ -850,12 +852,12 @@ async function assertClawHubPreflight() {
850852if (!response.ok) {
851853const body = await withTimeout(
852854`ClawHub package preflight response for ${packageName}`,
853-CLAWHUB_PREFLIGHT_TIMEOUT_MS,
855+limits.timeoutMs,
854856() =>
855857readBoundedResponseText(
856858response,
857859`ClawHub package preflight response for ${packageName}`,
858-CLAWHUB_PREFLIGHT_BODY_MAX_BYTES,
860+limits.bodyMaxBytes,
859861),
860862);
861863throw new Error(
@@ -864,17 +866,17 @@ async function assertClawHubPreflight() {
864866}
865867const rawDetail = await withTimeout(
866868`ClawHub package preflight response for ${packageName}`,
867-CLAWHUB_PREFLIGHT_TIMEOUT_MS,
869+limits.timeoutMs,
868870() =>
869871readBoundedResponseText(
870872response,
871873`ClawHub package preflight response for ${packageName}`,
872-CLAWHUB_PREFLIGHT_BODY_MAX_BYTES,
874+limits.bodyMaxBytes,
873875),
874876);
875877const detail = await withTimeout(
876878`ClawHub package preflight JSON for ${packageName}`,
877-CLAWHUB_PREFLIGHT_TIMEOUT_MS,
879+limits.timeoutMs,
878880() => JSON.parse(rawDetail),
879881);
880882const family = detail.package?.family;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。