Skip to content

[Test Coverage] Add 100% test coverage for logs-audit command#1411

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
test-coverage/logs-audit-command-782ad793d7da44b7
Draft

[Test Coverage] Add 100% test coverage for logs-audit command#1411
github-actions[bot] wants to merge 1 commit intomainfrom
test-coverage/logs-audit-command-782ad793d7da44b7

Conversation

@github-actions
Copy link
Contributor

Summary

This PR adds comprehensive unit tests for src/commands/logs-audit.ts, bringing it from 0% to 100% statement coverage.

Coverage Improvement

File Before After
commands/logs-audit.ts 0% 100% statements, 95.65% branches
Overall 80.53% 83.86% (+3.33%)

What's Tested

The new test file src/commands/logs-audit.test.ts (18 tests) covers:

Error Paths

  • Exit with error when no log entries found
  • Exit with error when no policy manifest found

Output Formats

  • JSON format: correct structure with domain, decision, matchedRule
  • Markdown format: policy summary, rule evaluation table
  • Pretty format: rule evaluation display
  • Default fallback to pretty for unrecognized formats

Filtering

  • Filter by rule ID (--rule)
  • Filter by domain — case-insensitive substring match (--domain)
  • Filter by decision=allowed or denied (--decision)
  • Automatic exclusion of error:transaction-end-before-headers operational entries

Output Details

  • Markdown denied requests section (capped at 50 rows with overflow count)
  • Markdown policy flags: SSL Bump, DLP, Host Access status
  • Pretty denied requests section (capped at 20 rows with overflow count)
  • Source option passed correctly to discoverAndSelectSource
  • shouldLog callback correctly suppresses logs for JSON format

Test Approach

All external dependencies are mocked (logs-command-helpers, log-aggregator, audit-enricher, logger), ensuring tests are fast and deterministic with no filesystem or network I/O.

Validation

  • ✅ All 18 new tests pass
  • ✅ All pre-existing 1167 tests continue to pass (3 pre-existing failures unrelated to this PR)
  • ✅ Linter: 0 errors
  • ✅ Coverage thresholds maintained

AI generated by Weekly Test Coverage Improver

Add comprehensive tests for src/commands/logs-audit.ts, covering:
- auditCommand with all three output formats (json, markdown, pretty)
- Error cases: no log entries found, no policy manifest found
- Filtering by rule ID, domain (case-insensitive), and decision
- Exclusion of error:transaction-end-before-headers entries
- Markdown output details: denied requests table, 50-row cap, policy flags
- Pretty output details: denied requests section, 20-row cap
- Source option and shouldLog callback behavior

Coverage improvement:
- logs-audit.ts: 0% to 100% statements (95.65% branches)
- Overall: 80.53% to 83.86% statements (+3.33%)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants