feat(backend): ThtRunner session mutation + documents methods

This commit is contained in:
2026-06-29 12:29:14 +02:00
parent 03053b0716
commit 4a63db51e8
2 changed files with 61 additions and 0 deletions
+41
View File
@@ -73,3 +73,44 @@ test("sqlPreview argv has no positional file — uses --session to resolve path"
expect(calledArgs).toEqual(["sql", "preview", "--session", "ses2", "--json", "--limit", "20", "--offset", "0"]);
expect(calledArgs).not.toContain("sessions/ses2/sql_final.sql");
});
test("setName builds the right argv", async () => {
const calls: string[][] = [];
const r = new ThtRunner({ thtBin: "tht", harnessDir: "/h", configPath: "config/tht.yaml" });
r.run = async (args) => { calls.push(args); return { code: 0, stdout: "", stderr: "" }; };
await r.setName("sid", "Mio nome");
expect(calls[0]).toEqual(["session", "set-name", "sid", "--name", "Mio nome"]);
});
test("setGroup / archive / unarchive / deleteSession build argv", async () => {
const calls: string[][] = [];
const r = new ThtRunner({ thtBin: "tht", harnessDir: "/h", configPath: "config/tht.yaml" });
r.run = async (args) => { calls.push(args); return { code: 0, stdout: "", stderr: "" }; };
await r.setGroup("sid", "G1");
await r.archive("sid");
await r.unarchive("sid");
await r.deleteSession("sid");
expect(calls).toEqual([
["session", "set-group", "sid", "--group", "G1"],
["session", "archive", "sid"],
["session", "unarchive", "sid"],
["session", "delete", "sid"],
]);
});
test("ok() throws on non-zero exit", async () => {
const r = new ThtRunner({ thtBin: "tht", harnessDir: "/h", configPath: "config/tht.yaml" });
r.run = async () => ({ code: 1, stdout: "", stderr: "ERRORE: nope" });
await expect(r.archive("sid")).rejects.toThrow(/nope/);
});
test("documents parses the JSON array", async () => {
const r = new ThtRunner({ thtBin: "tht", harnessDir: "/h", configPath: "config/tht.yaml" });
r.run = async () => ({
code: 0,
stdout: '[{"phase":"—","key":"question","title":"Domanda originale","format":"text","content":"q"}]',
stderr: "",
});
const docs = await r.documents("sid");
expect(docs[0].key).toBe("question");
});