Item 8: import warning, bounded update backups, migrated open lessons keep a cycle due. done / next: repeat runs and outputs

This commit is contained in:
swaits committed 2026-11-23 12:30:12 -07:00
1 parent 9632c6addb
commit 7d7f10428a
4 files changed
+83 -2

No files matched your search

+30
View File
@@ -386,6 +386,24 @@ class UpdateTests(PersonalCase):
self.assertIn("backup:", r.stdout)
self.assertIn("rulebook rebuilt", r.stdout)
def test_update_keeps_a_bounded_number_of_its_own_backups(self):
"""R-3.2-4: the update step keeps at most N of its own snapshots, never one it did not
make, and never the newest."""
pdata.ensure()
json.dump({"backups": {"keep_update": 2}}, open(os.path.join(self.data, "config.json"), "w"))
foreign = os.path.join(self.data, "backups", "20200101T000000-update") # someone else's, same look
os.makedirs(foreign)
for _ in range(4):
self.ok("update")
bk = os.path.join(self.data, "backups")
mine = sorted(d for d in os.listdir(bk) if os.path.exists(os.path.join(bk, d, ".made-by-sisi-update")))
self.assertEqual(len(mine), 2, os.listdir(bk))
self.assertTrue(os.path.isdir(foreign))
json.dump({"backups": {"keep_update": 0}}, open(os.path.join(self.data, "config.json"), "w"))
self.ok("update")
mine = [d for d in os.listdir(bk) if os.path.exists(os.path.join(bk, d, ".made-by-sisi-update"))]
self.assertEqual(len(mine), 1) # never fewer than the newest one
def _seed_legacy_db(path, lessons, proj):
"""A pre-rebuild retro.db: the sqlite lesson store the migration reads."""
@@ -477,6 +495,18 @@ class MigrationTests(PersonalCase):
self.assertEqual(self.lessons_of(os.path.join(self.data, "retro.db")), before)
self.assertEqual(self.ok("lessons", "--json").stdout.count('"id": "L-'), 2)
def test_a_due_cycle_stays_due_after_migration(self):
"""R-3.1-2: five open lessons made a cycle due in the old store; migrated, they still do."""
os.makedirs(os.path.join(self.state, "backups"))
_seed_legacy_db(os.path.join(self.state, "retro.db"),
[dict(aim="speed", moment="moment %d" % i, cause="cause %d" % i, change_kind="rule",
change="Change number %d to the way of working" % i, target=None) for i in range(5)],
self.proj)
self.ok("update", "--post")
out = self.ok("cycle", "due").stdout
self.assertIn("a learning cycle is due", out)
self.assertIn("5 proposed", out)
def test_old_layout_keeps_working_before_migration(self):
self.legacy_state()
self.ok("update", "--post") # lessons now live in learnings.jsonl; migration is the one path in
+14
View File
@@ -177,6 +177,20 @@ class StoreHistoryTests(RouteCase):
self.assertNotIn("oracle.md", shown)
class ImportWarningTests(RouteCase):
def test_import_of_a_file_without_ledger_rows_warns(self):
"""R-7.2-3: importing the wrong file is said out loud, not reported as a quiet success."""
src = os.path.join(self.tmp, "not-a-ledger.jsonl")
open(src, "w").write('{"hello": "world"}\nnot json\n')
r = self.sisi("workers", "import", src, env=self.env())
self.assertIn("contains no ledger rows", r.stderr)
good = os.path.join(self.tmp, "ledger.jsonl")
open(good, "w").write(json.dumps({"kind": "attempt", "id": "a1", "ts": 1760000000, "worker": "wk-x",
"type": "read", "difficulty": 1, "outcome": "accepted"}) + "\n")
ok = self.sisi("workers", "import", good, env=self.env())
self.assertNotIn("no ledger rows", ok.stderr)
class SessionStartTests(RouteCase):
def tick(self, sid, model="mystery-9", source="startup"):
return self.sisi("tick", stdin=json.dumps({"session_id": sid, "cwd": self.proj, "source": source,