[Test Coverage] Add 100% test coverage for logs-audit command#1411
[Test Coverage] Add 100% test coverage for logs-audit command#1411github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
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>
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
Coverage comparison generated by |
There was a problem hiding this comment.
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.tswith mocked dependencies to coverauditCommanderror 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 (
sourceoption) andshouldLogsuppression for JSON.
Comments suppressed due to low confidence (1)
src/commands/logs-audit.test.ts:285
- Using
anyin the JSON parsing assertions will trigger@typescript-eslint/no-explicit-anywarnings. Consider typingparsed(e.g., as an array of objects with adecisionfield) 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; |
There was a problem hiding this comment.
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.
| const options = { format: 'unknown' as any } as AuditCommandOptions; | |
| const options = { format: 'unknown' } as unknown as AuditCommandOptions; |
|
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 Overall: PASS
|
Smoke Test Results
Overall: PASS
|
Chroot Version Comparison Results
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.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results
Warning
|
Summary
This PR adds comprehensive unit tests for
src/commands/logs-audit.ts, bringing it from 0% to 100% statement coverage.Coverage Improvement
commands/logs-audit.tsWhat's Tested
The new test file
src/commands/logs-audit.test.ts(18 tests) covers:Error Paths
Output Formats
Filtering
--rule)--domain)--decision)error:transaction-end-before-headersoperational entriesOutput Details
discoverAndSelectSourceshouldLogcallback correctly suppresses logs for JSON formatTest 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