File size: 2,386 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
"""Tests for harness/B/launch.py -- multi-GPU scene sharding across workers."""

import pytest

from harness.B import launch


def test_launcher_imports():
    assert callable(launch.main)


class _FakeRun:
    rows = [{"id": 1}, {"id": 3}]

    @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-b"
    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-b"
    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")


def test_launch_rejects_question_id_filter_that_matches_nothing(monkeypatch, tmp_path):
    monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
    with pytest.raises(ValueError, match="no questions found"):
        launch.launch(
            "qwen3.5-2b",
            "explicit",
            "selective",
            64,
            ["scene-b"],
            results_dir=tmp_path,
            question_ids={999},
        )