from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from chekan.store import Run


def test_cmd_prompt_g2_and_g4(tmp_path: Path, monkeypatch, capsys) -> None:
    from chekan.__main__ import build_parser

    # Initialize a test run
    run = Run.create(tmp_path, "Проверка генератора промптов", "auto", "T1")
    monkeypatch.chdir(tmp_path)
    parser = build_parser()

    # Test prompt g2
    args_g2 = parser.parse_args(["prompt", "g2"])
    res_g2 = args_g2.func(args_g2)
    captured_g2 = capsys.readouterr()
    assert res_g2 == 0
    assert "Ты — независимый читатель спецификации Чекана" in captured_g2.out
    assert "Проверка генератора промптов" in captured_g2.out
    assert '"unresolved": []' in captured_g2.out

    # Test prompt g4
    args_g4 = parser.parse_args(["prompt", "g4"])
    res_g4 = args_g4.func(args_g4)
    captured_g4 = capsys.readouterr()
    assert res_g4 == 0
    assert "Ты — слепой приёмщик Чекана" in captured_g4.out
    assert '"done": [' in captured_g4.out
    assert '"missing": [' in captured_g4.out
