From 061ecedd9c32385807631fae671873e9bd985d10 Mon Sep 17 00:00:00 2001 From: mayaa6 Date: Fri, 31 Jul 2026 15:13:30 +0800 Subject: [PATCH] test(tdx): make stats cache root assertions platform-aware The two stats-cache tests hard-coded the Windows LOCALAPPDATA layout (`AxData/cache/tdx/stats`) as the expected default cache root. On macOS and Linux the production `user_tdx_stats_cache_root()` correctly returns `~/Library/Caches/AxData/tdx/stats` and `$XDG_CACHE_HOME/axdata/tdx/stats` respectively, so both tests failed on non-Windows platforms even though the code under test was behaving correctly. Add a small `_expected_default_tdx_stats_cache_root()` helper that mirrors the production per-OS branch and use it in both tests, so the expectation follows the running platform. The cwd-independence assertion is unchanged. Affected tests: - test_tdx_direct_adapter_default_stats_cache_is_independent_of_cwd - test_tdx_provider_installed_from_wheel_is_discovered_and_can_route Co-Authored-By: Claude Opus 4.8 --- tests/test_tdx_provider_package.py | 5 ++--- tests/test_tdx_source_request_adapter.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/test_tdx_provider_package.py b/tests/test_tdx_provider_package.py index dcbd9fe..9f636e2 100644 --- a/tests/test_tdx_provider_package.py +++ b/tests/test_tdx_provider_package.py @@ -24,6 +24,7 @@ from tests.test_tdx_source_request_adapter import ( EchoTqlexClient, FakeTdxClient, + _expected_default_tdx_stats_cache_root, _minimal_stat2_line, _minimal_stat_line, _stats_zip_bytes, @@ -6769,9 +6770,7 @@ def test_tdx_provider_installed_from_wheel_is_discovered_and_can_route( ).stdout.strip() for cwd in (first_cwd, second_cwd) ] - expected_cache = str( - (local_app_data / "AxData" / "cache" / "tdx" / "stats").resolve() - ) + expected_cache = str(_expected_default_tdx_stats_cache_root(local_app_data)) assert cache_paths == [expected_cache, expected_cache] diff --git a/tests/test_tdx_source_request_adapter.py b/tests/test_tdx_source_request_adapter.py index e6ae736..c4e033d 100644 --- a/tests/test_tdx_source_request_adapter.py +++ b/tests/test_tdx_source_request_adapter.py @@ -5515,6 +5515,22 @@ def test_tdx_stats_resource_reuses_parsed_resource_in_process(tmp_path): assert second is first +def _expected_default_tdx_stats_cache_root(local_app_data: Path) -> Path: + """Expected default TDX stats cache root for the current OS. + + Mirrors ``axdata_source_tdx.stats_cache.user_tdx_stats_cache_root`` so the + assertion matches the running platform instead of assuming the Windows + ``LOCALAPPDATA`` layout. + """ + + if os.name == "nt": + return (local_app_data / "AxData" / "cache" / "tdx" / "stats").resolve() + if sys.platform == "darwin": + return (Path.home() / "Library" / "Caches" / "AxData" / "tdx" / "stats").resolve() + base = Path(os.getenv("XDG_CACHE_HOME") or (Path.home() / ".cache")) + return (base / "axdata" / "tdx" / "stats").resolve() + + def test_tdx_direct_adapter_default_stats_cache_is_independent_of_cwd(monkeypatch, tmp_path): from axdata_source_tdx.stats_cache import default_tdx_stats_cache_root @@ -5532,7 +5548,7 @@ def test_tdx_direct_adapter_default_stats_cache_is_independent_of_cwd(monkeypatc second = default_tdx_stats_cache_root() assert first == second - assert first == (local_app_data / "AxData" / "cache" / "tdx" / "stats").resolve() + assert first == _expected_default_tdx_stats_cache_root(local_app_data) def test_tdx_adapter_refreshes_stats_cache_older_than_previous_trade_date(monkeypatch, tmp_path):