From 8bd42c782d17c0e95fbdd431814d0e3cb06d36b3 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 4 Oct 2026 06:54:31 +0200 Subject: [PATCH] Keep dispatcher fixture diagnostics useful and bounded --- tests/test_fixtures.py | 33 +++++++++++++++++++++++++++++++++ tools/test_dispatch.py | 26 ++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tests/test_fixtures.py diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py new file mode 100644 index 000000000..e4642eb05 --- /dev/null +++ b/tests/test_fixtures.py @@ -0,0 +1,33 @@ +import json +import subprocess +import unittest + +from tools.test_dispatch import failure_summary + + +class FixtureDiagnosticTests(unittest.TestCase): + def test_only_exit_count_and_exception_types_leave_private_log(self): + output = '\n'.join([ + 'Exception in thread "private-thread-name" java.lang.NoClassDefFoundError: private-token', + 'Caused by: java.lang.ClassNotFoundException: /private/world/path', + 'Caused by: java.lang.ClassNotFoundException: other-private-message', + ' at private.World.method(World.java:42)', + 'session-token=private-token', + ]) + run = subprocess.CompletedProcess(['private-command'], 1, output) + report = failure_summary(run, 0) + self.assertEqual(report, {'exit_code': 1, 'result_count': 0, + 'java_exception_types': ['java.lang.NoClassDefFoundError', 'java.lang.ClassNotFoundException']}) + self.assertNotIn('private', json.dumps(report)) + + def test_type_list_and_names_are_bounded(self): + output = '\n'.join('Caused by: sample.Failure%d: private-message' % index for index in range(20)) + output = 'Caused by: sample.' + 'A' * 201 + ': private-message\n' + output + report = failure_summary(subprocess.CompletedProcess([], 2, output), 3) + self.assertEqual(len(report['java_exception_types']), 8) + self.assertEqual(report['java_exception_types'][0], 'sample.Failure0') + self.assertEqual(report['result_count'], 3) + + def test_unknown_failure_still_reports_exit_and_count(self): + report = failure_summary(subprocess.CompletedProcess([], -15, 'private unrelated message'), 0) + self.assertEqual(report, {'exit_code': -15, 'result_count': 0, 'java_exception_types': []}) diff --git a/tools/test_dispatch.py b/tools/test_dispatch.py index b3afd1950..77593c505 100644 --- a/tools/test_dispatch.py +++ b/tools/test_dispatch.py @@ -6,15 +6,30 @@ import json import os from pathlib import Path import platform +import re import shutil import subprocess import sys try: from . import build_mod, build_pack + from .test_culling_rays import run_fixture except ImportError: import build_mod import build_pack + from test_culling_rays import run_fixture + + +def failure_summary(run, report_count): + """Publish only exit/count and bounded Java type names, never log messages.""" + types = [] + pattern = r"(?:Caused by:|Exception in thread \"[^\"]*\")\s+([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+)(?=[:\s]|$)" + for kind in re.findall(pattern, run.stdout, flags=re.ASCII): + if len(kind) <= 200 and kind not in types: + types.append(kind) + if len(types) == 8: + break + return {"exit_code": run.returncode, "result_count": report_count, "java_exception_types": types} def main(): @@ -37,13 +52,16 @@ def main(): command = ["xvfb-run", "-a", *command] environment = os.environ.copy() environment["_JAVA_OPTIONS"] = "-Dhorizon.fixture.exit=true" - run = subprocess.run(command, cwd=root, env=environment, text=True, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, timeout=240) - (instance / "fixture.log").write_text(run.stdout) + try: + run = run_fixture(command, instance, environment) + except RuntimeError: + print("HORIZON_FIXTURE_FAILURE " + json.dumps({"fixture": "dispatch", "completed": False}), flush=True) + raise RuntimeError("Dispatch fixture did not complete; full diagnostics remain private") from None marker = "HORIZON_DISPATCH_RESULT " reports = [json.loads(line.split(marker, 1)[1]) for line in run.stdout.splitlines() if marker in line] if run.returncode or len(reports) != 1: - raise RuntimeError(f"Dispatch fixture failed; inspect {instance / 'fixture.log'}") + print("HORIZON_FIXTURE_FAILURE " + json.dumps(failure_summary(run, len(reports))), flush=True) + raise RuntimeError("Dispatch fixture failed; full diagnostics remain in the private fixture.log") report = reports[0] if report["enabled"] != enabled or report["tasks_completed"] != 2 or report["occupied_slots"] != 0: raise AssertionError("Fixture outcome did not match the selected hook")