"""Issue #60, Linux check: the defects the opencode 2.x check on Linux found. 1. The 2.x home screen's placeholder (`Ask anything… ""`, cut without its closing quote in a narrow box) is not typed input. """ from __future__ import annotations import re import sys from pathlib import Path import pytest REPO_ROOT = Path(__file__).resolve().parent.parent SKILLS = REPO_ROOT / ".agents" / "skills" PANES = REPO_ROOT / "tests" / "fixtures" / "panes" if str(SKILLS) not in sys.path: sys.path.insert(0, str(SKILLS)) from lib_py import stall_watch # noqa: E402 from lib_py.agents.input_region import extract_input_region # noqa: E402 from lib_py.agents.registry import get_adapter # noqa: E402 # 140 columns (herdr capture) and 60 columns, where the example loses its # closing quote. HOME_SCREENS = ("opencode_idle_2x_home.txt", "opencode_idle_2x_home_narrow.txt") PLACEHOLDER_LINE = re.compile(r'^(\s*┃\s*)Ask anything… ".*$', re.M) def _pane(name: str) -> str: return "".join(l for l in (PANES / name).read_text(encoding="utf-8").splitlines(True) if not l.startswith("# ")) # --------------------------------------------------------------------------- # 1. the 2.x home screen's placeholder # --------------------------------------------------------------------------- @pytest.mark.parametrize("name", HOME_SCREENS) def test_the_2x_home_screen_reads_as_an_empty_box(name): assert extract_input_region(_pane(name), "opencode") == "" def test_the_narrow_capture_has_a_cut_example(): # The case the pattern must keep: no closing quote on screen. (line,) = [l for l in _pane(HOME_SCREENS[1]).splitlines() if "Ask anything" in l] assert '"' in line and not line.rstrip().endswith('"') def test_the_narrow_screen_stops_at_its_status_line_and_reads_ready(): text = _pane(HOME_SCREENS[1]) # Under ~60 columns the status line drops `auto`: `Build · `. assert re.search(r"^\s*┃\s*Build · ", text, re.M) and "Build auto" not in text assert re.search(get_adapter("opencode").ready_tokens, text) @pytest.mark.parametrize("name", HOME_SCREENS) @pytest.mark.parametrize("typed", [ "please continue", 'Ask anything… "x" and fix it', "Ask anything about the build", 'Ask anything… "a"b', ]) def test_typed_text_is_read_as_typed(name, typed): text, n = PLACEHOLDER_LINE.subn(lambda m: m.group(1) + typed, _pane(name), count=1) assert n == 1 assert extract_input_region(text, "opencode") == typed def test_the_1x_capture_still_reads_empty(): assert extract_input_region(_pane("opencode_idle.txt"), "opencode") == "" @pytest.mark.parametrize("name", HOME_SCREENS) def test_stall_watch_sees_the_2x_home_box_empty(name, monkeypatch): src = stall_watch.HerdrSource("t", "opencode") monkeypatch.setattr(src, "_herdr", lambda *args: _pane(name)) assert src.input_empty() is True def test_other_adapters_have_no_placeholder_pattern(): for agent in ("claude", "agy", "grok", "codex", "hermes"): assert get_adapter(agent).input_placeholder_pattern is None, agent