Isolate the XDG data directory so a real login cannot leak into core tests - #51
Merged
Merged
Conversation
… into core tests Three ModelsDev tests were green in CI and red on any developer machine where somebody had run `redrob providers login`. They clear `REDROB_API_KEY` and then assert the static fallback catalog is served -- but `resolveApiKey()` reads THREE sources in order: that env var, the Integration store, and `auth.json` under `Global.Path.data`. The suite stubs the second and clears the first. The third was the developer's own credential. So the service found a key, fetched, and returned the live listing's figures -- `limit.output: 64000` where the fallback publishes `32000`. The assertion was reporting the difference between two catalogues rather than the thing it claims to check, and nothing in the test named the variable it depended on. `XDG_DATA_HOME` is pointed at a fresh temp directory in the preload, which is early enough: `Global.Path.data` is computed once at module load, so redirecting it afterwards is impossible -- the suite's own `REDROB_TEST_HOME` seam is a getter and covers `home` only, not the data directory where credentials live. Fixed in the test setup rather than by adding a seam to production code. Nothing about the CLI's real path resolution is wrong, and `XDG_DATA_HOME` is the standard way to say where that directory is. Verified by removing only the isolation: exactly those three fail again, and nothing else in the 974 does.
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.
Three ModelsDev tests were green in CI and red on any developer machine where somebody had run
redrob providers login.Why
They clear
REDROB_API_KEYand assert the static fallback catalog is served. ButresolveApiKey()reads three sources in order:process.env.REDROB_API_KEYcredentialLayerauth.jsonunderGlobal.Path.dataSo the service found a key, fetched, and returned the live listing's figures —
limit.output: 64000where the fallback publishes32000. The assertion was reporting the difference between two catalogues rather than the thing it claims to check, and nothing in the test named the variable it depended on.This is the same shape as the variants bugs earlier in this series: a test that is green for a reason unrelated to its claim.
The fix
XDG_DATA_HOMEpoints at a fresh temp directory in the preload, which is early enough —Global.Path.datais computed once at module load, so redirecting it afterwards is impossible. The suite's ownREDROB_TEST_HOMEseam is a getter and covershomeonly, not the data directory where credentials live.Done in the test setup rather than by adding a seam to production code: nothing about the CLI's real path resolution is wrong, and
XDG_DATA_HOMEis the standard way to say where that directory is.Verified by control
Removing only the
XDG_DATA_HOMEline brings back exactly those three and nothing else:Gates