Merge pull request #1958 from alexandersato0830/codex/guest-scene-output-ownership

Reserve synthetic guest scene output before writing reports (GUEST-SCENE-OUTPUT-OWNERSHIP)
This commit is contained in:
MoonEyes
2026-11-28 20:29:43 +01:00
committed by GitHub
2 changed files with 28 additions and 2 deletions

View File

@ -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())

View File

@ -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
@ -101,6 +103,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)