Strict rule placement: every rule names its level; core queue; rules move; level audit; unknown flags refused

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-12-01 15:45:21 -07:00
1 parent 4e549dedde
commit bbf21ef178
9 files changed
+291 -87

No files matched your search

+150 -38
View File
@@ -7,9 +7,10 @@ import glob, hashlib, json, os, random, re, shutil, subprocess, sys, tempfile, t
from unittest import mock
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
IMP = ("--improve", "Always name the level of a rule you file")
GAP = ("--gap", "the export dropped rows with empty names until the person noticed",
"--cause", "no check compared the row counts before and after", "--term", "evidence",
"--problem", "export drops empty names")
"--problem", "export drops empty names", "--level", "project")
NG = ("--term", "time", "--better", "start the first build in the same turn as research")
@@ -140,7 +141,7 @@ class Core(unittest.TestCase):
self.assertEqual(self.hook("gate")[1], "") # held: the turn may end
self.assertIn("Compare row counts", self.hook("tick", sid="s2")[1]) # next session here
self.assertNotIn("Compare row counts", self.hook("tick", sid="s3", cwd=self.project("beta"))[1]) # not elsewhere
self.sisi("retro", *GAP, "--improve", "Ask one question with options, never three open ones", "--scope", "user", sid="s1")
self.sisi("retro", *GAP[:-2], "--improve", "Ask one question with options, never three open ones", "--scope", "user", sid="s1")
book = self.read(self.data, "generated", "core.md")
self.assertIn("## 8. Close with a retro", book)
self.assertIn("## Learned here", book)
@@ -157,7 +158,7 @@ class Core(unittest.TestCase):
first = self.records()[-1]["rules"]
self.assertEqual(first, {"hash": hashlib.sha256(book.encode()).hexdigest()[:12], "chars": len(book),
"lines": sum(l.startswith("- ") for l in book.splitlines())})
self.assertEqual(self.sisi("learn", "Always name the rulebook in every retro record", sid="s1")[0], 0)
self.assertEqual(self.sisi("learn", "--level", "user", "Always name the rulebook in every retro record", sid="s1")[0], 0)
self.sisi("retro", *GAP, "--improve", "Name the rulebook in every retro record", sid="s1")
second = self.records()[-1]["rules"]
self.assertNotEqual(second["hash"], first["hash"])
@@ -168,7 +169,7 @@ class Core(unittest.TestCase):
self.done()
self.tool("Write")
for args in (["--gap", "bad"], ["--no-gap", "fine"], GAP + ("--improve", "be careful"), ["--later", "x"],
GAP + ("--improve", "Compare the row counts every time", "--scope", "everyone")):
GAP[:-2] + ("--improve", "Compare the row counts every time", "--scope", "everyone")):
self.assertEqual(self.sisi("retro", *args, sid="s1")[0], 1, args)
self.assertIn('"block"', self.hook("gate")[1])
self.assertEqual(self.sisi("retro", "--no-gap", "the person accepted it first time and every check passed", *NG, sid="s1")[0], 0)
@@ -197,7 +198,7 @@ class Core(unittest.TestCase):
self.hook("tick")
self.done()
self.tool("Write")
base = GAP[:4] + ("--improve", "Compare row counts before and after every export change")
base = GAP[:4] + ("--level", "project", "--improve", "Compare row counts before and after every export change")
for extra in ((), ("--term", "speed")):
rc, out, _ = self.sisi("retro", *base, *extra, sid="s1")
self.assertEqual(rc, 1, extra)
@@ -241,7 +242,7 @@ class Core(unittest.TestCase):
def test_a_secret_never_reaches_a_rule(self):
self.hook("tick")
self.sisi("retro", "--gap", "the deploy failed because the key was pasted wrong", "--cause", "the key was typed by hand each time",
self.sisi("retro", "--level", "project", "--gap", "the deploy failed because the key was pasted wrong", "--cause", "the key was typed by hand each time",
"--term", "evidence", "--problem", "deploy key typed by hand", "--improve", "Read the deploy key from the keyring, never paste api_key=sk-abcdefghijklmnopqrstuvwx into a command", sid="s1")
stored = "".join(self.read(p) for p in glob.glob(os.path.join(self.data, "**", "*.*"), recursive=True))
proj_rules = self.read(self.proj, ".sisi", "rules.md")
@@ -314,12 +315,10 @@ class Core(unittest.TestCase):
def test_outside_git_a_subfolder_is_its_own_project(self):
root = self.mkdir(self.tmp, "plain-proj")
self.assertEqual(self.sisi("learn", "--project", "Rule of the outer plain folder", cwd=root)[0], 0)
sub = self.mkdir(root, "a", "b")
self.assertNotIn("Rule of the outer plain folder", self.hook("tick", sid="ng1", cwd=sub)[1])
self.assertEqual(self.sisi("learn", "--project", "Rule of the inner plain folder", cwd=sub)[0], 0)
self.assertIn("Rule of the inner plain folder", self.read(sub, ".sisi", "rules.md"))
self.assertNotIn("Rule of the inner plain folder", self.read(root, ".sisi", "rules.md"))
for where in (root, sub): # outside git no folder is a project: nothing is written
self.assertEqual(self.sisi("learn", "--project", "Rule of a plain folder", cwd=where)[0], 1)
self.assertFalse(os.path.lexists(os.path.join(where, ".sisi")))
def test_reading_project_with_no_rules_creates_no_sisi_dir(self):
plain = self.mkdir(self.tmp, "plain-empty")
@@ -328,8 +327,8 @@ class Core(unittest.TestCase):
self.assertEqual(self.sisi("rules", cwd=folder)[0], 0)
self.assertEqual(self.sisi("doctor", cwd=folder)[0], 0)
self.assertFalse(os.path.lexists(os.path.join(folder, ".sisi")), folder)
self.assertEqual(self.sisi("learn", "--project", "First rule creates the sisi directory", cwd=plain)[0], 0)
self.assertTrue(os.path.isfile(os.path.join(plain, ".sisi", "rules.md")))
self.assertEqual(self.sisi("learn", "--project", "First rule creates the sisi directory", cwd=plain)[0], 1)
self.assertFalse(os.path.lexists(os.path.join(plain, ".sisi")))
def test_legacy_project_rules_migrate_on_read_and_stay_idempotent(self):
real_rows = [
@@ -584,7 +583,7 @@ class Core(unittest.TestCase):
self.write(os.path.join(p, "app.txt"), "v2\n")
for n, why in (("1", "row counts match at 10"), ("2", "empty name exported as row")):
self.assertEqual(self.sisi("done", "--pass", n, why, cwd=p, sid=sid)[0], 0)
rc, out, _ = self.sisi("retro", *GAP[:4], "--improve", rule_text, "--term", "time", "--problem", "problem-" + sid, cwd=p, sid=sid)
rc, out, _ = self.sisi("retro", *GAP[:4], "--level", "project", "--improve", rule_text, "--term", "time", "--problem", "problem-" + sid, cwd=p, sid=sid)
self.assertEqual(rc, 0, out)
# 1. Exact four-step sequence: retro writes tracked .sisi/rules.md, commit that one file -> no demand
@@ -636,7 +635,7 @@ class Core(unittest.TestCase):
self.assertIn('"block"', self.hook("gate", sid="r5", cwd=p5)[1])
for n, why in (("1", "row counts match at 10"), ("2", "empty name exported as row")):
self.assertEqual(self.sisi("done", "--pass", n, why, cwd=p5, sid="r5")[0], 0)
self.assertEqual(self.sisi("retro", *GAP, "--improve", "Non-git project rules still record cleanly", cwd=p5, sid="r5")[0], 0)
self.assertEqual(self.sisi("retro", *GAP[:-2], "--level", "user", "--improve", "Non-git project rules still record cleanly", cwd=p5, sid="r5")[0], 0)
self.assertEqual(self.hook("gate", sid="r5", cwd=p5)[1], "")
def test_doctor_reports_project_agents_note_without_writing(self):
@@ -996,7 +995,7 @@ class Core(unittest.TestCase):
self.assertEqual(self.read(self.proj, ".sisi", "rules.md"), rows)
beta = self.project("mig-with-prior")
self.assertEqual(self.sisi("learn", "User rule recorded before migration")[0], 0)
self.assertEqual(self.sisi("learn", "--level", "user", "User rule recorded before migration")[0], 0)
old_b = self.legacy(beta, rows)
self.hook("tick", sid="mb", cwd=beta)
self.assertFalse(os.path.exists(old_b))
@@ -1191,7 +1190,7 @@ class Core(unittest.TestCase):
([sys.executable, os.path.join(REPO, "bin", "sisi"), "learn", "--project", "Alpha one rule round %d" % rnd], pa, ""),
([sys.executable, os.path.join(REPO, "bin", "sisi"), "learn", "--project", "Alpha two rule round %d" % rnd], pa, ""),
([sys.executable, os.path.join(REPO, "bin", "sisi"), "retro", *GAP, "--improve", "Beta one rule round %d" % rnd], pb, ""),
([sys.executable, os.path.join(REPO, "bin", "sisi"), "retro", *GAP, "--scope", "user", "--improve", "User rule round %d" % rnd], pa, ""),
([sys.executable, os.path.join(REPO, "bin", "sisi"), "retro", *GAP[:-2], "--scope", "user", "--improve", "User rule round %d" % rnd], pa, ""),
([sys.executable, os.path.join(REPO, "bin", "sisi"), "retro", *GAP, "--improve", "Retro rule round %d" % rnd], pa, ""),
([sys.executable, os.path.join(REPO, "bin", "sisi"), "tick"], pc, json.dumps({"session_id": "c1-%d" % rnd, "cwd": pc})),
([sys.executable, os.path.join(REPO, "bin", "sisi"), "tick"], pc, json.dumps({"session_id": "c2-%d" % rnd, "cwd": pc})),
@@ -1290,7 +1289,7 @@ class Core(unittest.TestCase):
# organize replaced rules/user.md under a project's lock; a user rule's concurrent `git add` read it as it
# shrank: "short read while indexing rules/user.md".
from sisi import rules, store
self.sisi("learn", "User rule before organizing")
self.sisi("learn", "--level", "user", "User rule before organizing")
user, real_lock, seen = os.path.join(self.data, "rules", "user.md"), store.lock, []
before = self.read(user)
@@ -1308,8 +1307,8 @@ class Core(unittest.TestCase):
def test_folders_outside_git_are_each_their_own_project(self):
notes, other, thing = (self.mkdir(self.tmp, *p) for p in (("notes",), ("code", "other"), ("code", "thing")))
self.assertEqual(self.sisi("learn", "--project", "A rule written at the home folder", cwd=self.tmp)[0], 0)
self.assertEqual(self.sisi("learn", "--project", "A rule written in the notes folder", cwd=notes)[0], 0)
self.assertEqual(self.sisi("learn", "--project", "A rule written at the home folder", cwd=self.tmp)[0], 1)
self.assertEqual(self.sisi("learn", "--project", "A rule written in the notes folder", cwd=notes)[0], 1)
old = self.legacy(thing, "- Old rule of the thing folder [owner 2026-11-20]\n")
out = self.hook("tick", sid="o1", cwd=other)[1]
self.assertNotIn("home folder", out)
@@ -1430,18 +1429,18 @@ cli.main(["tick"])
rc, out, err = self.sisi("learn", "--project", "Rule saved even when store rules dir is read only")
self.assertEqual((rc, err), (0, ""), out)
self.assertIn("Rule saved even when store rules dir is read only", self.read(self.proj, ".sisi", "rules.md"))
self.assertEqual(len(out.strip().splitlines()), 2, out)
self.assertEqual(len(out.strip().splitlines()), 3, out)
self.assertIn("the rule is in", out)
self.assertIn("could not be recorded for undo", out)
self.assertNotIn("Nothing was changed", out)
def test_failed_store_commit_reports_failure_and_blocks_older_revert(self):
self.assertEqual(self.sisi("learn", "Older user rule that revert must not silently undo")[0], 0)
self.assertEqual(self.sisi("learn", "--level", "user", "Older user rule that revert must not silently undo")[0], 0)
lock = self.write(os.path.join(self.data, ".git", "index.lock"), "")
rc, out, err = self.sisi("learn", "--project", "Project rule while index lock blocks commit")
self.assertEqual((rc, err), (0, ""), out)
self.assertIn("Project rule while index lock blocks commit", self.read(self.proj, ".sisi", "rules.md"))
self.assertEqual(len(out.strip().splitlines()), 2, out)
self.assertEqual(len(out.strip().splitlines()), 3, out)
self.assertIn("could not be recorded for undo", out)
os.remove(lock)
rc_rev, out_rev, _ = self.sisi("rules", "revert")
@@ -1469,9 +1468,9 @@ cli.main(["tick"])
dot_git = os.path.join(self.proj, ".git")
for where in (dot_git, os.path.join(dot_git, "refs")):
rc, out, err = self.sisi("retro", *GAP, "--improve", "Never write rules inside a git directory", cwd=where)
self.assertEqual((rc, err), (0, ""), (where, out))
self.assertNotIn("could not write (", out)
self.assertIn("could not write %s (" % where, out)
self.assertEqual((rc, err), (1, ""), (where, out))
self.assertIn("no project here", out)
self.assertFalse(os.path.lexists(os.path.join(where, ".sisi")))
def test_byte_order_mark_and_non_utf8_project_file(self):
old = os.path.join(self.mkdir(self.data, "rules", "projects"), self.project_key_for(self.proj) + ".md")
@@ -1508,7 +1507,7 @@ cli.main(["tick"])
self.sisi("learn", "--project", "A rule that must not land here", cwd=where)):
rc, out = (r.returncode, r.stdout) if hasattr(r, "returncode") else r[:2]
self.assertEqual((rc, len(out.strip().splitlines())), (1, 1), (where, out))
self.assertIn("inside a git directory or a bare repository", out)
self.assertIn("no project here", out)
self.assertEqual(self.hook("tick", sid="b", cwd=where)[0], 0)
self.assertFalse(os.path.lexists(os.path.join(where, ".sisi")), where)
self.assertFalse(os.path.lexists(os.path.join(self.tmp, ".sisi")))
@@ -1609,7 +1608,7 @@ cli.main(["tick"])
def test_the_models_table_is_researched_recorded_and_goes_stale(self):
self.assertIn("no models table yet", self.hook("tick")[1])
self.hook("prompt", prompt="Only the cheapest models on the shared plan")
self.sisi("learn", "Only the cheapest models on the shared plan", sid="s1")
self.sisi("learn", "--level", "user", "Only the cheapest models on the shared plan", sid="s1")
brief = self.sisi("models", "research")[1]
self.assertIn("Fallback order:", brief)
self.assertIn("Only the cheapest models on the shared plan", brief) # the person's words bind the researcher
@@ -2502,7 +2501,7 @@ cli.main(["tick"])
book = self.read(self.data, "generated", "core.md")
text = self.read(mine)
self.assertEqual(text, "<!-- sisi:begin -->\n%s<!-- sisi:end -->\n# my notes\nno newline at the end" % book)
self.assertEqual(self.sisi("learn", "Always say which check proved it")[0], 0) # a rebuild refreshes the block
self.assertEqual(self.sisi("learn", "--level", "user", "Always say which check proved it")[0], 0) # a rebuild refreshes the block
new = self.read(mine)
self.assertIn("Always say which check proved it", new)
self.assertTrue(new.endswith("<!-- sisi:end -->\n# my notes\nno newline at the end"))
@@ -2512,7 +2511,7 @@ cli.main(["tick"])
self.assertFalse(os.path.lexists(os.path.join(home, ".pi", "agent", "AGENTS.md")))
self.assertEqual(os.readlink(os.path.join(home, ".gemini", "GEMINI.md")), elsewhere)
# a rebuild alone never creates anything in a tool
self.sisi("learn", "Name the check that failed first")
self.sisi("learn", "--level", "user", "Name the check that failed first")
self.assertFalse(os.path.lexists(os.path.join(home, ".pi", "agent", "AGENTS.md")))
self.assertEqual(self.read(mine), "# my notes\nno newline at the end")
@@ -2524,7 +2523,7 @@ cli.main(["tick"])
self.assertEqual(self.sisi("install")[0], 0)
book = self.read(self.data, "generated", "core.md")
self.assertEqual(self.read(target), "<!-- sisi:begin -->\n%s<!-- sisi:end -->\n# my notes\n%s" % (book, second))
self.assertEqual(self.sisi("learn", "Keep second marked block in global instructions")[0], 0)
self.assertEqual(self.sisi("learn", "--level", "user", "Keep second marked block in global instructions")[0], 0)
new_book = self.read(self.data, "generated", "core.md")
self.assertIn("Keep second marked block in global instructions", new_book)
self.assertEqual(self.read(target), "<!-- sisi:begin -->\n%s<!-- sisi:end -->\n# my notes\n%s" % (new_book, second))
@@ -2618,7 +2617,7 @@ cli.main(["tick"])
subprocess.run(["git", "clone", "-q", src, mine], check=True, capture_output=True) # the person's checkout, with its remote
self.assertEqual(run(os.path.join(mine, "bin", "sisi"), "release").returncode, 0)
self.assertEqual(self.read(self.env["SISI_LIB"], "current", "SOURCE").split("\n")[0], src)
self.sisi("learn", "Always keep what the person wrote")
self.sisi("learn", "--level", "user", "Always keep what the person wrote")
self.write(os.path.join(self.data, "models.md"), WORKERS)
self.write(os.path.join(self.data, "retro.jsonl"), '{"gap": "g"}\n')
keep = {n: self.read(self.data, n) for n in ("models.md", "retro.jsonl", "rules/user.md")}
@@ -3749,7 +3748,7 @@ cli.main(["tick"])
def test_owner_tag_means_the_persons_own_words(self):
said = "Please, ALWAYS name the check that failed first!"
rc, out, _ = self.sisi("learn", "always name the check that failed first", sid="o1") # no message of the person yet
rc, out, _ = self.sisi("learn", "--level", "user", "always name the check that failed first", sid="o1") # no message of the person yet
rules_u = lambda: self.read(self.data, "rules", "user.md")
self.assertEqual(rc, 0, out)
self.assertIn("[agent, attributed to owner", rules_u())
@@ -3757,11 +3756,11 @@ cli.main(["tick"])
self.assertIn("not found in the person's recent messages", out)
self.hook("prompt", sid="o1", prompt=said)
self.hook("prompt", sid="w1", prompt="You are a worker. Do this task yourself.\nnever use tabs anywhere")
self.assertEqual(self.sisi("learn", "ALWAYS name the check -- that failed first", sid="o1")[0], 0)
self.assertEqual(self.sisi("learn", "--level", "user", "ALWAYS name the check -- that failed first", sid="o1")[0], 0)
self.assertRegex(rules_u().splitlines()[-1], r"first \[owner \d{4}-\d\d-\d\d\]$")
self.assertEqual(self.sisi("learn", "never use tabs anywhere", sid="w1")[0], 0) # a worker records nothing
self.assertEqual(self.sisi("learn", "--level", "user", "never use tabs anywhere", sid="w1")[0], 0) # a worker records nothing
self.assertIn("never use tabs anywhere [agent, attributed", rules_u())
rc, out, _ = self.sisi("learn", "ALWAYS name the check that failed first", "--means", "name the failing check in every report", sid="o1")
rc, out, _ = self.sisi("learn", "--level", "user", "ALWAYS name the check that failed first", "--means", "name the failing check in every report", sid="o1")
last = rules_u().splitlines()[-2:]
self.assertRegex(last[0], r"failed first \[owner \d{4}-\d\d-\d\d\]$")
self.assertRegex(last[1], r"^- name the failing check in every report \[agent reading \d{4}-\d\d-\d\d\]$")
@@ -3889,7 +3888,7 @@ cli.main(["tick"])
self.assertEqual(self.sisi("fault", sid="s1")[1].strip(), "no open faults.")
def test_learn_means_is_one_store_commit_so_revert_undoes_both(self):
self.assertEqual(self.sisi("learn", "always name the check that failed first", "--means", "name the failing check in every report")[0], 0)
self.assertEqual(self.sisi("learn", "--level", "user", "always name the check that failed first", "--means", "name the failing check in every report")[0], 0)
rules_u = lambda: self.read(self.data, "rules", "user.md")
self.assertEqual(len(rules_u().strip().splitlines()), 2)
self.assertEqual(self.sisi("rules", "revert")[0], 0)
@@ -3946,9 +3945,122 @@ cli.main(["tick"])
with open(os.path.join(REPO, rel), "rb") as f:
self.assertEqual(hashlib.sha256(f.read()).hexdigest(), digest, rel)
# strict placement: every rule names its level
def user_file(self, text):
os.makedirs(os.path.join(self.data, "rules"), exist_ok=True)
return self.write(os.path.join(self.data, "rules", "user.md"), text)
def test_learn_and_retro_without_a_level_are_refused_and_write_nothing(self):
rc, out, _ = self.sisi("learn", "Always name the level of a rule")
self.assertEqual(rc, 1)
self.assertIn("core = ", out)
self.assertIn("--level core|user|project", out)
rc, out, _ = self.sisi("retro", *GAP[:-2], *IMP)
self.assertEqual(rc, 1)
self.assertIn("user = ", out)
self.assertFalse(os.path.exists(os.path.join(self.data, "rules", "user.md")))
self.assertFalse(os.path.exists(os.path.join(self.proj, ".sisi")))
self.assertEqual(self.sisi("retro", "--no-gap", "the export kept every row", *NG)[0], 0) # no rule, no level needed
self.assertEqual(self.sisi("retro", *GAP[:-2], *IMP, "--scope", "user")[0], 0) # --scope is an alias
def test_unknown_options_are_refused_not_folded_into_the_rule(self):
for args in (("learn", "--level", "user", "Always name the level", "--scopee", "project"),
("learn", "--level", "user", "--bogus", "Always name the level")):
rc, out, _ = self.sisi(*args)
self.assertEqual(rc, 1, args)
self.assertIn("usage: sisi learn", out)
self.assertEqual(self.sisi("retro", *GAP[:-2], *IMP, "--level", "user", "--bogus", "x")[0], 1)
self.assertFalse(os.path.exists(os.path.join(self.data, "rules", "user.md")))
def test_project_level_needs_a_git_repo_and_never_creates_sisi_elsewhere(self):
plain = os.path.join(self.tmp, "plain")
os.makedirs(plain)
for where in (plain, self.tmp): # a plain folder, and the home folder
for args in (("learn", "--level", "project", "Always check this folder first"), ("retro", *GAP[:-2], *IMP, "--level", "project")):
rc, out, _ = self.sisi(*args, cwd=where)
self.assertEqual(rc, 1, args)
self.assertIn("no project here", out)
self.assertIn("use user", out)
self.assertFalse(os.path.exists(os.path.join(where, ".sisi")), where)
rc, out, _ = self.sisi("learn", "--level", "project", "Always check this folder first")
self.assertEqual(rc, 0, out)
self.assertIn('filed as project rule in %s' % os.path.join(self.proj, ".sisi", "rules.md"), out)
self.assertIn('Wrong level? sisi rules move "Always check this folder first"', out)
def test_core_rules_are_queued_shown_in_the_sisi_repo_and_never_loaded(self):
rc, out, _ = self.sisi("learn", "--level", "core", "Every sisi user should see this line")
self.assertEqual(rc, 0, out)
self.assertIn("Every sisi user should see this line", self.read(self.data, "rules", "core.md"))
self.assertEqual(self.sisi("retro", *GAP[:-2], *IMP, "--level", "core")[0], 0)
self.assertEqual(len(self.read(self.data, "rules", "core.md").splitlines()), 2)
self.sisi("rulebook")
self.assertNotIn("Every sisi user", self.read(self.data, "generated", "core.md"))
self.assertNotIn("Every sisi user", self.hook("tick", sid="c1")[1])
repo = self.project("sisi-checkout")
for rel in (("canon", "core.md"), ("sisi", "rules.py")):
os.makedirs(os.path.join(repo, rel[0]), exist_ok=True)
self.write(os.path.join(repo, *rel), "x\n")
out = self.hook("tick", sid="c2", cwd=repo)[1]
self.assertIn("2 rules proposed for the product: add each to canon/core.md or move it", out)
def test_rules_move_carries_an_owner_line_verbatim_between_levels(self):
line = "- Keep the words exactly as spoken [owner 2026-11-20]"
self.user_file(line + "\n- Another user rule [retro 2026-11-21]\n")
rc, out, _e = self.sisi("rules", "move", "Keep the words", "project"); out += _e
self.assertEqual(rc, 0, out)
self.assertEqual(self.read(self.proj, ".sisi", "rules.md"), line + "\n")
self.assertEqual(self.read(self.data, "rules", "user.md"), "- Another user rule [retro 2026-11-21]\n")
self.assertEqual(self.sisi("rules", "move", "Keep the words", "user")[0], 0)
self.assertEqual(self.read(self.data, "rules", "user.md").splitlines()[-1], line)
self.assertEqual(self.read(self.proj, ".sisi", "rules.md"), "")
self.assertEqual(self.sisi("rules", "move", "Keep the words", "core")[0], 0)
self.assertEqual(self.read(self.data, "rules", "core.md"), line + "\n")
other = self.project("other")
self.assertEqual(self.sisi("rules", "move", "Keep the words", "project", "--project", other)[0], 0)
self.assertEqual(self.read(other, ".sisi", "rules.md"), line + "\n")
self.assertEqual(self.sisi("rules", "move", "Keep the words", "project", "--project", self.tmp)[0], 1) # not a repo root
def test_rules_move_refuses_no_match_or_several(self):
self.user_file("- Same start one [owner 2026-11-20]\n- Same start two [owner 2026-11-20]\n")
before = self.read(self.data, "rules", "user.md")
for start, want in (("Nothing like this", "no rule line"), ("Same start", "more than one")):
rc, out, _ = self.sisi("rules", "move", start, "project")
self.assertEqual(rc, 1)
self.assertIn(want, out)
self.assertIn("Same start two", self.sisi("rules", "move", "Same start", "core")[1])
self.assertEqual(self.read(self.data, "rules", "user.md"), before)
self.assertFalse(os.path.exists(os.path.join(self.proj, ".sisi")))
def test_organize_moves_an_owner_line_across_levels_but_never_rewords_it(self):
mine = "- Words about this one project [owner 2026-11-20]"
self.user_file(mine + "\n")
self.assertEqual(self.sisi("rules", "organize")[0], 0)
ok = self.write(os.path.join(self.tmp, "ok.md"), "## user\n## project\n%s\n## core\n" % mine)
rc, out, _ = self.sisi("rules", "organize", "--record", ok)
self.assertEqual(rc, 0, out)
self.assertEqual(self.read(self.proj, ".sisi", "rules.md"), mine + "\n")
self.assertEqual(self.read(self.data, "rules", "user.md"), "")
self.assertEqual(self.sisi("rules", "organize")[0], 0)
bad = self.write(os.path.join(self.tmp, "bad.md"), "## user\n- Words about this one project, reworded [owner 2026-11-20]\n## project\n")
rc, out, _ = self.sisi("rules", "organize", "--record", bad)
self.assertEqual(rc, 1)
self.assertIn("owner rule missing or changed", out)
self.assertEqual(self.read(self.proj, ".sisi", "rules.md"), mine + "\n")
def test_the_level_audit_becomes_due_by_a_retro_count(self):
self.user_file("- A user rule [retro 2026-11-20]\n")
os.makedirs(self.data, exist_ok=True)
self.write(os.path.join(self.data, "retro.jsonl"), '{"x": 1}\n' * 3)
self.assertNotIn("need organizing", self.hook("tick", sid="a1")[1])
self.write(os.path.join(self.data, "retro.jsonl"), '{"x": 1}\n' * 12)
out = self.hook("tick", sid="a2")[1]
self.assertIn("need organizing", out)
self.assertIn("time to audit their levels", out)
def test_the_product_stays_small(self):
code = sum(len(self.read(p).splitlines()) for p in glob.glob(os.path.join(REPO, "sisi", "*.py")))
self.assertLessEqual(code, 2290, "sisi is two loops. If it needs more than this, find the simpler shape.")
self.assertLessEqual(code, 2381, "sisi is two loops. If it needs more than this, find the simpler shape.")
rulebook = self.read(REPO, "canon", "core.md")
self.assertLess(len(rulebook.splitlines()), 139)
self.assertLessEqual(len(rulebook), 10711)
+7 -7
View File
@@ -11,7 +11,7 @@ import unittest
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
GAP = ("--gap", "the export dropped rows with empty names until the person noticed",
"--cause", "no check compared the row counts before and after", "--term", "evidence")
"--cause", "no check compared the row counts before and after", "--term", "evidence", "--level", "project")
def tree():
@@ -61,11 +61,11 @@ class OrganizeEvidence(unittest.TestCase):
return f.read()
def test_brief_has_problem_evidence_and_respects_caps(self):
self.assertEqual(self.sisi("retro", "--gap", "export dropped rows with empty names in table",
self.assertEqual(self.sisi("retro", "--level", "project", "--gap", "export dropped rows with empty names in table",
"--cause", "first cause missed null guard",
"--improve", "Check null names before exporting rows",
"--term", "evidence", "--problem", "row count mismatch")[0], 0)
self.assertEqual(self.sisi("retro", "--gap", "export dropped rows again on blank fields",
self.assertEqual(self.sisi("retro", "--level", "project", "--gap", "export dropped rows again on blank fields",
"--cause", "second cause forgot whitespace trim",
"--improve", "Strip whitespace and assert total row count matches",
"--term", "evidence", "--problem", "1")[0], 0)
@@ -85,7 +85,7 @@ class OrganizeEvidence(unittest.TestCase):
long_cause = "word " * 1000
for i in range(2, 19):
cause = long_cause if i == 18 else "cause number %02d in batch" % i
self.assertEqual(self.sisi("retro", "--gap", "gap number %02d failed verification check" % i,
self.assertEqual(self.sisi("retro", "--level", "project", "--gap", "gap number %02d failed verification check" % i,
"--cause", cause,
"--improve", "Rule number %02d for problem" % i,
"--term", "evidence", "--problem", "problem item %02d" % i)[0], 0)
@@ -116,7 +116,7 @@ class OrganizeEvidence(unittest.TestCase):
shape = brief.split("Answer with exactly this shape")[1].split("===")[0]
self.assertLess(shape.index("## project"), shape.index("## drops"))
self.assertLess(shape.index("## drops"), shape.index("## flags"))
self.assertEqual(len(brief.split("=== The first list now")[0].splitlines()), 35)
self.assertEqual(len(brief.split("=== The first list now")[0].splitlines()), 40)
proj_line = self.read(self.proj, ".sisi", "rules.md").splitlines()[0]
ans = self.write(os.path.join(self.tmp, "ans.md"),
"## user\n## project\n- Kept project rule [retro 2026-11-26]\n"
@@ -165,7 +165,7 @@ class OrganizeEvidence(unittest.TestCase):
def test_owner_rules_stay_verbatim_with_drops_format(self):
self.sisi("prompt", sid="o1", stdin=json.dumps({"session_id": "o1", "cwd": self.proj, "prompt": "Always keep the owner rule verbatim"}))
self.assertEqual(self.sisi("learn", "Always keep the owner rule verbatim", sid="o1")[0], 0)
self.assertEqual(self.sisi("learn", "--level", "user", "Always keep the owner rule verbatim", sid="o1")[0], 0)
self.assertEqual(self.sisi("retro", *GAP, "--improve", "Check row counts before export", "--problem", "empty names")[0], 0)
own = self.read(self.data, "rules", "user.md").splitlines()[0]
ret = self.read(self.proj, ".sisi", "rules.md").splitlines()[0]
@@ -297,7 +297,7 @@ class OrganizeEvidence(unittest.TestCase):
def test_drops_ignore_kept_owner_and_invented_rules(self):
self.sisi("prompt", sid="o1", stdin=json.dumps({"session_id": "o1", "cwd": self.proj, "prompt": "Always keep the owner rule verbatim"}))
self.assertEqual(self.sisi("learn", "Always keep the owner rule verbatim", sid="o1")[0], 0)
self.assertEqual(self.sisi("learn", "--level", "user", "Always keep the owner rule verbatim", sid="o1")[0], 0)
self.assertEqual(self.sisi("retro", *GAP, "--improve", "Kept retro rule always here", "--problem", "empty names")[0], 0)
own = self.read(self.data, "rules", "user.md").splitlines()[0]
ret = self.read(self.proj, ".sisi", "rules.md").splitlines()[0]
+3 -3
View File
@@ -16,7 +16,7 @@ REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, REPO)
from sisi import retro, store
GAP = ("--gap", "the export dropped rows with empty names until the person noticed",
"--cause", "no check compared the row counts before and after", "--term", "evidence")
"--cause", "no check compared the row counts before and after", "--term", "evidence", "--level", "project")
def tree():
@@ -87,7 +87,7 @@ class Problems(unittest.TestCase):
self.assertNotIn("has come back", out)
# Open problem #2 by words
rc, out, err = self.sisi("retro", "--gap", "build script left stale artifacts in output",
rc, out, err = self.sisi("retro", "--level", "project", "--gap", "build script left stale artifacts in output",
"--cause", "clean step was skipped on incremental runs",
"--improve", "Always clean output directory before packaging release",
"--term", "value", "--problem", "stale build artifacts")
@@ -125,7 +125,7 @@ class Problems(unittest.TestCase):
# Add more non-problem records and cite #2; numbers stay stable
self.assertEqual(self.sisi("retro", "--no-gap", "the build passed cleanly on first run",
"--term", "time", "--better", "parallelize the test suite run here")[0], 0)
rc, out, _ = self.sisi("retro", "--gap", "build script left stale artifacts again",
rc, out, _ = self.sisi("retro", "--level", "project", "--gap", "build script left stale artifacts again",
"--cause", "incremental cache kept old binary",
"--improve", "Hash inputs before reusing build artifacts",
"--term", "value", "--problem", "2")