Files
core/test/bun/health.test.ts
T
chrnx 86d6954f72
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 31s
CI / runtimes (edge) (pull_request) Successful in 23s
CI / runtimes (deno) (pull_request) Successful in 34s
test(runtimes): close the 1c exit-gate cells for health and compression on Deno and Bun
The CARD-22 gate audit found these runtime cells without tests:

- CARD-17 T1-T3 (booting, ok, degraded) existed only on Node. Add them
  on Deno and Bun. T1 goes through app.fetch, because serveDeno and
  serveBun boot before they bind. T2 and T3 go through a real listener
  and assert the response body, not only the status.
- CARD-16 T6 (encodings ['gzip'] with a br-only client gives identity)
  was missing on Deno and Bun.
- CARD-16 T8 on Deno and Bun lacked the handler-set content-encoding
  case and the 204 case.

A negative run of T6 against compression: true fails with 'encoded as
br', so the check can tell the two cases apart.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-30 10:26:30 -05:00

90 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// CARD-17 T1–T3 on Bun: the probe states a load balancer reads. T1 goes through `app.fetch`, because
// `serveBun` boots before it binds and so never answers while booting; T2 and T3 go through a real
// `serveBun` listener. T5 (the drain window) lives in `shutdown.test.ts`.
//
// Run with: npm run test:bun (or: bun test test/bun/)
import 'reflect-metadata';
import { test, expect } from 'bun:test';
import { createApp, Route, Get, Module, Provider } from '../../src/index.ts';
import { serveBun } from '../../src/bun.ts';
@Route('/')
class Ctl {
@Get('/ping')
ping() {
return { ok: true };
}
}
const quiet = { debug() {}, info() {}, warn() {}, error() {} };
async function probe(res: Response) {
return { status: res.status, body: await res.json() };
}
test('CARD-17 T1: /__ready__ 503 booting while a slow provider boots, /__live__ 200', async () => {
let finish: () => void = () => {};
@Provider({ provides: 'slowDb' })
class SlowDb {
async provide() {
await new Promise<void>((resolve) => (finish = resolve));
return {};
}
}
@Module({ mountpoint: '/', controllers: [Ctl], providers: [SlowDb] })
class Slow {}
const app = createApp({ modules: [Slow], health: true, logger: quiet });
const booting = app.boot();
await Bun.sleep(10);
expect(await probe(await app.fetch(new Request('http://x/__ready__')))).toEqual({
status: 503,
body: { status: 'booting' },
});
expect(await probe(await app.fetch(new Request('http://x/__live__')))).toEqual({
status: 200,
body: { status: 'ok' },
});
finish();
await booting;
expect(await probe(await app.fetch(new Request('http://x/__ready__')))).toEqual({
status: 200,
body: { status: 'ok' },
});
});
test('CARD-17 T2: serveBun, booted with nothing degraded → 200 ok', async () => {
@Module({ mountpoint: '/', controllers: [Ctl] })
class M {}
const server = await serveBun(createApp({ modules: [M], health: true, logger: quiet }), { port: 0 });
try {
const base = `http://127.0.0.1:${server.port}`;
expect(await probe(await fetch(`${base}/__ready__`))).toEqual({ status: 200, body: { status: 'ok' } });
expect(await probe(await fetch(`${base}/__live__`))).toEqual({ status: 200, body: { status: 'ok' } });
} finally {
await server.close();
}
});
test('CARD-17 T3: serveBun, an optional provider failed → 200 degraded with its name', async () => {
@Provider({ provides: 'x', optional: true })
class X {
provide(): never {
throw new Error('down');
}
}
@Module({ mountpoint: '/', controllers: [Ctl], providers: [X] })
class D {}
const server = await serveBun(createApp({ modules: [D], health: true, logger: quiet }), { port: 0 });
try {
expect(await probe(await fetch(`http://127.0.0.1:${server.port}/__ready__`))).toEqual({
status: 200,
body: { status: 'degraded', degraded: ['x'] },
});
} finally {
await server.close();
}
});