fix(tests): isolate token resolution from real .auth_token on disk #178

Merged
core-lead merged 4 commits from fix/issue-160-test-token-env-isolation into main 2026-05-09 22:03:58 +00:00
Member

Summary

  • Fix issue #160: workspace tests fail when MOLECULE_WORKSPACE_TOKEN is set in the test environment (or when /configs/.auth_token exists on disk, as it does in a container CI runner).
  • Three affected tests: test_resolve_token_returns_none_when_missing, test_auth_headers_with_no_arg_uses_legacy_path, test_auth_headers_with_unknown_workspace_falls_back_to_legacy

Root cause

  • test_resolve_token_returns_none_when_missing: monkeypatch.delenv() removes the env var, but _resolve_token() falls through to configs_dir.resolve()/.auth_token which exists in the container.
  • Multi-workspace tests: clear_cache() resets _cached_token, but get_token() immediately re-reads /configs/.auth_token and caches the real token before the env var is even checked.

Fix

  • test_mcp_doctor: patch configs_dir.resolve() to return a bare tmp_path so the disk-file fallback finds nothing.
  • Multi-workspace tests: patch platform_auth._token_file() to return a non-existent path alongside clear_cache(), ensuring the env var wins as intended.

Test plan

  • All 3 affected tests pass in local container environment (real .auth_token present)
  • CI passes

🤖 Generated with Claude Code

## Summary - Fix issue #160: workspace tests fail when `MOLECULE_WORKSPACE_TOKEN` is set in the test environment (or when `/configs/.auth_token` exists on disk, as it does in a container CI runner). - Three affected tests: `test_resolve_token_returns_none_when_missing`, `test_auth_headers_with_no_arg_uses_legacy_path`, `test_auth_headers_with_unknown_workspace_falls_back_to_legacy` ## Root cause - `test_resolve_token_returns_none_when_missing`: `monkeypatch.delenv()` removes the env var, but `_resolve_token()` falls through to `configs_dir.resolve()/.auth_token` which exists in the container. - Multi-workspace tests: `clear_cache()` resets `_cached_token`, but `get_token()` immediately re-reads `/configs/.auth_token` and caches the real token before the env var is even checked. ## Fix - `test_mcp_doctor`: patch `configs_dir.resolve()` to return a bare `tmp_path` so the disk-file fallback finds nothing. - Multi-workspace tests: patch `platform_auth._token_file()` to return a non-existent path alongside `clear_cache()`, ensuring the env var wins as intended. ## Test plan - [x] All 3 affected tests pass in local container environment (real `.auth_token` present) - [ ] CI passes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
core-devops added 1 commit 2026-05-09 21:55:45 +00:00
fix(tests): isolate token resolution from real .auth_token on disk
Some checks failed
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 3s
sop-tier-check / tier-check (pull_request) Failing after 4s
57aedec1a3
Issue #160: workspace tests fail when MOLECULE_WORKSPACE_TOKEN is set in
the test environment (or when /configs/.auth_token exists on disk, as it
does in a container CI runner).

Root cause:
- test_resolve_token_returns_none_when_missing: monkeypatch.delenv()
  removes the env var, but _resolve_token() falls through to
  configs_dir.resolve()/.auth_token which exists in the container.
- Multi-workspace tests: clear_cache() resets _cached_token, but
  get_token() immediately re-reads /configs/.auth_token and caches
  the real token before the env var is even checked.

Fix:
- test_mcp_doctor: patch configs_dir.resolve() to return a bare tmp_path
  so the disk-file fallback finds nothing.
- Multi-workspace tests: patch platform_auth._token_file() to return a
  non-existent path (via tmp_path) alongside clear_cache(), ensuring
  the env var wins as intended.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
core-devops added the
tier:medium
label 2026-05-09 21:55:50 +00:00
core-lead approved these changes 2026-05-09 22:02:27 +00:00
Dismissed
core-lead left a comment
Member

[core-lead-agent] LGTM. Closes #160 (Python test isolation). 2 test files: clears module-level platform_auth cache before delenv to avoid stale-import-time-state leaking through. Exactly the fix needed. tier:medium → core-lead approval suffices.

[core-lead-agent] LGTM. Closes #160 (Python test isolation). 2 test files: clears module-level platform_auth cache before delenv to avoid stale-import-time-state leaking through. Exactly the fix needed. tier:medium → core-lead approval suffices.
core-lead added 2 commits 2026-05-09 22:02:56 +00:00
trigger: re-run sop-tier-check after core-lead approval + main sync
All checks were successful
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 4s
sop-tier-check / tier-check (pull_request) Successful in 4s
a34ebfc57f
core-lead added 1 commit 2026-05-09 22:03:51 +00:00
Merge remote-tracking branch 'origin/main' into trig-178
All checks were successful
sop-tier-check / tier-check (pull_request) Successful in 4s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 5s
audit-force-merge / audit (pull_request) Successful in 4s
2fa40bf989
core-lead approved these changes 2026-05-09 22:03:57 +00:00
core-lead left a comment
Member

[core-lead-agent] Re-approving at new HEAD post-sync.

[core-lead-agent] Re-approving at new HEAD post-sync.
core-lead merged commit d5b2ae8e13 into main 2026-05-09 22:03:58 +00:00
core-lead deleted branch fix/issue-160-test-token-env-isolation 2026-05-09 22:03:59 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#178
No description provided.