Harden release packaging and recoverable installation after review

This commit is contained in:
bholman committed 2026-11-18 16:26:25 -07:00
1 parent cb40fed3b9
commit 8088c1fbf6
14 files changed
+933 -101

No files matched your search

+60 -1
View File
@@ -118,6 +118,13 @@ class PublicSourceReleaseGuards(unittest.TestCase):
'LICENSES/Fixture.txt': b'Fixture license text.\n',
'rtl/ssc/LICENSE': b'Fixture SSC notice only; no ROM contents.\n',
'rtl/example.sv': b'module example; endmodule\n',
'tools/project_inputs.json': json.dumps({'files': [
'.gitignore', 'README.md', 'changes.txt', 'rtl/example.sv'
]}).encode(),
'releases/old.rbf': b'Historic binary fixture; not source payload',
'docs/old.pdf': b'Historic PDF fixture; not source payload',
'docs/old.docx': b'Historic Office fixture; not source payload',
'unused.bin': b'Historic binary fixture; not source payload',
}
for name, data in files.items():
path = self.root / name
@@ -140,6 +147,7 @@ class PublicSourceReleaseGuards(unittest.TestCase):
'passed': True,
'rbf_bytes': rbf.stat().st_size,
'rbf_sha256': digest(rbf),
'project_inventory_sha256': digest(self.root / 'tools/project_inputs.json'),
'inputs': {'rtl/example.sv': digest(self.root / 'rtl/example.sv')},
}
(self.build / 'build.json').write_text(json.dumps(record))
@@ -163,6 +171,7 @@ class PublicSourceReleaseGuards(unittest.TestCase):
def test_untracked_private_files_do_not_enter_public_release(self):
(self.root / '.env').write_text('fixture-private-value=not-for-export\n')
(self.root / 'private-notes.txt').write_text('private fixture notes\n')
(self.root / 'LICENSES/private-notice.txt').write_text('PRIVATE NOTICE FIXTURE MUST NOT LEAK\n')
untracked = self.git('ls-files', '--others', '--exclude-standard').decode()
self.assertIn('.env', untracked)
self.assertIn('private-notes.txt', untracked)
@@ -183,12 +192,62 @@ class PublicSourceReleaseGuards(unittest.TestCase):
with zipfile.ZipFile(self.output / 'corresponding-source.zip') as archive:
source_files = {n for n in archive.namelist() if not n.endswith('/')}
self.assertEqual(source_files,
{'coco3plus/' + n for n in self.tracked})
{'coco3plus/' + n for n in self.tracked
if release.source_member(n)})
self.assertFalse(any('.env' in n or 'private-notes' in n
for n in source_files))
self.assertNotIn('coco3plus/LICENSES/private-notice.txt', source_files)
self.assertFalse(any(n.endswith(('.rbf', '.pdf', '.docx', '.bin'))
for n in source_files))
with zipfile.ZipFile(self.output.with_name('public-release.zip')) as archive:
self.assertNotIn('.env', archive.namelist())
self.assertNotIn('private-notes.txt', archive.namelist())
self.assertNotIn('fat/games/coco3plus/licenses/private-notice.txt',
archive.namelist())
for name in archive.namelist():
self.assertNotIn(b'PRIVATE NOTICE FIXTURE MUST NOT LEAK',
archive.read(name))
checkout = archive.read('SOURCE-CHECKOUT.txt').decode()
self.assertIn('git clone ' + release.SOURCE_REPOSITORY, checkout)
self.assertIn('git checkout --detach ' + self.revision, checkout)
self.assertIn('ZIP alone is not a standalone build checkout', checkout)
self.assertEqual(record['project_inventory_sha256'],
digest(self.root / 'tools/project_inputs.json'))
self.assertNotIn('games/coco3plus/licenses/private-notice.txt', record['files'])
def rewrite_receipt(self, transform):
receipt = self.build / 'build.json'
record = json.loads(receipt.read_text())
transform(record)
receipt.write_text(json.dumps(record))
def assert_rejected_without_output(self, pattern):
with self.assertRaisesRegex(RuntimeError, pattern):
self.package()
self.assertFalse(self.output.exists())
self.assertFalse(self.output.with_name('public-release.zip').exists())
def test_legacy_receipt_is_rejected_without_backfilling_evidence(self):
self.rewrite_receipt(lambda r: r.pop('project_inventory_sha256'))
original = (self.build / 'build.json').read_bytes()
self.assert_rejected_without_output('Legacy FPGA receipt lacks')
self.assertEqual((self.build / 'build.json').read_bytes(), original)
def test_stale_inventory_identity_is_rejected(self):
self.rewrite_receipt(lambda r: r.update(project_inventory_sha256='0' * 64))
self.assert_rejected_without_output('does not qualify the current')
def test_subset_input_receipt_is_rejected(self):
self.rewrite_receipt(lambda r: r['inputs'].pop('rtl/example.sv'))
self.assert_rejected_without_output('exact current project input set')
def test_extra_input_receipt_is_rejected(self):
self.rewrite_receipt(lambda r: r['inputs'].update({'NOTICE.md': digest(self.root / 'NOTICE.md')}))
self.assert_rejected_without_output('exact current project input set')
def test_matching_set_with_changed_input_bytes_is_rejected(self):
self.rewrite_receipt(lambda r: r['inputs'].update({'rtl/example.sv': '0' * 64}))
self.assert_rejected_without_output('Source differs from built input')
def test_dirty_tracked_source_rejects_before_output_creation(self):
notice = self.root / 'NOTICE.md'