Skip to content

Tighten pkg/actionpins spec coverage around formatter edge cases and mapping behavior#47379

Merged
pelikhan merged 4 commits into
mainfrom
copilot/testify-expert-improve-test-quality-yet-again
Jul 22, 2026
Merged

Tighten pkg/actionpins spec coverage around formatter edge cases and mapping behavior#47379
pelikhan merged 4 commits into
mainfrom
copilot/testify-expert-improve-test-quality-yet-again

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

pkg/actionpins/spec_test.go was missing coverage for a few high-value edge cases and had a couple of assertion/organization gaps that reduced failure signal. This update strengthens the spec tests without changing production behavior.

  • Formatter edge cases

    • Added table rows for FormatPinnedActionReference with:
      • empty version comment
      • empty SHA as an explicit panic case
    • This aligns the test with the current API contract: empty SHA is invalid and must not silently produce malformed workflow YAML.
  • Mapping behavior

    • Added a self-mapping case to TestSpec_PublicAPI_ResolveActionPin_AppliesMapping
    • Verifies that repo@ref -> same repo@ref preserves the resolved output while still recording the mapping notification key
  • Assertion upgrades

    • Replaced assert.NoError with require.NoError inside the two require.NotPanics closures
    • Ensures follow-on assertions do not run on invalid state
  • Test organization

    • Wrapped TestSpec_PublicAPI_ResolveActionPin_EmbeddedMatch in a named t.Run for consistency with the rest of the file
{
    name:     "formats reference with empty version comment",
    repo:     "actions/checkout",
    sha:      "abc123",
    version:  "",
    expected: "actions/checkout@abc123 # ",
},
{
    name:      "panics for empty sha",
    repo:      "actions/checkout",
    sha:       "",
    version:   "v4",
    wantPanic: "FormatPinnedActionReference called with empty SHA for repo=actions/checkout version=v4 — this would produce invalid workflow YAML",
}

Generated by 👨‍🍳 PR Sous Chef · gpt54 7.24 AIC · ⌖ 6.95 AIC · ⊞ 7K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve test quality in pkg/actionpins/spec_test.go Tighten pkg/actionpins spec coverage around formatter edge cases and mapping behavior Jul 22, 2026
Copilot AI requested a review from pelikhan July 22, 2026 18:55
@pelikhan
pelikhan marked this pull request as ready for review July 22, 2026 19:02
Copilot AI review requested due to automatic review settings July 22, 2026 19:02

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

Strengthens pkg/actionpins specification tests without changing production behavior.

Changes:

  • Covers formatter empty-version and empty-SHA behavior.
  • Tests self-mapping resolution and notification recording.
  • Improves assertion gating and test organization.
Show a summary per file
File Description
pkg/actionpins/spec_test.go Expands edge-case coverage and improves test failure isolation.

Review details

Tip

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

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

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (57 additions, threshold 100).

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Jul 22, 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: Test Quality Improvements ✅

The changes are correct and well-targeted. Quick verification on key points:

  • Panic message matches the production string in actionpins.go line 260 exactly.
  • Warning key "map:actions/checkout@v4" is the correct output of FormatCacheKey for the self-mapping test.
  • Empty version comment test expectation "actions/checkout@abc123 # " is consistent with the repo@sha # version format contract.
  • require.NoError inside require.NotPanics — valid improvement; t.FailNow() is safe to call from within a NotPanics closure in Go test goroutines.

No blocking issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 22.2 AIC · ⌖ 4.51 AIC · ⊞ 5K

@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 /tdd — changes are test-only, well-structured, and clearly aligned with the spec.

📋 Key Themes & Highlights

Positive Highlights

  • ✅ Panic test correctly uses require.PanicsWithValue with the exact message string
  • require.NoError upgrades inside require.NotPanics closures are the right call — they stop execution on bad state
  • ✅ Self-mapping test properly validates both the resolved value and the warning key — good dual-assertion discipline
  • ✅ Wrapping TestSpec_PublicAPI_ResolveActionPin_EmbeddedMatch in a named t.Run improves consistency and failure readability
  • ✅ Empty-version-comment case ("actions/checkout@abc123 # ") is a useful edge case that pins the trailing-space behaviour explicitly

One Issue Found

A single inline comment was left: the wantPanic/expected fields in the table struct are mutually exclusive but not enforced. A stale copy-paste row could silently skip assertions.

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

},
{
name: "panics for empty sha",
repo: "actions/checkout",

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.

[/tdd] wantPanic and expected are mutually exclusive fields, but the table loop doesn't enforce that — a row with both set will silently skip the expected assertion.

💡 Suggested guard

Add a quick sanity check at the top of the panic branch:

if tt.wantPanic != "" {
    assert.Empty(t, tt.expected, "test case %q: wantPanic and expected are mutually exclusive", tt.name)
    require.PanicsWithValue(t, tt.wantPanic, func() {
        actionpins.FormatPinnedActionReference(tt.repo, tt.sha, tt.version)
    })
    return
}

This makes the mutual-exclusion contract explicit and catches copy-paste mistakes early.

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

REQUEST_CHANGES — 3 issues must be fixed before merging

The test additions cover real gaps but have three concrete problems.

### Blocking issues
  1. Non-hermetic self-mapping test (high): The new sub-test calls ResolveActionPin twice against the real GitHub API. This will fail in air-gapped CI and on rate-limit. Use the testSHAResolver stub already in the file. See inline comment at line 106.

  2. Trailing-space expected value (high): "actions/checkout@abc123 # " canonicalizes a dangling comment marker. If this is intentional production behavior, it needs a comment explaining why; if it is a bug in the implementation, fix it rather than ossifying it in a test. See inline comment at line 33.

  3. Warning assertion lacks negative baseline (medium): The assert.True(t, ctx.Warnings["map:actions/checkout@v4"]) assertion has no corresponding negative check on the no-mapping baseline, so it cannot distinguish a mapping-triggered warning from one that fires unconditionally. See inline comment at line 109.

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

Comments that could not be inline-anchored

pkg/actionpins/spec_test.go:106

Self-mapping sub-test makes real network calls: both baseline and result calls hit the live GitHub API with no stub, making this test non-hermetic and CI-fragile.

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

Use the testSHAResolver already present in this file and inject it via PinContext:

resolver := &amp;testSHAResolver{shas: map[string]string{&quot;actions/checkout@v4&quot;: &quot;abc123&quot;}}
ctx := &amp;actionpins.PinContext{
    Warnings:  make(map[string]bool),
    SHAResolver: resolver,
   …

</details>

<details><summary>pkg/actionpins/spec_test.go:33</summary>

**Expected value has a trailing space after `# `**: the test asserts `&quot;actions/checkout@abc123 # &quot;`a dangling comment marker with whitespacewhich may be documenting a bug rather than valid behavior.

&lt;details&gt;
&lt;summary&gt;💡 Details&lt;/summary&gt;

When `version` is empty, the most defensible outputs are either:
- Omit the comment entirely: `&quot;actions/checkout@abc123&quot;`
- Or emit the marker with a blank: `&quot;actions/checkout@abc123 # &quot;`

If the implementation intentionally emits the trailing space, t</details>

<details><summary>pkg/actionpins/spec_test.go:109</summary>

**Self-mapping warning assertion tests unverified behavior**: the test assumes that an identity mapping (`A→A`) records a warning key, but there is no baseline check showing the key is absent without a mapping.

&lt;details&gt;
&lt;summary&gt;💡 Details&lt;/summary&gt;

The assertion `assert.True(t, ctx.Warnings[&quot;map:actions/checkout@v4&quot;], ...)` is only meaningful if:
1. The implementation actually emits this key for self-mappings, and  
2. The no-mapping baseline does **not** emit it (otherwise the mapping is i</details>

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 95/100 — Excellent

Analyzed 3 test(s): 3 design, 0 implementation, 0 violation(s).

📊 Metrics (3 tests)
Metric Value
Analyzed 3 (Go: 3, JS: 0)
Design 3 (100%)
Implementation 0 (0%)
Edge/error coverage 3 (100%)
Duplicate clusters 0
Inflation N/A (no production file changed)
Violations 0
Test File Classification Issues
FormatPinnedActionReference — formats reference with empty version comment pkg/actionpins/spec_test.go design_test / behavioral_contract None
FormatPinnedActionReference — panics for empty sha pkg/actionpins/spec_test.go design_test / behavioral_contract None
ResolveActionPin_AppliesMapping — self-mapping preserves the same resolved reference pkg/actionpins/spec_test.go design_test / behavioral_contract None

Notes

  • Build tag //go:build !integration present on line 1
  • No Go mock libraries used
  • Two assert.NoError to require.NoError upgrades improve test-failure isolation
  • TestSpec_PublicAPI_ResolveActionPin_EmbeddedMatch wrapped in t.Run(...) — structural improvement, no new assertions added

Verdict

Passed. 0% implementation tests (threshold: 30%). All 3 new test scenarios enforce behavioral contracts with edge/error coverage.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 34.6 AIC · ⌖ 11 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: 95/100. 0% implementation tests (threshold: 30%). All new test scenarios enforce behavioral contracts with edge/error coverage.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address unresolved review feedback, and rerun checks once the branch is up to date.

Generated by 👨‍🍳 PR Sous Chef · gpt54 7.24 AIC · ⌖ 6.95 AIC · ⊞ 7K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI requested a review from gh-aw-bot July 22, 2026 19:48
@pelikhan
pelikhan merged commit 731a348 into main Jul 22, 2026
23 checks passed
@pelikhan
pelikhan deleted the copilot/testify-expert-improve-test-quality-yet-again branch July 22, 2026 20:35
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.1

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.

[testify-expert] Improve Test Quality: pkg/actionpins/spec_test.go

4 participants