Skip to content

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

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

[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
Copy Markdown
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>
@Mossaka Mossaka marked this pull request as ready for review March 25, 2026 16:53
@Mossaka Mossaka self-requested a review as a code owner March 25, 2026 16:53
Copilot AI review requested due to automatic review settings March 25, 2026 16:53
@Mossaka Mossaka closed this Mar 25, 2026
@Mossaka Mossaka reopened this Mar 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor Author

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 82.69% 85.92% 📈 +3.23%
Statements 82.35% 85.79% 📈 +3.44%
Functions 81.11% 86.36% 📈 +5.25%
Branches 75.88% 78.56% 📈 +2.68%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 86.3% → 86.7% (+0.44%) 85.7% → 86.1% (+0.42%)
src/commands/logs-audit.ts 0.0% → 100.0% (+100.00%) 0.0% → 100.0% (+100.00%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a full unit test suite for the awf logs audit command to substantially improve coverage and lock in behavior across output formats, filtering, and failure paths.

Changes:

  • Added src/commands/logs-audit.test.ts with mocked dependencies to cover auditCommand error paths and success paths.
  • Added assertions for JSON/Markdown/Pretty output behaviors, including filtering options and operational-entry suppression.
  • Added coverage for source selection wiring (source option) and shouldLog suppression for JSON.
Comments suppressed due to low confidence (1)

src/commands/logs-audit.test.ts:285

  • Using any in the JSON parsing assertions will trigger @typescript-eslint/no-explicit-any warnings. Consider typing parsed (e.g., as an array of objects with a decision field) to keep tests type-safe and lint-clean.
      const parsed = JSON.parse(output);
      expect(parsed.every((e: any) => e.decision === 'allowed')).toBe(true);
      expect(parsed).toHaveLength(2);
    });

    it('should filter by decision=denied', async () => {
      setupMocksWithMultipleEntries();

      const options: AuditCommandOptions = { format: 'json', decision: 'denied' };
      await auditCommand(options);

      const output = mockConsoleLog.mock.calls[0][0] as string;
      const parsed = JSON.parse(output);
      expect(parsed.every((e: any) => e.decision === 'denied')).toBe(true);
      expect(parsed).toHaveLength(1);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

setupMocks(entries);

// Cast to bypass TypeScript to test the default branch
const options = { format: 'unknown' as any } as AuditCommandOptions;
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as any here triggers the repo's @typescript-eslint/no-explicit-any lint warning (rule is configured as warn for src/**/*.ts). Prefer avoiding any by casting through unknown (or adding a targeted eslint-disable with justification) so the test suite stays warning-free.

This issue also appears on line 271 of the same file.

Suggested change
const options = { format: 'unknown' as any } as AuditCommandOptions;
const options = { format: 'unknown' } as unknown as AuditCommandOptions;

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor Author

Smoke Test Results — run 23553272110

✅ GitHub MCP — #1420 "fix: restore GITHUB_API_URL in agent container when api-proxy is enabled" | #1419 "fix: exclude GITHUB_API_URL from agent container when api-proxy is enabled" (both by @Copilot)
✅ Playwright — github.com title contains "GitHub"
✅ File write — /tmp/gh-aw/agent/smoke-test-copilot-23553272110.txt created
✅ Bash verify — file read back successfully

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot for issue #1411

@github-actions
Copy link
Copy Markdown
Contributor Author

Smoke Test Results

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude for issue #1411

@github-actions
Copy link
Copy Markdown
Contributor Author

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.14.0 v20.20.1
Go go1.22.12 go1.22.12

Result: Some versions differ between host and chroot. Go matches, but Python and Node.js are on different versions. The chroot environment uses the system-installed versions (from Ubuntu 22.04 base), while the host runner has newer toolchain versions installed.

Tested by Smoke Chroot for issue #1411

@github-actions
Copy link
Copy Markdown
Contributor Author

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #1411 ·

@github-actions
Copy link
Copy Markdown
Contributor Author

Smoke Test Results

  • PR titles: "docs: Fix proxy env var docs and add missing CLI flags"; "fix: write apiKeyHelper to ~/.claude/settings.json for Claude Code v2.1.81+"
    1. GitHub MCP (last 2 merged PRs): ✅
    1. safeinputs-gh PR query: ❌ (tool not available in this run)
    1. Playwright title contains "GitHub": ✅
    1. Tavily web search: ❌ (Tavily tool not available in this run)
    1. File write + 6) cat verify: ✅
    1. Discussion query + mystical discussion comment: ❌ (required tools/endpoint not available)
    1. npm ci && npm run build: ✅
  • Overall status: FAIL

🔮 The oracle has spoken through Smoke Codex

Warning

⚠️ Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • ab.chatgpt.com
  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"
    - "registry.npmjs.org"

See Network Configuration for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants