Skip to content

Drop SP_BASE_URL and SP_API_TOKEN from the test environment - #4

Merged
cfsmp3 merged 1 commit into
masterfrom
fix/test-env-isolation
Aug 15, 2026
Merged

Drop SP_BASE_URL and SP_API_TOKEN from the test environment#4
cfsmp3 merged 1 commit into
masterfrom
fix/test-env-isolation

Conversation

@cfsmp3

@cfsmp3 cfsmp3 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

The symptom

$ export SP_BASE_URL=https://sampleplatform.ccextractor.org/api/v1
$ python -m pytest -q
1 failed, 215 passed

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__.py sandboxes HOME and XDG_CONFIG_HOME, which covers the config file. But the CLI also takes settings from the environment through click's envvar= (main.py:31-33):

@click.option('--base-url', envvar='SP_BASE_URL', default=DEFAULT_BASE_URL, ...)
@click.option('--token', envvar='SP_API_TOKEN', default=None, ...)

The failing test asserts that a saved session beats the default base URL. An exported SP_BASE_URL outranks the saved value, so the assertion fails — correctly, given the environment it was handed.

SP_API_TOKEN is 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_HOME redirect.

Testing

environment runner result
SP_BASE_URL + SP_API_TOKEN set pytest 216 pass
SP_BASE_URL + SP_API_TOKEN set unittest discover OK
neither set pytest 216 pass

isort, 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.

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.
@cfsmp3
cfsmp3 merged commit 8fb73cd into master Aug 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant