Item 1: contract must state risk.profile; init writes the floor; gate lists it. done 1 / next 2 (routing adjustments reader)

This commit is contained in:
swaits committed 2026-11-23 12:20:40 -07:00
1 parent 216f39e8f7
commit c8aef3dc23
8 files changed
+72 -20

No files matched your search

+2 -2
View File
@@ -126,8 +126,8 @@ def human(id, rung=5, kind="general"):
def contract(checks, invariants=()):
return {"id": "t", "goal": "g", "checks": list(checks), "invariants": list(invariants),
"assumptions": [], "questions": []}
return {"id": "t", "goal": "g", "risk": {"profile": "isolated"}, "checks": list(checks),
"invariants": list(invariants), "assumptions": [], "questions": []}
def skip_timing_if_busy(case):
+33
View File
@@ -4,6 +4,39 @@ from sisi import contract as C
class ContractTests(SisiCase):
def test_the_contract_must_state_its_risk_profile(self):
"""R-5.3-1: `risk.profile` is the agent's own judgement and is required; init writes the floor as its start."""
good = contract([check("a", "true")])
for name, risk in (("missing", None), ("empty object", {}), ("unknown", {"profile": "huge"})):
with self.subTest(name):
c = dict(good)
c.pop("risk")
if risk is not None:
c["risk"] = risk
errs = C.validate(c)
self.assertTrue(any("risk" in e and "sisi risk" in e and "integration" in e and "release" in e
for e in errs), errs)
self.assertEqual(C.validate(good), [])
self.git_init()
self.assertEqual(self.sisi("contract", "init").returncode, 0)
c = C.load(os.path.join(self.proj, ".sisi", "contract.json"))
self.assertIn(c["risk"]["profile"], C.RISK_PROFILES)
with open(os.path.join(self.proj, "migrations_001.sql"), "w") as f:
f.write("alter table t add column c int;\n")
os.remove(os.path.join(self.proj, ".sisi", "contract.json"))
self.assertEqual(self.sisi("contract", "init").returncode, 0)
floor = self.sisi("risk", "--json")
import json as _j
self.assertEqual(C.load(os.path.join(self.proj, ".sisi", "contract.json"))["risk"]["profile"],
_j.loads(floor.stdout)["floor"])
self.assertNotEqual(_j.loads(floor.stdout)["floor"], "trivial")
c = C.load(os.path.join(self.proj, ".sisi", "contract.json"))
c["risk"] = {}
C.save(os.path.join(self.proj, ".sisi", "contract.json"), c)
r = self.sisi("contract", "check")
self.assertEqual(r.returncode, 1)
self.assertIn("risk.profile", r.stdout)
def test_skeleton_is_valid_but_fails(self):
c = C.skeleton("goal")
self.assertEqual(C.validate(c), [])
+1 -1
View File
@@ -132,7 +132,7 @@ class EndToEnd(SisiCase):
"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["risk"] = {"profile": "data", "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))
+12 -2
View File
@@ -25,7 +25,7 @@ def full(**over):
[dict(check("keeps", "test -f README.md"), covers="the readme is deleted")])
c.update(id="t", goal="make the feature work",
requirements=[{"id": "r1", "kind": "explicit", "text": "ok.txt exists when the feature is done", "decision": "now"}],
risk={"blast_radius": "only the feature file; nothing else reads it", "rollback": "git revert the commit"},
risk={"profile": "isolated", "blast_radius": "only the feature file; nothing else reads it", "rollback": "git revert the commit"},
approach={"chosen": "write the file directly", "why": "the simplest thing that works",
"alternatives": ["generate it from a template: more moving parts"]},
started=store.now(), status="open", pauses=[], deviations=[])
@@ -174,6 +174,16 @@ class RequirementTests(GateBase):
self.assertIn("sisi contract init", miss[0][1])
self.assertEqual(assure.missing("isolated", contract([check("a", "false")]), self.proj), [])
def test_a_contract_without_a_risk_profile_is_missing_one_in_the_gates_list(self):
"""R-5.3-1: the declared profile is on the "what is missing" list, once, with the field that supplies it."""
c = full()
c["risk"] = {"blast_radius": "x" * 20, "rollback": "git revert"}
miss = assure.missing("isolated", c, self.proj, errors=C.validate(c))
self.assertEqual(len(miss), 1, miss)
self.assertIn("risk profile", miss[0][0])
self.assertIn('"profile"', miss[0][1])
self.assertEqual(assure.missing("isolated", full(), self.proj, errors=C.validate(full())), [])
def test_logic_needs_covers_on_every_check(self):
"""R-5.3-6."""
c = contract([check("a", "false"), dict(check("b", "false"), covers="the parser drops a line")])
@@ -185,7 +195,7 @@ class RequirementTests(GateBase):
def test_integration_needs_invariants_requirements_a_risk_note_and_an_approach(self):
"""R-5.3-7: each missing piece is named, with the field that supplies it."""
c = full(invariants=[], requirements=[], risk={}, approach=None)
c = full(invariants=[], requirements=[], risk={"profile": "isolated"}, approach=None)
text = " | ".join("%s -> %s" % m for m in assure.missing("integration", c, self.proj))
for field in ('"invariants"', '"requirements"', '"risk"', '"approach"'):
self.assertIn(field, text)
+1 -1
View File
@@ -264,7 +264,7 @@ class NothingUnrunIsEverPassedTests(SisiCase):
if wc:
x["when_changed"] = wc
return x
c = {"id": "t", "goal": "g", "assumptions": [], "questions": [], "invariants": [],
c = {"id": "t", "goal": "g", "risk": {"profile": "isolated"}, "assumptions": [], "questions": [], "invariants": [],
"checks": [mk("a", "f_a", None, True), mk("b", "f_b", ["f_b*"], True),
mk("c", "f_c", ["nothing/**"], True), mk("d", "f_d", None, False)]}
self.write_contract(c, d)