Retire note, propose, audit, dev mode, build-canon, canon cost and migrate commands

This commit is contained in:
swaits committed 2026-11-23 10:55:41 -07:00
1 parent 9fcd617391
commit 9b69d41950
16 files changed
+126 -343

No files matched your search

+24 -20
View File
@@ -58,6 +58,9 @@ class PersonalCase(SisiCase):
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
return r
def build_canon(self):
return overlay.build_canon()
def generated(self):
with open(paths.generated()) as f:
return f.read()
@@ -80,19 +83,19 @@ class PersonalCase(SisiCase):
class OverlayTests(PersonalCase):
def test_first_use_creates_personal_repo(self):
self.ok("build-canon")
self.build_canon()
self.assertTrue(os.path.isdir(os.path.join(self.data, ".git")))
self.assertEqual(open(os.path.join(self.data, "VERSION")).read().strip(), str(pdata.FORMAT_VERSION))
self.assertIn("retro.db", open(os.path.join(self.data, ".gitignore")).read())
g = self.generated()
self.assertTrue(g.startswith("<!-- generated by sisi build-canon"))
self.assertTrue(g.startswith("<!-- generated by sisi "))
self.assertEqual(g.split("\n")[0].count("<!--"), 1)
self.assertIn("## 1. Alpha rule {#alpha}", g)
self.assertEqual(pdata.git("log", "--format=%an <%ae>").stdout.split("\n")[0], "sisi <sisi@localhost>")
self.assertFalse(os.path.exists(os.path.join(self.p1, "oracle.md")))
def test_hooks_and_global_config_are_ignored(self):
self.ok("build-canon")
self.build_canon()
hook = os.path.join(self.data, ".git", "hooks", "pre-commit")
os.makedirs(os.path.dirname(hook), exist_ok=True)
with open(hook, "w") as f:
@@ -158,7 +161,7 @@ class OverlayTests(PersonalCase):
self.assertRegex(self.ok("verifiers").stdout, r"\n mutmut ")
def test_size_budget_refuses_and_changes_nothing(self):
self.ok("build-canon")
self.build_canon()
gen0, log0 = self.generated(), self.git_log()
room = overlay.MAX_LINES - len(gen0.splitlines())
big = rule_file("Big", "\n".join("line %d" % i for i in range(room + 30)))
@@ -180,13 +183,13 @@ class OverlayTests(PersonalCase):
self.ok("overlay", "add-rule", "--id", "delta", "-", stdin=rule_file("Delta", "Body."))
a = self.generated()
for _ in range(2):
self.ok("build-canon")
self.build_canon()
self.assertEqual(self.generated(), a)
self.assertFalse(overlay.is_stale())
t = os.stat(os.path.join(self.p1, "canon", "core.md")).st_mtime_ns - 5_000_000_000
os.utime(paths.generated(), ns=(t, t)) # the product's core.md is now newer than the generated file
self.assertTrue(overlay.is_stale())
self.ok("build-canon")
self.build_canon()
self.assertFalse(overlay.is_stale())
def test_stale_rulebook_is_reported_by_tick_only_when_wired(self):
@@ -195,13 +198,13 @@ class OverlayTests(PersonalCase):
self.assertEqual(wiring.quick_problem(), None)
os.remove(paths.generated())
self.assertIn("generated rulebook is missing", wiring.quick_problem())
self.ok("build-canon")
self.build_canon()
t = os.stat(os.path.join(self.p1, "canon", "core.md")).st_mtime_ns - 5_000_000_000
os.utime(paths.generated(), ns=(t, t))
self.assertIn("out of date", wiring.quick_problem())
def test_one_commit_per_change_and_revert_restores_bytes(self):
self.ok("build-canon")
self.build_canon()
n0 = len(self.git_log())
steps = [(("add-rule", "--id", "delta", "-"), rule_file("Delta", "Body.")),
(("replace-rule", "alpha", "-"), rule_file("Alpha, mine", "Mine.")),
@@ -237,14 +240,14 @@ class OverlayTests(PersonalCase):
self.ok("overlay", "revert", pdata.git("rev-parse", "--short", "HEAD").stdout.strip())
self.assertEqual(open(paths.generated(), "rb").read(), before)
def test_canon_cost_and_status(self):
self.ok("build-canon")
out = self.ok("canon", "cost").stdout
def test_doctor_shows_always_loaded_size(self):
self.build_canon()
out = self.ok("doctor").stdout
lines = len(self.generated().splitlines())
self.assertIn("rulebook %d lines" % lines, out)
self.assertIn("%d characters" % len(self.generated()), out)
self.assertIn("lessons block at most %d characters" % retro.LIMIT, out)
self.assertIn(out.strip(), self.ok("status").stdout)
self.assertIn("rulebook %d lines" % lines, self.ok("status").stdout)
def test_core_md_rules_have_unique_ids_and_the_budget_holds(self):
text = open(os.path.join(REPO, "canon", "core.md")).read()
@@ -406,7 +409,7 @@ class MigrationTests(PersonalCase):
self.legacy_state()
before = self.lessons_of(os.path.join(self.state, "retro.db"))
self.assertEqual(len(before[0]), 2)
out = self.ok("migrate").stdout
out = self.ok("update", "--post").stdout
self.assertIn("backed up", out)
for n in ("retro.db", "trusted.json", "config.json", "learn-quarantine.jsonl", "notes.jsonl", "proposals.jsonl", "manifest.json", "backups"):
self.assertFalse(os.path.exists(os.path.join(self.state, n)), n + " should have moved")
@@ -425,10 +428,11 @@ class MigrationTests(PersonalCase):
self.assertIn(f, files)
self.assertNotIn("retro.db", files)
self.assertEqual(len(open(os.path.join(self.data, "lessons.jsonl")).read().splitlines()), 2 + len(before[1]))
self.assertTrue(self.git_log()[0].startswith("migrate:"))
self.assertTrue(any(l.startswith("migrate:") for l in self.git_log()))
# the backup has what moved, before it moved
bk = os.path.join(self.data, "backups")
b = os.path.join(bk, os.listdir(bk)[0])
b = next(os.path.join(bk, d) for d in sorted(os.listdir(bk))
if os.path.exists(os.path.join(bk, d, "state", "retro.db")))
self.assertEqual(self.lessons_of(os.path.join(b, "state", "retro.db")), before)
self.assertTrue(os.path.exists(os.path.join(b, "state", "trusted.json")))
self.assertTrue(os.path.exists(os.path.join(b, "product", "canon", "oracle.md")))
@@ -436,7 +440,7 @@ class MigrationTests(PersonalCase):
self.assertTrue(os.path.exists(os.path.join(self.p1, "canon", "oracle.md")))
# a second run does nothing
n = len(self.git_log())
self.assertIn("nothing to migrate", self.ok("migrate").stdout)
self.ok("update", "--post")
self.assertEqual(len(self.git_log()), n)
self.assertEqual(self.lessons_of(os.path.join(self.data, "retro.db")), before)
self.assertEqual(self.ok("lessons", "--json").stdout.count('"change_kind"'), 2)
@@ -461,7 +465,7 @@ class MigrationTests(PersonalCase):
change_kind="rule", change="Run sisi oracle before asking anything", target=None), self.proj, None)
con.commit()
con.close()
self.ok("migrate")
self.ok("update", "--post")
rows, _ = self.lessons_of(os.path.join(self.data, "retro.db"))
changes = sorted(r["change"] for r in rows)
self.assertEqual(len(changes), len(set(changes)), "a lesson was duplicated")
@@ -472,7 +476,7 @@ class MigrationTests(PersonalCase):
self.legacy_state()
os.makedirs(os.path.join(self.data, "notes"))
open(os.path.join(self.data, "notes", "fuzz.md"), "w").write("# Field notes for fuzz\n\n- newer note\n")
self.ok("migrate")
self.ok("update", "--post")
t = open(os.path.join(self.data, "notes", "fuzz.md")).read()
self.assertIn("newer note", t)
self.assertIn("a field note", t)
@@ -736,10 +740,10 @@ class ProductIsReadOnlyTests(PersonalCase):
out.seek(0), err.seek(0)
return subprocess.CompletedProcess(a, p.returncode, out.read(), err.read())
gate_in = json.dumps({"session_id": "s1", "cwd": self.proj, "stop_hook_active": False})
cmds = [("install",), ("doctor",), ("tick", "--tool", "t"), ("build-canon",), ("status",),
cmds = [("install",), ("doctor",), ("tick", "--tool", "t"), ("status",),
("overlay", "add-rule", "--id", "z", "-"), ("overlay", "diff"), ("overlay", "disable-rule", "z"),
("learn", "--scope", "everywhere", "x"), ("lessons", "export"), ("verifiers", "show", "shellcheck"),
("contract", "init", "--goal", "g"), ("verify",), ("migrate",), ("update",),
("contract", "init", "--goal", "g"), ("verify",), ("update", "--post"),
("export", os.path.join(self.tmp, "e.tar.gz")), ("gate",), ("uninstall",)]
for c in cmds:
r = run(*c, stdin=rule_file("Z", "Zed.") if c[:2] == ("overlay", "add-rule") else (gate_in if c == ("gate",) else None))