Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 63: [PATCH 63/68] fix(release): restore signed five-platform CI releases

ci/test/test_runner_release_notices.py

Before: /dev/null · After: ci/test/test_runner_release_notices.py

File metadata
new file mode 100644
index 0000000000000000000000000000000000000000..b4a02a66cfbb0a7fd7e692edec7418177fcd65c7

Download original patch · Release notes

Diff rows 1–184 of 184. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

ci/test/test_runner_release_notices.py ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # Copyright (c) 2026-present The Bitcoin Roots developers
3
+ # Distributed under the MIT software license, see the accompanying
4
+ # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
+
6
+ import importlib.util
7
+ import io
8
+ import json
9
+ import os
10
+ from types import SimpleNamespace
11
+ from pathlib import Path
12
+ import sys
13
+ import tarfile
14
+ import tempfile
15
+ import unittest
16
+ from unittest.mock import patch
17
+
18
+ ROOT = Path(__file__).resolve().parents[2]
19
+ sys.path.insert(0, str(ROOT / 'ci/release'))
20
+ spec = importlib.util.spec_from_file_location('runner', ROOT / 'ci/release/runner-notices.py')
21
+ runner = importlib.util.module_from_spec(spec)
22
+ spec.loader.exec_module(runner)
23
+
24
+
25
+ class RunnerNoticeTest(unittest.TestCase):
26
+ def setUp(self):
27
+ temporary = tempfile.TemporaryDirectory()
28
+ self.addCleanup(temporary.cleanup)
29
+ self.work = Path(temporary.name)
30
+
31
+ def archive(self, name='source/LICENSE'):
32
+ archive = self.work / 'source.tar.gz'
33
+ with tarfile.open(archive, 'w:gz') as out:
34
+ entry = tarfile.TarInfo(name)
35
+ data = b'Exact upstream copyright and license\n'
36
+ entry.size = len(data)
37
+ out.addfile(entry, io.BytesIO(data))
38
+ return archive, runner.sha256(archive)
39
+
40
+ def test_pinned_depends_receipt_uses_real_archive_and_host_selection(self):
41
+ source, checksum = self.archive()
42
+ depends = self.work / 'depends'
43
+ (depends / 'packages').mkdir(parents=True)
44
+ (depends / 'packages/boost.mk').write_text('pinned recipe\n')
45
+ installed = self.work / 'installed'
46
+ installed.mkdir()
47
+ (installed / 'toolchain.cmake').write_text('installed toolchain\n')
48
+ values = {'packages': 'boost', 'host_prefix': str(installed), 'SOURCES_PATH': str(self.work),
49
+ 'boost_version': '1.88.0', 'boost_source': str(source), 'boost_sha256_hash': checksum,
50
+ 'boost_download_path': 'https://example.invalid', 'boost_download_file': 'source.tar.gz',
51
+ 'boost_extra_sources': ''}
52
+ def execute(*args):
53
+ if args[0] == 'git':
54
+ return 'a' * 40
55
+ return '\n'.join(x.removeprefix('print-') + '=' + values[x.removeprefix('print-')]
56
+ for x in args if x.startswith('print-'))
57
+ with patch.object(runner, 'run', side_effect=execute):
58
+ result = runner.depends_notices(depends, 'aarch64-linux-gnu', self.work / 'notices')
59
+ self.assertEqual(result['boost']['source_sha256'], checksum)
60
+ receipt = json.loads(Path(result['boost']['evidence']).read_text())
61
+ self.assertEqual(receipt['host'], 'aarch64-linux-gnu')
62
+ self.assertEqual(receipt['source_commit'], 'a' * 40)
63
+ source.unlink()
64
+ with self.assertRaises(FileNotFoundError):
65
+ runner.depends_notices(depends, 'aarch64-linux-gnu', self.work / 'missing')
66
+
67
+ def test_source_hash_and_unsafe_member_fail_closed(self):
68
+ source, checksum = self.archive()
69
+ with self.assertRaisesRegex(ValueError, 'hash mismatch'):
70
+ runner.source_notices(source, '0' * 64, self.work / 'bad')
71
+ source, checksum = self.archive('../LICENSE')
72
+ with self.assertRaisesRegex(ValueError, 'Unsafe'):
73
+ runner.source_notices(source, checksum, self.work / 'bad')
74
+
75
+ def test_brew_retains_actual_receipt_matching_version_and_source(self):
76
+ source, checksum = self.archive()
77
+ prefix = self.work / 'installed'
78
+ prefix.mkdir()
79
+ (prefix / 'INSTALL_RECEIPT.json').write_text('{"built_as_bottle":true}')
80
+ formula = {'name': 'boost', 'installed': [{'version': '1.88.0'}],
81
+ 'versions': {'stable': '1.88.0'}, 'urls': {'stable': {'url': 'https://example.invalid/source', 'checksum': checksum}}}
82
+ def execute(*args):
83
+ if args[:2] == ('brew', 'deps'):
84
+ return 'boost\nca-certificates\nqt\nqtbase\nqtwebengine'
85
+ if args[:2] == ('brew', 'info'):
86
+ if args[-1] == 'boost':
87
+ return json.dumps({'formulae': [formula]})
88
+ if args[-1] not in {'ca-certificates', 'qt', 'qt@6', 'qtwebengine'}:
89
+ return json.dumps({'formulae': [{**formula, 'name': args[-1]}]})
90
+ return json.dumps({'formulae': [{'name': args[-1], 'urls': {'stable': {'url': 'not-an-archive'}}}]})
91
+ if args[:2] == ('brew', '--prefix'):
92
+ return str(prefix)
93
+ return 'fixture system identity'
94
+ with patch.object(runner, 'run', side_effect=execute), patch.object(runner, 'acquire', return_value=source):
95
+ result = runner.brew_notices(self.work / 'brew')
96
+ receipt = json.loads(Path(result['boost']['evidence']).read_text())
97
+ self.assertTrue(receipt['installed_receipt']['built_as_bottle'])
98
+ self.assertEqual(result['sqlite']['role'], 'system-library')
99
+ self.assertIn('qt', result)
100
+ self.assertNotIn('ca-certificates', result)
101
+ self.assertNotIn('qtwebengine', result)
102
+ formula['installed'][0]['version'] = '1.87.0'
103
+ with self.assertRaisesRegex(ValueError, 'version mismatch'):
104
+ runner.brew_notices(self.work / 'wrong-version')
105
+ formula['installed'][0]['version'] = '1.88.0'
106
+ (prefix / 'INSTALL_RECEIPT.json').unlink()
107
+ with self.assertRaises(FileNotFoundError):
108
+ runner.brew_notices(self.work / 'missing-receipt')
109
+
110
+ def test_vcpkg_uses_installed_static_port_version_and_copyright(self):
111
+ installed = self.work / 'vcpkg-installed'
112
+ (installed / 'vcpkg').mkdir(parents=True)
113
+ status = 'Package: qtbase\nVersion: 6.8.2\nArchitecture: x64-windows-static\nStatus: install ok installed\n'
114
+ (installed / 'vcpkg/status').write_text(status)
115
+ copyright = installed / 'x64-windows-static/share/qtbase/copyright'
116
+ copyright.parent.mkdir(parents=True)
117
+ copyright.write_text('Exact installed Qt copyright\n')
118
+ with patch.object(runner, 'run', return_value='a' * 40):
119
+ result = runner.vcpkg_notices(installed, self.work / 'output')
120
+ self.assertEqual(result['qt']['version'], '6.8.2')
121
+ self.assertEqual(Path(result['qt']['files'][0]).read_bytes(), copyright.read_bytes())
122
+ (installed / 'vcpkg/status').write_text(status + '\n' + status)
123
+ with self.assertRaisesRegex(ValueError, 'Duplicate'):
124
+ runner.vcpkg_notices(installed, self.work / 'duplicate')
125
+ (installed / 'vcpkg/status').write_text(status.replace('x64-windows-static', 'x64-windows'))
126
+ self.assertEqual(runner.vcpkg_notices(installed, self.work / 'wrong-triplet'), {})
127
+ (installed / 'vcpkg/status').write_text(status)
128
+ copyright.unlink()
129
+ with self.assertRaisesRegex(ValueError, 'copyright missing'):
130
+ runner.vcpkg_notices(installed, self.work / 'missing')
131
+
132
+ def test_vcpkg_aggregates_real_boost_ports_and_required_components(self):
133
+ installed = self.work / 'vcpkg'
134
+ (installed / 'vcpkg').mkdir(parents=True)
135
+ ports = sorted(runner.notices.required_components('windows-x86_64') - {'boost', 'qt', 'sqlite', 'qrencode'})
136
+ ports += ['boost-multi-index', 'boost-signals2', 'qtbase', 'sqlite3', 'libqrencode']
137
+ paragraphs = []
138
+ for name in ports:
139
+ version = '1.87.0' if name.startswith('boost-') else '1.0'
140
+ paragraphs.append(f'Package: {name}\nVersion: {version}\nArchitecture: x64-windows-static\nStatus: install ok installed\n')
141
+ notice = installed / 'x64-windows-static/share' / name / 'copyright'
142
+ notice.parent.mkdir(parents=True)
143
+ notice.write_text(f'Actual installed {name} copyright\n')
144
+ (installed / 'vcpkg/status').write_text('\n'.join(paragraphs))
145
+ with patch.object(runner, 'run', return_value='a' * 40):
146
+ result = runner.vcpkg_notices(installed, self.work / 'receipts')
147
+ self.assertTrue(runner.notices.required_components('windows-x86_64') <= result.keys())
148
+ self.assertEqual(len(result['boost']['files']), 2)
149
+ descriptor = self.work / 'descriptor.json'
150
+ descriptor.write_text(json.dumps(result))
151
+ runner.notices.collect('windows-x86_64', descriptor, self.work / 'collected')
152
+
153
+ def test_release_notice_platform_passes_container_allowlist_without_signing_secret(self):
154
+ spec = importlib.util.spec_from_file_location('container', ROOT / 'ci/test/02_run_container.py')
155
+ container = importlib.util.module_from_spec(spec)
156
+ spec.loader.exec_module(container)
157
+ env = {'USER': self.work.name, 'CONTAINER_NAME': 'notice-fixture',
158
+ 'RELEASE_NOTICE_PLATFORM': 'linux-aarch64', 'BITCOIN_ROOTS_GPG_SK': 'fixture-never-export'}
159
+ path = Path(f"/tmp/env-{env['USER']}-{env['CONTAINER_NAME']}")
160
+ self.addCleanup(path.unlink, missing_ok=True)
161
+ with patch.dict(os.environ, env, clear=True), patch.object(container, 'run', return_value=SimpleNamespace(stdout='export CONTAINER_NAME=fixture')):
162
+ container.main()
163
+ text = path.read_text()
164
+ self.assertIn('RELEASE_NOTICE_PLATFORM=linux-aarch64', text)
165
+ self.assertNotIn('BITCOIN_ROOTS_GPG_SK', text)
166
+ self.assertNotIn('fixture-never-export', text)
167
+
168
+ def test_all_runner_workflow_blocks_stage_and_validate_before_upload(self):
169
+ workflow = (ROOT / '.github/workflows/release.yml').read_text()
170
+ for job, following in [('linux-release', 'windows-release'), ('windows-release', 'macos-release'), ('macos-release', 'publish-release')]:
171
+ block = workflow.split(f' {job}:', 1)[1].split(f' {following}:', 1)[0]
172
+ if job == 'linux-release':
173
+ self.assertIn('export RELEASE_NOTICE_PLATFORM=', block)
174
+ hook = (ROOT / 'ci/test/03_test_script.sh').read_text()
175
+ self.assertIn('if [[ -n "${RELEASE_NOTICE_PLATFORM:-}" ]]', hook)
176
+ self.assertIn('--depends "$DEPENDS_DIR" --host "$HOST"', hook)
177
+ else:
178
+ self.assertLess(block.index('ci/release/runner-notices.py'), block.index('ci/release/notices.py stage'))
179
+ self.assertLess(block.index('ci/release/notices.py stage'), block.index('ci/release/notices.py validate'))
180
+ self.assertLess(block.index('ci/release/notices.py validate'), block.index('uses: actions/upload-artifact'))
181
+
182
+
183
+ if __name__ == '__main__':
184
+ unittest.main()