diff --git a/backend/src/app.ts b/backend/src/app.ts index 2cd24ef3..9881fbe8 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -14,6 +14,7 @@ import { loadSettings, type Settings } from "./settings/settings-store.js"; export interface BuildAppDeps { thtRunner?: ThtRunner; + mgr?: PiProcessManager; spawnFn?: () => any; listModels?: ListModelsFn; getSettings?: () => Settings; @@ -34,7 +35,7 @@ export function buildApp(config: AppConfig, deps?: BuildAppDeps): FastifyInstanc harnessDir: config.harnessDir, configPath: "config/tht.yaml", }); - const mgr = new PiProcessManager(config, deps?.spawnFn ? { spawnFn: deps.spawnFn } : undefined); + const mgr = deps?.mgr ?? new PiProcessManager(config, deps?.spawnFn ? { spawnFn: deps.spawnFn } : undefined); const hub = new SseHub(); const listModels = deps?.listModels ?? createPiModelLister(config); diff --git a/backend/test/routes-sessions.test.ts b/backend/test/routes-sessions.test.ts index 7b79d0b0..ee01fb00 100644 --- a/backend/test/routes-sessions.test.ts +++ b/backend/test/routes-sessions.test.ts @@ -87,6 +87,19 @@ test("DELETE /sessions/:id calls deleteSession", async () => { expect(deleted).toBe("s1"); }); +test("DELETE /sessions/:id tears down the runtime before deleting on disk", async () => { + const order: string[] = []; + const app = buildApp(loadConfig({ THT_HARNESS_DIR: "../harness" }), { + thtRunner: { deleteSession: async (id: string) => { order.push(`del:${id}`); } } as any, + mgr: { teardown: (id: string) => { order.push(`teardown:${id}`); } } as any, + getSettings: () => ({ workspace: "w" }) as any, + spawnFn: () => nodeSpawn("node", [FAKE, SCRIPT]) as any, + }); + const res = await app.inject({ method: "DELETE", url: "/sessions/s1" }); + expect(res.statusCode).toBe(204); + expect(order).toEqual(["teardown:s1", "del:s1"]); +}); + test("GET /sessions/:id/documents returns the runner output", async () => { const app = mutApp({ documents: async () => [{ phase: "—", key: "question", title: "t", format: "text", content: "q" }] }); const res = await app.inject({ method: "GET", url: "/sessions/s1/documents" });