Skip to content

Add goleak-based package leak checks for pkg/cli and pkg/console tests#47865

Merged
pelikhan merged 3 commits into
mainfrom
copilot/add-goleak-to-test-packages
Jul 25, 2026
Merged

Add goleak-based package leak checks for pkg/cli and pkg/console tests#47865
pelikhan merged 3 commits into
mainfrom
copilot/add-goleak-to-test-packages

Conversation

Copilot AI commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

The repo has goroutine-heavy code paths but no CI guard for leaked goroutines in tests. This change adds package-level goleak verification in the first two target packages (pkg/cli, pkg/console) to catch regressions early.

  • Test lifecycle guardrails

    • Add go.uber.org/goleak to test dependencies.
    • Enable package-level leak verification via goleak.VerifyTestMain(...) in:
      • pkg/cli
      • pkg/console
  • pkg/cli TestMain integration

    • Migrate existing TestMain to run under goleak.VerifyTestMain.
    • Preserve existing .github test-artifact cleanup by moving it into goleak.Cleanup(...).
  • pkg/console coverage

    • Introduce a unit-test TestMain for pkg/console that applies goleak.VerifyTestMain.
func TestMain(m *testing.M) {
	goleak.VerifyTestMain(m)
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add goleak to goroutine-heavy test packages for CI Add goleak-based package leak checks for pkg/cli and pkg/console tests Jul 24, 2026
Copilot AI requested a review from pelikhan July 24, 2026 21:53
@github-actions

Copy link
Copy Markdown
Contributor

Triage | Category: test | Risk: low | Score: 30/100 (impact:10, urgency:10, quality:10)

Recommended action: batch_review (Batch C: Go test additions) — Adds goleak leak checks for pkg/cli and pkg/console; draft, no CI yet.

Score breakdown: impact=10 (test quality), urgency=10 (draft), quality=10 (no CI yet)

Generated by 🔧 PR Triage Agent · sonnet46 · 31.3 AIC · ⌖ 5.51 AIC · ⊞ 5.7K ·

@pelikhan
pelikhan marked this pull request as ready for review July 25, 2026 02:33
Copilot AI review requested due to automatic review settings July 25, 2026 02:33

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

Adds package-level goroutine leak detection to unit tests in pkg/cli and pkg/console.

Changes:

  • Adds goleak test dependency.
  • Integrates leak checks into both packages’ TestMain.
  • Preserves CLI test-artifact cleanup.
Show a summary per file
File Description
pkg/console/test_main_test.go Adds package-level leak verification.
pkg/cli/test_main_test.go Adds leak verification while preserving cleanup.
go.mod Declares the goleak dependency.
go.sum Adds dependency checksums.

Review details

Tip

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

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

Comment thread go.mod Outdated
go.opentelemetry.io/otel v1.44.0 // indirect
go.opentelemetry.io/otel/metric v1.44.0 // indirect
go.opentelemetry.io/otel/trace v1.44.0 // indirect
go.uber.org/goleak v1.3.0 // indirect
@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #47865 does not have the 'implementation' label and has only 23 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@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.

Review: Add goleak-based package leak checks

The implementation is correct — goleak.VerifyTestMain is wired properly in both packages, and the goleak.Cleanup pattern in pkg/cli correctly preserves the existing artifact cleanup.

One issue to address (non-blocking): go.uber.org/goleak is added as // indirect in go.mod, but it is directly imported by test files in pkg/cli and pkg/console. Direct test imports are direct dependencies. Running go mod tidy should promote it to the direct block and remove the // indirect marker. CI go mod tidy checks will flag this.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 12.3 AIC · ⌖ 7.3 AIC · ⊞ 5K

@github-actions github-actions Bot mentioned this pull request Jul 25, 2026

@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 — one consistency issue found between the two new TestMain files.

📋 Key Themes & Highlights

Key Themes

  • Build tag inconsistency: pkg/console/test_main_test.go has //go:build !integration but pkg/cli/test_main_test.go does not, so goleak fires on different test modes across the two packages.
  • go.mod indirect marker: go.uber.org/goleak is a direct test dependency and should not be marked // indirect (already noted in an existing review comment).

Positive Highlights

  • ✅ Clean use of goleak.Cleanup(...) to preserve existing filesystem teardown while integrating leak detection.
  • ✅ Minimal, surgical diff — only the two target packages are touched.
  • goleak.VerifyTestMain(m) is the idiomatic pattern; no custom wiring needed.

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

Comment thread pkg/cli/test_main_test.go
@@ -17,15 +19,12 @@ func TestMain(m *testing.M) {
panic("Failed to get current working directory: " + err.Error())

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.

[/codebase-design] Missing //go:build !integration build tag — pkg/console/test_main_test.go has it but pkg/cli/test_main_test.go does not. This means goleak runs during integration tests for pkg/cli but not for pkg/console, creating inconsistent leak coverage.

💡 Suggested fix

Add the build constraint at the top of pkg/cli/test_main_test.go to match pkg/console:

(go/redacted):build !integration

package cli

Or remove the tag from pkg/console/test_main_test.go if goleak should cover integration test runs in both packages.

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 70/100 — Acceptable

Analyzed 2 test infrastructure entry point(s): 2 design, 0 implementation, 0 violation(s).
Note: No func Test* behavioral test functions were added — only TestMain goroutine-leak guards. Score is adjusted for infrastructure-only changes.

📊 Metrics (2 TestMain entries)
Metric Value
Analyzed 2 (Go: 2, JS: 0)
✅ Design 2 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 0 (0%)
Duplicate clusters 0
Inflation No
🚨 Violations 0
Test File Classification Issues
TestMain (goleak) pkg/cli/test_main_test.go design_test None
TestMain (goleak) pkg/console/test_main_test.go design_test None

Analysis Notes

  • Both files include //go:build !integration on line 1. ✅
  • No Go mock libraries (gomock, testify/mock). ✅
  • pkg/cli/test_main_test.go (modified): replaces the previous TestMain setup with goleak.VerifyTestMain, adding goroutine-leak detection across all unit tests in the cli package. Includes a cleanup callback to remove .github/aw/actions-lock.json artifacts created during tests. ✅
  • pkg/console/test_main_test.go (added): new TestMain wrapping the entire console unit suite with goleak.VerifyTestMain. Enforces the invariant that no goroutine is leaked by any test in the package. ✅
  • No new behavioral func Test* functions were added. The edge/error score (0%) reflects that — not a concern for infrastructure-only changes.
  • Test inflation: pkg/console/test_main_test.go is a new 13-line file with no corresponding production file delta — not flagged (infrastructure file, no paired source).

Verdict

Passed. 0% implementation tests (threshold: 30%). No guideline violations. These changes improve test reliability by enforcing goroutine-leak detection package-wide — a high-value design invariant addition.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 29.1 AIC · ⌖ 7.79 AIC · ⊞ 7K ·
Comment /review 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.

✅ Test Quality Sentinel: 70/100. 0% implementation tests (threshold: 30%). No guideline violations. Both TestMain entries use goleak with proper build tags.

@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.

REQUEST_CHANGES — one build-constraint bug must be fixed before merge.

Missing !js && !wasm build tags in pkg/console/test_main_test.go

The new TestMain only carries //go:build !integration, but go.uber.org/goleak doesn't compile for js/wasm targets. Every other wasm-incompatible test in pkg/console (e.g., confirm_test.go, prompt_form_test.go) uses //go:build !integration && !js && !wasm. Without the matching constraint here, any wasm/js build of the test binary will fail to compile.

The go.mod indirect-vs-direct classification is also wrong (goleak is directly imported by test files), but that's a pre-existing CI concern already noted in comments.

🔎 Code quality review by PR Code Quality Reviewer · sonnet46 · 35.6 AIC · ⌖ 4.61 AIC · ⊞ 5.7K
Comment /review to run again

@@ -0,0 +1,13 @@
//go:build !integration

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.

Missing !js && !wasm build constraints: goleak.VerifyTestMain is imported, but go.uber.org/goleak is not wasm/js-compatible. Other test files in this package (e.g., confirm_test.go, prompt_form_test.go) gate themselves with !js && !wasm, but this new TestMain does not—breaking compilation for those targets.

💡 Suggested fix

Change line 1 from:

(go/redacted):build !integration

to:

(go/redacted):build !integration && !js && !wasm

This matches the constraint pattern in the other wasm-incompatible test files in pkg/console.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Ran go mod tidygoleak is now in the direct require block in go.mod (commit fix: run go mod tidy to promote goleak to direct dependency).

@pelikhan
pelikhan merged commit c55a6d1 into main Jul 25, 2026
24 checks passed
@pelikhan
pelikhan deleted the copilot/add-goleak-to-test-packages branch July 25, 2026 03:28
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.3

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.

[deep-report] Add goleak to goroutine-heavy test packages to catch leaks in CI

3 participants