Repository navigation
[test-parallel] Add t.Parallel() to safe cross-run audit and agent example tests - #52860
Conversation
Analyzed 25 test files in pkg/cli (batch after add_description_test.go). Added t.Parallel() to: - TestAgentFriendlyOutputFailureScenario (audit_agent_example_test.go): pure struct construction, no shared state - 18 tests in audit_cross_run_test.go: buildCrossRunAuditReport/render/logs-command tests operating on local values with no env, filesystem, or shared-global mutation Left unparallelized: tests using os.Chdir, os.Setenv/t.Setenv, package-level mock globals, os.Stderr/os.Stdout reassignment, or external CLI/network dependencies (see sub-agent analysis). Co-authored-by: Copilot <[email protected]>
|
✅ Test Quality Sentinel completed test quality analysis.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. No ADR enforcement needed: PR #52860 does not have the implementation label and has only 20 new lines of code in business logic directories (threshold: 100).
|
|
✅ Ponytail Reviewer completed successfully! Lean already. Ship.
|
|
✅ PR Code Quality Reviewer completed the code quality review. Completed PR review analysis for #52860; no actionable review comments were warranted because the diff only adds t.Parallel() to tests that operate on local state and intentionally excludes tests that mutate global stdio.
|
There was a problem hiding this comment.
LGTM. All added t.Parallel() calls are on stateless, side-effect-free test functions. No shared mutable state is present in the changed tests, so parallelisation is safe.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 14.3 AIC · ⌖ 6.99 AIC · ⊞ 5.6K
There was a problem hiding this comment.
Pull request overview
Adds parallel execution to safe-looking CLI audit tests to reduce Go test runtime.
Changes:
- Adds
t.Parallel()to 19 cross-run audit tests. - Adds
t.Parallel()to one agent failure scenario test. - Four cross-run tests remain unsafe because they mutate global
os.Stdout.
Show a summary per file
| File | Description |
|---|---|
pkg/cli/audit_cross_run_test.go |
Parallelizes cross-run audit tests. |
pkg/cli/audit_agent_example_test.go |
Parallelizes the failure scenario test. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Suppressed comments (3)
pkg/cli/audit_cross_run_test.go:272
- This test cannot run in parallel while it replaces process-global
os.Stdout. The other newly parallel render tests perform the same replacement, allowing output to be redirected to the wrong pipe and causing race-detector failures. Removet.Parallel()or rewrite the test to call the writer-based renderer directly.
t.Parallel()
pkg/cli/audit_cross_run_test.go:840
t.Parallel()lets this test overlap with three other newly parallel tests that also replaceos.Stdout. Concurrent assignment and restoration of that global can redirect output into another test's pipe and trigger data races. Remove this parallel marker unless stdout capture is changed to use an injected writer.
t.Parallel()
pkg/cli/audit_cross_run_test.go:631
- Parallelizing this test is unsafe because its stdout-capture block mutates
os.Stdout, which is shared by the entire process. It can race with the other parallel render tests and make their output assertions nondeterministic. Keep it serial or pass the pipe/buffer to the writer-based renderer instead.
t.Parallel()
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
| } | ||
|
|
||
| func TestRenderCrossRunReportJSON(t *testing.T) { | ||
| t.Parallel() |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd — changes look correct; two minor suggestions for completeness.
📋 Key Themes & Highlights
Positive Highlights
- ✅ Excellent safety judgement:
os.Stderr-reassigning tests correctly left non-parallel - ✅ All parallelised tests are genuinely pure (local struct construction only)
- ✅
-racevalidation confirmed in PR description - ✅ Clean, minimal diff — only
t.Parallel()lines, nothing else touched
Minor Suggestions
- The two table-driven tests (
TestLogsCommand_FormatPrecedence,TestLogsCommand_RepoParsingWithHost) already havet.Parallel()on the parent, but their subtests insidet.Rundon't callt.Parallel(). Since Go 1.22+ the loop variable capture concern is gone, and both subtest bodies are pure — addingt.Parallel()inside the closures would maximise intra-test parallelism.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 36.3 AIC · ⌖ 8.53 AIC · ⊞ 7.7K
Comment /matt to run again
Comments that could not be inline-anchored
pkg/cli/audit_cross_run_test.go:422
[/tdd] The subtests inside TestLogsCommand_FormatPrecedence are pure (no shared state, no I/O) — they could also call t.Parallel() to maximise parallelism within the parent test.
<details>
<summary>💡 Suggested change</summary>
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel() // safe: subtests are pure
// existing assertions ...
})
}Since this repo targets Go 1.26.5, loop variable capture is already correct — just add t.Parallel() as the …
pkg/cli/audit_cross_run_test.go:482
[/tdd] Same as the sibling table-driven test above — TestLogsCommand_RepoParsingWithHost subtests are pure string-splitting logic with no side effects and could call t.Parallel() inside t.Run.
@copilot please address this.
🧪 Test Quality Sentinel Report✅ Test Quality Score: N/A — Parallelization Only
📊 Infrastructure Signals
Parallelization safety verified: tests operate on locally-constructed values with no shared state, environment mutation, or global Verdict
|
|
🎉 This pull request is included in a new release. Release: |
Summary
Daily Go test parallelizer run analyzing a batch of 25
pkg/clitest files (round-robin, starting afterpkg/cli/add_description_test.go).Files analyzed (batch)
add_gitattributes_test.go,add_integration_test.go,add_interactive_engine_test.go,add_interactive_git_test.go,add_interactive_orchestrator_test.go,add_interactive_schedule_test.go,add_interactive_secrets_test.go,add_interactive_workflow_test.go,add_no_args_test.go,add_package_manifest_test.go,add_skill_rewrite_test.go,add_source_test.go,add_wildcard_test.go,add_wizard_command_test.go,add_wizard_tuistory_integration_test.go,add_workflow_pr_test.go,add_workflow_resolution_manifest_ref_test.go,add_workflow_resolution_redirect_test.go,audit_agent_example_test.go,audit_agent_output_test.go,audit_agentic_analysis_test.go,audit_ambient_context_test.go,audit_comparison_test.go,audit_concurrency_test.go,audit_cross_run_test.go.Changes made
pkg/cli/audit_agent_example_test.go: addedt.Parallel()toTestAgentFriendlyOutputFailureScenario— it only constructs localWorkflowRun/audit data values and has no shared state (the sibling test in the same file,TestAgentFriendlyOutputExample, was left untouched because a subtest reassigns the globalos.Stderr).pkg/cli/audit_cross_run_test.go: addedt.Parallel()to 18 top-level tests (TestBuildCrossRunAuditReport_*,TestRenderCrossRunReport*,TestNewLogsCommand_HasFormatFlag,TestLogsCommand_FormatPrecedence,TestLogsCommand_RepoParsingWithHost,TestBuildMetricsTrend_*,TestBuildDrain3InsightsFromCrossRunInputs_*) — all operate purely on locally-constructed values/report structs with no environment, filesystem, or shared-global mutation.TestRenderPrettyMetricsTrend_IncludesDurationWithoutTokenswas left alone because it reassigns globalos.Stderr.Left unchanged (unsafe)
Files/tests using
os.Chdir,os.Setenv/t.Setenv, package-level mock function globals,os.Stderr/os.Stdoutreassignment, external CLI/network dependencies (git, gh, npx/tuistory, PTY sessions), or fixed shared binaries were intentionally left withoutt.Parallel()per the safety rules.Validation
go build ./...— passes.go test -race ./pkg/cli/... -run '<all newly-parallel tests>'— all pass.go test ./pkg/cli/...— only two pre-existing, unrelated failures remain (TestRenderScheduleCalendarCell_UsesANSIInColorTerminal,TestConfirmRunAddedWorkflow_ContextCancelled), both environment-dependent (terminal color /ghauth) and untouched by this change.t.Parallel()additions in the two files above, no other changes.State persisted to cache for next round-robin run:
last_file = pkg/cli/audit_cross_run_test.go.