Skip to content

Commit f664f7f

Browse files
committed
fix(e2e): share ClawHub preflight timeout across fetch and body
1 parent a24cf63 commit f664f7f

2 files changed

Lines changed: 64 additions & 34 deletions

File tree

‎scripts/e2e/lib/plugins/assertions.mjs‎

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -846,46 +846,28 @@ async function assertClawHubPreflight() {
846846
).replace(/\/+$/, "");
847847
const token = process.env.CLAWHUB_TOKEN || process.env.CLAWHUB_AUTH_TOKEN || "";
848848
const preflightUrl = `${baseUrl}/api/v1/packages/${encodeURIComponent(packageName)}`;
849-
const response = await withTimeout(
849+
// One deadline covers fetch + body read. timeoutMs is a total budget, not per phase.
850+
const detail = await withTimeout(
850851
`ClawHub package preflight for ${packageName}`,
851852
limits.timeoutMs,
852-
(signal) =>
853-
fetch(preflightUrl, {
853+
async (signal, timeoutPromise) => {
854+
const response = await fetch(preflightUrl, {
854855
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
855856
signal,
856-
}),
857-
);
858-
if (!response.ok) {
859-
const body = await withTimeout(
860-
`ClawHub package preflight response for ${packageName}`,
861-
limits.timeoutMs,
862-
(_signal, timeoutPromise) =>
863-
readBoundedResponseText(
864-
response,
865-
`ClawHub package preflight response for ${packageName}`,
866-
limits.bodyMaxBytes,
867-
timeoutPromise,
868-
),
869-
);
870-
throw new Error(
871-
`ClawHub package preflight failed for ${packageName}: ${response.status} ${body}`,
872-
);
873-
}
874-
const rawDetail = await withTimeout(
875-
`ClawHub package preflight response for ${packageName}`,
876-
limits.timeoutMs,
877-
(_signal, timeoutPromise) =>
878-
readBoundedResponseText(
857+
});
858+
const rawDetail = await readBoundedResponseText(
879859
response,
880860
`ClawHub package preflight response for ${packageName}`,
881861
limits.bodyMaxBytes,
882862
timeoutPromise,
883-
),
884-
);
885-
const detail = await withTimeout(
886-
`ClawHub package preflight JSON for ${packageName}`,
887-
limits.timeoutMs,
888-
() => JSON.parse(rawDetail),
863+
);
864+
if (!response.ok) {
865+
throw new Error(
866+
`ClawHub package preflight failed for ${packageName}: ${response.status} ${rawDetail}`,
867+
);
868+
}
869+
return JSON.parse(rawDetail);
870+
},
889871
);
890872
const family = detail.package?.family;
891873
if (family !== "code-plugin" && family !== "bundle-plugin") {

‎test/scripts/plugins-assertions.test.ts‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ describe("plugins Docker assertions", () => {
225225
expect(script).toContain("run(controller.signal, timeoutPromise)");
226226
expect(
227227
script.match(/readBoundedResponseText\([\s\S]*?limits\.bodyMaxBytes,\n\s+timeoutPromise,/gu),
228-
).toHaveLength(2);
228+
).toHaveLength(1);
229+
expect(script).toMatch(
230+
/withTimeout\(\s*`ClawHub package preflight for \$\{packageName\}`,\s*limits\.timeoutMs,\s*async \(signal, timeoutPromise\) => \{[\s\S]*?fetch\([\s\S]*?readBoundedResponseText\([\s\S]*?JSON\.parse\(rawDetail\)/u,
231+
);
229232
});
230233

231234
it("keeps sweep artifact paths aligned with the assertion scratch root", () => {
@@ -1444,8 +1447,53 @@ test -d "$OPENCLAW_PLUGINS_TMP_DIR"
14441447

14451448
expect(result.status).not.toBe(0);
14461449
expect(result.stderr).toContain(
1447-
"ClawHub package preflight response for @openclaw/kitchen-sink timed out after 75ms",
1450+
"ClawHub package preflight for @openclaw/kitchen-sink timed out after 75ms",
1451+
);
1452+
} finally {
1453+
await new Promise<void>((resolve) => {
1454+
server.close(() => resolve());
1455+
});
1456+
}
1457+
});
1458+
1459+
it("keeps ClawHub preflight wall time within one shared timeout budget", async () => {
1460+
const timeoutMs = 300;
1461+
const headerDelayMs = 250;
1462+
// Shared budget finishes near spawn + timeoutMs. Stacked per-phase budgets need at
1463+
// least spawn + headerDelayMs + timeoutMs, so they cannot pass this ceiling.
1464+
const maxSharedElapsedMs = timeoutMs + 240;
1465+
const server = createServer((_request, response) => {
1466+
const timer = setTimeout(() => {
1467+
response.writeHead(200, { "content-type": "application/json" });
1468+
response.flushHeaders();
1469+
response.write("{");
1470+
}, headerDelayMs);
1471+
timer.unref?.();
1472+
});
1473+
await new Promise<void>((resolve) => {
1474+
server.listen(0, "127.0.0.1", resolve);
1475+
});
1476+
1477+
try {
1478+
const address = server.address();
1479+
if (!address || typeof address === "string") {
1480+
throw new Error("expected TCP server address");
1481+
}
1482+
const started = Date.now();
1483+
const result = await runAssertionAsync(["clawhub-preflight"], {
1484+
CLAWHUB_PLUGIN_ID: "openclaw-kitchen-sink-fixture",
1485+
CLAWHUB_PLUGIN_SPEC: "clawhub:@openclaw/kitchen-sink",
1486+
OPENCLAW_CLAWHUB_URL: `http://127.0.0.1:${address.port}`,
1487+
OPENCLAW_PLUGINS_E2E_CLAWHUB_PREFLIGHT_TIMEOUT_MS: String(timeoutMs),
1488+
});
1489+
const elapsedMs = Date.now() - started;
1490+
1491+
expect(result.status).not.toBe(0);
1492+
expect(result.stderr).toContain(
1493+
`ClawHub package preflight for @openclaw/kitchen-sink timed out after ${timeoutMs}ms`,
14481494
);
1495+
expect(maxSharedElapsedMs).toBeLessThan(headerDelayMs + timeoutMs);
1496+
expect(elapsedMs).toBeLessThan(maxSharedElapsedMs);
14491497
} finally {
14501498
await new Promise<void>((resolve) => {
14511499
server.close(() => resolve());

0 commit comments

Comments
 (0)