Files
Athena-Deck/test_legacy_cleanup.py
T

55 lines
2.6 KiB
Python

import unittest
import tempfile
from pathlib import Path
from unittest.mock import patch
from deploy import remove_legacy_router as cleanup
class LegacyCleanupTests(unittest.TestCase):
def test_path_boundary_does_not_include_new_backup_tree(self):
self.assertFalse(cleanup.inside('/data/athena-deck/backups', '/data/models'))
self.assertFalse(cleanup.inside('/opt/mike-ai-new', '/opt/mike-ai'))
self.assertTrue(cleanup.inside('/data/models/legacy/model.gguf', '/data/models'))
def test_rule_must_match_address_and_table(self):
expected = (12010, 'from', '172.30.10.0/24', '51821')
good = dict(priority=12010, src='172.30.10.0/24', table=51821)
self.assertTrue(cleanup.validate_rule(good, expected))
self.assertTrue(cleanup.validate_rule(dict(priority=12010, src='172.30.10.0', srclen=24, table='51821'), expected))
self.assertFalse(cleanup.validate_rule(dict(good, table=51826), expected))
self.assertFalse(cleanup.validate_rule(dict(good, src='192.168.1.212'), expected))
def test_container_absolute_model_link_resolves_to_native_state(self):
with tempfile.TemporaryDirectory() as folder:
state = Path(folder)
(state / 'models').mkdir()
(state / 'runtime').mkdir()
weight = state / 'runtime' / 'weight.bin'
weight.write_bytes(b'weight')
link = state / 'models' / 'weight.bin'
# Resolution is scripted below; no real link into a live-state path
# is necessary to exercise container-to-native path translation.
link.touch()
# Athena is Linux; macOS resolves /var to /private/var instead.
expected = weight.resolve()
with patch.object(cleanup, 'STATE', state), patch.object(
Path, 'resolve', side_effect=[Path('/var/lib/deck/runtime/weight.bin'), expected]
):
self.assertEqual(cleanup.deck_host_path(link), expected)
def test_running_legacy_container_blocks_cleanup(self):
rows = [dict(Name='/mike-ai-router', State=dict(Running=True))]
with self.assertRaisesRegex(RuntimeError, 'unexpectedly running'):
cleanup.preflight(rows)
def test_retained_mount_blocks_cleanup_before_any_command(self):
rows = [dict(Name='/athena-deck-dev', State=dict(Running=True), Mounts=[dict(Source='/data/models/x.gguf')])]
with patch.object(cleanup, 'run') as run:
with self.assertRaisesRegex(RuntimeError, 'Non-target container'):
cleanup.preflight(rows)
run.assert_not_called()
if __name__ == '__main__':
unittest.main()