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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
ci/test/test_roots_regressions.py
CHANGED
|
@@ -2,12 +2,17 @@
|
|
| 2 |
# Copyright (c) 2026-present The Bitcoin Roots developers
|
| 3 |
# Distributed under the MIT software license, see the accompanying file COPYING.
|
| 4 |
"""Exercise actual affected selections, execution budgets and failure artifacts."""
|
|
|
|
| 5 |
import importlib.util
|
|
|
|
| 6 |
import json
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
import sys
|
| 9 |
import tempfile
|
|
|
|
| 10 |
import unittest
|
|
|
|
| 11 |
|
| 12 |
ROOT = Path(__file__).resolve().parents[2]
|
| 13 |
SPEC = importlib.util.spec_from_file_location('roots_regressions', ROOT / 'ci/test/roots-regressions.py')
|
|
@@ -60,7 +65,9 @@ class RootsRegressionTest(unittest.TestCase):
|
|
| 60 |
for cadence, expected in [('fast', 5), ('nightly', 60)]:
|
| 61 |
artifacts = build / cadence
|
| 62 |
plan = MODULE.selection(['src/wallet/wallet.cpp'], cadence)
|
| 63 |
-
self.assertEqual(MODULE.execute(plan, 'fuzz', build, artifacts, []), 1)
|
|
|
|
|
|
|
| 64 |
results = json.loads((artifacts / 'fuzz-results.json').read_text())['results']
|
| 65 |
self.assertEqual(len(results), 2)
|
| 66 |
for record in results:
|
|
@@ -69,6 +76,8 @@ class RootsRegressionTest(unittest.TestCase):
|
|
| 69 |
self.assertIn('-max_total_time=' + str(expected), record['command'])
|
| 70 |
self.assertNotIn('-runs=', ' '.join(record['command']))
|
| 71 |
self.assertIn(record['target'], (artifacts / (record['target'] + '.log')).read_text())
|
|
|
|
|
|
|
| 72 |
|
| 73 |
def test_real_timeout_is_failure_with_retained_log(self):
|
| 74 |
with tempfile.TemporaryDirectory() as directory:
|
|
@@ -79,6 +88,65 @@ class RootsRegressionTest(unittest.TestCase):
|
|
| 79 |
self.assertEqual(MODULE.run_bounded([str(Path(directory) / 'absent')], 1, log), 127)
|
| 80 |
self.assertTrue(log.stat().st_size)
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
if __name__ == '__main__':
|
| 84 |
unittest.main()
|
|
|
|
| 2 |
# Copyright (c) 2026-present The Bitcoin Roots developers
|
| 3 |
# Distributed under the MIT software license, see the accompanying file COPYING.
|
| 4 |
"""Exercise actual affected selections, execution budgets and failure artifacts."""
|
| 5 |
+
import contextlib
|
| 6 |
import importlib.util
|
| 7 |
+
import io
|
| 8 |
import json
|
| 9 |
+
import os
|
| 10 |
from pathlib import Path
|
| 11 |
import sys
|
| 12 |
import tempfile
|
| 13 |
+
from types import SimpleNamespace
|
| 14 |
import unittest
|
| 15 |
+
from unittest.mock import patch
|
| 16 |
|
| 17 |
ROOT = Path(__file__).resolve().parents[2]
|
| 18 |
SPEC = importlib.util.spec_from_file_location('roots_regressions', ROOT / 'ci/test/roots-regressions.py')
|
|
|
|
| 65 |
for cadence, expected in [('fast', 5), ('nightly', 60)]:
|
| 66 |
artifacts = build / cadence
|
| 67 |
plan = MODULE.selection(['src/wallet/wallet.cpp'], cadence)
|
| 68 |
+
summary = io.StringIO()
|
| 69 |
+
with contextlib.redirect_stderr(summary):
|
| 70 |
+
self.assertEqual(MODULE.execute(plan, 'fuzz', build, artifacts, []), 1)
|
| 71 |
results = json.loads((artifacts / 'fuzz-results.json').read_text())['results']
|
| 72 |
self.assertEqual(len(results), 2)
|
| 73 |
for record in results:
|
|
|
|
| 76 |
self.assertIn('-max_total_time=' + str(expected), record['command'])
|
| 77 |
self.assertNotIn('-runs=', ' '.join(record['command']))
|
| 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())
|
| 81 |
|
| 82 |
def test_real_timeout_is_failure_with_retained_log(self):
|
| 83 |
with tempfile.TemporaryDirectory() as directory:
|
|
|
|
| 88 |
self.assertEqual(MODULE.run_bounded([str(Path(directory) / 'absent')], 1, log), 127)
|
| 89 |
self.assertTrue(log.stat().st_size)
|
| 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 |
+
|
| 150 |
|
| 151 |
if __name__ == '__main__':
|
| 152 |
unittest.main()
|