Skip to content

test-quality-sentinel: fix TestMain misclassification, add goleak detection and goroutine-leak guards#47891

Merged
pelikhan merged 4 commits into
mainfrom
copilot/optimize-agentic-workflow
Jul 25, 2026
Merged

test-quality-sentinel: fix TestMain misclassification, add goleak detection and goroutine-leak guards#47891
pelikhan merged 4 commits into
mainfrom
copilot/optimize-agentic-workflow

Conversation

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

The workflow incorrectly treated func TestMain(m *testing.M) as a behavioral test function, polluting go-new-test-funcs.txt and the awk stats counters. Infrastructure-only PRs (e.g. adding goleak.VerifyTestMain) had no defined scoring path, forcing the agent to improvise a 70/100 score by judgment each time.

Workflow fixes (test-quality-sentinel.md)

Pre-fetch step:

  • Excludes TestMain from go-new-test-funcs.txt via grep -v "^\+func TestMain\b"
  • Adds go-testmain-funcs.txt — infrastructure entries captured separately
  • Adds go-goleak-entries.txt — detects goleak.VerifyTestMain as a quality signal
  • awk stats: if (test_name == "TestMain") test_name="" to skip infrastructure from counts

Prompt:

  • Step 2: separates TestMain infrastructure from behavioral func Test* functions; defines "infrastructure-only PR"
  • Step 4: goleak.VerifyTestMain classified as design_test / behavioral_contract / high_value — no traditional assertions required
  • Step 5: inflation scoring exempt for TestMain-only files
  • Step 6: infrastructure-only PR path → Score: N/A, approve when no hard violations
  • Step 8: explicit APPROVE verdict for infrastructure-only PRs
  • Guidelines: goroutine-leak guard and infrastructure-only calibration rules

Repository test quality

  • Adds go.uber.org/goleak v1.3.0
  • pkg/parser: upgrades no-op TestMain to goleak.VerifyTestMain
  • pkg/workflow: new test_main_test.go with goleak.VerifyTestMain, covering all ~100 unit tests

Run: https://github.com/github/gh-aw/actions/runs/30143146258

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.03 AIC · ⌖ 8.45 AIC · ⊞ 7.1K ·
Comment /souschef to run again

…ection, improve scoring

- Pre-fetch: exclude TestMain from go-new-test-funcs.txt, add go-testmain-funcs.txt and go-goleak-entries.txt
- Pre-fetch awk: skip TestMain entries from stats so they don't pollute test counts
- Prompt Step 1: reference new pre-fetched files (testmain-funcs, goleak-entries)
- Prompt Step 2: distinguish behavioral tests from TestMain infrastructure
- Prompt Step 4: classify goleak.VerifyTestMain as design invariant (high_value, behavioral_contract)
- Prompt Step 5: skip inflation scoring for TestMain-only files
- Prompt Step 6: add infrastructure-only PR path (no numeric score, approve on no violations)
- Prompt Step 8: add APPROVE verdict for infrastructure-only PRs
- Guidelines: add goroutine-leak guard and infrastructure-only PR calibration rules
- Add go.uber.org/goleak v1.3.0 dependency
- pkg/parser: upgrade TestMain to use goleak.VerifyTestMain
- pkg/workflow: add test_main_test.go with goleak.VerifyTestMain

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title optimize test-quality-sentinel: fix TestMain handling, add goleak detection and goroutine-leak guards test-quality-sentinel: fix TestMain misclassification, add goleak detection and goroutine-leak guards Jul 25, 2026
Copilot AI requested a review from pelikhan July 25, 2026 03:11
@pelikhan
pelikhan marked this pull request as ready for review July 25, 2026 03:13
Copilot AI review requested due to automatic review settings July 25, 2026 03:13
@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer failed during the skills-based review.

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

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

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

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

Improves test-quality classification for TestMain infrastructure and adds package-wide goroutine leak detection.

Changes:

  • Separates TestMain and goleak signals from behavioral tests.
  • Adds infrastructure-only scoring and approval guidance.
  • Enables goleak checks for parser and workflow tests.
Show a summary per file
File Description
.github/workflows/test-quality-sentinel.md Adds infrastructure detection and scoring rules.
.github/workflows/test-quality-sentinel.lock.yml Recompiles the workflow.
pkg/parser/frontmatter_hash_test_main_test.go Enables parser goleak detection.
pkg/workflow/test_main_test.go Enables workflow goleak detection.
go.mod Adds the goleak dependency.
go.sum Adds goleak checksums.

Review details

Tip

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

Comments suppressed due to low confidence (2)

.github/workflows/test-quality-sentinel.md:72

  • This unanchored search also records removed lines and unchanged diff context. A PR that removes goleak.VerifyTestMain can therefore be reported as adding a positive leak guard. Restrict the signal to added diff lines.
        grep -E "goleak\.VerifyTestMain" /tmp/gh-aw/agent/test-diff.txt \

.github/workflows/test-quality-sentinel.md:344

  • “Approve without hesitation” applies to every PR containing a goleak guard, including mixed PRs with failing behavioral tests or hard violations, and conflicts with the guarded approval rule in Step 8. Treat goleak as a positive signal, but only approve infrastructure-only PRs when no hard violations exist; mixed PRs must still use normal scoring.
- **Goroutine-leak guards**: `TestMain` with `goleak.VerifyTestMain` is an unconditional design invariant — approve without hesitation; note it as a positive quality signal
  • Files reviewed: 5/6 changed files
  • Comments generated: 4
  • Review effort level: Medium

Comment on lines +69 to +70
grep -E "^\+func TestMain\b" /tmp/gh-aw/agent/test-diff.txt \
> /tmp/gh-aw/agent/go-testmain-funcs.txt || true

**Infrastructure vs. behavioral**: `TestMain(m *testing.M)` entries in `go-testmain-funcs.txt` are test infrastructure, not behavioral test cases. Do not score them as test functions. Instead, note them separately in the report and credit any `goleak.VerifyTestMain` usage (see `go-goleak-entries.txt`) as a goroutine-leak design invariant.

If `go-new-test-funcs.txt` is empty and `go-testmain-funcs.txt` is non-empty, this is an **infrastructure-only PR** — see the scoring guidance in Step 6.

Thresholds: `>=80 ✅ Excellent`, `60-79 ⚠️ Acceptable`, `40-59 🔶 Needs improvement`, `<40 ❌ Poor`.

**Infrastructure-only PRs**: If `go-new-test-funcs.txt` is empty (no behavioral `func Test*` functions) but `go-testmain-funcs.txt` is non-empty (only `TestMain` infrastructure added), skip the numeric score formula and assign **Score: N/A — Infrastructure**. Do not fail the PR on implementation ratio (there are no behavioral tests to evaluate). Still flag hard violations (missing build tags, go mock library usage). If `go-goleak-entries.txt` is non-empty, report it as a quality improvement and approve.
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 mentioned this pull request Jul 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

🏗️ Test Quality Score: N/A — Infrastructure

Analyzed 0 behavioral test(s). This PR adds only TestMain infrastructure — no behavioral func Test* functions were added or modified.

📊 Metrics
Metric Value
Analyzed 0 (Go: 0, JS: 0)
✅ Design 0
⚠️ Implementation 0
Edge/error coverage 0
Duplicate clusters 0
Inflation N/A (infrastructure only)
🚨 Violations 0

Infrastructure added:

File Content Build Tag
pkg/workflow/test_main_test.go TestMain + goleak.VerifyTestMain(m) //go:build !integration
pkg/parser/frontmatter_hash_test_main_test.go TestMain + goleak.VerifyTestMain(m) //go:build !integration

🟢 Goroutine-Leak Guards

goleak.VerifyTestMain(m) was added to 2 packages (pkg/workflow, pkg/parser). This is a package-level design invariant: any future test that leaks a goroutine will cause the test suite for that package to fail. Positive quality signal.

Verdict

Passed. Infrastructure-only PR. No behavioral test ratio to evaluate. No violations. Goroutine-leak guards added.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 37.8 AIC · ⌖ 13.1 AIC · ⊞ 7.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: Infrastructure only. goleak.VerifyTestMain added to pkg/workflow and pkg/parser — goroutine-leak guards installed. No violations.

@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 PR Review

The workflow fixes and goroutine-leak guard additions are well-structured and correct. One blocking issue found:

go.uber.org/goleak listed as // indirect in go.mod — this package is directly imported in test files; // indirect is incorrect and should be removed by running go mod tidy.

All other changes look good:

  • TestMain exclusion from behavioral test counters is correct
  • goleak.VerifyTestMain integration is clean
  • New pkg/workflow/test_main_test.go has proper build tag and minimal, correct implementation
  • Workflow prompt updates are clear and well-scoped

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 20.3 AIC · ⌖ 4.56 AIC · ⊞ 5K

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

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.

`go.uber.org/goleak` is marked `// indirect` but is a direct dependency.

This package is directly imported in `pkg/parser/frontmatter_hash_test_main_test.go` and `pkg/workflow/test_main_test.go`. Running `go mod tidy` will remove the `// indirect` annotation.

Please run `go mod tidy` to fix this.

@copilot please address this.

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

Two issues need fixing before merge

1. not run — is directly imported in test files but marked in go.mod. CI tidy-enforcement will fail.

2. Goleak detection grep has no anchor (correctness bug) — grep -E "goleak\.VerifyTestMain" matches both added and removed diff lines. A PR that deletes goleak will still get approved as a quality improvement. Fix: anchor to ^+.

Other observations (non-blocking)
  • pkg/workflow/test_main_test.go uses package workflow_test (external test package). This is valid — Go compiles both into one binary and there can only be one TestMain — but it means the TestMain controls the whole binary regardless. No compile error, just worth confirming intentionally.
  • No goleak.IgnoreTopFunction options are set. If any third-party library (otel, etc.) leaves goroutines running, every test run will start failing. This is a future maintenance risk, not a blocker now.

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

Comments that could not be inline-anchored

go.mod:105

goleak is marked // indirect but is directly imported: the package is explicitly used in pkg/parser and pkg/workflow test files, so go mod tidy was not run after adding the import.

<details>
<summary>💡 Suggested fix</summary>

Remove the // indirect comment from the entry:

go.uber.org/goleak v1.3.0

Then run go mod tidy. Any CI that enforces tidy will fail on this mismatch.

</details>

.github/workflows/test-quality-sentinel.md:36

Goleak detection grep matches removed lines too: the pattern grep -E &quot;goleak\.VerifyTestMain&quot; has no ^+ anchor, so it will match both added (+) and removed (-) lines from the diff, causing false positive quality credit when goleak is being deleted from a file.

<details>
<summary>💡 Suggested fix</summary>

Anchor to added lines only:

grep -E &quot;^\+.*goleak\.VerifyTestMain&quot; /tmp/gh-aw/agent/test-diff.txt   &gt; /tmp/gh-aw/agent/go-goleak-entries.txt || true

Without this, …

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the skill, confirm the branch is up to date, address unresolved review feedback, and rerun or retrigger checks as needed on the latest HEAD.

Unresolved review feedback:

Failed checks on the latest head:

Run: https://github.com/github/gh-aw/actions/runs/30143146258

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.03 AIC · ⌖ 8.45 AIC · ⊞ 7.1K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…in checks

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the skill, confirm the branch is up to date, address unresolved review feedback, and rerun or retrigger checks as needed on the latest HEAD.

Unresolved review feedback:...

Addressed in commit dd21fea.

I ran the requested workflow skill, confirmed the branch is up to date (includes merge from main), fixed the unresolved test-quality-sentinel review feedback, and validated the goroutine-leak regressions seen in failing jobs.

Latest HEAD checks were retriggered by the push, but current runs for dd21fea7bd204c196fd990160b54c9869e984f5b are in action_required state (no jobs scheduled yet), so there are no runnable failed jobs to rerun at this moment.

Copilot AI requested a review from gh-aw-bot July 25, 2026 04:31
@pelikhan
pelikhan merged commit e804026 into main Jul 25, 2026
24 checks passed
@pelikhan
pelikhan deleted the copilot/optimize-agentic-workflow branch July 25, 2026 04:40
@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants