test: stabilize flaky and environment-dependent tests

- test_catalog_bounds_failure_only_keys failed 3/5 runs on Windows: all
  three get() calls land within one time.monotonic() tick, so the eviction
  victim in _reserve() is decided by hash-seeded set iteration order among
  tied recency keys. Pin the catalog to a synthetic strictly-increasing
  monotonic clock (the constructor already accepts one) so the oldest
  entry is evicted deterministically. 5/5 stable after, 3/5 failures before.
- test_equivalent_workspace_paths_share_one_store requires directory
  symlinks, which need admin/developer mode on Windows (WinError 1314).
  Skip with the same pattern the file already uses for file symlinks.
- tests/agent/conftest.py: make_provider() assigned through a spec'd mock
  by reading provider.estimate_prompt_tokens first, which raises
  AttributeError because the attribute is not on the LLMProvider class
  spec; assign a MagicMock directly instead. Latent - no test hit the
  default-provider path until now.
This commit is contained in:
KDB authored and chengyongru committed 2026-09-07 10:54:26 +08:00
1 parent 3f128505d0
commit db918bddd3
3 files changed
+12 -2

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ def make_provider(
temperature=0.1,
reasoning_effort=None,
)
provider.estimate_prompt_tokens.return_value = (10_000, "test")
provider.estimate_prompt_tokens = MagicMock(return_value=(10_000, "test"))
return provider
@@ -387,10 +387,16 @@ def test_catalog_bounds_failure_only_keys() -> None:
calls += 1
raise httpx.ConnectError("offline")
# Real monotonic time can serve identical timestamps to all three
# lookups, making the eviction victim in _reserve() depend on set
# iteration order (hash-seeded). A synthetic strictly-increasing clock
# pins the oldest entry deterministically.
ticks = iter(range(10_000))
catalog = OAuthModelCatalog(
fallback_models=(_fallback_model(),),
fetch=fetch,
max_entries=2,
monotonic=lambda: float(next(ticks)),
)
for key in ("one", "two", "three"):
+5 -1
View File
@@ -193,7 +193,11 @@ def test_equivalent_workspace_paths_share_one_store(tmp_path: Path) -> None:
real_workspace = tmp_path / "real_ws"
real_workspace.mkdir()
link_workspace = tmp_path / "link_ws"
link_workspace.symlink_to(real_workspace, target_is_directory=True)
try:
link_workspace.symlink_to(real_workspace, target_is_directory=True)
except OSError as exc:
# Creating directory symlinks needs admin/developer mode on Windows.
pytest.skip(f"directory symlink unavailable: {exc}")
# Save via the real path, then read via a symlink to the same directory.
manager = SessionManager(workspace=real_workspace)