




















@@ -8,6 +8,8 @@ import { setTimeout as delay } from "node:timers/promises";
88import { fileURLToPath } from "node:url";
991010const TOKEN = "bundled-plugin-runtime-smoke-token";
11+const RUNTIME_PORT_BASE_ENV = "OPENCLAW_BUNDLED_PLUGIN_RUNTIME_PORT_BASE";
12+const TCP_PORT_MAX = 65535;
1113const OUTPUT_CAPTURE_CHARS = readPositiveIntEnv(
1214"OPENCLAW_BUNDLED_PLUGIN_RUNTIME_OUTPUT_CHARS",
13151024 * 1024,
@@ -87,6 +89,17 @@ function readNonNegativeInt(raw, fallback, name) {
8789return parsed;
8890}
899192+export function resolveRuntimeSmokePort(pluginIndex, offset = 0, env = process.env) {
93+const base = readPositiveInt(env[RUNTIME_PORT_BASE_ENV], 19000, RUNTIME_PORT_BASE_ENV);
94+const port = base + pluginIndex * 3 + offset;
95+if (!Number.isSafeInteger(port) || port > TCP_PORT_MAX) {
96+throw new Error(
97+`${RUNTIME_PORT_BASE_ENV} with bundled plugin runtime index ${pluginIndex} and offset ${offset} must resolve to a TCP port from 1 to 65535. Got: ${port}`,
98+);
99+}
100+return port;
101+}
102+90103function readJson(file) {
91104return JSON.parse(fs.readFileSync(file, "utf8"));
92105}
@@ -966,8 +979,7 @@ async function smokePlugin(pluginId, pluginDir, requiresConfig, pluginIndex, plu
966979}
967980const manifest = loadManifest(pluginDir, pluginRoot);
968981const plan = buildPluginPlan(manifest);
969-const port =
970-readPositiveIntEnv("OPENCLAW_BUNDLED_PLUGIN_RUNTIME_PORT_BASE", 19000) + pluginIndex * 3;
982+const port = resolveRuntimeSmokePort(pluginIndex);
971983const config = ensureGatewayConfig(
972984activateSmokePlugin(readConfig(), pluginId, plan.channels),
973985port,
@@ -1299,8 +1311,7 @@ async function smokeTtsGlobalDisable(pluginId, pluginDir, provider, pluginIndex,
12991311console.log(`Global-disable TTS smoke skipped for ${pluginId}: no speech provider contract`);
13001312return;
13011313}
1302-const port =
1303-readPositiveIntEnv("OPENCLAW_BUNDLED_PLUGIN_RUNTIME_PORT_BASE", 19000) + pluginIndex * 3 + 1;
1314+const port = resolveRuntimeSmokePort(pluginIndex, 1);
13041315const env = createIsolatedStateEnv(`tts-disabled-${pluginId}`);
13051316writeConfig(
13061317ensureGatewayConfig(
@@ -1352,8 +1363,7 @@ async function smokeOpenAiTts(pluginIndex) {
13521363console.log("OpenAI key-backed TTS smoke skipped: OPENAI_API_KEY is not set");
13531364return;
13541365}
1355-const port =
1356-readPositiveIntEnv("OPENCLAW_BUNDLED_PLUGIN_RUNTIME_PORT_BASE", 19000) + pluginIndex * 3 + 2;
1366+const port = resolveRuntimeSmokePort(pluginIndex, 2);
13571367const env = createIsolatedStateEnv("tts-openai-live");
13581368writeConfig(
13591369ensureGatewayConfig(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。