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,
)
| 156 | ids=["local_path_rebuilds_when_stale", "git_url_skips_revalidation"], |
| 157 | ) |
| 158 | async 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 |