Refuse prune apply when requested image inventories are unavailable
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s

Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a06ecb-456a-71c2-b41e-0755d336e883
This commit is contained in:
codex 2026-09-05 02:00:50 +02:00
parent 0349a08e1b
commit f637989a69
4 changed files with 58 additions and 4 deletions

View file

@ -18,6 +18,36 @@ SPEC.loader.exec_module(prune)
class ForgejoPackagePruneTests(unittest.TestCase):
def test_apply_refuses_any_unavailable_export_before_authentication(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
good = root / "good.txt"
good.write_text("forgejo.coulomb.social/coulomb/app:live\n")
bad = root / "bad.txt"
for content in [None, b"", b"# no inventory\n", b"\xff"]:
with self.subTest(content=content):
if content is not None:
bad.write_bytes(content)
with mock.patch.object(prune, "load_token") as auth, \
mock.patch.object(prune, "build_delete_plans") as plans, \
mock.patch.object(prune, "delete_version") as delete:
result = prune.main([
"--apply", "--live-images-file", str(good),
"--live-images-file", str(bad),
])
self.assertEqual(result, 2)
auth.assert_not_called()
plans.assert_not_called()
delete.assert_not_called()
def test_non_forgejo_image_export_is_not_empty(self):
with tempfile.TemporaryDirectory() as tmp:
export = Path(tmp) / "images.txt"
export.write_text("nginx:stable\n")
protected, notes = prune.collect_live_images_from_files([export])
self.assertEqual(protected, set())
self.assertEqual(notes, [])
def test_collect_protected_versions_from_helm_values(self) -> None:
import tempfile