fix(reports): auto-detect PoC language with Python fallback

This commit is contained in:
Ahmed Allam
2026-07-25 13:09:57 -07:00
committed by Ahmed Allam
parent 31c18f8f75
commit 97ed7e79a1
9 changed files with 211 additions and 165 deletions
+20 -1
View File
@@ -2,7 +2,13 @@
from __future__ import annotations
from strix.interface.tui.renderers.fenced import parse_fenced_code
from pygments.lexers import BashLexer, PythonLexer
from strix.interface.tui.renderers.fenced import (
guess_language_name,
parse_fenced_code,
resolve_lexer,
)
from strix.viewer.report_pdf import _strip_code_fence
@@ -43,3 +49,16 @@ def test_strip_code_fence_removes_fence() -> None:
def test_strip_code_fence_passes_through_non_string_and_unfenced() -> None:
assert _strip_code_fence(None) is None
assert _strip_code_fence("x = 1") == "x = 1"
def test_resolve_lexer_honors_explicit_language() -> None:
assert isinstance(resolve_lexer("bash", "echo hi"), BashLexer)
def test_resolve_lexer_falls_back_to_python_when_unresolvable() -> None:
# Unknown language name and empty body -> nothing to auto-detect -> Python.
assert isinstance(resolve_lexer("not-a-language", ""), PythonLexer)
def test_guess_language_name_defaults_to_python_when_inconclusive() -> None:
assert guess_language_name("") == "python"