feat: harden runtime readiness and session workflow

This commit is contained in:
User
2026-07-14 10:27:25 +02:00
parent 6d7738d538
commit 6dbf93fff9
52 changed files with 1464 additions and 169 deletions
@@ -1,5 +1,8 @@
const test = require("node:test");
const assert = require("node:assert");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { createFakePi } = require("./fake_pi_runtime.js");
const installGate = require("../../tht-gate.js").default ?? require("../../tht-gate.js");
@@ -14,6 +17,13 @@ test("con THT_SESSION il kickoff usa l'id fornito e NON crea la sessione", async
const text = injected?.systemPrompt ?? "";
assert.match(text, /2026-06-27-100000-test/);
assert.doesNotMatch(text, /tht session new/);
assert.match(text, /retrieval pack non era ancora disponibile/i);
assert.match(text, /tht search pack/);
assert.doesNotMatch(text, /<retrieval-pack>/);
assert.match(text, /<tht-sessione-skill>/);
assert.match(text, /# Thoth session workflow \(phases 1-8\)/);
assert.match(text, /non esplorare il repository/i);
assert.doesNotMatch(text, /Carica la skill leggendo/);
} finally {
delete process.env.THT_SESSION;
}
@@ -28,3 +38,39 @@ test("senza THT_SESSION il kickoff contiene tht session new (comportamento attua
const text = injected?.systemPrompt ?? "";
assert.match(text, /tht session new/);
});
test("con retrieval pack persistito lo inietta senza chiedere tool call ridondanti", async () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "tht-gate-pack-"));
const bin = path.join(tmp, "bin");
fs.mkdirSync(bin);
const tht = path.join(bin, "tht");
fs.writeFileSync(
tht,
"#!/bin/sh\n" +
"printf \"# Retrieval pack\\n\\nTABELLA_CANDIDATA\\n\"\n",
{ mode: 0o755 },
);
const oldPath = process.env.PATH;
process.env.PATH = bin + ":" + oldPath;
process.env.THT_SESSION = "2026-06-27-100000-pack";
try {
const { pi, ctx } = createFakePi();
ctx.cwd = tmp;
installGate(pi);
await pi.emit("input", { source: "rpc", text: `/nuova-domanda "x"` });
const injected = await pi.emit("before_agent_start", { systemPrompt: "BASE_STATIC" });
const text = injected?.systemPrompt ?? "";
assert.match(text, /<retrieval-pack>[\s\S]*TABELLA_CANDIDATA[\s\S]*<\/retrieval-pack>/);
assert.match(text, /NON eseguire `tht search pack`/);
assert.match(text, /SOLA ambiguità/);
assert.match(text, /chiama subito `reviewer_select`/);
assert.ok(text.indexOf("BASE_STATIC") < text.indexOf("<tht-sessione-skill>"));
assert.ok(text.indexOf("<tht-sessione-skill>") < text.indexOf("Istruzioni operative"));
assert.ok(text.indexOf("Istruzioni operative") < text.lastIndexOf("<retrieval-pack>"));
} finally {
process.env.PATH = oldPath;
delete process.env.THT_SESSION;
fs.rmSync(tmp, { recursive: true, force: true });
}
});
@@ -18,4 +18,17 @@ test("the resume kickoff injects the bootstrap steps and forces in-turn action",
// hardening: act now, in this same turn; do not stop after merely stating intent.
assert.match(text, /in QUESTO stesso turno/i);
assert.match(text, /NON terminare il turno/i);
assert.match(text, /<tht-sessione-skill>/);
assert.match(text, /# Thoth session workflow \(phases 1-8\)/);
assert.match(text, /non esplorare il repository/i);
assert.doesNotMatch(text, /Carica la skill leggendo/);
});
test("session_start after RPC input preserves the armed resume kickoff", async () => {
const { pi } = createFakePi();
installGate(pi);
await pi.emit("input", { source: "rpc", text: "/riprendi-sessione 2026-06-30-000000-x" });
await pi.emit("session_start", {});
const injected = await pi.emit("before_agent_start", { systemPrompt: "" });
assert.match(injected?.systemPrompt ?? "", /in QUESTO stesso turno/i);
});