Skip to content

The agent that grows with you

test: two timing tests read the effect, not the clock

Tekniumc6750f29f255
diff --git a/tests/agent/lsp/test_service.py b/tests/agent/lsp/test_service.py
index 0864db1e2e3..825f85368cb 100644
--- a/tests/agent/lsp/test_service.py
+++ b/tests/agent/lsp/test_service.py
@@ -108,7 +108,7 @@ def mock_pyright_silent(monkeypatch, tmp_path):
pass
-def test_snapshot_baseline_honors_wait_timeout(mock_pyright_silent):
+def test_snapshot_baseline_honors_wait_timeout(mock_pyright_silent, monkeypatch):
"""``snapshot_baseline`` must wait at most ``lsp.wait_timeout``, not
the hardcoded client fallback of 5s.
@@ -121,6 +121,18 @@ def test_snapshot_baseline_honors_wait_timeout(mock_pyright_silent):
f = repo / "x.py"
f.write_text("print('hi')\n")
+ # The budget is read off the call, not inferred from wall time: server spawn and initialize
+ # sit inside snapshot_baseline too, and on a loaded runner they ate the margin to 5s.
+ from agent.lsp.client import LSPClient
+ budgets = []
+ real_wait = LSPClient.wait_for_diagnostics
+
+ async def recording_wait(self, path, version, *, mode="document", timeout=None):
+ budgets.append(timeout)
+ return await real_wait(self, path, version, mode=mode, timeout=timeout)
+
+ monkeypatch.setattr(LSPClient, "wait_for_diagnostics", recording_wait)
+
svc = LSPService(
enabled=True,
wait_mode="document",
@@ -132,12 +144,10 @@ def test_snapshot_baseline_honors_wait_timeout(mock_pyright_silent):
svc.snapshot_baseline(str(f))
elapsed = time.monotonic() - start
- # The wait is deadline-based: it always runs the full budget
- # (never less than wait_timeout) and the server never pushes,
- # so both bounds are stable under load.
+ # The wait is deadline-based and the server never pushes, so it runs the full budget.
assert elapsed >= 1.5, f"baseline returned before the wait budget: {elapsed:.2f}s"
- assert elapsed < 4.5, (
- f"baseline ignored wait_timeout=2.0 and ran the 5s fallback: {elapsed:.2f}s"
+ assert budgets and all(b == pytest.approx(2.0) for b in budgets), (
+ f"baseline must wait with wait_timeout=2.0, not the 5s fallback: {budgets}"
)
assert svc.get_status()["broken"] == []
# No fresh data pre-edit -> empty (never stale) baseline.
diff --git a/tests/agent/test_compression_review.py b/tests/agent/test_compression_review.py
index d530c39ce34..d7c49aad0e1 100644
--- a/tests/agent/test_compression_review.py
+++ b/tests/agent/test_compression_review.py
@@ -90,9 +90,11 @@ class TestF1CommitOverrunWhileHung:
t = threading.Thread(target=run, name="f1-hung-commit-host")
t.start()
try:
- assert entered.wait(timeout=2)
+ # Generous: Event.wait returns the moment it is set; a cold executor under load
+ # can take over 2s just to start the worker.
+ assert entered.wait(timeout=10)
# ── Assert WHILE the commit worker is still blocked ──────
- assert overrun_fired.wait(timeout=5), (
+ assert overrun_fired.wait(timeout=10), (
"on_commit_overrun must fire while the commit is hung"
)
assert not release.is_set() # worker provably still blocked