diff --git a/tests/test_journal_cli_migration.py b/tests/test_journal_cli_migration.py index d41eb987a..b313dd431 100644 --- a/tests/test_journal_cli_migration.py +++ b/tests/test_journal_cli_migration.py @@ -4,6 +4,7 @@ from __future__ import annotations import re +import subprocess from pathlib import Path from solstone.think.sol_cli import ALIASES, COMMANDS @@ -58,12 +59,22 @@ def _is_text_surface(path: Path) -> bool: return path.suffix in TEXT_SUFFIXES -def _candidate_files() -> list[Path]: - return sorted( - path - for path in Path(".").rglob("*") - if path.is_file() and _is_text_surface(path) +def _tracked_sol_lines() -> list[tuple[Path, int, str]]: + result = subprocess.run( + ["git", "grep", "-n", "-I", "-F", "sol ", "--"], + check=False, + capture_output=True, + text=True, ) + if result.returncode not in {0, 1}: + result.check_returncode() + matches = [] + for raw_line in result.stdout.splitlines(): + path_text, line_number, line = raw_line.split(":", maxsplit=2) + path = Path(path_text) + if path.exists() and _is_text_surface(path): + matches.append((path, int(line_number), line)) + return matches def _skip_line(path: Path, line: str) -> bool: @@ -123,17 +134,17 @@ SERVICE_SOL_LITERAL_RE = re.compile( def test_service_tagged_commands_are_not_documented_as_sol() -> None: - service_matches = [] - missing_access_expectations = [] - for path in _candidate_files(): - text = path.read_text(encoding="utf-8") - for line_number, line in enumerate(text.splitlines(), start=1): - if not _skip_line(path, line) and SERVICE_SOL_RE.search(line): - service_matches.append(f"{path}:{line_number}: {line}") - - access_expectation = ACCESS_POSITIVE_EXPECTATIONS.get(path) - if access_expectation is not None and access_expectation.search(text) is None: - missing_access_expectations.append(str(path)) + service_matches = [ + f"{path}:{line_number}: {line}" + for path, line_number, line in _tracked_sol_lines() + if not _skip_line(path, line) and SERVICE_SOL_RE.search(line) + ] + missing_access_expectations = [ + str(path) + for path, expectation in ACCESS_POSITIVE_EXPECTATIONS.items() + if not path.exists() + or expectation.search(path.read_text(encoding="utf-8")) is None + ] assert service_matches == [] assert missing_access_expectations == []