test(deploy): cover validation boundary and failed image cleanup

This commit is contained in:
Pavlo Ratushnyi
2026-10-04 20:59:17 +02:00
parent 7a77ac1176
commit 770fdb2505
2 changed files with 23 additions and 1 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ def freeze(package, stage, receipt_sha, cpu_fixture):
raise ValueError('package file checksum mismatch')
p = json.loads((stage / 'PROVENANCE.json').read_text())
kind = 'cpu-fixture' if cpu_fixture else 'static-cuda-preview'
if (p.get('schema_version') != 1 or p.get('kind') != kind or
if (not isinstance(p, dict) or type(p.get('schema_version')) is not int or p['schema_version'] != 1 or p.get('kind') != kind or
p.get('target') != 'x86_64-unknown-linux-musl' or
not re.fullmatch(r'[0-9a-f]{40}', p.get('source_revision', ''))):
raise ValueError('unsupported package provenance or explicit fixture mode mismatch')
+22
View File
@@ -5,6 +5,8 @@ import json
from pathlib import Path
import tempfile
import unittest
from types import SimpleNamespace
from unittest.mock import patch
spec = importlib.util.spec_from_file_location('builder', Path(__file__).with_name('build-runtime-image.py'))
b = importlib.util.module_from_spec(spec)
@@ -77,6 +79,26 @@ class PackageTests(unittest.TestCase):
with tempfile.TemporaryDirectory() as stage:
with self.assertRaisesRegex(ValueError, 'identity'): b.freeze(self.pkg, Path(stage), self.sha, True)
def test_bad_package_never_reaches_docker(self):
args = SimpleNamespace(base=b.BASE, package=self.pkg, receipt_sha256='0'*64, cpu_fixture=False)
with patch.object(b, 'docker') as docker:
with self.assertRaisesRegex(ValueError, 'pinned receipt'): b.assemble(args)
docker.assert_not_called()
def test_failed_image_identity_removes_only_created_image(self):
args = SimpleNamespace(base=b.BASE, package=self.pkg, receipt_sha256=self.sha, cpu_fixture=False)
image = 'sha256:' + 'c'*64
calls = []
def docker(*argv, **kwargs):
calls.append(argv)
if argv[0] == 'build':
Path(argv[argv.index('--iidfile')+1]).write_text(image)
return SimpleNamespace(stdout='')
with patch.object(b, 'docker', side_effect=docker), patch.object(b, 'isolated_run', side_effect=['glibc 2.43', '{}']):
with self.assertRaisesRegex(ValueError, 'metadata differs'): b.assemble(args)
self.assertEqual(calls[-1], ('image','rm',image))
self.assertFalse(any('--gpus' in call for call in calls))
def test_missing_elf_audit_and_size_bound(self):
self.provenance['engine_elf_audit'] = {}; self.write()
with self.assertRaisesRegex(ValueError, 'ELF audit'): self.freeze()