From ab3eb20e6d7663a004aaf953861afefb76cb38d6 Mon Sep 17 00:00:00 2001 From: alexandersato0830 <66799221+alexandersato0830@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:46:20 -0600 Subject: [PATCH] Reserve synthetic guest scene output before writing reports --- scripts/run_guest_scene.py | 5 +++-- tests/test_guest_scene_reference.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/scripts/run_guest_scene.py b/scripts/run_guest_scene.py index 60d5ded90..55f770c8b 100644 --- a/scripts/run_guest_scene.py +++ b/scripts/run_guest_scene.py @@ -256,12 +256,13 @@ def negative_controls(session: Session, out: Path) -> dict: def execute(args: argparse.Namespace, out: Path, temporary: bool) -> int: + session = Session(args, out) try: out.mkdir(parents=True, exist_ok=True) # parse_args has checked that it is new or empty + session.logs.mkdir() # Reserve the output even if another run passed the same check. except OSError as exc: print(f"error: could not create output directory {out}: {exc}", file=sys.stderr) return 1 - session = Session(args, out) report: dict = {"status": "fail", "frames": FRAMES, "headless": True, "wine": args.wine, "temporary": temporary, "audio_mode": "winmm" if args.play_audio else "offline", "report": str(out / "report.json")} try: @@ -271,7 +272,7 @@ def execute(args: argparse.Namespace, out: Path, temporary: bool) -> int: "guest": {"path": str(args.guest), "sha256": sha256(args.guest.read_bytes())}, "shaders": {"path": str(args.shaders), "files": len(shader_files), "tree_sha256": tree_hash(shader_files)}, "scene.bin": sha256(scene_bytes())} - for sub in ("logs", "package", *MODES): + for sub in ("package", *MODES): (out / sub).mkdir() package = out / "package" write_new(package / "scene.bin", scene_bytes()) diff --git a/tests/test_guest_scene_reference.py b/tests/test_guest_scene_reference.py index 9c6df51f8..ef1ae33bb 100644 --- a/tests/test_guest_scene_reference.py +++ b/tests/test_guest_scene_reference.py @@ -1,6 +1,8 @@ """Fixed reference points for the synthetic guest's renderer and input trace (no GPU).""" import argparse +import contextlib import importlib.util +import io import json from pathlib import Path import struct @@ -100,6 +102,29 @@ class GuestSceneReferenceTest(unittest.TestCase): self.assertEqual(result.stdout, "") self.assertEqual(placeholder.read_bytes(), b"synthetic input") + def test_run_leaves_a_competing_runs_output_untouched(self): + with tempfile.TemporaryDirectory() as temp: + root = Path(temp) + loader = root / "loader.txt" + loader.write_bytes(b"synthetic input") + shaders = root / "shaders" + shaders.mkdir() + args = argparse.Namespace(wine=None, loader=loader, guest=loader, shaders=shaders, play_audio=False) + out = root / "output" + logs = out / "logs" + # The other run claimed this directory after our argument check. + logs.mkdir(parents=True) + first_run_log = logs / "full.stdout.log" + first_run_log.write_bytes(b"first run") + + stderr = io.StringIO() + with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(stderr): + self.assertEqual(runner.execute(args, out, temporary=False), 1) + + self.assertEqual(list(out.iterdir()), [logs]) + self.assertEqual(first_run_log.read_bytes(), b"first run") + self.assertIn(f"could not create output directory {out}", stderr.getvalue()) + def test_launch_failure_preserves_run_record_and_logs(self): with tempfile.TemporaryDirectory() as temp: root = Path(temp)