Skip to content

test(cli): never start the background update check in package tests - #5

Merged
MakFly merged 1 commit into
mainfrom
fix/tests-skip-background-update-check
Dec 2, 2026
Merged

MakFly merged 1 commit into
mainfrom
fix/tests-skip-background-update-check

Conversation

@MakFly

@MakFly MakFly commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Why

The macOS race job on main (bc1c1ee) failed TestDoctorOutdatedFailsOnlyWhenALookupCouldNotRun with race detected during execution of test. The race report pointed at update_check.go:31 (read of version.Version in the background update check goroutine) against doctor_outdated_test.go:281 (a test setting version.Version).

Cause

Every command runs the root PersistentPreRun, which starts checkForUpdateAsync. Since the public release origin became the default, that goroutine calls the real origin during package tests, writes the check file under HOME, and outlives the command. A later test that changes version.Version races with it.

Fix

  • updateCheckEnabled (default true) gates the background check; the package TestMain sets it to false. Production behavior is unchanged.
  • TestPackageTestsNeverStartTheBackgroundUpdateCheck runs the root PersistentPreRun against a counting server and fails if the release origin is called. It failed before the fix.

Checks

  • gofmt -l . (empty), go vet ./..., go test -count=1 ./... pass.
  • go test -race -count=1 ./internal/cli passes with no race report.

🤖 Generated with Claude Code

The macOS race job on main (bc1c1ee) failed TestDoctorOutdatedFailsOnlyWhenALookupCouldNotRun
with "race detected during execution of test". Every command runs the root
PersistentPreRun, whose update check starts a goroutine that calls the real
release origin, writes under HOME and reads version.Version after the
command returns; a later test that set version.Version raced with it.
TestMain now turns the check off, and a test proves no command reaches the
release origin during package tests (it failed before this change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MakFly
MakFly merged commit 519a74d into main Dec 2, 2026
3 checks passed
@MakFly
MakFly deleted the fix/tests-skip-background-update-check branch December 2, 2026 01:13
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.

1 participant