Skip to content

Refactor audit report largefunc slice in pkg/cli - #47262

Merged
pelikhan merged 3 commits into
mainfrom
copilot/lint-monster-refactor-function-lengths
Jul 22, 2026
Merged

Refactor audit report largefunc slice in pkg/cli#47262
pelikhan merged 3 commits into
mainfrom
copilot/lint-monster-refactor-function-lengths

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the lint-monster function-length slice in pkg/cli by breaking up the highest-impact audit-report functions without changing their external behavior. The refactor targets the audit reporting path specifically and reduces the assigned largefunc findings by turning long mixed-responsibility functions into small coordinators over focused helpers.

  • Audit report assembly

    • Split buildAuditData into narrow helpers for:
      • overview construction
      • metric fallback resolution
      • job/error extraction
      • narrative assembly
      • final AuditData composition
    • Kept the existing data flow intact while making fallback and enrichment steps independently readable.
  • Findings and recommendations

    • Refactored generateFindings into focused helpers for:
      • failure description selection
      • performance findings
      • tooling findings
      • firewall findings
      • success findings
    • Refactored generateRecommendations into helper-driven branches for:
      • failure follow-up
      • cost/iteration guidance
      • tooling and firewall configuration guidance
      • success-only defaults
  • Console rendering

    • Reworked renderConsole into a thin top-level renderer that delegates to section-specific helpers:
      • overview/context
      • comparison/fingerprint
      • metrics/session/resource usage
      • jobs/prompt
      • actionable sections
      • operational sections
      • policy/experiments/log path
    • Preserved output shape while making each render block isolated and easier to evolve.
  • Focused regression coverage

    • Added targeted tests around extracted formatting logic, including blocked-network descriptions and deterministic experiment ordering in console output.

Example of the new structure:

func renderConsole(data AuditData, logsPath string) {
	auditReportLog.Print("Rendering compact audit report to console")

	renderConsoleOverview(data)
	renderConsoleComparison(data.Comparison)
	renderConsoleFingerprint(data.BehaviorFingerprint)
	renderConsoleMetrics(data.Metrics)
	renderConsoleSession(data.SessionAnalysis)
	renderConsoleTokenUsage(data.FirewallTokenUsage)
	renderConsoleGitHubAPIUsage(data.GitHubRateLimitUsage)
	renderConsoleJobs(data.Jobs)
	renderConsolePrompt(data.PromptAnalysis)
	renderConsoleActionableSections(data)
	renderConsoleOperationalSections(data)
	renderConsolePolicyAndExperiments(data)
	renderConsoleLogsPath(logsPath)
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor long functions in pkg/cli for lint compliance Refactor audit report largefunc slice in pkg/cli Jul 22, 2026
Copilot AI requested a review from pelikhan July 22, 2026 10:24
@pelikhan
pelikhan marked this pull request as ready for review July 22, 2026 10:30
Copilot AI review requested due to automatic review settings July 22, 2026 10:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors audit reporting into focused helpers while preserving report assembly, findings, recommendations, and console output behavior.

Changes:

  • Split audit data assembly and metric fallback logic.
  • Decomposed findings, recommendations, and console rendering.
  • Added focused formatting and ordering tests.
Show a summary per file
File Description
pkg/cli/audit_report.go Extracts audit assembly helpers.
pkg/cli/audit_report_analysis.go Decomposes findings and recommendations.
pkg/cli/audit_report_render.go Splits console rendering by section.
pkg/cli/audit_report_test.go Adds formatting regression tests.

Review details

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Medium

@pelikhan

Copy link
Copy Markdown
Collaborator

/matt

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, inspect the latest PR state, fix the failing check below if needed, and rerun checks once the branch is up to date.

Failed checks:

Generated by 👨‍🍳 PR Sous Chef · gpt54 27.4 AIC · ⌖ 8.1 AIC · ⊞ 5.5K ·
Comment /souschef to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /codebase-design and /tdd — commenting with improvement suggestions; no blocking correctness issues.

📋 Key Themes & Highlights

Key Themes

  • Thin pass-through wrappers: buildAuditAssessments and appendToolingRecommendations group calls without adding depth — opportunities to either inline or deepen remain.
  • auditDataInputs carries forwarding fields: metrics and mcpToolUsage are in the struct only to thread them into buildSessionAnalysis/buildMCPServerHealth; pre-computing those outside assembleAuditData would let the struct hold only results.
  • Test scope: the new TestRenderConsoleExperimentsSorted goes through the full renderConsole path and swaps os.Stderr globally — testing the extracted renderConsoleExperiments helper directly would be tighter and parallel-safe.
  • appendToolingRecommendations naming mismatch: it handles missing tools, MCP failures and firewall blocks — inconsistent with the single-concern pattern of the rest of the family.

Positive Highlights

  • ✅ The renderConsole decomposition is clean and the naming is consistent — each helper does exactly what its name says.
  • buildFailureFindingDescription is a genuine improvement: early-return structure and named constants make the branching readable.
  • generateErrorVolumeFindings and generateFirewallFindings converting to direct []Finding{{...}} returns is idiomatic Go.
  • TestBuildBlockedNetworkFindingDescription covers all four switch branches — solid table-driven coverage.
  • lookupFallbackMetrics correctly moves the logsPath == "" guard to the top, eliminating a repeated condition.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 78.5 AIC · ⌖ 8.1 AIC · ⊞ 6.7K
Comment /matt to run again

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, inspect the latest PR state, fix the failing check below if needed, and rerun checks once the branch is up to date.

Failed checks:...

Investigated the failure: run 29911655000 / job 88897507342 was on older SHA 4c22df7 and failed on a network timeout while resolving docker.io/library/alpine:3.21, not on the audit-report refactor itself. Current HEAD 16581fe already has Alpine Container Test passing on run 29913946230 / job 88903243960, and local go test ./pkg/cli/..., make fmt, make lint, make test-unit, and make test all passed. No code change or new commit was needed here; if you want a fresh CI signal, a maintainer will need to re-trigger workflows manually.

Copilot AI requested a review from gh-aw-bot July 22, 2026 11:18
@pelikhan
pelikhan merged commit 933d01c into main Jul 22, 2026
30 checks passed
@pelikhan
pelikhan deleted the copilot/lint-monster-refactor-function-lengths branch July 22, 2026 11:27
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.0

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.

[lint-monster] lint-monster: function-length refactoring — pkg/cli slice B

4 participants