File size: 2,441 Bytes
24c5a49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
627c6cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pytest

from tiny_computer_agent import __main__ as cli


def test_demo_runs_dry_run_by_default(capsys):
    assert cli.main([]) == 0
    out = capsys.readouterr().out
    assert "dry-run" in out
    assert "(dry-run) would click" in out
    assert "result: success" in out


def test_real_input_needs_the_allow_env_var(monkeypatch, capsys):
    monkeypatch.delenv(cli.ALLOW_REAL_INPUT_ENV, raising=False)
    assert cli.main(["--real-input"]) == 2
    assert "refusing --real-input" in capsys.readouterr().err


def test_bad_script_json_is_reported(capsys):
    assert cli.main(["--script", "{not json"]) == 2
    assert "not valid JSON" in capsys.readouterr().err


def test_script_replay(capsys):
    assert cli.main(["--script", '[{"kind": "done", "reason": "nothing to do"}]']) == 0
    assert "nothing to do" in capsys.readouterr().out


def test_failure_exit_code(capsys):
    # the planner gives up when the target never appears, so the CLI exits non-zero
    assert cli.main(["click 'Nonexistent button'"]) == 1
    assert "gave up" in capsys.readouterr().out


def test_doctor_exits_with_a_status(capsys):
    assert cli.main(["--doctor"]) in (0, 1)
    assert "preflight" in capsys.readouterr().out


def test_live_is_refused_without_a_display(capsys, monkeypatch):
    from tiny_computer_agent.desktop import display_available

    if display_available()[0]:
        pytest.skip("this machine has a display, so --live would really run")
    assert cli.main(["--live"]) == 2
    captured = capsys.readouterr()
    assert "refusing to run live" in captured.err
    assert "no DISPLAY" in captured.out


def test_screenshot_replay_needs_no_display(capsys):
    """The whole pipeline - OCR index, menu, action - on a still image."""
    from tiny_computer_agent.perception import detector_available

    if not detector_available()[0]:
        pytest.skip("no OCR engine installed")
    assert cli.main(["--image", "example", "--brain", "planner"]) == 0
    out = capsys.readouterr().out
    assert "screenshot replay" in out
    assert "elements detected" in out
    assert "would click" in out


def test_a_missing_image_is_reported_not_crashed(capsys):
    assert cli.main(["--image", "/nonexistent/shot.png"]) == 2
    assert "could not start" in capsys.readouterr().err


def test_vlm_brain_requires_a_live_screen(capsys):
    assert cli.main(["--brain", "vlm"]) == 2
    assert "needs --live" in capsys.readouterr().err