File size: 2,191 Bytes
f628309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Tests for the gate that keeps the printed commands of the card runnable."""

from __future__ import annotations

import importlib.util
from pathlib import Path

_ROOT = Path(__file__).resolve().parent.parent
# The kernel bundle carries a tools/run_gates.py of its own, so this file loads
# the bundle runner by path instead of by package name.
_spec = importlib.util.spec_from_file_location(
    "codex_python_gates_runner_card", _ROOT / "tools" / "run_gates.py"
)
assert _spec is not None and _spec.loader is not None
_run_gates = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_run_gates)

_card_commands = _run_gates._card_commands
_card_command_problems = _run_gates._card_command_problems
_parser_surface = _run_gates._parser_surface
gate_cli_card_agreement = _run_gates.gate_cli_card_agreement

from lingologos_python.cli import _build_parser


def test_the_card_agreement_gate_confirms_the_real_pair() -> None:
    res = gate_cli_card_agreement()
    assert res.verdict == "CONFIRMED"
    assert "agree with" in res.note


def test_a_wrapped_example_is_still_one_command() -> None:
    card = (
        "text\n\n"
        "```bash\n"
        "$ python -B -m lingologos_python edit --workspace w \\\n"
        "    --file f.py --search a --replace b --json\n"
        "```\n"
    )
    commands = _card_commands(card)
    assert commands == [("edit", ["--workspace", "--file", "--search", "--replace", "--json"])]


def test_the_parser_surface_carries_the_flags_a_reader_copies_today() -> None:
    top, verbs = _parser_surface(_build_parser())
    assert "--version" in top
    assert "--search-file" in verbs["edit"] and "--replace-file" in verbs["edit"]
    for verb in ("create", "delete", "patterns"):
        assert "--allow-single-prover" in verbs[verb]


def test_a_flag_invented_in_the_card_is_reported_as_not_carried() -> None:
    card = (
        "python -B -m lingologos_python edit --workspace w --file f.py --invented-flag x\n"
        "python -B -m lingologos_python frobnicate --workspace w\n"
    )
    problems = _card_command_problems(card, _build_parser())
    assert "edit --invented-flag" in problems
    assert "verb frobnicate" in problems