MCPcopy
hub / github.com/MinishLab/semble / test_index_cache_staleness_check_scope

Function test_index_cache_staleness_check_scope

tests/test_mcp.py:158–179  ·  view source on GitHub ↗

Local paths are revalidated (and rebuilt when stale) on every get(); git URLs never are.

(
    cache: _IndexCache,
    tmp_path: Path,
    source: str,
    patch_target: str,
    expected_build_calls: int,
    validate_called: bool,
)

Source from the content-addressed store, hash-verified

156 ids=["local_path_rebuilds_when_stale", "git_url_skips_revalidation"],
157)
158async def test_index_cache_staleness_check_scope(
159 cache: _IndexCache,
160 tmp_path: Path,
161 source: str,
162 patch_target: str,
163 expected_build_calls: int,
164 validate_called: bool,
165) -> None:
166 """Local paths are revalidated (and rebuilt when stale) on every get(); git URLs never are."""
167 resolved_source = str(tmp_path) if source == "local_tmp_path" else source
168 with (
169 patch(f"semble.mcp.SembleIndex.{patch_target}", return_value=MagicMock()) as mock_build,
170 patch("semble.mcp.save_index_to_cache"),
171 patch("semble.mcp.get_validated_cache", return_value=None) as mock_validate,
172 # Disable the cooldown: real build duration (here, just thread-dispatch overhead) would
173 # otherwise sometimes exceed the gap between the two get() calls below, flaking the test.
174 patch("semble.mcp._MIN_REVALIDATE_FACTOR", 0),
175 ):
176 await cache.get(resolved_source)
177 await cache.get(resolved_source)
178 assert mock_build.call_count == expected_build_calls
179 assert mock_validate.called is validate_called
180
181
182@pytest.mark.anyio

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected