From 0808e8259ab74a1de8569003fe149b7c30ed962f Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 8 Sep 2026 10:39:42 -0400 Subject: [PATCH] test(telemetry): the old surface needs a row in the window to have a bucket at all (#3712) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The per-source grain test gave `auto_inject` a single row 90 days back and `pre_tool_rule` one 2 days back, then asserted on both buckets. Only the young arm got a bucket: `out["sources"]` is built from the WINDOWED query, so a source with no rows inside the window is absent entirely, and the assertion died on KeyError before it could test anything. `complete_from` and the bucket come from different queries — all-time for the first, windowed for the second — and the fixture only satisfied one of them. Gave `auto_inject` a second row inside the window, which is also the shape being described: an old surface that is STILL recording. The 90-day row still sets its `complete_from`. Still discriminating: auto_inject reads True and pre_tool_rule False, and a per-table `_complete_from` would make both 90 days and fail the second assertion — the regression this test is for. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_011cPyzNnegXHr5iRMzzy5KJ --- tests/test_services_retrieval_telemetry.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_services_retrieval_telemetry.py b/tests/test_services_retrieval_telemetry.py index 709840f..8605e39 100644 --- a/tests/test_services_retrieval_telemetry.py +++ b/tests/test_services_retrieval_telemetry.py @@ -706,11 +706,19 @@ async def test_coverage_is_per_source_because_the_table_is_older_than_its_arms( UID = 990077 now = datetime.now(timezone.utc) async with async_session() as s: - # An old surface, recording since well before any window we ask for. + # An old surface, recording since well before any window we ask for, + # AND still recording inside it. Both rows are needed: `complete_from` + # comes from the all-time query, but a source only gets a bucket at all + # if it has rows in the window, so the 90-day row alone would leave + # nothing to assert on. s.add(RetrievalLog( user_id=UID, source="auto_inject", result_count=1, created_at=now - timedelta(days=90), )) + s.add(RetrievalLog( + user_id=UID, source="auto_inject", result_count=1, + created_at=now - timedelta(days=1), + )) # A young arm, first written INSIDE the window below. s.add(RetrievalLog( user_id=UID, source="pre_tool_rule", result_count=1,