fix(qa): reject loose OpenWebUI probe statuses · openclaw/openclaw@e8022eb
vincentkoc
·
2026-06-17
·
via Recent Commits to openclaw:main
File tree
scripts/e2e/lib/openwebui
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,7 +6,15 @@ if (!url) {
|
6 | 6 | throw new Error("usage: http-probe.mjs <url> [status|lt500]"); |
7 | 7 | } |
8 | 8 | |
| 9 | +function parseExpectedStatus(raw) { |
| 10 | +if (!/^[1-5]\d\d$/u.test(raw)) { |
| 11 | +throw new Error(`expected status must be lt500 or a decimal HTTP status. Got: ${raw}`); |
| 12 | +} |
| 13 | +return Number(raw); |
| 14 | +} |
| 15 | + |
9 | 16 | const timeoutMs = readPositiveIntEnv("OPENCLAW_HTTP_PROBE_TIMEOUT_MS", 30_000); |
| 17 | +const expectedStatus = expectedRaw === "lt500" ? undefined : parseExpectedStatus(expectedRaw); |
10 | 18 | const controller = new AbortController(); |
11 | 19 | const timer = setTimeout(() => controller.abort(), timeoutMs); |
12 | 20 | |
@@ -17,9 +25,7 @@ try {
|
17 | 25 | } |
18 | 26 | const res = await fetch(url, { headers, signal: controller.signal }).catch(() => null); |
19 | 27 | const ok = |
20 | | -expectedRaw === "lt500" |
21 | | - ? Boolean(res && res.status < 500) |
22 | | - : res?.status === Number(expectedRaw); |
| 28 | +expectedRaw === "lt500" ? Boolean(res && res.status < 500) : res?.status === expectedStatus; |
23 | 29 | process.exit(ok ? 0 : 1); |
24 | 30 | } finally { |
25 | 31 | clearTimeout(timer); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -170,6 +170,15 @@ describe("e2e helper numeric env limits", () => {
|
170 | 170 | expect(result.stderr).toContain("invalid OPENCLAW_HTTP_PROBE_TIMEOUT_MS: 8000ms"); |
171 | 171 | }); |
172 | 172 | |
| 173 | +it("rejects loose Open WebUI HTTP probe expected statuses", () => { |
| 174 | +const result = runScript(httpProbePath, ["http://127.0.0.1:9", "2e2"]); |
| 175 | + |
| 176 | +expect(result.status).not.toBe(0); |
| 177 | +expect(result.stderr).toContain( |
| 178 | +"expected status must be lt500 or a decimal HTTP status. Got: 2e2", |
| 179 | +); |
| 180 | +}); |
| 181 | + |
173 | 182 | it("keeps Open WebUI HTTP probe status checks working with strict timeouts", async () => { |
174 | 183 | const server = createServer((_request, response) => { |
175 | 184 | response.writeHead(204).end(); |
@@ -185,4 +194,20 @@ describe("e2e helper numeric env limits", () => {
|
185 | 194 | server.close(); |
186 | 195 | } |
187 | 196 | }); |
| 197 | + |
| 198 | +it("keeps Open WebUI HTTP probe lt500 status checks working", async () => { |
| 199 | +const server = createServer((_request, response) => { |
| 200 | +response.writeHead(404).end(); |
| 201 | +}); |
| 202 | +const url = await listen(server); |
| 203 | +try { |
| 204 | +const result = await runScriptAsync(httpProbePath, [url, "lt500"], { |
| 205 | +OPENCLAW_HTTP_PROBE_TIMEOUT_MS: "500", |
| 206 | +}); |
| 207 | + |
| 208 | +expect(result.status).toBe(0); |
| 209 | +} finally { |
| 210 | +server.close(); |
| 211 | +} |
| 212 | +}); |
188 | 213 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。