test(incumbent): stamp the cache-rate fixture with now, not a fixed date #109

Merged
alee merged 1 commits from fix/incumbent-test-time-bomb into main 2026-10-03 14:54:47 +00:00

View File

@@ -12,6 +12,7 @@ The database tests use the same offline temp-DB pattern as
import sqlite3 import sqlite3
import tempfile import tempfile
from datetime import datetime, timezone
from pathlib import Path from pathlib import Path
import pytest import pytest
@@ -469,16 +470,21 @@ def _seed_measured_cache_rate(conn, provider, model_id,
objective.incumbent_rate_min_observations defaults to 25, so we seed objective.incumbent_rate_min_observations defaults to 25, so we seed
enough rows to clear the floor. enough rows to clear the floor.
Rows are stamped "now", not a fixed date: _measured_cache_rates only reads
rows inside objective.cache_rate_window_hours (168), so a literal date
ages out of the window and the incumbent silently falls back to the
assumed rate. That is how this fixture started failing on 2026-09-20.
""" """
observed_at = datetime.now(timezone.utc).isoformat()
for _ in range(observations): for _ in range(observations):
conn.execute( conn.execute(
"""INSERT INTO energy_observations ( """INSERT INTO energy_observations (
model_id, provider, task_category, model_id, provider, task_category,
prompt_tokens, completion_tokens, cached_prompt_tokens, prompt_tokens, completion_tokens, cached_prompt_tokens,
cached_tokens_source, observed_at cached_tokens_source, observed_at
) VALUES (?, ?, 'general', ?, 500, ?, 'reported', ) VALUES (?, ?, 'general', ?, 500, ?, 'reported', ?)""",
'2026-09-13T00:00:00+00:00')""", (model_id, provider, prompt_tokens, cached_tokens, observed_at),
(model_id, provider, prompt_tokens, cached_tokens),
) )
conn.commit() conn.commit()