Make buildApp injectable (deps.thtRunner + deps.spawnFn); create
src/routes/sessions.ts with all 7 session routes under authPreHandler;
wire bridge.onClientEvent→hub.publish before returning {id} from POST
/sessions; SSE subscribes with pendingWidget safety net.
18/18 tests pass, tsc clean.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
import { test, expect } from "vitest";
|
|
import { spawn } from "node:child_process";
|
|
import path from "node:path";
|
|
import { buildApp } from "../src/app.js";
|
|
import { loadConfig } from "../src/config.js";
|
|
|
|
const FAKE = path.resolve("../harness/tests/fake_pi/fake_pi_rpc.mjs");
|
|
const SCRIPT = path.resolve("../harness/tests/fake_pi/scripts/f1_disambiguation.json");
|
|
|
|
test("POST /sessions crea e avvia, GET /sessions lista", async () => {
|
|
const app = buildApp(loadConfig({ THT_HARNESS_DIR: "../harness" }), {
|
|
thtRunner: { sessionNew: async () => ({ id: "s1" }), sessionList: async () => [{ id: "s1" }] } as any,
|
|
spawnFn: () => spawn("node", [FAKE, SCRIPT]) as any,
|
|
});
|
|
const created = await app.inject({ method: "POST", url: "/sessions", payload: { workspace: "w", question: "q" } });
|
|
expect(created.json()).toEqual({ id: "s1" });
|
|
const list = await app.inject({ method: "GET", url: "/sessions" });
|
|
expect(list.json()).toEqual([{ id: "s1" }]);
|
|
});
|
|
|
|
test("POST /sessions/:id/response inoltra al bridge (no error)", async () => {
|
|
const app = buildApp(loadConfig({ THT_HARNESS_DIR: "../harness" }), {
|
|
thtRunner: { sessionNew: async () => ({ id: "s1" }) } as any,
|
|
spawnFn: () => spawn("node", [FAKE, SCRIPT]) as any,
|
|
});
|
|
await app.inject({ method: "POST", url: "/sessions", payload: { workspace: "w", question: "q" } });
|
|
const res = await app.inject({ method: "POST", url: "/sessions/s1/response",
|
|
payload: { ui_response: { id: "u1", choices: ["a"] } } });
|
|
expect(res.statusCode).toBe(204);
|
|
});
|