From 9811bb64240a2454e2f1e174a68532a8fb5d4729 Mon Sep 17 00:00:00 2001 From: SoundMindsAI Date: Sat, 11 Jul 2026 20:57:12 -0400 Subject: [PATCH] fix(test): make UBI fast-seed rung test time-independent (anchor to now) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_synthetic_ubi_seed_round_trip_hits_rung_3 has been red on main since ~2026-06-28: it hardcoded seed_anchor_iso='2026-05-29', but classify_rung counts events only within a trailing [now - 30d, now] window. ~30 days after the anchor date every seeded event falls outside the window, the count drops to 0, and the rung collapses to rung_1 — deterministically, for everyone, regardless of ES health. (It surfaced on the 2026-07-11 security PR simply as the first CI run past the time-bomb.) Fix: anchor the synthetic events to (now - 1 day) so they always land inside classify's window — matching the real demo paths (demo_seeding.py, seed_meaningful_demos.py), which already anchor at now. This is the only call site that runs the real now-windowed classify_rung against a hardcoded past anchor. Unblocks 'backend (contract + integration)' as a future required status check under the new main branch protection. Signed-off-by: SoundMindsAI --- .../integration/test_demo_seeding_ubi_fast.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/tests/integration/test_demo_seeding_ubi_fast.py b/backend/tests/integration/test_demo_seeding_ubi_fast.py index 08a1ffa9..a402ce5e 100644 --- a/backend/tests/integration/test_demo_seeding_ubi_fast.py +++ b/backend/tests/integration/test_demo_seeding_ubi_fast.py @@ -25,6 +25,7 @@ import json import uuid +from datetime import UTC, datetime, timedelta from pathlib import Path import httpx @@ -121,13 +122,24 @@ async def test_synthetic_ubi_seed_round_trip_hits_rung_3() -> None: query_text_by_index = {i: f"fast-test query {i}" for i in range(5)} # 2. Generate synthetic rows (pure-domain — no I/O). + # + # Anchor the events relative to NOW, not a fixed past date. classify_rung + # (step 5) counts events in a trailing [now - DEFAULT_READINESS_WINDOW_DAYS, + # now] window (30 days), so a hardcoded anchor is a time-bomb: it passes + # until ~30 days after the anchor date, then every event falls outside the + # window and the rung collapses to rung_1. (This is what made the test fail + # ~30 days after its 2026-05-29 anchor — the real demo paths in + # demo_seeding.py / seed_meaningful_demos.py already anchor at `now`.) + # `now - 1 day` keeps events comfortably inside the window with margin below + # classify's half-open `timestamp < until` upper bound. + seed_anchor_iso = (datetime.now(UTC) - timedelta(days=1)).isoformat() queries, events = fabricate_ubi_for_scenario( scenario_judgments_map=scenario_judgments_map, query_id_by_index=query_id_by_index, query_text_by_index=query_text_by_index, target_application=target_application, target_rung="rung_3", - seed_anchor_iso="2026-05-29T00:00:00+00:00", + seed_anchor_iso=seed_anchor_iso, ) assert len(queries) == 5, "rung_3 fabricates one ubi_queries row per query" # rung_3 volumes: 560 impressions + 40 clicks + 40 dwells = 640 events total.