Answer stability round 1: 0 🔴, 6 🟡 (0 misread); slim chunk_figures, type a call's kind, keep the state through replace_json, add the missing state and raise tests

This commit is contained in:
2026-11-08 20:02:58 +01:00
parent 0c93614f4a
commit f0ff379251
9 changed files with 73 additions and 33 deletions
+21 -7
View File
@@ -420,13 +420,27 @@ class Archive(unittest.TestCase):
a, b, c = Call("reports", ("Explore",)), Call("rounds", ("x", "y")), Call("unfinished", ("x", "y"))
self.assertEqual(state.raised(self.root), state.Raised("", frozenset()))
self.assertIsNone(state.mark_raised(self.root, [a], "2026-10-15T00:00:00Z"))
self.assertIsNone(state.mark_raised(self.root, [b], "2026-10-15T01:00:00Z"))
self.assertEqual((self.root / state.RAISED).read_text(), f"# Routing calls raised\n\n- 2026-10-15T00:00:00Z {a.sentence()}\n- 2026-10-15T01:00:00Z {b.sentence()}\n")
self.assertEqual(state.raised(self.root), state.Raised("", frozenset({a, b})))
self.assertIsNone(state.mark_raised(self.root, [b, c], "2026-10-15T01:00:00Z"))
self.assertEqual((self.root / state.RAISED).read_text(), f"# Routing calls raised\n\n- 2026-10-15T00:00:00Z {a.sentence()}\n- 2026-10-15T01:00:00Z {b.sentence()}\n- 2026-10-15T01:00:00Z {c.sentence()}\n")
self.assertEqual(state.raised(self.root), state.Raised("", frozenset({a, b, c})))
with open(self.root / state.RAISED, "a") as handle:
handle.write("- 2026-10-15T00:30:00Z Reset\n")
self.assertIsNone(state.mark_raised(self.root, [c], "2026-10-15T00:20:00Z"))
self.assertEqual(state.raised(self.root), state.Raised("2026-10-15T00:30:00Z", frozenset({b})))
handle.write("- 2026-10-15T01:00:00Z Reset\n")
self.assertEqual(state.raised(self.root), state.Raised("2026-10-15T01:00:00Z", frozenset()), "a call stamped at the reset's second was raised before it")
self.assertIsNone(state.mark_raised(self.root, [a], "2026-10-15T02:00:00Z"))
self.assertEqual(state.raised(self.root), state.Raised("2026-10-15T01:00:00Z", frozenset({a})))
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
def test_fails_when_it_cannot_keep_the_state(self):
self.root.chmod(0o555)
self.addCleanup(self.root.chmod, 0o755)
self.assertIsInstance(state.mark_measured(self.root, 40), Failure)
self.assertIsInstance(state.mark_raised(self.root, [Call("reports", ("Explore",))], "2026-10-15T00:00:00Z"), Failure)
def test_fails_when_it_cannot_list_a_raised_call_for_the_human(self):
self.assertIsNone(state.mark_measured(self.root, 40))
written = state.replace_file
with unittest.mock.patch.object(state, "replace_file", lambda path, data: Failure("full") if path.name == state.RAISED else written(path, data)):
self.assertEqual(state.mark_raised(self.root, [Call("reports", ("Explore",))], "2026-10-15T00:00:00Z"), Failure(f"could not write {self.root / state.RAISED}: full"))
def test_knows_a_raised_call_by_its_fields_whatever_its_line_reads(self):
call = Call("reports", ("Explore",))
@@ -435,7 +449,7 @@ class Archive(unittest.TestCase):
self.assertEqual(state.raised(self.root).calls, frozenset({call}))
def test_fails_on_a_state_it_cannot_read(self):
for text in ("not json", "[]", '{"measured_at": "40", "raised": []}', '{"measured_at": 40, "raised": [{"at": "x", "kind": "nope", "subjects": []}]}', '{"measured_at": 40, "raised": [{"at": "x", "kind": "reports", "subjects": ["a", "b"]}]}', '{"measured_at": true, "raised": []}'):
for text in ("not json", "[]", '{"measured_at": "40", "raised": []}', '{"measured_at": 40, "raised": [{"at": "x", "kind": "nope", "subjects": []}]}', '{"measured_at": 40, "raised": [{"at": "x", "kind": "reports", "subjects": ["a", "b"]}]}', '{"measured_at": true, "raised": []}', '{"measured_at": 40, "raised": [{"at": "x", "kind": "reports", "subjects": "a"}]}'):
with self.subTest(text):
(self.root / state.STATE).write_text(text)
self.assertIsInstance(state.read_state(self.root), Failure)