import { afterAll, beforeAll, describe, expect, it } from "vitest"; import type { FastifyInstance } from "fastify"; import { buildApp } from "../src/app.js"; let app: FastifyInstance; beforeAll(async () => { app = await buildApp(); }); afterAll(async () => app.close()); describe("server", () => { it("is healthy", async () => { const r = await app.inject({ url: "/health" }); expect(r.statusCode).toBe(200); expect(r.json().requestId).toMatch(/^req_/); }); it("creates a session and redacts model key", async () => { const c = await app.inject({ method: "POST", url: "/api/sessions" }); const id = c.json().sessionId; const r = await app.inject({ method: "PUT", url: `/api/sessions/${id}/model-config`, payload: { providerId: "openai", api: "openai-responses", baseUrl: "https://api.openai.com/v1", apiKey: "secret-value", modelId: "demo", supportsImages: true, }, }); expect(r.statusCode).toBe(200); expect(r.body).not.toContain("secret-value"); expect(r.json().config.keyHint).toBe("••••alue"); }); it("returns unified 404", async () => { const r = await app.inject({ url: "/api/sessions/nope/model-config" }); expect(r.statusCode).toBe(404); expect(r.json().error.code).toBe("SESSION_NOT_FOUND"); }); });