diff --git a/app/api/chat/__tests__/route.test.ts b/app/api/chat/__tests__/route.test.ts new file mode 100644 index 000000000..e903c3768 --- /dev/null +++ b/app/api/chat/__tests__/route.test.ts @@ -0,0 +1,30 @@ +import { describe, it, expect, vi } from "vitest"; +import { NextRequest } from "next/server"; + +import { POST, OPTIONS } from "@/app/api/chat/route"; +import { handleChatWorkflowStream } from "@/lib/chat/handleChatWorkflowStream"; + +vi.mock("@/lib/chat/handleChatWorkflowStream", () => ({ + handleChatWorkflowStream: vi.fn(async () => new Response("ok", { status: 200 })), +})); + +vi.mock("@/lib/networking/getCorsHeaders", () => ({ + getCorsHeaders: vi.fn(() => ({ "Access-Control-Allow-Origin": "*" })), +})); + +describe("POST /api/chat route shell", () => { + it("delegates to handleChatWorkflowStream (canonical path; alias of /api/chat/workflow)", async () => { + const req = new NextRequest("http://localhost/api/chat", { method: "POST" }); + const res = await POST(req); + + expect(handleChatWorkflowStream).toHaveBeenCalledWith(req); + expect(res.status).toBe(200); + }); + + it("OPTIONS returns 200 with CORS headers", async () => { + const res = await OPTIONS(); + + expect(res.status).toBe(200); + expect(res.headers.get("Access-Control-Allow-Origin")).toBe("*"); + }); +}); diff --git a/app/api/chat/workflow/route.ts b/app/api/chat/route.ts similarity index 74% rename from app/api/chat/workflow/route.ts rename to app/api/chat/route.ts index 19445c03b..2df3c5016 100644 --- a/app/api/chat/workflow/route.ts +++ b/app/api/chat/route.ts @@ -18,11 +18,12 @@ export async function OPTIONS() { } /** - * POST /api/chat/workflow + * POST /api/chat * - * Streams a sandbox-driven agent loop (Vercel Workflow) for an existing - * session + chat. Currently returns a hardcoded UIMessage stream stub — - * the workflow is wired up in a follow-up PR. + * Canonical path for the sandbox-driven agent loop (Vercel Workflow). + * Delegates to the same handler as `POST /api/chat/workflow`, which is + * retained as a backward-compatible alias while consumers (chat, + * open-agents, API-key callers) migrate to `/api/chat`. * * Contract: https://developers.recoupable.com/api-reference/chat/workflow *