






















@@ -0,0 +1,101 @@
1+import { spawn, spawnSync } from "node:child_process";
2+import { createServer, type Server } from "node:http";
3+import { describe, expect, it } from "vitest";
4+5+const browserFixturePath = "scripts/e2e/lib/browser-cdp-snapshot/fixture-server.mjs";
6+const clickclackFixturePath = "scripts/e2e/lib/release-user-journey/clickclack-fixture.mjs";
7+const httpProbePath = "scripts/e2e/lib/openwebui/http-probe.mjs";
8+9+function runScript(scriptPath: string, args: string[] = [], env: Record<string, string> = {}) {
10+return spawnSync(process.execPath, [scriptPath, ...args], {
11+encoding: "utf8",
12+env: { ...process.env, ...env },
13+});
14+}
15+16+function runScriptAsync(
17+scriptPath: string,
18+args: string[] = [],
19+env: Record<string, string> = {},
20+timeout = 3_000,
21+) {
22+return new Promise<{ stderr: string; stdout: string; status: number | null }>((resolve) => {
23+const child = spawn(process.execPath, [scriptPath, ...args], {
24+env: { ...process.env, ...env },
25+stdio: ["ignore", "pipe", "pipe"],
26+});
27+let stdout = "";
28+let stderr = "";
29+child.stdout.setEncoding("utf8");
30+child.stderr.setEncoding("utf8");
31+child.stdout.on("data", (chunk) => {
32+stdout += chunk;
33+});
34+child.stderr.on("data", (chunk) => {
35+stderr += chunk;
36+});
37+const timer = setTimeout(() => child.kill("SIGKILL"), timeout);
38+child.on("exit", (status) => {
39+clearTimeout(timer);
40+resolve({ stderr, stdout, status });
41+});
42+});
43+}
44+45+async function listen(server: Server): Promise<string> {
46+await new Promise<void>((resolve, reject) => {
47+server.once("error", reject);
48+server.listen(0, "127.0.0.1", () => {
49+server.off("error", reject);
50+resolve();
51+});
52+});
53+const address = server.address();
54+if (!address || typeof address === "string") {
55+throw new Error("test server did not expose a TCP port");
56+}
57+return `http://127.0.0.1:${address.port}`;
58+}
59+60+describe("e2e helper numeric env limits", () => {
61+it("rejects loose Browser CDP fixture ports", async () => {
62+const result = await runScriptAsync(browserFixturePath, [], { FIXTURE_PORT: "18080http" });
63+64+expect(result.status).not.toBe(0);
65+expect(result.stderr).toContain("invalid FIXTURE_PORT: 18080http");
66+});
67+68+it("rejects loose release ClickClack fixture ports", () => {
69+const result = runScript(clickclackFixturePath, [], {
70+CLICKCLACK_FIXTURE_PORT: "44181tcp",
71+});
72+73+expect(result.status).not.toBe(0);
74+expect(result.stderr).toContain("invalid CLICKCLACK_FIXTURE_PORT: 44181tcp");
75+});
76+77+it("rejects loose Open WebUI HTTP probe timeouts", () => {
78+const result = runScript(httpProbePath, ["http://127.0.0.1:9"], {
79+OPENCLAW_HTTP_PROBE_TIMEOUT_MS: "8000ms",
80+});
81+82+expect(result.status).not.toBe(0);
83+expect(result.stderr).toContain("invalid OPENCLAW_HTTP_PROBE_TIMEOUT_MS: 8000ms");
84+});
85+86+it("keeps Open WebUI HTTP probe status checks working with strict timeouts", async () => {
87+const server = createServer((_request, response) => {
88+response.writeHead(204).end();
89+});
90+const url = await listen(server);
91+try {
92+const result = await runScriptAsync(httpProbePath, [url, "204"], {
93+OPENCLAW_HTTP_PROBE_TIMEOUT_MS: "500",
94+});
95+96+expect(result.status).toBe(0);
97+} finally {
98+server.close();
99+}
100+});
101+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。