Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(e2e-web-bundle-guard): make health probe wait for server launch

Steven Enamakel91d53881ade6
diff --git a/scripts/__tests__/e2e-web-bundle-guard.test.mjs b/scripts/__tests__/e2e-web-bundle-guard.test.mjs
index 4dd59d4e68..1d666e77e2 100644
--- a/scripts/__tests__/e2e-web-bundle-guard.test.mjs
+++ b/scripts/__tests__/e2e-web-bundle-guard.test.mjs
@@ -54,10 +54,23 @@ function makeTree(script) {
// Every stub records that it ran, so a test can prove what was reached.
const record = (name) => `echo "${name} $*" >> "${log}"`;
- // The mock backend "starts" and exits at once; curl reports every health
- // probe as ready, so the session moves straight on to its next check.
+ // The mock backend "starts" and exits at once. Its launch is a background
+ // job, so the health probe waits for the stub to record the launch before
+ // reporting ready; otherwise a fast runner can race the child process.
writeExecutable(path.join(bin, "node"), `#!/usr/bin/env bash\n${record("node")}\n`);
- writeExecutable(path.join(bin, "curl"), `#!/usr/bin/env bash\n${record("curl")}\n`);
+ writeExecutable(
+ path.join(bin, "curl"),
+ `#!/usr/bin/env bash
+${record("curl")}
+if [[ "$1" == *"/__admin/health" ]]; then
+ for _ in {1..100}; do
+ grep -q 'mock-api-server.mjs' "${log}" && exit 0
+ sleep 0.01
+ done
+ exit 1
+fi
+`,
+ );
// `pnpm run build:web` behaves like Vite's `emptyOutDir: true`: it replaces
// dist-web wholesale, taking any marker from a previous build with it.