Skip to content

Add --junitxml export to sigma check with bug fixes and tests#91

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-code-comments
Open

Add --junitxml export to sigma check with bug fixes and tests#91
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-code-comments

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Implements JUnit XML output for sigma check (from PR #83), fixing an UnboundLocalError identified in review and adding test coverage.

Changes

sigma/cli/check.py

  • Add import xml.etree.ElementTree as ET, SEVERITY_ICONS dict, and generate_junit_report() — groups results into <testsuite> elements by error/issue type
  • Add --junitxml <path> option; wire through check() and load_and_check_rules() via an optional junit_results list parameter
  • Bug fix: In the SigmaConditionError handler, the original PR referenced rule_name/file_path variables that were never defined in that code path, causing an UnboundLocalError. Now reads directly from the current rule object:
    # Before (broken):
    "rule_name": rule_name,   # NameError — never assigned in this branch
    "file_path": file_path,
    # After:
    "rule_name": rule.title or str(rule.path),
    "file_path": str(rule.source) if rule.source else "unknown",
  • Guard against None severity values with (res.get("severity") or "ok").lower() / (res.get("severity") or "UNKNOWN").upper()
  • Generate the report after successful validation; also write an error-level entry when a top-level SigmaError is caught

tests/test_check.py

  • test_check_junitxml_creates_file — verifies the XML file is created, well-formed, and rooted at <testsuites>
  • test_check_junitxml_invalid — verifies failure entries are written for rules with parsing errors and that each testsuite/@failures count exactly matches the number of <failure> child elements

Both tests use tests/files/invalid with --pass-on-error to avoid the pre-existing network dependency on MITRE D3FEND data that already affects test_check_valid.

Copilot AI changed the title [WIP] Fix code according to review comments Add --junitxml export to sigma check with bug fixes and tests Jun 15, 2026
Copilot AI requested a review from thomaspatzke June 15, 2026 20:52
@thomaspatzke thomaspatzke reopened this Jun 15, 2026
@thomaspatzke thomaspatzke marked this pull request as ready for review June 15, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants