"""Tests for harness/A/launch.py -- multi-GPU scene sharding across workers.""" import pytest from harness.A import launch def test_launcher_imports(): assert callable(launch.main) def test_scenes_dedups_and_preserves_order(tmp_path, monkeypatch): manifest = tmp_path / "questions.jsonl" rows = [ '{"scene_name": "scene-a"}', '{"scene_name": "scene-b"}', '{"scene_name": "scene-a"}', ] manifest.write_text("\n".join(rows) + "\n") monkeypatch.setattr(launch, "JSONL", manifest) assert launch.scenes() == ["scene-a", "scene-b"] class _FakeRun: rows = [{"id": 1}, {"id": 2}] @staticmethod def results_dir_for( model, protocol, frame_selection, frame_count, results_dir=None ): return results_dir @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-a" 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", "uniform", 16, [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-a" 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: []) # Only assert it treats the scene as pending (doesn't take the all-skipped early # return); actually spawning workers needs a real model/GPU, exercised by the live # harness.A.launch smoke run instead of the unit suite. monkeypatch.setattr( launch.mp, "get_context", lambda *_: (_ for _ in ()).throw( RuntimeError("rebuild correctly reached worker dispatch") ), ) try: launch.launch( "qwen3.5-2b", "uniform", 16, [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") def test_launch_rejects_scene_with_no_questions(monkeypatch, tmp_path): class EmptyRun(_FakeRun): rows = [] monkeypatch.setattr(launch, "_load_run_module", lambda: EmptyRun) with pytest.raises(ValueError, match="no questions found"): launch.launch("qwen3.5-2b", "uniform", 16, ["missing"], results_dir=tmp_path)