test(backend): make mgr injectable; assert teardown-before-delete ordering
This commit is contained in:
+2
-1
@@ -14,6 +14,7 @@ import { loadSettings, type Settings } from "./settings/settings-store.js";
|
|||||||
|
|
||||||
export interface BuildAppDeps {
|
export interface BuildAppDeps {
|
||||||
thtRunner?: ThtRunner;
|
thtRunner?: ThtRunner;
|
||||||
|
mgr?: PiProcessManager;
|
||||||
spawnFn?: () => any;
|
spawnFn?: () => any;
|
||||||
listModels?: ListModelsFn;
|
listModels?: ListModelsFn;
|
||||||
getSettings?: () => Settings;
|
getSettings?: () => Settings;
|
||||||
@@ -34,7 +35,7 @@ export function buildApp(config: AppConfig, deps?: BuildAppDeps): FastifyInstanc
|
|||||||
harnessDir: config.harnessDir,
|
harnessDir: config.harnessDir,
|
||||||
configPath: "config/tht.yaml",
|
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 hub = new SseHub();
|
||||||
|
|
||||||
const listModels = deps?.listModels ?? createPiModelLister(config);
|
const listModels = deps?.listModels ?? createPiModelLister(config);
|
||||||
|
|||||||
@@ -87,6 +87,19 @@ test("DELETE /sessions/:id calls deleteSession", async () => {
|
|||||||
expect(deleted).toBe("s1");
|
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 () => {
|
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 app = mutApp({ documents: async () => [{ phase: "—", key: "question", title: "t", format: "text", content: "q" }] });
|
||||||
const res = await app.inject({ method: "GET", url: "/sessions/s1/documents" });
|
const res = await app.inject({ method: "GET", url: "/sessions/s1/documents" });
|
||||||
|
|||||||
Reference in New Issue
Block a user