From a0d12dec3032c9182c8bc3900228cd88b4f1462d Mon Sep 17 00:00:00 2001 From: Raymond Chen Date: Mon, 16 Nov 2026 00:04:29 +0000 Subject: [PATCH] test(wakatime): start the read-audit cache cold so the status load count is exact The status route reads the OAuth client secret beside the client id. That secret read asks the vault's read audit whether it is on, and with no live snapshot `secrets.read_audit._enabled` loads config.json once per TTL and caches the answer process-wide. So the route loads config twice on a cold cache and once on a warm one, and the test's exact `[False]` pin passed or failed depending on which test ran before it. Pin both inputs: no live snapshot and an empty audit cache. The test now asserts the exact cold-cache sequence `[False, False]`, both loads off the event loop, whatever ran first. --- test/test_wakatime_handlers.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/test_wakatime_handlers.py b/test/test_wakatime_handlers.py index cb621ecb9852..21287ddb145d 100644 --- a/test/test_wakatime_handlers.py +++ b/test/test_wakatime_handlers.py @@ -19,7 +19,9 @@ import kiro_crew.dashboard.handlers.wakatime as wt import kiro_crew.wakatime.service as wt_service +from kiro_crew.config import live from kiro_crew.dashboard.handlers.wakatime import _csv_safe, _rows_by_project +from kiro_crew.secrets import read_audit class _StubClient: @@ -496,11 +498,18 @@ def _load(cls: Any) -> Any: return _Cfg() monkeypatch.setattr("kiro_crew.config.loader.KiroCrewConfig.load", classmethod(_load)) + # The secret read beside the client-id read asks the vault's read audit + # whether it is on; with no live snapshot that loads config.json once per + # TTL and caches the answer process-wide. Start both cold so the count does + # not depend on which test ran first: one load for the client id, one for + # the audit switch. + monkeypatch.setattr(live, "snapshot", lambda: None) + monkeypatch.setattr(read_audit, "_loaded", None) async with TestClient(TestServer(_oauth_app())) as client: resp = await client.get("/api/wakatime/oauth/status") assert resp.status == 200 assert (await resp.json())["client_configured"] is True - assert on_loop == [False] + assert on_loop == [False, False] @pytest.mark.asyncio