fix: copy serve.ts into the Docker build stage

The image build ran the tests without serve.ts present, so the server the
tests spawn never started and the hook stalled until it timed out. The
runtime stage would have failed on the same missing file immediately after.

The test now bails the moment the process exits and reports its stderr, so
this shows up as "serve.ts exited with 1 before listening" in 53ms rather
than an unexplained hook timeout after five seconds.

serve.ts is also in tsconfig's include now — it was outside it, so a type
error in the file that serves the app would only have surfaced at runtime.
Adding it immediately caught one in the test.

Verified by replaying the build stage against exactly the copied file set.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Lucas Winther
2026-08-15 01:35:25 +02:00
co-authored by Claude Opus 5
parent fd1111017f
commit 3bab95acd5
5 changed files with 44 additions and 16 deletions
+18 -5
View File
@@ -33,19 +33,32 @@ beforeAll(async () => {
proc = Bun.spawn(["bun", "run", "serve.ts"], {
env: { ...process.env, PORT: String(port), PUBLIC_DIR: root },
stdout: "ignore",
stderr: "ignore",
stderr: "pipe",
});
for (let i = 0; i < 60; i += 1) {
// Bail as soon as the process dies rather than retrying against a corpse:
// a missing serve.ts otherwise shows up only as "a hook timed out", which
// says nothing about the cause.
for (let i = 0; i < 40; i += 1) {
if (proc.exitCode !== null) {
const stderr = proc.stderr;
const why =
stderr instanceof ReadableStream
? await new Response(stderr).text()
: "(no stderr captured)";
throw new Error(
`serve.ts exited with ${proc.exitCode} before listening:\n${why.slice(0, 500)}`,
);
}
try {
await fetch(`${base}/api/health`);
return;
} catch {
await Bun.sleep(100);
await Bun.sleep(50);
}
}
throw new Error("server did not start");
});
throw new Error(`server did not listen on ${base} within 2s`);
}, 10_000);
afterAll(async () => {
proc.kill();