diff --git a/src/app/api/tools/agent-bridge/agents/[id]/dns/route.ts b/src/app/api/tools/agent-bridge/agents/[id]/dns/route.ts index 368f8bcded..fa7f5f6abc 100644 --- a/src/app/api/tools/agent-bridge/agents/[id]/dns/route.ts +++ b/src/app/api/tools/agent-bridge/agents/[id]/dns/route.ts @@ -13,10 +13,10 @@ import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error"; import { createErrorResponse } from "@/lib/api/errorResponse"; import { ALL_TARGETS } from "@/mitm/targets/index"; -type Params = { params: { id: string } }; +type Params = { params: Promise<{ id: string }> }; export async function POST(request: Request, { params }: Params): Promise { - const { id } = params; + const { id } = await params; let body: unknown; try { diff --git a/tests/unit/agent-bridge-dns-params-7271.test.ts b/tests/unit/agent-bridge-dns-params-7271.test.ts new file mode 100644 index 0000000000..013d5ade89 --- /dev/null +++ b/tests/unit/agent-bridge-dns-params-7271.test.ts @@ -0,0 +1,37 @@ +import test from "node:test"; +import assert from "node:assert/strict"; + +import { POST } from "../../src/app/api/tools/agent-bridge/agents/[id]/dns/route.ts"; + +/** + * Regression for #7271: Agent Bridge "Start DNS" returned HTTP 404. + * + * Next.js 16 makes a dynamic route's `params` a Promise. The handler destructured + * `id` directly from the (un-awaited) Promise, so `id` was `undefined` and the + * agent lookup always missed — producing `404 Unknown agent: undefined` for every + * request, including valid agents. + * + * This test drives the handler with the Next.js 16 params shape (a Promise) and an + * unknown agent id. It never reaches the DNS side-effects (the 404 fires before + * `addDNSEntry`), so it is a pure, side-effect-free reproduction: the 404 message + * must echo the *resolved* id — proving `params` was awaited — not `undefined`. + */ +test("POST /agents/[id]/dns awaits params — 404 echoes the real id, not 'undefined'", async () => { + const agentId = "definitely-not-a-real-agent-7271"; + const request = new Request("http://localhost/api/tools/agent-bridge/agents/x/dns", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ enabled: false }), + }); + + const res = await POST(request, { params: Promise.resolve({ id: agentId }) }); + const body = await res.json(); + + assert.equal(res.status, 404); + // Before the fix, `id` was `undefined`, so the message read "Unknown agent: undefined". + assert.equal(body.error.message, `Unknown agent: ${agentId}`); + assert.ok( + !body.error.message.includes("undefined"), + "params must be awaited — message should not contain 'undefined'" + ); +});