v31.1-roots.1 · Commit 11: [PATCH 11/17] fix(test): bound policy oracles and retain CI diagnostics
ci/test/test_roots_regressions.py
Before: ci/test/test_roots_regressions.py · After: ci/test/test_roots_regressions.py
File metadata
index 0c65dd7a2a5e2335be1dc1dee906f6ecd548fa19..722a2775c7986aaf2edac7ec2bccf86c1e2b54cc 100644
Download original patch · Release notes
Diff rows 1–100 of 100. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
ci/test/test_roots_regressions.py
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
# Copyright (c) 2026-present The Bitcoin Roots developers
|
|
3
3
|
# Distributed under the MIT software license, see the accompanying file COPYING.
|
|
4
4
|
"""Exercise actual affected selections, execution budgets and failure artifacts."""
|
|
5
|
+
import contextlib
|
|
5
6
|
import importlib.util
|
|
7
|
+
import io
|
|
6
8
|
import json
|
|
9
|
+
import os
|
|
7
10
|
from pathlib import Path
|
|
8
11
|
import sys
|
|
9
12
|
import tempfile
|
|
13
|
+
from types import SimpleNamespace
|
|
10
14
|
import unittest
|
|
15
|
+
from unittest.mock import patch
|
|
11
16
|
|
|
12
17
|
ROOT = Path(__file__).resolve().parents[2]
|
|
13
18
|
SPEC = importlib.util.spec_from_file_location('roots_regressions', ROOT / 'ci/test/roots-regressions.py')
|
|
@@ -60,7 +65,9 @@ class RootsRegressionTest(unittest.TestCase):
|
|
|
60
65
|
for cadence, expected in [('fast', 5), ('nightly', 60)]:
|
|
61
66
|
artifacts = build / cadence
|
|
62
67
|
plan = MODULE.selection(['src/wallet/wallet.cpp'], cadence)
|
|
63
|
-
self.assertEqual(MODULE.execute(plan, 'fuzz', build, artifacts, []), 1)
|
|
68
|
+
summary = io.StringIO()
|
|
69
|
+
with contextlib.redirect_stderr(summary):
|
|
70
|
+
self.assertEqual(MODULE.execute(plan, 'fuzz', build, artifacts, []), 1)
|
|
64
71
|
results = json.loads((artifacts / 'fuzz-results.json').read_text())['results']
|
|
65
72
|
self.assertEqual(len(results), 2)
|
|
66
73
|
for record in results:
|
|
@@ -69,6 +76,8 @@ class RootsRegressionTest(unittest.TestCase):
|
|
|
69
76
|
self.assertIn('-max_total_time=' + str(expected), record['command'])
|
|
70
77
|
self.assertNotIn('-runs=', ' '.join(record['command']))
|
|
71
78
|
self.assertIn(record['target'], (artifacts / (record['target'] + '.log')).read_text())
|
|
79
|
+
self.assertEqual(record['log'], record['target'] + '.log')
|
|
80
|
+
self.assertIn(record['target'] + ' failed (exit 3)', summary.getvalue())
|
|
72
81
|
|
|
73
82
|
def test_real_timeout_is_failure_with_retained_log(self):
|
|
74
83
|
with tempfile.TemporaryDirectory() as directory:
|
|
@@ -79,6 +88,65 @@ class RootsRegressionTest(unittest.TestCase):
|
|
|
79
88
|
self.assertEqual(MODULE.run_bounded([str(Path(directory) / 'absent')], 1, log), 127)
|
|
80
89
|
self.assertTrue(log.stat().st_size)
|
|
81
90
|
|
|
91
|
+
def test_failure_summary_is_bounded_and_full_output_is_retained(self):
|
|
92
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
93
|
+
build = Path(directory)
|
|
94
|
+
runner = build / 'test/functional/test_runner.py'
|
|
95
|
+
runner.parent.mkdir(parents=True)
|
|
96
|
+
runner.write_text('import sys\nprint("x" * 20000, flush=True)\nprint("specific failure", file=sys.stderr)\nsys.exit(4)\n')
|
|
97
|
+
artifacts = build / 'host-artifacts'
|
|
98
|
+
summary = io.StringIO()
|
|
99
|
+
with contextlib.redirect_stderr(summary):
|
|
100
|
+
result = MODULE.execute(MODULE.selection(['src/wallet/spend.cpp'], 'fast'), 'functional', build, artifacts, [])
|
|
101
|
+
self.assertEqual(result, 1)
|
|
102
|
+
record = json.loads((artifacts / 'functional-results.json').read_text())['results'][0]
|
|
103
|
+
self.assertEqual(record['log'], 'functional.log')
|
|
104
|
+
self.assertEqual(record['exit'], 4)
|
|
105
|
+
self.assertGreater((artifacts / record['log']).stat().st_size, 20000)
|
|
106
|
+
self.assertIn('specific failure', summary.getvalue())
|
|
107
|
+
self.assertIn('exit 4', summary.getvalue())
|
|
108
|
+
self.assertLess(len(summary.getvalue()), 3500)
|
|
109
|
+
|
|
110
|
+
def test_container_binds_artifacts_and_forwards_explicit_path(self):
|
|
111
|
+
spec = importlib.util.spec_from_file_location('container', ROOT / 'ci/test/02_run_container.py')
|
|
112
|
+
container = importlib.util.module_from_spec(spec)
|
|
113
|
+
spec.loader.exec_module(container)
|
|
114
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
115
|
+
work = Path(directory)
|
|
116
|
+
artifacts = work / 'host-artifacts'
|
|
117
|
+
env = {'USER': work.name, 'CONTAINER_NAME': 'diagnostic-fixture',
|
|
118
|
+
'PATH': os.environ.get('PATH', '/usr/bin'), 'ROOTS_ARTIFACTS_DIR': str(artifacts),
|
|
119
|
+
'BASE_READ_ONLY_DIR': str(ROOT), 'BASE_ROOT_DIR': str(work / 'guest'),
|
|
120
|
+
'CCACHE_DIR': str(work / 'ccache'), 'DEPENDS_DIR': str(work / 'depends'),
|
|
121
|
+
'PREVIOUS_RELEASES_DIR': str(work / 'previous'), 'CI_IMAGE_NAME_TAG': 'fixture',
|
|
122
|
+
'CI_IMAGE_PLATFORM': 'linux', 'FILE_ENV': 'fixture'}
|
|
123
|
+
env_file = Path(f"/tmp/env-{env['USER']}-{env['CONTAINER_NAME']}")
|
|
124
|
+
self.addCleanup(env_file.unlink, missing_ok=True)
|
|
125
|
+
calls = []
|
|
126
|
+
|
|
127
|
+
def run(command, **kwargs):
|
|
128
|
+
calls.append(command)
|
|
129
|
+
if command[:2] == ['bash', '-c']:
|
|
130
|
+
return SimpleNamespace(stdout='export ROOTS_ARTIFACTS_DIR=\n')
|
|
131
|
+
if command[:2] == ['docker', 'run']:
|
|
132
|
+
self.assertTrue(artifacts.is_dir())
|
|
133
|
+
self.assertIn(f'--mount=type=bind,src={artifacts},dst={artifacts}', command)
|
|
134
|
+
self.assertIn(f'ROOTS_ARTIFACTS_DIR={artifacts}', env_file.read_text())
|
|
135
|
+
return SimpleNamespace(stdout='fixture-container\n')
|
|
136
|
+
if command[:2] == ['docker', 'exec'] and command[-1].endswith('/03_test_script.sh'):
|
|
137
|
+
# Emulate writes through the declared bind mount. No actual
|
|
138
|
+
# Docker build, dependency install or fuzz target executes.
|
|
139
|
+
log = artifacts / 'functional.log'
|
|
140
|
+
result = MODULE.run_bounded([sys.executable, '-c', 'import sys; print("host-visible failure"); sys.exit(3)'], 5, log)
|
|
141
|
+
(artifacts / 'functional-results.json').write_text(json.dumps({'exit': result, 'log': log.name}))
|
|
142
|
+
return SimpleNamespace(stdout='', returncode=0)
|
|
143
|
+
|
|
144
|
+
with patch.dict(os.environ, env, clear=True), patch.object(container, 'run', side_effect=run):
|
|
145
|
+
container.main()
|
|
146
|
+
self.assertIn('host-visible failure', (artifacts / 'functional.log').read_text())
|
|
147
|
+
self.assertEqual(json.loads((artifacts / 'functional-results.json').read_text())['exit'], 3)
|
|
148
|
+
self.assertTrue(any(command[:2] == ['docker', 'run'] for command in calls))
|
|
149
|
+
|
|
82
150
|
|
|
83
151
|
if __name__ == '__main__':
|
|
84
152
|
unittest.main()
|