Files
core/test/deno/health.test.ts
T
chrnx 44c783439c fix(graph)!: enforce the node and handler return contracts instead of failing silently
provide() and run() must return an object holding every token the node
provides. A provider that returned its value bare (return client rather
than return { db: client }) booted without complaint: the token was
undefined, and the client's own properties were spread over every
request's context. That now fails, naming the node and the fix:
- providers fail the boot;
- steps fail the request;
- plugin nodes are held to the same rule for each token in provides.

A handler that returned a Fetch Response was JSON-encoded and went out
as 200 {}, with its status, headers and body lost. It now fails the
request with a TypeError that points to a plain value, @Transformer or
HttpError. Sending a Response as is can be added later without
breaking anything; taking it back would not be possible.

The check stays synchronous for a synchronous node, so a plain step
adds no microtask. Fixed health tests whose providers returned {}.

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

87 lines
3.1 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 Deno: the probe states a load balancer reads. T1 goes through `app.fetch`, because
// `serveDeno` boots before it binds and so never answers while booting; T2 and T3 go through a real
// `serveDeno` listener. T5 (the drain window) lives in `shutdown.test.ts`.
//
// Run with: npm run test:deno
import 'reflect-metadata';
import { createApp, Route, Get, Module, Provider } from '../../src/index.ts';
import { serveDeno } from '../../src/deno.ts';
@Route('/')
class Ctl {
@Get('/ping')
ping() {
return { ok: true };
}
}
const quiet = { debug() {}, info() {}, warn() {}, error() {} };
async function expectProbe(res: Response, status: number, body: unknown): Promise<void> {
const got = await res.json();
if (res.status !== status || JSON.stringify(got) !== JSON.stringify(body)) {
throw new Error(`expected ${status} ${JSON.stringify(body)}, got ${res.status} ${JSON.stringify(got)}`);
}
}
Deno.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 { slowDb: {} };
}
}
@Module({ mountpoint: '/', controllers: [Ctl], providers: [SlowDb] })
class Slow {}
const app = createApp({ modules: [Slow], health: true, logger: quiet });
const booting = app.boot();
await new Promise((r) => setTimeout(r, 10));
await expectProbe(await app.fetch(new Request('http://x/__ready__')), 503, { status: 'booting' });
await expectProbe(await app.fetch(new Request('http://x/__live__')), 200, { status: 'ok' });
finish();
await booting;
await expectProbe(await app.fetch(new Request('http://x/__ready__')), 200, { status: 'ok' });
});
Deno.test('CARD-17 T2: serveDeno, booted with nothing degraded → 200 ok', async () => {
@Module({ mountpoint: '/', controllers: [Ctl] })
class M {}
const server = await serveDeno(createApp({ modules: [M], health: true, logger: quiet }), {
port: 0,
onListen: () => {},
});
try {
const base = `http://127.0.0.1:${(server as unknown as { addr: { port: number } }).addr.port}`;
await expectProbe(await fetch(`${base}/__ready__`), 200, { status: 'ok' });
await expectProbe(await fetch(`${base}/__live__`), 200, { status: 'ok' });
} finally {
await server.close();
}
});
Deno.test('CARD-17 T3: serveDeno, 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 serveDeno(createApp({ modules: [D], health: true, logger: quiet }), {
port: 0,
onListen: () => {},
});
try {
const base = `http://127.0.0.1:${(server as unknown as { addr: { port: number } }).addr.port}`;
await expectProbe(await fetch(`${base}/__ready__`), 200, { status: 'degraded', degraded: ['x'] });
} finally {
await server.close();
}
});