test(router): run the parity differential on Deno, Bun and workerd

The matcher comparison does not depend on the runtime, so it should run on every
runtime core supports. Only the Node suite ran it before.

The comparison and the app.fetch fixtures move into differential.ts and
app-fixture.ts, which use neither vitest nor a file API. Each runtime passes in
a loader for the frozen JSON. The vitest files use the same modules, plus a
Node check that the neutral runners report no mismatch, so the two paths cannot
drift.

- Deno and Bun: test/{deno,bun}/router-parity.test.ts run all 1158 frozen
  matcher cases (hand-picked, owner, generated v1 and v2, WS) through the oracle
  and the live router, plus the 55 app.fetch cases.
- workerd: test/edge/parity-worker.ts bundles the frozen JSON and runs the
  same checks; test/edge/run.ts adds the phase after its existing assertions.

The Node-socket, WS-upgrade, boot and mesh captures stay Node-only: they need
http.request, the ws client, or a mesh peer on a port.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-10 17:38:36 -05:00
1 parent a4562b2b23
commit 684795a2de
11 files changed
+553 -247

No files matched your search

+2 -45
View File
@@ -7,50 +7,12 @@ import http from 'http';
import net from 'net';
import type { AddressInfo } from 'net';
import { describe, it, afterAll, beforeAll } from 'vitest';
import { createApp, Route, Get, Post, Delete, Module, param } from '../../src/index';
import { createApp, Route, Get, Module } from '../../src/index';
import { ALLOW_REQUESTS, CrossAllowModule, fetchRequest, type Seen } from './app-fixture';
import type { App } from '../../src/app/types';
import type { Logger } from '../../src/logger';
import { frozen, expectFrozenEqual } from './frozen';
// `/ca` is GET :id + POST b; `/cb` adds DELETE :rest*. Two prefixes because one app cannot hold both
// variants at the same path.
@Route('/')
class CrossAllow {
@Get('/ca/:id') caGet(@param() p: Record<string, string>) {
return { id: 'caGet', p };
}
@Post('/ca/b') caPost() {
return { id: 'caPost' };
}
@Get('/cb/:id') cbGet(@param() p: Record<string, string>) {
return { id: 'cbGet', p };
}
@Post('/cb/b') cbPost() {
return { id: 'cbPost' };
}
@Delete('/cb/:rest*') cbDelete(@param() p: Record<string, string>) {
return { id: 'cbDelete', p };
}
}
@Module({ mountpoint: '/', controllers: [CrossAllow] })
class CrossAllowModule {}
const ALLOW_REQUESTS: Array<[string, string]> = ['/ca', '/cb'].flatMap((base): Array<[string, string]> => [
['PUT', `${base}/b`],
['OPTIONS', `${base}/b`],
['PUT', `${base}/x`],
['HEAD', `${base}/b`],
['PUT', `${base}/x/y`],
]);
interface Seen {
method: string;
path: string;
status: number;
allow: string | null;
body: string;
}
function nodeRequest(port: number, method: string, path: string): Promise<Seen> {
return new Promise((resolve, reject) => {
const req = http.request({ host: '127.0.0.1', port, method, path, agent: false }, (res) => {
@@ -66,11 +28,6 @@ function nodeRequest(port: number, method: string, path: string): Promise<Seen>
});
}
async function fetchRequest(app: App, method: string, path: string): Promise<Seen> {
const res = await app.fetch(new Request(`http://parity.test${path}`, { method }));
return { method, path, status: res.status, allow: res.headers.get('allow'), body: await res.text() };
}
// ── mesh: the HTTP route table across a peer's lifetime ─────────────────────────────────────────
const SECRET = 'parity-secret';