Files
WRNexusJS/packages/dev-server/test/server-fn-rpc-request-context.test.ts
ClintchizandClaude Opus 5 aded2daab9 fix: restore the production gate after the migration tasks
- rebuild editors/vscode bundles, stale since the parser escape fix
- attach the caught ParseError as `cause` in both migration validators
- drop two unused test bindings flagged by eslint

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 12:19:53 +05:30

28 lines
1.1 KiB
TypeScript

import { expect, test } from "bun:test";
import { getRequestContext } from "@wrnexus/core";
import { withServerFnRequestContext } from "../src/index.ts";
// The server-function RPC path ("/__wrnexus/rpc", what server.fn() calls from
// the browser) is intercepted before fetchHandler in the dev server and would
// otherwise run entirely outside the AsyncLocalStorage wrap. This is the
// property that was broken: a handler invoked through that path must see the
// request context, not `undefined`.
test("a handler invoked through the server-function RPC path can read the request context", async () => {
let seen: unknown;
const innerHandler = async (_request: Request): Promise<Response> => {
seen = getRequestContext();
return new Response("ok");
};
const wrapped = withServerFnRequestContext(innerHandler);
const request = new Request("http://localhost/__wrnexus/rpc", { method: "POST" });
await wrapped(request);
expect(seen).toBeDefined();
expect((seen as { req: Request }).req).toBe(request);
});
test("there is no context outside the wrap", () => {
expect(getRequestContext()).toBeUndefined();
});