Files
next-ai-draw-io/tests/unit/log-save-route.test.ts
T
dayuan.jiang 8ca2d03e7f refactor(server): drop stale prompt text, duplicated routes and dead options
- lib/system-prompts.ts: delete the extended prompt kept only to reach
  the 4096-token cache threshold of two old Claude models; describe the
  current canvas-first UI in the App Features section
- app/api/chat/route.ts: remove the server-side example cache (the
  browser answers examples itself), the ENABLE_HISTORY_XML_REPLACE
  option and its helper, the unread messageMetadata fields; the
  DEBUG_LLM_PAYLOAD blocks become one describeMessages summary
- app/api/log-feedback and log-save share scoreLatestTrace in
  lib/langfuse.ts
- app/api/admin/test-model and validate-model call a shared
  testModelConnection() instead of one route faking a request to the
  other and passing trust through the body
- lib/dynamo-quota-manager.ts reads the failing item from the
  conditional update instead of a second GetItem
- lib/ai-providers.ts: geminiThinkingOptions helper for the google and
  vertexai cases, drop the unused fourth resolveBaseURL parameter
- edge-functions: always stream, shrink messageSchema, drop model
  aliases nothing sends
- delete app/api/chat/xml_guide.md, parseOutputTokenLimit, unused type
  exports and export keywords on file-internal symbols
- env.example: drop variables nothing reads, document the quota,
  validation and analytics variables, mention the apiKeyEnv array form
  (also in docs/*/ai-providers.md)
2026-10-12 08:15:15 +09:00

45 lines
1.4 KiB
TypeScript

// @vitest-environment node
import { describe, expect, it, vi } from "vitest"
import { POST as logSave } from "@/app/api/log-save/route"
// A Langfuse client with a trace to attach the save score to; the real
// scoreLatestTrace runs against it
const batch = vi.fn(async () => ({}))
vi.mock("@/lib/langfuse", async (importOriginal) => ({
...(await importOriginal<typeof import("@/lib/langfuse")>()),
getLangfuseClient: () => ({
api: {
trace: { list: async () => ({ data: [{ id: "trace-1" }] }) },
ingestion: { batch },
},
}),
}))
function post(body: unknown): Request {
return new Request("http://localhost/api/log-save", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
})
}
describe("POST /api/log-save", () => {
it.each(["drawio", "png", "svg", "xmlsvg"])(
"logs a save in %s format",
async (format) => {
const res = await logSave(
post({ filename: "diagram", format, sessionId: "s1" }),
)
expect(res.status).toBe(200)
expect(await res.json()).toEqual({ success: true, logged: true })
},
)
it("rejects an unknown format", async () => {
const res = await logSave(
post({ filename: "diagram", format: "pdf", sessionId: "s1" }),
)
expect(res.status).toBe(400)
})
})