test: refactor shared state DB reset into TestMain for cmd tests#458
Open
terminalchai wants to merge 6 commits into
Open
test: refactor shared state DB reset into TestMain for cmd tests#458terminalchai wants to merge 6 commits into
terminalchai wants to merge 6 commits into
Conversation
Member
|
I don't understand how this PR has 0 changes but 5 commits. Am I going crazy? lol |
0cf34b5 to
60026c0
Compare
Member
Yep my bad. Made a wrong merge commit |
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.
Problem
The \cmd\ package tests had inconsistent state DB teardown across test helpers. \setupXDGEnvIsolation\ in \ est_env_test.go\ called \state.CloseDB()\ directly in its cleanup function, but \TestMain\ only set \XDG_CONFIG_HOME\ and \APPDATA/\USERPROFILE\ — leaving \XDG_DATA_HOME, \XDG_STATE_HOME, \XDG_CACHE_HOME, \XDG_RUNTIME_DIR, and \HOME\ pointing at real user directories. This meant:
Fix
**\TestMain**: set all six XDG env vars (+ \HOME) to the temp dir, then call a new
esetSharedStateDB()\ helper that closes any existing DB, ensures config dirs exist, and reopens the DB against the isolated temp path. Also close the DB before \os.RemoveAll\ to avoid Windows file-lock errors.
**
esetSharedStateDB()**: single source of truth for suite-level DB reset — used by both \TestMain\ and the per-test cleanup in \setupXDGEnvIsolation.
**\setupXDGEnvIsolation**: replace the bare \state.CloseDB()\ call with
esetSharedStateDB()\ so the suite DB is always left in a known-open state after each per-test isolation window closes.
Testing
\
go test ./cmd/... -count=1 -race
\\
All tests pass.
Greptile Summary
This PR refactors the
cmdpackage test setup to ensure full XDG environment isolation.TestMainnow sets all six XDG env vars (plusHOME,APPDATA,USERPROFILE) to a temp directory, and a newresetSharedStateDBhelper provides a single, consistent path for closing, re-initialising, and reopening the suite-level DB.resetSharedStateDBis fixed to early-return onconfig.EnsureDirsfailure, preventingstate.Configurefrom being called against a directory that wasn't created.TestMainnow callsos.RemoveAll(tmpDir)beforeos.Exit(1)on setup failure, avoiding stale temp directories.internal/config/settings.goandinternal/engine/types/accuracy_test.goinclude cosmetic whitespace-only changes unrelated to the primary fix.Confidence Score: 5/5
Safe to merge — all changes are confined to test infrastructure with no production logic affected.
The functional changes correctly fix error handling in
resetSharedStateDBand temp-directory cleanup inTestMain. The remaining file touches are pure whitespace with no behavioral impact.No files require special attention.
Important Files Changed
resetSharedStateDBnow early-returns onEnsureDirsfailure (previously calledstate.Configureregardless), andTestMainnow cleans uptmpDirbeforeos.Exit(1)on setup failure.NetworkSettingsstruct fields — no functional changes.Prompt To Fix All With AI
Reviews (3): Last reviewed commit: "chore: go fmt" | Re-trigger Greptile
Context used: