const test = require("node:test"); const assert = require("node:assert"); const { createFakePi } = require("./fake_pi_runtime.js"); // The gate is ESM; resolve it once via dynamic import (Global Constraints: use await import() // if require() of ESM misbehaves on this Node version). const installGatePromise = import("../../tht-gate.js").then((m) => m.default); test("avvio workflow via input non-interattivo attiva il lock (free text bloccato)", async () => { const installGate = await installGatePromise; const { pi } = createFakePi(); installGate(pi); // entry del workflow con source 'rpc' (come un comando prompt RPC) await pi.emit("input", { source: "rpc", text: '/nuova-domanda "x"' }); // dopo l'entry, un testo libero senza '!' deve essere bloccato (lock attivo) const res = await pi.emit("input", { source: "rpc", text: "promuovi la tabella pazienti" }); assert.equal(res.action, "handled"); }); test("testo con '!' passa al modello (steer) anche con lock attivo", async () => { const installGate = await installGatePromise; const { pi } = createFakePi(); installGate(pi); await pi.emit("input", { source: "rpc", text: '/nuova-domanda "x"' }); const res = await pi.emit("input", { source: "rpc", text: "!considera solo il 2024" }); assert.deepEqual(res, { action: "transform", text: "considera solo il 2024" }); });