Skip to content

Improve test quality for pkg/console/confirm_test.go - #51434

Merged
pelikhan merged 3 commits into
mainfrom
copilot/testify-expert-improve-test-quality-again
Aug 8, 2026
Merged

pelikhan merged 3 commits into
mainfrom
copilot/testify-expert-improve-test-quality-again

Conversation

Copilot AI commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

TestConfirmAction was a placeholder (_ = ConfirmAction) that never exercised ConfirmAction, and TestShowTextConfirm was missing several edge cases despite otherwise being a solid table-driven test.

Changes

  • Replaced the placeholder test: TestConfirmAction_NonTTY redirects os.Stdin via os.Pipe() and calls ConfirmAction directly, exercising its non-TTY fallback path (which showTextConfirm implements) with yes/no/invalid-input cases.
  • Expanded TestShowTextConfirm table: added empty-input/EOF, whitespace-padded input, and single-letter uppercase (Y/N) cases.
  • Removed the no-op _ = ConfirmAction subtest.
func TestConfirmAction_NonTTY(t *testing.T) {
    // ...
    oldStdin := os.Stdin
    r, w, err := os.Pipe()
    require.NoError(t, err)
    t.Cleanup(func() { os.Stdin = oldStdin })
    t.Cleanup(func() { r.Close() })
    os.Stdin = r

    go func() {
        _, _ = w.WriteString(tt.input)
        w.Close()
    }()

    result, err := ConfirmAction("Delete all workflows?", "Yes, delete", "Cancel")
    // ...
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve test quality for confirm_test.go Improve test quality for pkg/console/confirm_test.go Aug 8, 2026
Copilot AI requested a review from pelikhan August 8, 2026 18:25
@pelikhan
pelikhan marked this pull request as ready for review August 8, 2026 18:32
Copilot AI balanced review requested due to automatic review settings August 8, 2026 18:32
@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • api.individual.githubcopilot.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.individual.githubcopilot.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

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

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 8, 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 42 new lines of code in business logic directories (threshold: 100).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

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 behavioral and edge-case coverage for console confirmation prompts.

Changes:

  • Replaces the no-op ConfirmAction test with non-TTY cases.
  • Adds uppercase, whitespace, and EOF cases for showTextConfirm.
Show a summary per file
File Description
pkg/console/confirm_test.go Expands confirmation prompt tests.

Review details

Tip

Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

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

Comment on lines +31 to +36
oldStdin := os.Stdin
r, w, err := os.Pipe()
require.NoError(t, err)
t.Cleanup(func() { os.Stdin = oldStdin })
t.Cleanup(func() { r.Close() })
os.Stdin = r

@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 — requesting changes on two correctness issues in the new test and one missing coverage gap.

📋 Key Themes & Highlights

Key Themes

  • Cleanup ordering bug: t.Cleanup registrations are LIFO, so r.Close() fires before os.Stdin is restored — opposite of intended order.
  • Unsynchronised goroutine: the goroutine writing to the pipe can race against cleanup if the test path panics or returns early; synchronous writes are simpler and safe for short inputs.
  • Missing EOF case in TestConfirmAction_NonTTY: the table covers yes/no/invalid but not empty/EOF, which is already tested in TestShowTextConfirm.

Positive Highlights

  • ✅ Replacing the _ = ConfirmAction no-op with a real exercise of the non-TTY path is exactly the right improvement.
  • ✅ Table-driven structure is clean and consistent with the rest of the file.
  • ✅ New edge cases in TestShowTextConfirm (uppercase, whitespace-padded) are well-chosen.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 25.8 AIC · ⌖ 9.99 AIC · ⊞ 7.1K
Comment /matt to run again

r, w, err := os.Pipe()
require.NoError(t, err)
t.Cleanup(func() { os.Stdin = oldStdin })
t.Cleanup(func() { r.Close() })

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] t.Cleanup registrations are LIFO, so r.Close() fires before os.Stdin = oldStdin is restored — inverted from the intended order.

💡 Fix: swap registration order

Register restore-stdin after r.Close so LIFO runs restore first:

t.Cleanup(func() { r.Close() })            // registered 1st → called 2nd
t.Cleanup(func() { os.Stdin = oldStdin })  // registered 2nd → called 1st

Currently harmless (ConfirmAction has returned by cleanup time), but the ordering will silently cause problems if cleanup logic ever changes.

@copilot please address this.

result, err := ConfirmAction("Delete all workflows?", "Yes, delete", "Cancel")
if tt.wantErr {
require.Error(t, err)
} else {

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] The goroutine writing to w is not synchronised with the test's cleanup — if the test subtree panics or ConfirmAction returns early, w.WriteString / w.Close() may race against r.Close() in the cleanup.

💡 Use a done channel or write synchronously for short inputs

For short inputs you can write and close synchronously before calling ConfirmAction, since os.Pipe has a kernel buffer large enough for a few bytes:

_, _ = w.WriteString(tt.input)
w.Close()
result, err := ConfirmAction(...)

If async writing is truly needed, track the goroutine with a WaitGroup and wait in a cleanup.

@copilot please address this.

// text-based confirmation prompt when stderr is not a terminal (as is the
// case in `go test` runs), reading the response from os.Stdin.
func TestConfirmAction_NonTTY(t *testing.T) {
tests := []struct {

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] TestConfirmAction_NonTTY is missing an empty/EOF case analogous to the one added to TestShowTextConfirm. Since ConfirmAction delegates to showTextConfirm, the same EOF path is reachable here.

💡 Add an EOF test case
{name: "empty input EOF", input: "", wantErr: true},

This rounds out the table and ensures the EOF error surfaces through the ConfirmAction wrapper too.

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

Review: Improve test quality for pkg/console/confirm_test.go

Overall this is a meaningful improvement — the old test only verified the function existed; the new tests exercise real behavior under non-TTY conditions.

Positive changes:

  • TestConfirmAction_NonTTY now exercises the actual ConfirmAction fallback path with stdin piping.
  • New TestShowTextConfirm cases add coverage for uppercase Y/N and whitespace-padded input, which are real code paths in showTextConfirm.
  • The EOF/empty-input case is correctly verified.

One minor issue flagged inline: the write-end of the pipe w in TestConfirmAction_NonTTY is only closed inside the goroutine; a t.Cleanup(func() { w.Close() }) would make teardown deterministic.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 22.6 AIC · ⌖ 7.23 AIC · ⊞ 5.5K

_, _ = w.WriteString(tt.input)
w.Close()
}()

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.

Minor: The write-end of the pipe w is only closed inside the goroutine. If the goroutine panics or is never scheduled before the test times out, the read end will block forever. Add a cleanup to ensure w is always closed deterministically:

t.Cleanup(func() { w.Close() })

@copilot please address this.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

✅ Test Quality Score: 90/100 — Excellent

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

📊 Metrics (2 tests)
Metric Value
Analyzed 2 (Go: 2, JS: 0)
✅ Design 2 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 2 (100%)
Duplicate clusters 0
Inflation ⚠️ Yes (42 test lines, 0 prod lines — expected for test-improvement PR)
🚨 Violations 0
Test File Classification Issues
TestConfirmAction_NonTTY pkg/console/confirm_test.go behavioral_contract / design_test / high_value None
TestShowTextConfirm pkg/console/confirm_test.go behavioral_contract / design_test / high_value None

Analysis

TestConfirmAction_NonTTY — Replaces a no-op placeholder. Uses os.Pipe() to inject stdin and directly exercises ConfirmAction's non-TTY fallback path with yes, no, and invalid-input cases. Solid behavioral contract with error-path coverage. t.Cleanup handles stdin restore and pipe close correctly.

TestShowTextConfirm — 13-row table covering affirmative variants (y/yes/1/Y/YES, whitespace-padded), negative variants (n/no/2/N/NO), invalid input, and empty/EOF. Both error rows use errContains for precise error message validation. Strong edge-case coverage.

Build tag: (go/redacted):build !integration && !js && !wasm on line 1 ✅
Mock libraries: None ✅
Inflation note: 42 lines added to test file with 0 production lines changed — expected and acceptable for a pure test-improvement PR.

Verdict

✅ Passed. 0% implementation tests (threshold: 30%). No violations.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 49.3 AIC · ⌖ 8.86 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: 90/100 — Excellent. 0% implementation tests (threshold: 30%). No violations. See comment for full analysis.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please address the remaining review feedback below, refresh the branch if GitHub can update it cleanly, run the pr-finisher skill, and push follow-up fixes.

Open review context (newest first):

  • Skills-Based Review 🧠

  • Review: Improve test quality for pkg/console/confirm_test.go

Failed checks:

Branch refresh was requested.

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

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 4.66 AIC · ⌖ 4.22 AIC · ⊞ 8.5K · ◷
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 August 8, 2026 19:17
@pelikhan
pelikhan merged commit 08df4c4 into main Aug 8, 2026
@pelikhan
pelikhan deleted the copilot/testify-expert-improve-test-quality-again branch August 8, 2026 19:21
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.2

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.

[testify-expert] Improve Test Quality: pkg/console/confirm_test.go

4 participants