Initial Commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* §16 conformance proof — the worker-proxy package consumes the
|
||||
* `@suaveplan/api-worker-rpc` contract directly (client + server +
|
||||
* MessagePort transport). This test exercises the canonical
|
||||
* `runWorkerRpcConformance` harness with a minimal handler set to
|
||||
* prove the consumer is wire-compatible end-to-end (request frame,
|
||||
* response frame, abort propagation) using the same port transport
|
||||
* the package builds on top of in `src/main-side` / `src/worker-side`.
|
||||
*/
|
||||
import { afterEach, describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { runWorkerRpcConformance } from "../../../api-worker-rpc/src/testing/conformance.js";
|
||||
|
||||
const handles: Array<{ dispose(): void }> = [];
|
||||
afterEach(() => {
|
||||
while (handles.length > 0) handles.pop()?.dispose();
|
||||
});
|
||||
|
||||
describe("api-worker-rpc contract conformance (consumer-side)", () => {
|
||||
it("round-trips a request through the canonical harness", {
|
||||
timeout: 5000,
|
||||
}, async () => {
|
||||
const h = runWorkerRpcConformance(() => ({
|
||||
echo: (params: ReadonlyArray<unknown>) => params[0],
|
||||
}));
|
||||
handles.push(h);
|
||||
const result = await h.client.call<number>("echo", [42]);
|
||||
expect(result).toBe(42);
|
||||
});
|
||||
|
||||
it("surfaces UNKNOWN_METHOD from the server", {
|
||||
timeout: 5000,
|
||||
}, async () => {
|
||||
const h = runWorkerRpcConformance(() => ({}));
|
||||
handles.push(h);
|
||||
await expect(h.client.call("missing", [])).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { marshalRequest } from "../src/marshal-request/marshal-request.js";
|
||||
|
||||
describe("no-raw-request invariant", () => {
|
||||
it("envelope contains no Request reference and JSON-serialises", {
|
||||
timeout: 5000,
|
||||
}, async () => {
|
||||
const wire = await marshalRequest(
|
||||
new Request("https://api.local/x", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
authorization: "Bearer leak",
|
||||
},
|
||||
body: JSON.stringify({ a: 1 }),
|
||||
})
|
||||
);
|
||||
const replaced = JSON.stringify(wire, (_k, v: unknown) => {
|
||||
if (v instanceof Uint8Array) return { __u8: Array.from(v) };
|
||||
return v;
|
||||
});
|
||||
// No "Request" prototype slipped in
|
||||
expect(replaced.includes("Request")).toBe(false);
|
||||
// No credentials cross the boundary
|
||||
expect(replaced.toLowerCase().includes("authorization")).toBe(false);
|
||||
expect(replaced.includes("Bearer leak")).toBe(false);
|
||||
// The envelope is a plain object — no Request instance
|
||||
expect((wire as unknown as object) instanceof Request).toBe(false);
|
||||
});
|
||||
|
||||
it("exposed keys match the documented surface", {
|
||||
timeout: 5000,
|
||||
}, async () => {
|
||||
const wire = await marshalRequest(new Request("https://api.local/"));
|
||||
expect(Object.keys(wire).sort()).toEqual([
|
||||
"body",
|
||||
"headers",
|
||||
"method",
|
||||
"url",
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user