Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Addresses 9 code review comments from PR #118 focusing on code duplication, type safety, and edge case handling in the new awf logs stats and awf logs summary commands.

Changes

Type consolidation

  • Moved duplicate StatsFormat/SummaryFormat type definitions to shared LogStatsFormat in types.ts
  • Both command-specific types now alias the shared type

Reduced duplication

  • Extracted format validation logic into validateFormat() helper (eliminates 3 identical validation blocks)
  • Refactored 50+ lines of duplicated command handler logic into logs-command-helpers.ts with:
    • discoverAndSelectSource() - handles log source discovery and selection with conditional logging
    • loadLogsWithErrorHandling() - wraps aggregation with error handling

Type safety improvements

  • Added runtime validation for source.path and source.containerName before use (replaces non-null assertions)
  • Throws clear error messages when required fields missing

Edge case fixes

  • Guard against -Infinity in formatStatsPretty() when all domains filtered out
  • Fix domain count discrepancy in markdown format by showing "(X valid)" when "-" domain present

Code quality

  • Simplified chalk fallback using Proxy pattern instead of 6-property object literal
  • Documented intentional logging behavior difference between stats (logs for non-JSON) and summary (logs only for pretty)
// Before: duplicate validation in 3 places
if (!validFormats.includes(options.format)) {
  logger.error(`Invalid format: ${options.format}. Must be one of: ${validFormats.join(', ')}`);
  process.exit(1);
}

// After: single helper
validateFormat(options.format, validFormats);

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Move duplicate StatsFormat/SummaryFormat types to shared LogStatsFormat in types.ts
- Simplify colorize fallback using Proxy pattern instead of object literal
- Add null checks for source.path and source.containerName before usage
- Extract duplicated format validation into validateFormat helper function
- Refactor duplicated command handler logic into shared logs-command-helpers module
- Document intentional logging suppression difference between stats and summary commands
- Fix uniqueDomains count discrepancy by showing valid domain count when "-" present
- Add guard for empty sortedDomains to prevent -Infinity in maxDomainLen calculation

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Add commands for firewall log statistics and summaries refactor: address code review feedback on logs stats/summary commands Dec 19, 2025
Copilot AI requested a review from Mossaka December 19, 2025 08:54
@Mossaka Mossaka added the smoke label Dec 19, 2025
@github-actions
Copy link

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link

💥 WHOOSH! Smoke Claude springs into action on this pull request! [Panel 1 begins...]

@Mossaka Mossaka marked this pull request as ready for review December 19, 2025 17:52
@github-actions
Copy link

Smoke Test: Copilot Engine - PASS

GitHub MCP:

File Writing:
Bash Tool:

📰 BREAKING: Report filed by Smoke Copilot fer issue #126 🗺️

@github-actions
Copy link

Smoke Test Results - Claude Engine

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP: Fetched recent PRs successfully
  • ✅ File Writing: Created /tmp/gh-aw/agent/smoke-test-claude-20378122408.txt
  • ✅ Bash Tool: Verified file contents
  • ✅ Playwright MCP: Navigated to GitHub (title: "GitHub · Change is constant. GitHub keeps you ahead. · GitHub")

Status: PASS

💥 [THE END] — Illustrated by Smoke Claude fer issue #126 🗺️

@Mossaka Mossaka merged commit 0c2b125 into feat/logs-stats-summary Dec 19, 2025
16 checks passed
@Mossaka Mossaka deleted the copilot/sub-pr-118 branch December 19, 2025 20:48
Mossaka added a commit that referenced this pull request Dec 19, 2025
* feat: add `awf logs stats` and `awf logs summary` commands

Add built-in log aggregation and summary generation to reduce complexity
of parsing firewall logs in GitHub Actions workflows.

New commands:
- `awf logs stats` - Show aggregated statistics (default: pretty format)
- `awf logs summary` - Generate summary report (default: markdown format)

Both commands support --format json|markdown|pretty for flexible output.

Example GitHub Actions usage:
  awf logs summary >> $GITHUB_STEP_SUMMARY

This replaces 150+ lines of custom JavaScript log parsing with a single command.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor: address code review feedback on logs stats/summary commands (#126)

* Initial plan

* refactor: address code review comments from PR #118

- Move duplicate StatsFormat/SummaryFormat types to shared LogStatsFormat in types.ts
- Simplify colorize fallback using Proxy pattern instead of object literal
- Add null checks for source.path and source.containerName before usage
- Extract duplicated format validation into validateFormat helper function
- Refactor duplicated command handler logic into shared logs-command-helpers module
- Document intentional logging suppression difference between stats and summary commands
- Fix uniqueDomains count discrepancy by showing valid domain count when "-" present
- Add guard for empty sortedDomains to prevent -Infinity in maxDomainLen calculation

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
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