Drop SP_BASE_URL and SP_API_TOKEN from the test environment - #4
Merged
Conversation
The suite sandboxes HOME and XDG_CONFIG_HOME, but the CLI also takes its base URL and token from the environment via click's envvar= (main.py:31-33). A developer with SP_BASE_URL exported -- which is what the README suggests for everyday use, and what anyone driving the CLI against the live platform will have -- fails the base-url precedence test in test_cli.py, because the test expects a saved session to win and the environment outranks it. SP_API_TOKEN is the worse of the two: a real token in the environment silently becomes test input. CI never noticed because it sets neither variable, so this only ever bites someone running the suite on a machine they also use the CLI from.
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.
The symptom
Unset the variable and the same commit is green. This showed up right after #3 merged, on master, with no code change between the two runs — only the environment differed.
The cause
tests/__init__.pysandboxesHOMEandXDG_CONFIG_HOME, which covers the config file. But the CLI also takes settings from the environment through click'senvvar=(main.py:31-33):The failing test asserts that a saved session beats the default base URL. An exported
SP_BASE_URLoutranks the saved value, so the assertion fails — correctly, given the environment it was handed.SP_API_TOKENis the more dangerous of the two: a real token sitting in the environment quietly becomes test input.CI has never caught this because it sets neither variable. It only bites someone running the suite on the same machine they drive the CLI from — which is everyone working on this tool.
The fix
Pop both in the existing sandbox block, next to the
HOME/XDG_CONFIG_HOMEredirect.Testing
SP_BASE_URL+SP_API_TOKENsetSP_BASE_URL+SP_API_TOKENsetunittest discoverisort, pycodestyle, pydocstyle and mypy all clean. Saved token verified unchanged (md5) after every run.
Same family as #2: the suite's isolation covered the file but not the environment.