Fix test that leaks files into the repo#120
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a test isolation issue in cmd/waza where package-level flag globals could leak between tests, causing go test ./cmd/waza/... to leave untracked cache/session-log artifacts in the repo.
Changes:
- Reset run-command package globals at the start of
TestRunCommandForSpec_NilCmd_OverridesTrialsviaresetRunGlobals(). - Remove the partial manual save/restore block that didn’t cover all relevant globals (e.g., session logging and cache settings).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #120 +/- ##
=======================================
Coverage ? 73.32%
=======================================
Files ? 135
Lines ? 15521
Branches ? 0
=======================================
Hits ? 11381
Misses ? 3308
Partials ? 832
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
richardpark-msft
approved these changes
Mar 12, 2026
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.
Running
go test ./cmd/waza/...left two untracked files in the repo:These were created by
TestRunCommandForSpec_NilCmd_OverridesTrials, which callsrunCommandForSpecdirectly without first resetting the package-level flag variables. When it ran afterTestRunCommand_CLIFlagsOverrideWazaYaml, it inherited that test's globals:sessionLog = true→ wrote a.jsonlsession log to the working directoryenableCache = true+runCacheDir = ".override-cache"→ created a cache directory in the working directoryBecause this test doesn't
os.Chdirinto a temp dir (unlike the.waza.yamlintegration tests), those files landed incmd/waza/— the default working directory forgo test.Fix
Added
resetRunGlobals()at the top of the test, matching the convention used by every other test in the file. This resetssessionLog,enableCache, and all other flag variables to their zero/default values before the test runs.Also removed the manual save/restore block for
trials,outputPath,contextDir, andformat—resetRunGlobals()already covers these, and the partial restore was the root cause (it didn't restoresessionLog,enableCache, orrunCacheDir).