Initial ABSDEV deployment framework development preview
ABSDEV Framework CI / framework-validation (push) Canceled after 0s

This commit is contained in:
2026-11-26 11:35:28 +00:00
commit d6e2317016
76 changed files with 20260 additions and 0 deletions
+313
View File
@@ -0,0 +1,313 @@
import json
import stat
import unittest
from unittest.mock import Mock, patch
import test_deployment
from core.archive import TransactionArchive, ArchiveError
from core.deployment import DeploymentError
from core.locking import DeploymentLock, LockError
class ArchiveTests(unittest.TestCase):
def setUp(self):
self.fixture = test_deployment.DeploymentTests()
self.addCleanup(self.fixture.doCleanups)
self.fixture.setUp()
self.root = self.fixture.root
self.journal = self.fixture.journal
self.transaction = self.fixture.deploy()
self.directory = self.root / "archives"
self.directory.mkdir(mode=0o700)
self.backup_verify = Mock(
return_value=dict(self.fixture.manifest)
)
self.health = Mock(
return_value={
"healthy": True,
"release": "2",
}
)
self.archive = TransactionArchive(
site="example-absdev-net",
directory=self.directory,
lock_path=self.root / ".deployment.lock",
journal=self.journal,
releases=self.fixture.releases,
provenance=self.fixture.provenance,
backup_evidence=self.fixture.evidence,
backup_verify=self.backup_verify,
health_probe=self.health,
)
def execute(self):
plan = self.archive.plan()
return self.archive.execute(
confirmation=plan["confirmation"],
fingerprint=plan["fingerprint"],
)
def test_valid_archive_plan(self):
self.assertEqual(
self.archive.plan()["status"],
"ARCHIVE_READY",
)
def test_plan_is_read_only(self):
before = self.journal.load()
self.archive.plan()
self.assertEqual(self.journal.load(), before)
self.assertEqual(list(self.directory.iterdir()), [])
def test_successful_archive(self):
result = self.execute()
self.assertEqual(result["status"], "ARCHIVED")
self.assertIsNone(self.journal.load())
def test_original_transaction_preserved(self):
result = self.execute()
self.assertEqual(
result["transaction"],
self.transaction,
)
def test_backup_evidence_preserved(self):
result = self.execute()
self.assertEqual(
result["backup_evidence"]["backup"],
self.fixture.manifest,
)
self.assertTrue(
self.fixture.evidence.path(
self.transaction["transaction_id"]
).exists()
)
def test_archive_persisted(self):
result = self.execute()
self.assertEqual(
self.archive.load(
self.transaction["transaction_id"]
),
result,
)
def test_archive_permissions(self):
self.execute()
path = self.archive.path(
self.transaction["transaction_id"]
)
self.assertEqual(
stat.S_IMODE(path.stat().st_mode),
0o600,
)
def test_wrong_confirmation_rejected(self):
plan = self.archive.plan()
with self.assertRaises(ArchiveError):
self.archive.execute(
confirmation="INVALID",
fingerprint=plan["fingerprint"],
)
self.assertIsNotNone(self.journal.load())
def test_wrong_fingerprint_rejected(self):
plan = self.archive.plan()
with self.assertRaises(ArchiveError):
self.archive.execute(
confirmation=plan["confirmation"],
fingerprint="0" * 64,
)
def test_wrong_active_release_rejected(self):
self.fixture.releases.activate("1")
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_unhealthy_application_rejected(self):
self.health.return_value["healthy"] = False
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_wrong_health_release_rejected(self):
self.health.return_value["release"] = "1"
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_missing_backup_evidence_rejected(self):
self.fixture.evidence.path(
self.transaction["transaction_id"]
).unlink()
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_changed_backup_rejected(self):
self.backup_verify.return_value["sha256"] = "0" * 64
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_changed_release_provenance_rejected(self):
self.fixture.new["fingerprint"] = "0" * 64
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_concurrent_operation_rejected(self):
with DeploymentLock(
self.root / ".deployment.lock"
):
with self.assertRaises(LockError):
self.archive.plan()
def test_publication_failure_preserves_journal(self):
plan = self.archive.plan()
with patch(
"core.archive.os.link",
side_effect=OSError("publication failed"),
):
with self.assertRaises(ArchiveError):
self.archive.execute(
confirmation=plan["confirmation"],
fingerprint=plan["fingerprint"],
)
self.assertEqual(
self.journal.load(),
self.transaction,
)
def test_existing_archive_rejected(self):
self.archive.path(
self.transaction["transaction_id"]
).touch(mode=0o600)
with self.assertRaises(ArchiveError):
self.execute()
self.assertIsNotNone(self.journal.load())
def test_corrupted_archive_rejected(self):
self.execute()
self.archive.path(
self.transaction["transaction_id"]
).write_text("{invalid")
with self.assertRaises(ArchiveError):
self.archive.load(
self.transaction["transaction_id"]
)
def test_modified_archive_rejected(self):
self.execute()
path = self.archive.path(
self.transaction["transaction_id"]
)
data = json.loads(path.read_text())
data["transaction"]["candidate"] = "99"
path.write_text(json.dumps(data))
with self.assertRaises(ArchiveError):
self.archive.load(
self.transaction["transaction_id"]
)
def test_invalid_archive_identifier_rejected(self):
with self.assertRaises(ArchiveError):
self.archive.load("../outside")
def test_insecure_directory_rejected(self):
self.directory.chmod(0o777)
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_missing_transaction_rejected(self):
self.execute()
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_wrong_site_rejected(self):
self.archive.site = "different-site"
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_no_database_restoration(self):
result = self.execute()
self.assertFalse(result["database_restored"])
def test_all_release_directories_preserved(self):
self.execute()
self.assertEqual(
self.fixture.releases.inventory(),
["1", "2"],
)
def test_failed_transaction_not_archived(self):
self.journal.path.unlink()
tx = self.journal.create(
"example-absdev-net",
"1",
"2",
"b" * 40,
self.fixture.new["fingerprint"],
)
self.journal.transition(
tx["transaction_id"],
"PREPARED",
"FAILED",
)
with self.assertRaises(ArchiveError):
self.archive.plan()
def test_new_deployment_no_longer_blocked_by_journal(self):
self.execute()
self.assertIsNone(self.journal.load())
self.fixture.controller.operation_guard.require_clear()
self.assertEqual(
self.fixture.releases.current(),
"2",
)
if __name__ == "__main__":
unittest.main()