From 76ac5a88dc2c2bef5656f0ba6cb8f45d0b6dff26 Mon Sep 17 00:00:00 2001 From: Molecule AI Core-BE Date: Sat, 9 May 2026 22:16:11 +0000 Subject: [PATCH 1/2] [core-be-agent] fix(tests): clear platform_auth cache before each test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue #160: workspace tests fail when MOLECULE_WORKSPACE_TOKEN is set in the environment. The bug: platform_auth._cached_token is populated at module import or first get_token() call and persists for the process lifetime. Tests that use monkeypatch.delenv("MOLECULE_WORKSPACE_TOKEN") to simulate "no token in env" were failing because delenv removes the env var but not the module-level cache — subsequent get_token() calls returned the stale cached value. Fix: add a function-scoped autouse fixture in conftest.py that calls platform_auth.clear_cache() before every test. The import is inside the fixture to avoid collection-time import issues when platform_auth is not yet available. Co-Authored-By: Claude Opus 4.7 --- workspace/tests/conftest.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/workspace/tests/conftest.py b/workspace/tests/conftest.py index abae4168..b946240d 100644 --- a/workspace/tests/conftest.py +++ b/workspace/tests/conftest.py @@ -401,6 +401,35 @@ if "a2a" not in sys.modules: # tests now live in the claude-code template repo, where the real SDK # IS installed via Dockerfile, so no stub is needed. + +# ==================== Test isolation fixtures ==================== + +import pytest + + +@pytest.fixture(scope="function", autouse=True) +def _clear_platform_auth_cache(): + """Reset platform_auth._cached_token before each test. + + Fixes issue #160: tests that use monkeypatch.delenv("MOLECULE_WORKSPACE_TOKEN") + to simulate "no token in env" fail when platform_auth._cached_token was already + set from a prior test's MOLECULE_WORKSPACE_TOKEN value. The cache is populated + at module import or first get_token() call and persists for the process lifetime + — monkeypatch.delenv removes the env var but not the module-level cache. + + Run at function scope so each test starts with a clean slate regardless of + what the previous test set. The import is inside the fixture (not at file + top-level) because conftest.py runs during test collection before + platform_auth might be available in all test environments. If the module is + absent (import error), the fixture is a no-op. + """ + try: + import platform_auth as _pa + _pa.clear_cache() + except ImportError: + pass + yield # run the test, then fixture teardown has nothing to do + if "langchain_core" not in sys.modules: _make_langchain_mocks() From 1cbdf69c8d7f9e7aa5ebb06085853ac7e1278546 Mon Sep 17 00:00:00 2001 From: Molecule AI Core Platform Lead Date: Sat, 9 May 2026 22:18:45 +0000 Subject: [PATCH 2/2] trigger: re-run sop-tier-check after core-lead approval + main sync