The end-of-turn gate rebuilt on risk profiles; non-findings refused as retro findings

The gate enforces exactly what the profile requires, lists everything missing in
one message, closes a green unit when a finding is recorded, lets a paused unit
stop silently, never blocks a subagent, records a release as unverified, and says
at commit time when the checks have not passed on the tree. Size thresholds and
the floors file are gone. 'It went well' and similar are refused as findings.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-23 12:16:29 -07:00
commit 216f39e8f7
31 files changed
+2383 -1807

No files matched your search

-11
View File
@@ -40,17 +40,6 @@ class ContractTests(SisiCase):
def test_rung_5_6_valid_without_cmd(self):
self.assertEqual(C.validate(contract([check("a", "true"), human("h", 5), human("i", 6)])), [])
def test_floors(self):
weak = contract([check("m", "true", rung=3, kind="money")])
self.assertEqual(len(C.floor_failures(weak)), 1)
self.assertEqual(C.floor_failures(contract([check("m", "true", rung=2, kind="money")])), [])
# one strong check among weak ones satisfies the floor
self.assertEqual(C.floor_failures(contract([check("m", "true", rung=3, kind="money"),
check("n", "true", rung=1, kind="money")])), [])
self.assertEqual(C.floor_failures(contract([check("u", "true", rung=4, kind="ui")])), [])
for k in ("concurrency", "parsing", "money", "state-machine", "migration"):
self.assertEqual(C.floors()[k], 2)
def test_find_stops_at_git_root(self):
self.git_init()
self.write_contract(contract([check("a", "true")]))
+4
View File
@@ -169,6 +169,10 @@ class DeliveryRowTests(SisiCase):
def test_send_backs_and_check_time_are_counted_for_the_request(self):
self.write_contract(contract([check("bad", "sleep 0.3; exit 1")]))
with open(self.tp, "a") as f: # the agent edited a source file this turn
f.write(json.dumps({"type": "assistant", "timestamp": "2026-01-01T00:00:00.000Z", "message": {
"role": "assistant", "content": [{"type": "tool_use", "name": "Edit",
"input": {"file_path": os.path.join(self.proj, "app.py")}}]}}) + "\n")
r = self.hook(transcript_path=self.tp)
self.assertEqual(json.loads(r.stdout)["decision"], "block")
self.assertEqual(self.rows(), []) # a send-back is not a delivery
+141 -15
View File
@@ -2,35 +2,161 @@ import json, os, unittest
from support import *
def load(path):
with open(path) as f:
return json.load(f)
def tool_line(name, inp):
return {"type": "assistant", "timestamp": "2026-01-01T00:00:00.000Z",
"message": {"role": "assistant", "content": [{"type": "tool_use", "name": name, "input": inp}]}}
class EndToEnd(SisiCase):
"""R-5.3-1, R-9-1, R-10.3-1..7, R-15-13, R-17-3, R-17-5, R-17-7: the real hook entry points with
Claude-Code-shaped hook JSON, in a temp home and a temp git project, from install to a closed unit
and a unit the gate had to release as unverified."""
def setUp(self):
super().setUp()
os.environ["SISI_RETRO_REQUIRED"] = "1"
self.addCleanup(lambda: os.environ.__setitem__("SISI_RETRO_REQUIRED", "0"))
def hook(self, event, **extra):
p = dict({"session_id": "e2e", "cwd": self.proj, "transcript_path": self.tp, "hook_event_name": event}, **extra)
return self.sisi("tick" if event == "SessionStart" else "gate", stdin=json.dumps(p))
def stop(self):
r = self.hook("Stop", stop_hook_active=False)
self.assertEqual(r.returncode, 0, r.stderr)
if not r.stdout.strip():
return "allow", None
d = json.loads(r.stdout)
return ("block", d["reason"]) if d.get("decision") == "block" else ("allow", d.get("systemMessage"))
def agent_writes(self, rel, text, tool="Write"):
p = os.path.join(self.proj, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "a" if tool == "Edit" else "w") as f:
f.write(text)
with open(self.tp, "a") as f:
f.write(json.dumps(tool_line(tool, {"file_path": p})) + "\n")
def agent_runs(self, command, *argv):
with open(self.tp, "a") as f:
f.write(json.dumps(tool_line("Bash", {"command": command})) + "\n")
return self.sisi(*argv)
def finding(self, n):
r = self.sisi("retro", "--finding", "`cargo test` run %d took 4 minutes with no fuzz verifier in the project" % n,
"--cause", "the recipe never named a fuzz verifier for parsers", "--impact", "time",
"--disposition", "promote",
"--change", "Add the fuzz verifier to the parser-or-codec recipe Checks, variant %d" % n,
"--mechanism", "verification", "--expect", "parser work gets a fuzz check",
"--validate", "run the recipe checks on a parser change", env={"SISI_SESSION_ID": "e2e"})
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
def test_full_flow(self):
for d in (".claude", ".codex", ".config/opencode"):
os.makedirs(os.path.join(self.home, d))
with open(os.path.join(self.home, ".claude", "settings.json"), "w") as f:
json.dump({"hooks": {"SessionStart": [{"matcher": "*", "hooks": [{"type": "command", "command": "existing"}]}]}}, f)
self.git_init()
with open(os.path.join(self.proj, "README.md"), "w") as f:
f.write("# project\n")
self.assertEqual(self.sisi("install").returncode, 0)
doc = self.sisi("doctor").stdout
self.assertIn("claude-code wired", doc)
payload = json.dumps({"session_id": "e2e", "cwd": self.proj, "hook_event_name": "SessionStart", "source": "startup"})
self.assertEqual(self.sisi("tick", stdin=payload).stdout, "")
stop = json.dumps({"session_id": "e2e", "cwd": self.proj, "hook_event_name": "Stop", "stop_hook_active": False})
self.assertIn("claude-code wired", self.sisi("doctor").stdout)
self.tp = os.path.join(self.tmp, "e2e.jsonl")
with open(self.tp, "w") as f:
f.write(json.dumps({"type": "user", "timestamp": "2026-01-01T00:00:00.000Z",
"message": {"role": "user", "content": "build the feature"}}) + "\n")
self.assertEqual(self.hook("SessionStart", source="startup").stdout, "")
self.write_contract(contract([check("feature", "test -f %s/done.txt" % self.proj, rung=3)]))
r = self.sisi("gate", stdin=stop)
self.assertEqual(r.returncode, 0)
d = json.loads(r.stdout)
self.assertEqual(d["decision"], "block")
self.assertIn("feature", d["reason"])
# a documentation change: silent, nothing run, nothing asked
self.agent_writes("README.md", "more words\n", "Edit")
self.assertEqual(self.stop(), ("allow", None))
open(os.path.join(self.proj, "done.txt"), "w").close()
r = self.sisi("gate", stdin=stop)
self.assertEqual((r.returncode, r.stdout), (0, ""))
# a source change with no contract: sent back, with what it needs
self.agent_writes("app.py", "def feature():\n return 1\n")
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("a contract for this isolated change", msg)
self.assertIn("sisi contract init", msg)
self.assertEqual(self.sisi("unit", "close").returncode, 0)
# a contract with a failing check: sent back with the failure
self.agent_runs("sisi contract init --goal 'build the feature'", "contract", "init", "--goal", "build the feature")
c = load(os.path.join(self.proj, ".sisi", "contract.json"))
c["id"] = "feature"
c["checks"] = [{"id": "feature", "claim": "done.flag exists", "kind": "general", "rung": 3,
"cmd": "test -f done.flag", "expect": {"exit": 0}}]
self.agent_writes(os.path.join(".sisi", "contract.json"), json.dumps(c))
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("feature", msg)
self.assertIn("Failing checks", msg)
# fixed: the two ways on are offered
self.agent_writes("done.flag", "ok\n")
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("sisi retro", msg)
self.assertIn("sisi unit pause", msg)
# paused: silent
self.assertEqual(self.agent_runs("sisi unit pause 'the reviewer'", "unit", "pause", "the reviewer").returncode, 0)
self.assertEqual(self.stop(), ("allow", None))
self.assertIn("paused", self.sisi("status").stdout)
# a new change ends the wait; everything is green, so the two ways on come again
self.agent_writes("app.py", "# a change\n", "Edit")
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertEqual(load(os.path.join(self.proj, ".sisi", "contract.json"))["status"], "open")
# the retro is recorded: the unit closes, is archived, and the stop is silent
self.finding(1)
self.assertEqual(self.stop(), ("allow", None))
rec = load(os.path.join(self.proj, ".sisi", "units", "feature.json"))
self.assertEqual(rec["delivery_status"], "delivered")
out = self.sisi("status").stdout
self.assertIn("[delivered]", out)
self.assertIn("correctness and assurance", out)
# a migration with no independent evidence: sent back with the list
self.agent_writes("migrations/001_users.sql", "CREATE TABLE users (id integer);\n")
self.agent_runs("sisi contract init --goal 'add users'", "contract", "init", "--goal", "add users")
c = load(os.path.join(self.proj, ".sisi", "contract.json"))
c["id"] = "users"
c["checks"] = [{"id": "schema", "claim": "the migration file is present", "kind": "migration", "rung": 3,
"cmd": "test -f migrations/001_users.sql", "expect": {"exit": 0},
"covers": "the migration is deleted"}]
c["invariants"] = [{"id": "readme", "claim": "the readme stays", "cmd": "test -f README.md", "expect": {"exit": 0}}]
c["requirements"] = [{"id": "r1", "kind": "explicit", "text": "a users table exists", "decision": "now"}]
c["risk"] = {"blast_radius": "one new table; nothing reads it yet", "rollback": "drop the table"}
c["approach"] = {"chosen": "a plain SQL migration", "why": "the project already uses them",
"alternatives": ["an ORM auto-migration: hides the schema"]}
self.agent_writes(os.path.join(".sisi", "contract.json"), json.dumps(c))
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("this data change is not ready to hand over (send-back 1 of 3)", msg)
self.assertIn("independent evidence", msg)
self.assertLessEqual(len(msg.splitlines()), 25)
self.migration_message = msg
# three send-backs in a row, then released as unverified and recorded
self.assertEqual(self.stop()[0], "block")
self.assertEqual(self.stop()[0], "block")
a, msg = self.stop()
self.assertEqual(a, "allow")
self.assertIn("UNVERIFIED", msg)
rows = [r for r in self.results() if r.get("check") == "gate" and r.get("status") == "unverified"]
self.assertEqual(len(rows), 1)
self.assertIn("independent evidence", rows[0]["reason"])
self.assertIn("released unverified by the gate", self.sisi("status").stdout)
self.assertEqual(self.sisi("unit", "close").returncode, 0)
rec = load(os.path.join(self.proj, ".sisi", "units", "users.json"))
self.assertEqual(rec["delivery_status"], "unverified")
self.assertEqual(self.sisi("uninstall").returncode, 0)
+931 -833
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -345,7 +345,7 @@ class PauseTests(UnitCase):
self.assertEqual(c["pauses"][0]["what"], "the owner's decision")
stop = json.dumps({"session_id": "p1", "cwd": self.proj, "hook_event_name": "Stop", "stop_hook_active": False})
self.sisi("tick", stdin=json.dumps({"session_id": "p1", "cwd": self.proj, "hook_event_name": "SessionStart"}))
open(os.path.join(self.proj, "new.txt"), "w").write("x") # a change after the pause
open(os.path.join(self.proj, "new.py"), "w").write("x = 1\n") # a change after the pause
self.assertIn("block", self.sisi("gate", stdin=stop).stdout)
self.assertEqual(C.load(self.contract_path)["status"], "open") # the wait ended
self.assertTrue(C.load(self.contract_path)["pauses"][0]["until"])
-11
View File
@@ -161,17 +161,6 @@ class ShowAndChooseTests(LibCase):
out = self.sisi("verifiers", "for", "widget").stdout
self.assertEqual(len([l for l in out.splitlines() if l[:1].isdigit()]), 8)
def test_for_kind_floor_marking(self):
self.seed()
out = self.sisi("verifiers", "for", "parsing round trip", "--kind", "parsing").stdout
self.assertIn("Floor: parsing claims need rung 2", out)
self.assertIn("[floor ok]", out)
self.put("prove/weakparse.md", vfile("weakparse", rung=4, kinds="parsing", answers="Does parsing look fine?"))
out = self.sisi("verifiers", "for", "parsing looks fine", "--kind", "parsing").stdout
self.assertIn("[below floor]", out)
out = self.sisi("verifiers", "for", "page looks", "--kind", "ui").stdout
self.assertNotIn("Floor:", out)
def test_for_lang_and_kind_filters(self):
self.seed()
out = self.sisi("verifiers", "for", "random inputs parsing", "--lang", "rust").stdout
-7
View File
@@ -45,13 +45,6 @@ class VerifyTests(SisiCase):
r = self.run_verify(contract([check("pwd", "pwd", stdout_contains=self.proj)]))
self.assertEqual(r.returncode, 0, r.stdout)
def test_floor_fails(self):
r = self.run_verify(contract([check("m", "true", rung=3, kind="money")]))
self.assertEqual(r.returncode, 1)
self.assertIn("floor", r.stdout)
r = self.run_verify(contract([check("m", "true", rung=2, kind="money")]))
self.assertEqual(r.returncode, 0)
def test_no_contract_exit_2(self):
self.assertEqual(self.sisi("verify").returncode, 2)