Repository navigation
[repository-quality] Repository Quality: Test Isolation & Hermeticity #66890
Closed
Replies: 1 comment
|
This discussion has been marked as outdated by Repository Quality Improvement Agent. A newer discussion is available at Discussion #67208. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
🎯 Repository Quality Improvement Report - Test Isolation & Hermeticity
Analysis Date: 2026-10-08
Focus Area: Test isolation & hermeticity (process-global state in tests)
Strategy Type: Custom
Custom Area: Yes — the test suite is ~2x source LOC (613k vs 328k), so process-global mutations (cwd, env) are the main flakiness and parallelism risk.
Executive Summary
The suite has 1,893 test files. Only 575 use
t.Parallel(), and 1,318 files do not. Process-global state is still widely mutated: 677os.Chdiroccurrences across 94 files, 195os.Setenvcalls in 24 files, and only 33t.Chdiruses.t.Setenvis already common (450 uses), so the migration path is established.Several files combine
os.Chdirwitht.Parallel()(e.g.pkg/cli/commands_test.go,list_workflows_command_test.go,add_no_args_test.go,git_test.go,forecast_test.go). This is a latent race condition.os.Setenvwith manual restore (e.g.pkg/cli/security_regression_test.go:365,engine_secrets_test.go:550) is fragile on earlyt.Fatalor panics, and it blocks parallelism. There are 222t.Skipcalls (132 without an obvious short-mode/platform reason) and 29time.Sleepcalls in tests.Full Analysis Report
Current State Assessment
t.Parallel()os.Chdiroccurrences (94 files)t.Chdirusesos.Setenvin tests (24 files)t.Setenvusest.Skipcalls (no clear reason)time.Sleepin testsFindings
Strengths
t.Setenvadoption./tmpfile writes in tests.Areas for Improvement
os.Setenv+ manual restore.t.Skipcalls lack a documented reason.time.Sleep(7 inpkg/console/spinner_test.go).🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Improvement Tasks
Task 1: Remove Chdir/Parallel conflicts
Priority: High
Estimated Effort: Medium
Focus Area: Test isolation
Description: Tests that call
os.Chdirmust not run in parallel. Convert them tot.Chdir(Go 1.24+, which panics undert.Parallel) and dropt.Parallel()where cwd is needed, or pass explicit directories to the code under test.Acceptance Criteria:
os.Chdirandt.Parallel()go test -race ./pkg/cli/...passesCode Region:
pkg/cli/commands_test.go,list_workflows_command_test.go,add_no_args_test.go,git_test.go,forecast_test.goTask 2: Migrate remaining os.Chdir to t.Chdir
Priority: Medium
Estimated Effort: Large
Focus Area: Test isolation
Description: Mechanically replace the
os.Chdir+ defer-restore pattern in the other ~90 files.Acceptance Criteria:
os.Chdirin*_test.goreduced by >80%Code Region:
pkg/cli/*_test.go,pkg/workflow/*_test.goTask 3: Replace os.Setenv with t.Setenv
Priority: Medium
Estimated Effort: Small
Focus Area: Test hermeticity
Description: 24 files use
os.Setenvwith manual restore.Acceptance Criteria:
os.Setenvin tests except inside TestMainCode Region:
pkg/cli/security_regression_test.go:365,pkg/cli/engine_secrets_test.go:550Replace os.Setenv/os.Unsetenv with t.Setenv in test files, removing manual restore code. Use os.Unsetenv after t.Setenv("X","") when the variable must be unset.Task 4: Audit t.Skip reasons and Sleep
Priority: Low
Estimated Effort: Small
Focus Area: Test reliability
Description: Give every
t.Skipa clear reason (condition + message), delete stale skips, and replacetime.Sleepwith synchronization where feasible (start withpkg/console/spinner_test.go).Acceptance Criteria:
Code Region:
pkg/**/*_test.go,pkg/console/spinner_test.go📊 Historical Context
Previous Focus Areas
🎯 Recommendations
Immediate Actions (This Week)
Short-term Actions (This Month)
Long-term Actions (This Quarter)
📈 Success Metrics
Next Steps
Generated by Repository Quality Improvement Agent
Next analysis: 2026-10-09 — Focus area selected by diversity algorithm
All reactions