File size: 2,868 Bytes
e8055cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""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)