Skip to content

Commit 2cefeac

Browse files
committed
fix(batch): keep warning names literal with Rich and plain output
Signed-off-by: yashrajbasav <[email protected]>
1 parent 2669280 commit 2cefeac

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎contrib/batch_scan/batch_scan.py‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def _main_impl() -> None:
141141
try:
142142
from rich.console import Console
143143
from rich.markup import escape
144+
from rich.text import Text
144145
except ImportError:
145146
Console = None # type: ignore[assignment] # noqa: N806
146147

@@ -327,12 +328,17 @@ def _print(*args: object, **kwargs: object) -> None:
327328
with _print_lock:
328329
# Non-English LLM guard warning
329330
if lang != "en" and not use_llm and args.require_llm:
331+
warning = (
332+
f"non-English skill '{_terminal_text(rel_name)}' "
333+
f"({_terminal_text(lang)}) scanned with --no-llm. "
334+
"Static pattern recall is reduced for this language. "
335+
"Re-run without --no-llm for full coverage, or use "
336+
"--no-require-llm to suppress this warning."
337+
)
330338
_print(
331-
f"[yellow]WARNING:[/yellow] non-English skill "
332-
f"'{display(rel_name)}' ({display(lang)}) scanned with --no-llm. "
333-
f"Static pattern recall is reduced for this language. "
334-
f"Re-run without --no-llm for full coverage, or use "
335-
f"--no-require-llm to suppress this warning.",
339+
Text.assemble(("WARNING:", "yellow"), " ", warning)
340+
if c
341+
else f"WARNING: {warning}",
336342
file=sys.stderr,
337343
)
338344

‎tests/test_batch_scan_security.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,20 @@ def fail_gap_fill(file_cache, language, **kwargs):
188188
assert entry["risk_assessment"]["severity"] == "ERROR"
189189

190190

191+
@pytest.mark.parametrize("rich_available", [True, False])
192+
@pytest.mark.parametrize("skill_name", ["safe-skill", "x\\"])
191193
def test_cli_warns_using_detected_language(
192-
batch_skill, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
194+
batch_skill,
195+
monkeypatch: pytest.MonkeyPatch,
196+
capsys: pytest.CaptureFixture[str],
197+
rich_available: bool,
198+
skill_name: str,
193199
) -> None:
194200
skill, _ = batch_skill
201+
if skill.name != skill_name:
202+
skill = skill.rename(skill.with_name(skill_name))
203+
if not rich_available:
204+
monkeypatch.setitem(sys.modules, "rich.console", None)
195205
observed = _mock_scan(monkeypatch)
196206
monkeypatch.setattr(batch_scan, "create_api_key_pool_from_env", lambda: None)
197207
monkeypatch.setattr(
@@ -205,7 +215,7 @@ def test_cli_warns_using_detected_language(
205215
output = capsys.readouterr()
206216
output_text = " ".join((output.out + output.err).split())
207217
assert "WARNING:" in output_text
208-
assert "(zh) scanned with --no-llm." in output_text
218+
assert f"skill '{skill_name}' (zh) scanned with --no-llm." in output_text
209219
assert observed["calls"] == []
210220

211221

0 commit comments

Comments
 (0)