test(backend): make mgr injectable; assert teardown-before-delete ordering

This commit is contained in:
2026-06-29 12:36:29 +02:00
parent bd29ac517c
commit 387ae56583
2 changed files with 15 additions and 1 deletions
+2 -1
View File
@@ -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);
+13
View File
@@ -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" });