From 92943e0a9d6251ed205bb1535ba3a4fb51137628 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sun, 1 Nov 2026 02:44:18 +0800 Subject: [PATCH] ci: identify overdue Rust tests and last running target by hash --- scripts/private-ci-diagnostics.py | 11 +++++++++++ scripts/tests/test_private_ci.py | 32 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/scripts/private-ci-diagnostics.py b/scripts/private-ci-diagnostics.py index 65852b6..f6c1c58 100644 --- a/scripts/private-ci-diagnostics.py +++ b/scripts/private-ci-diagnostics.py @@ -34,6 +34,17 @@ def report_tests(output): for name, line, column in panics} for fingerprint, line, column in sorted(locations): print(f'::error::Rust test panic location: {fingerprint} {line}:{column}') + overdue = set(re.findall(r'^test (.+?) has been running for over 60 seconds\r?$', + output, re.MULTILINE)) + for fingerprint in sorted(hashlib.sha256(name.encode()).hexdigest() for name in overdue): + print(f'::error::Rust overdue test fingerprint: {fingerprint}') + running = re.findall(r'^\s+Running (.+?) \(([^\r\n]+)\)\r?$', output, re.MULTILINE) + if running: + source, executable = running[-1] + basename = re.sub(r'-[0-9a-f]{16}$', '', Path(executable).name) + identity = f'{" ".join(source.split())} ({basename})' + fingerprint = hashlib.sha256(identity.encode()).hexdigest() + print(f'::error::Rust last running target fingerprint: {fingerprint}') def main(): diff --git a/scripts/tests/test_private_ci.py b/scripts/tests/test_private_ci.py index ae6c0e2..59aef43 100644 --- a/scripts/tests/test_private_ci.py +++ b/scripts/tests/test_private_ci.py @@ -254,6 +254,38 @@ class PrivateTestStageTests(unittest.TestCase): f'::error::Rust test panic location: {digest} 321:9\n') self.assertEqual(result.stderr, '') + def test_overdue_diagnostics_hash_names_without_exposing_messages(self): + with tempfile.TemporaryDirectory() as temporary: + log = Path(temporary) / 'private.log' + log.write_text('test private::slow has been running for over 60 seconds\n' + 'PRIVATE_SOURCE_PATH: PRIVATE_PAYLOAD\n' + 'test private::slow has been running for over 60 seconds\n') + result = subprocess.run([sys.executable, str(ROOT / 'scripts/private-ci-diagnostics.py'), + 'tests', str(log)], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) + digest = hashlib.sha256(b'private::slow').hexdigest() + self.assertEqual(result.stdout, f'::error::Rust overdue test fingerprint: {digest}\n') + self.assertEqual(result.stderr, '') + + def test_last_running_target_hash_is_stable_without_paths_or_build_hashes(self): + for source, basename in [('unittests src/lib.rs', 'private_crate'), + ('tests/PRIVATE_HARNESS.rs', 'private_harness')]: + for prefix, build_hash in [('/PRIVATE_SOURCE_ONE', '0123456789abcdef'), + ('/PRIVATE_SOURCE_TWO', 'fedcba9876543210')]: + with self.subTest(source=source, prefix=prefix), tempfile.TemporaryDirectory() as temporary: + log = Path(temporary) / 'private.log' + log.write_text(' Running tests/previous.rs (/PRIVATE_SOURCE/previous-1111111111111111)\n' + f' Running {source} ({prefix}/target/debug/deps/{basename}-{build_hash})\n' + 'PRIVATE_PAYLOAD\n') + result = subprocess.run([sys.executable, str(ROOT / 'scripts/private-ci-diagnostics.py'), + 'tests', str(log)], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) + identity = f'{source} ({basename})' + digest = hashlib.sha256(identity.encode()).hexdigest() + self.assertEqual(result.stdout, + f'::error::Rust last running target fingerprint: {digest}\n') + self.assertEqual(result.stderr, '') + class MacOSArtifactSelectionTests(unittest.TestCase): def select(self, jobs, artifacts=None):