33from __future__ import annotations
44
55import json
6+ import re
67from io import StringIO
78from pathlib import Path
89
1819)
1920from cocoindex_code .protocol import SearchResponse , SearchResult
2021
22+ _ANSI_RE = re .compile (r"\x1b\[[0-?]*[ -/]*[@-~]" )
23+
24+
25+ def _strip_ansi (text : str ) -> str :
26+ return _ANSI_RE .sub ("" , text )
27+
2128
2229def test_require_project_root_success (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
2330 project = tmp_path / "project"
@@ -94,8 +101,9 @@ def test_search_help_includes_json_option() -> None:
94101 result = runner .invoke (cli .app , ["search" , "--help" ], catch_exceptions = False )
95102
96103 assert result .exit_code == 0
97- assert "--json" in result .output
98- assert "--repo-key" in result .output
104+ output = _strip_ansi (result .output )
105+ assert "--json" in output
106+ assert "--repo-key" in output
99107
100108
101109def test_bridge_help_includes_jsonrpc_option () -> None :
@@ -104,7 +112,7 @@ def test_bridge_help_includes_jsonrpc_option() -> None:
104112 result = runner .invoke (cli .app , ["bridge" , "--help" ], catch_exceptions = False )
105113
106114 assert result .exit_code == 0
107- assert "--jsonrpc" in result .output
115+ assert "--jsonrpc" in _strip_ansi ( result .output )
108116
109117
110118def test_print_search_results_json_outputs_machine_readable_payload (
0 commit comments