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
+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" });