Skip to content

Commit 4cdb77d

Browse files
committed
fix(report): label the rule-set exception row as a rule set
The Markdown and terminal completeness tables printed the rule-load exception under its path label `yara_rules`, exactly like a real file of that name, even though JSON carries scope="rule_set" and SARIF gives it no physical location. Prefix the location with "rule set" when the row is scoped to a rule set, so the two can be told apart in every format. Signed-off-by: Souptik Chakraborty <[email protected]>
1 parent 61e9821 commit 4cdb77d

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

‎src/skillspector/nodes/report.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737

3838
from skillspector import __version__ as skillspector_version
3939
from skillspector.inference_usage import sanitize_inference_usage
40-
from skillspector.inspection_ledger import MAX_FINDING_OUTPUT_RECORDS, AnalysisCompleteness
40+
from skillspector.inspection_ledger import (
41+
MAX_FINDING_OUTPUT_RECORDS,
42+
RULE_SET_SCOPE,
43+
AnalysisCompleteness,
44+
)
4145
from skillspector.llm_utils import is_llm_available
4246
from skillspector.logging_config import get_logger
4347
from skillspector.models import Finding
@@ -871,6 +875,9 @@ def render_rows(title: str, rows: object) -> None:
871875
end_line = row.get("end_line")
872876
if isinstance(start_line, int):
873877
location += f":{start_line}" + (f"-{end_line}" if end_line else "")
878+
if row.get("scope") == RULE_SET_SCOPE:
879+
# The path of a rule-set row is a label, not an artifact.
880+
location = f"rule set {location}"
874881
reason = str(row.get("reason_code", row.get("status", "status")))
875882
message = str(row.get("message", ""))
876883
console.print(f" - {escape(reason)} {escape(location)}: {escape(message)}")
@@ -1262,8 +1269,12 @@ def render_rows(title: str, rows: object) -> None:
12621269
if isinstance(start_line, int):
12631270
location += f":{start_line}" + (f"-{end_line}" if end_line else "")
12641271
reason = row.get("reason_code", row.get("status", "status"))
1272+
location_cell = f"`{_markdown_cell(location)}`"
1273+
if row.get("scope") == RULE_SET_SCOPE:
1274+
# The path of a rule-set row is a label, not an artifact.
1275+
location_cell = f"rule set {location_cell}"
12651276
lines.append(
1266-
f"| {_markdown_cell(reason)} | `{_markdown_cell(location)}` | "
1277+
f"| {_markdown_cell(reason)} | {location_cell} | "
12671278
f"{_markdown_cell(row.get('message', ''))} |"
12681279
)
12691280
lines.append("")

‎tests/nodes/test_report.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,56 @@ def test_report_markdown_lists_nonfatal_llm_validation_exception(self) -> None:
631631
assert "### Analyzer Statuses" in body
632632
assert "### Limitations" in body
633633

634+
@pytest.mark.parametrize("output_format", ["markdown", "terminal"])
635+
def test_report_labels_rule_set_exception_as_rule_set_not_file(
636+
self, output_format: str
637+
) -> None:
638+
"""A rule-set row must not read like a file row that shares its path label."""
639+
state: SkillspectorState = {
640+
"filtered_findings": [],
641+
"component_metadata": [],
642+
"has_executable_scripts": False,
643+
"manifest": {},
644+
"skill_path": None,
645+
"output_format": output_format,
646+
"execution_successful": True,
647+
"analysis_completeness": {
648+
"coverage_percent": 100.0,
649+
"fully_inspected_files": 1,
650+
"partially_inspected_files": 0,
651+
"entirely_uninspected_files": 0,
652+
"is_complete": False,
653+
"execution_successful": True,
654+
"ledger_exceptions": [
655+
{
656+
"reason_code": "read_error",
657+
"path": "yara_rules",
658+
"message": "Rule dropped.",
659+
"fatal": False,
660+
"scope": "rule_set",
661+
},
662+
{
663+
"reason_code": "read_error",
664+
"path": "yara_rules",
665+
"message": "File unreadable.",
666+
"fatal": False,
667+
},
668+
],
669+
"scope_exclusions": [],
670+
"analyzer_statuses": [],
671+
"limitations": [],
672+
},
673+
}
674+
675+
body = report(state)["report_body"]
676+
677+
if output_format == "markdown":
678+
assert "| read_error | rule set `yara_rules` | Rule dropped. |" in body
679+
assert "| read_error | `yara_rules` | File unreadable. |" in body
680+
else:
681+
assert "read_error rule set yara_rules: Rule dropped." in body
682+
assert "read_error yara_rules: File unreadable." in body
683+
634684
def test_report_output_format_terminal(self) -> None:
635685
"""output_format terminal produces Rich-formatted output."""
636686
state: SkillspectorState = {

0 commit comments

Comments
 (0)