fix(storage): remove t.Parallel() from tests that mutate shared state#76
Merged
platinummonkey merged 1 commit intomainfrom Feb 17, 2026
Merged
Conversation
The factory_test.go tests all mutate shared global state — the singleton storage cache via ResetStorage()/GetStorage() and the DD_TOKEN_STORAGE env var via os.Setenv(). Running them concurrently caused a race where one test's cache reset or env var change was visible to another, producing flaky failures (nil error → nil pointer dereference on err.Error()). - Remove t.Parallel() from all tests that touch global storage state - Replace manual os.Setenv/defer os.Unsetenv with t.Setenv for automatic cleanup and parallel-safety enforcement - Change t.Error to t.Fatal where execution must stop on nil error to prevent nil pointer dereferences Fixes CI flake: TestDetectBackend_InvalidEnvValue panic in headless environments where keychain is unavailable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a flaky CI failure (
TestDetectBackend_InvalidEnvValuepanic) caused by parallel tests racing on shared global state — the singleton storage cache and theDD_TOKEN_STORAGEenvironment variable.Changes
t.Parallel()from all factory tests that callResetStorage()or modify env vars (pkg/auth/storage/factory_test.go)os.Setenv/defer os.Unsetenvwitht.Setenv()for automatic cleanup and parallel-safety enforcementt.Error→t.Fatalwhere execution must stop on nil error to prevent nil pointer dereferencesRoot Cause
All tests in
factory_test.gowere markedt.Parallel()but they all mutate the same global state:ResetStorage()clears the singleton cacheos.Setenv(StorageEnvVar, ...)modifies a process-wide env varWhen
TestDetectBackend_InvalidEnvValueran concurrently with other tests, another test could populate the cache or clear the env var beforeGetStorage(nil)was called, causing it to succeed instead of returning an error. The subsequenterr.Error()call on nil then panicked.Test plan
go test ./pkg/auth/storage/ -v -race -count=1passesgo test ./... -count=1passes🤖 Generated with Claude Code