test(runtimes): close the 1c exit-gate cells for health and compression on Deno and Bun
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

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>
This commit is contained in:
chrnx committed 2026-10-30 10:26:30 -05:00
1 parent fea87b3af4
commit 86d6954f72
6 files changed
+221 -5

No files matched your search

+19 -2
View File
@@ -4,7 +4,7 @@
// which decodes nothing, so a double encoding cannot hide.
import http from 'node:http';
import zlib from 'node:zlib';
import { JSON_BODY, HTML_BODY, SSE_EVENTS, SSE_GAP_MS } from './compression-app';
import { JSON_BODY, HTML_BODY, TEXT, SSE_EVENTS, SSE_GAP_MS } from './compression-app';
interface Raw {
status: number;
@@ -57,7 +57,7 @@ async function negotiation(port: number): Promise<void> {
}
}
/** T7, T8, T11, T15: skips, and the 304 shape. */
/** T7, T8, T11, T15: skips, a handler's own coding, a 204, and the 304 shape. */
async function skips(port: number): Promise<void> {
for (const [path, vary] of [
['/c/small', false],
@@ -71,6 +71,12 @@ async function skips(port: number): Promise<void> {
check(hasVary(r) === vary, `${path}: Vary ${String(r.headers.vary)}`);
}
// T8: a handler that set its own content-encoding is left byte-for-byte alone, and a 204 has nothing to encode.
const pre = await get(port, '/c/pre', { 'accept-encoding': 'gzip, br' });
check(pre.headers['content-encoding'] === 'gzip' && decode(pre.bytes, undefined) === TEXT, 'T8: handler coding touched');
const empty = await get(port, '/c/empty', { 'accept-encoding': 'gzip' });
check(empty.status === 204 && empty.headers['content-encoding'] === undefined && !hasVary(empty), 'T8: 204 shape');
const head = await get(port, '/c/json', { 'accept-encoding': 'gzip' }, 'HEAD');
check(head.headers['content-encoding'] === undefined && hasVary(head), 'HEAD: encoded or no Vary');
const nm = await get(port, '/c/304', { 'accept-encoding': 'gzip' });
@@ -132,6 +138,17 @@ async function sse(port: number): Promise<Record<string, number[]>> {
export const checks = { negotiation, skips, etag, ndjson, sse };
/**
* T6: with `encodings: ['gzip']`, a client that accepts only br gets identity. Run against
* `compressionApp({ compression: { encodings: ['gzip'] } })`.
*/
export async function gzipOnlyRefusesBr(port: number): Promise<void> {
const r = await get(port, '/c/json', { 'accept-encoding': 'br' });
check(r.headers['content-encoding'] === undefined, `T6: encoded as ${String(r.headers['content-encoding'])}`);
check(hasVary(r), 'T6: no Vary');
check(decode(r.bytes, undefined) === JSON_BODY, 'T6: body differs');
}
/**
* How many 1 ms timer ticks fire while `zlib.gzip` (the async API core uses) compresses 16 MB of
* random bytes — incompressible, so the work takes a few hundred ms on any machine (repetitive