From 0e4563b7fe098f1b77fac9e530e3975aa3bc4620 Mon Sep 17 00:00:00 2001 From: dktsudgg Date: Mon, 10 Aug 2026 22:33:41 +0900 Subject: [PATCH 1/2] Test not-found delegation in @fedify/elysia The fedify() plugin relies on the onNotFound callback of Federation.fetch() to let non-federation requests fall through to the app's own Elysia routes. Add a test that registers no dispatcher, so the request reports not-found via onNotFound, and verifies the status, headers, and body all come from the app's own Elysia route rather than from Fedify. Assisted-by: Claude Code:claude-fable-5 --- packages/elysia/src/index.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/elysia/src/index.test.ts b/packages/elysia/src/index.test.ts index 1d4084dc1..0dd5168a6 100644 --- a/packages/elysia/src/index.test.ts +++ b/packages/elysia/src/index.test.ts @@ -1,3 +1,4 @@ +import { createFederation, MemoryKvStore } from "@fedify/fedify"; import { Elysia } from "elysia"; import { strict as assert } from "node:assert"; import { describe, test } from "node:test"; @@ -46,4 +47,34 @@ describe("[elysia] fedify() plugin", () => { "federation.fetch() must receive the context data returned by the factory", ); }); + + test("fedify() falls through to Elysia routes when federation reports not-found via onNotFound", async () => { + const elysia = new Elysia().get( + "/hello-world", + ({ set, status }) => { + set.headers["X-Custom-Header"] = "custom-value"; + return status(201, "Hello World"); + }, + ); + const federationWithoutDispatcher = createFederation({ + kv: new MemoryKvStore(), + }); + + elysia.use(fedify(federationWithoutDispatcher, () => undefined)); + const response = await elysia.handle( + new Request("http://localhost/hello-world"), + ); + + assert.strictEqual(response.status, 201, "status must come from Elysia"); + assert.strictEqual( + response.headers.get("X-Custom-Header"), + "custom-value", + "header must come from Elysia", + ); + assert.strictEqual( + await response.text(), + "Hello World", + "body must come from Elysia", + ); + }); }); From dd84fe22cd0d07fc449528ee79467fa98bdd1a69 Mon Sep 17 00:00:00 2001 From: dktsudgg Date: Mon, 10 Aug 2026 23:13:08 +0900 Subject: [PATCH 2/2] Test not-acceptable delegation in @fedify/elysia The fedify() plugin also delegates via the onNotAcceptable callback. When a request matches a federation route but its Accept header rules out JSON-LD (ex: Accept: text/html), the response must come from the app's own Elysia routes. Add a test that registers an actor dispatcher so the route matches, asks for text/html, and verifies the status, headers, and body all come from the app's own Elysia route rather than from Fedify. Assisted-by: Claude Code:claude-fable-5 --- packages/elysia/src/index.test.ts | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/elysia/src/index.test.ts b/packages/elysia/src/index.test.ts index 0dd5168a6..aeb9f2db6 100644 --- a/packages/elysia/src/index.test.ts +++ b/packages/elysia/src/index.test.ts @@ -77,4 +77,37 @@ describe("[elysia] fedify() plugin", () => { "body must come from Elysia", ); }); + + test("fedify() falls through to Elysia routes when federation declines the request via onNotAcceptable", async () => { + const elysia = new Elysia().get( + "/users/alice", + ({ set, status }) => { + set.headers["X-Custom-Header"] = "custom-value"; + return status(200, "Hello Alice"); + }, + ); + // Register the actor route so the request matches, but ask for text/html + // so federation declines via onNotAcceptable instead of handling it. + const federation = createFederation({ kv: new MemoryKvStore() }); + federation.setActorDispatcher("/users/{identifier}", () => null); + + elysia.use(fedify(federation, () => undefined)); + const response = await elysia.handle( + new Request("http://localhost/users/alice", { + headers: { Accept: "text/html" }, + }), + ); + + assert.strictEqual(response.status, 200, "status must come from Elysia"); + assert.strictEqual( + response.headers.get("X-Custom-Header"), + "custom-value", + "header must come from Elysia", + ); + assert.strictEqual( + await response.text(), + "Hello Alice", + "body must come from Elysia", + ); + }); });