Repository navigation
[repository-quality] Repository Quality: Test Isolation & Process-Global State #70261
Closed
Replies: 1 comment
|
This discussion was automatically closed because it expired on 2026-10-20T13:07:31.013Z.
|
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 & Process-Global State
Analysis Date: 2026-10-19
Focus Area: Test Isolation & Process-Global State (concurrency hygiene)
Strategy Type: Custom
Custom Area: Yes — the repo has ~2,100 test files and a dedicated
test-raceCI job. Process-global mutation in tests (os.Chdir,t.Setenv) blockst.Parallel()and makes race coverage fragile.Executive Summary
Production concurrency code is in good shape: all 9 non-test goroutine launch sites inspected (
cli/shellcheck.go,cli/docker_images.go,cli/update_check.go,console/spinner.go, etc.) usedefer recover(), semaphores or WaitGroups, and agoroutinemissingrecoverlinter exists.The weaker area is tests. There are ~620
os.Chdircalls in tests (~450 inpkg/cli), ~1,190t.Setenv/os.Chdiruses overall, and 31time.Sleepcalls in tests.os.Chdiris process-wide, so those tests cannot run in parallel. Inpkg/cli, only 426 of 648 test files uset.Parallel().make test-racecovers only 4 packages with-short.Full Analysis Report
Current State Assessment
gostatements (incl. linter testdata)os.Chdirin testst.Setenv+os.Chdirin testst.Parallel()time.Sleepin tests-racecoverage-shortFindings
Strengths
syncutil/onceloader.goprovides shared lazy-init primitives.test-race.Areas for Improvement
os.Chdirin tests is process-global and incompatible witht.Parallel(). Go 1.24+ offerst.Chdir, which restores the directory automatically but still forbids parallel use. Tests should take explicit directory parameters instead.pkg/*that may be written at runtime need an audit. Unwritten ones should be documented read-only, or guarded.time.Sleepcalls in tests are flake risks. Replace with channels,require.Eventuallyor fake clocks.test-raceomitspkg/agentdrain,pkg/workqueue,pkg/syncutil,pkg/console(console is included), andpkg/parservirtual FS users beyond the listed four.🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Improvement Tasks
Task 1: Replace raw
os.Chdirin tests witht.ChdirPriority: High
Estimated Effort: Large (do per-package batches)
Focus Area: Test isolation
Description: Raw
os.Chdirplus manual deferred restore is error-prone and leaks cwd on failure. Migrate tot.Chdir(dir)(Go 1.24+; repo is on 1.26).Acceptance Criteria:
os.Chdirinpkg/**/*_test.go, except where the test needs raw semantics (documented)make test-unitpassest.Parallel()combined witht.ChdirCode Region:
pkg/cli/*_test.go,pkg/workflow/*_test.go,pkg/parser/*_test.goTask 2: Add a ratchet linter/test banning new
os.Chdirin testsPriority: Medium
Estimated Effort: Small
Focus Area: Test isolation
Description: Prevent regressions using the existing
pkg/lintersframework.Acceptance Criteria:
os.Chdirin_test.gofiles, with testdataCode Region:
pkg/linters/Task 3: Remove
time.Sleepfrom testsPriority: Medium
Estimated Effort: Medium
Focus Area: Flake reduction
Description: 31 sleeps in tests; replace with synchronisation.
Acceptance Criteria:
Eventually/injected clock, or justified in a comment-race -count=20locallyCode Region:
grep -rn "time.Sleep" pkg --include=*_test.goTask 4: Audit package-level mutable maps/slices
Priority: Medium
Estimated Effort: Medium
Focus Area: Concurrency safety
Description: Identify package-level maps written after init; guard with a mutex or convert to constructors.
Acceptance Criteria:
packagelevelmutableslicemaplinter allowlistCode Region:
pkg/parser/schema_*.go,pkg/workflow/*registry*.go,pkg/constants/Task 5: Broaden
make test-racePriority: Low
Estimated Effort: Small
Focus Area: CI/CD
Description: Add concurrency-heavy packages to the race job.
Acceptance Criteria:
agentdrain,workqueue,syncutil,loggeradded totest-raceCode Region:
Makefile:95-98📊 Historical Context
Previous Focus Areas
🎯 Recommendations
Immediate Actions (This Week)
os.Chdirratchet linter (Task 2) — Priority: HighShort-term Actions (This Month)
os.Chdirtot.Chdir(Task 1); remove sleeps (Task 3) — Priority: MediumLong-term Actions (This Quarter)
📈 Success Metrics
Next Steps
Generated by Repository Quality Improvement Agent
Next analysis: 2026-10-20 — Focus area selected by diversity algorithm
All reactions