From a5bf22b9eefa32322b2587ac930e5680d97500be Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 10 Sep 2026 11:02:46 +0200 Subject: fix: restore the footer guard, with the sequence that needs it The previous commit removed this guard after a mutation check said it was redundant. The check was wrong: it only exercised runs that skipped the identity from the start, where [reporter] is never written and the footer always trails a rendered table. The sequence that breaks is answering the identity and then re-running and skipping it. [reporter] is then PRESERVED rather than rendered, so the footer that trailed it in the old file rides across while this run emits its own, and the file grows a second copy per run. Covered by a test naming that sequence, and both guards now fail when removed. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LByBnw83xr9YP85nskzkyE --- tests/test_init.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/test_init.py b/tests/test_init.py index 4f2042c..55153f4 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -348,3 +348,24 @@ class TestRepeatedInit(unittest.TestCase): self.assertEqual(text.count("# Later parts of abusectl"), 1) # The unknown section still rides across untouched. self.assertEqual(tomllib.loads(text)["misp"]["api_key"], "SECRET") + + def test_the_footer_survives_an_identity_answered_then_skipped(self): + # The sequence a hand test actually hit, and the one the first fix + # missed: answering the identity, then re-running and skipping it, + # leaves [reporter] PRESERVED rather than rendered, so the footer + # trailing it rides across while this run emits its own. + relays = {"trusted_relays": ["192.0.2.0/24"], "cases": ""} + answered = dict(relays, reporter_name="A Reporter", + reporter_org="example.org", + reporter_email="r@example.org") + with tempfile.TemporaryDirectory() as tmp: + path = pathlib.Path(tmp) / "config.toml" + init.write(path, answered) + init.write(path, relays, force=True) + + text = path.read_text() + self.assertEqual(text.count("# Later parts of abusectl"), 1) + self.assertEqual(text.count("# abusectl configuration."), 1) + self.assertEqual( + tomllib.loads(text)["reporter"]["name"], "A Reporter" + ) -- cgit v1.2.3