"""Tests for harness/C/launch.py -- multi-GPU scene sharding across workers.""" from harness.C import launch def test_launcher_imports(): assert callable(launch.main) class _FakeRun: rows = [{"id": 1}, {"id": 2}] @staticmethod def results_dir_for(*args, **kwargs): return args[-1] @classmethod def load_questions(cls, scene=None): return list(cls.rows) def test_launch_skips_scene_already_fully_answered(tmp_path, capsys, monkeypatch): scene = "scene-c" monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun) scene_dir = tmp_path / scene scene_dir.mkdir() for row in _FakeRun.rows: (scene_dir / f"{row['id']}.json").write_text("{}") launch.launch( "qwen3.5-2b", "explicit", "selective", 64, [scene], results_dir=tmp_path ) output = capsys.readouterr().out assert "skipped" in output assert "DONE: 1 ok, 0 failed" in output def test_launch_rebuild_forces_pending_even_when_answered(tmp_path, monkeypatch): scene = "scene-c" monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun) scene_dir = tmp_path / scene scene_dir.mkdir() for row in _FakeRun.rows: (scene_dir / f"{row['id']}.json").write_text("{}") monkeypatch.setattr(launch, "visible_gpus", lambda: []) monkeypatch.setattr( launch.mp, "get_context", lambda *_: (_ for _ in ()).throw( RuntimeError("rebuild correctly reached worker dispatch") ), ) try: launch.launch( "qwen3.5-2b", "explicit", "selective", 64, [scene], results_dir=tmp_path, rebuild=True, ) except RuntimeError as exc: assert "rebuild correctly reached worker dispatch" in str(exc) else: raise AssertionError("expected rebuild to force scene into the pending path")