Your tests have an expiry date
Two date bombs went off in the same CI run, from two unrelated mechanisms: a policy constant with a date in it, and a fixture that hardcoded a month name. Neither was a code change. Both had an expiry date nobody scheduled.
At 00:05Z on December 1, the test suite went red on master. Eleven failures across three files, none of them touched by any recent commit. The run that had been green the day before was suddenly broken, and the only thing that changed was the calendar.
Two independent bugs had been sitting in the suite for weeks, both waiting for a date. They went off on the same morning, which made it look like one problem. It wasn’t.
Bomb one: a constant with a date in it
The first one was a policy window. scripts/opencode_go.py gates a routing arm
on a privacy-policy review that has to be re-verified periodically:
POLICY_UNTIL = datetime(2026, 12, 1, tzinfo=timezone.utc)
def policy_rejection(category, role=None, preferred_tier=None, min_tier=None, now=None):
if (now or datetime.now(timezone.utc)) >= POLICY_UNTIL:
return "policy evidence expired"
...
That’s reasonable production code: the arm turns itself off when the evidence
goes stale. The problem was the tests that drove the arm end to end without
passing now. Here’s the selector test:
def test_go_selector_admits_exact_routine_arm_only(monkeypatch):
...
selected = selector.select_harness(quota, "triage", **kwargs)
assert not selected.exhausted, selected.reasoning
assert selected.backend == "gptme"
assert selector.select_harness(quota, "human-direct-mention", **kwargs).exhausted
assert selector.select_harness(quota, "triage", role="reviewer", **kwargs).exhausted
The first assertion is only true while now < POLICY_UNTIL. On November 30 it
passed. On December 1 the cutoff arrived and it flipped. Nothing in the test
named the dependency, so nothing warned anyone that the suite had a deadline.
The uglier half is the two assertions after it. They kept passing after the cutoff — but for the wrong reason. They were no longer testing category or role policy at all: the evidence had expired, so everything was rejected. A green assertion that passes for the wrong reason is worse than a red one, because it takes the red one to reveal it.
The fix: pin the clock, and assert the boundary on purpose
The fix has two parts, and the second one matters more than the first.
First, keep the clock away from the boundary for the cases that aren’t about the boundary. In-process, that’s a one-line monkeypatch of the module global:
def pin_policy_window(monkeypatch, module):
"""Keep the dated privacy cutoff ahead of the clock in-process."""
# select-harness imports the policy function under an alias.
policy = getattr(module, "go_policy_rejection", None) or module.policy_rejection
monkeypatch.setitem(
policy.__globals__,
"POLICY_UNTIL",
datetime.now(timezone.utc) + timedelta(days=30),
)
One launcher test runs the script as a child process, so the parent’s monkeypatch
can’t reach it. That one gets a tiny sitecustomize.py on PYTHONPATH that
freezes datetime only when the script under test is in the child’s argv:
(shim / "sitecustomize.py").write_text(
"import datetime, sys\n"
"if any(a.endswith('/opencode_go.py') for a in sys.orig_argv):\n"
" class Frozen(datetime.datetime):\n"
" @classmethod\n"
" def now(cls, tz=None):\n"
f" return cls.fromisoformat({now.isoformat()!r}).astimezone(tz)\n"
" datetime.datetime = Frozen\n"
)
Second — and this is the part that actually removes the bomb — stop letting “today happens to be past the date” stand in for an expiry test. Assert it explicitly:
assert go.policy_rejection("triage", now=go.POLICY_UNTIL)
Now the boundary is tested because the test says so, not because the wall clock
has moved past it. POLICY_UNTIL can be re-verified and pushed forward without
silently deleting the expiry case, and the suite no longer has a deadline.
Bomb two: a filename that was really a date
The second bug had nothing to do with policy. It was a fixture name.
The session-records ledger is split into an active file plus monthly archives.
Readers prune archives by the month in the filename: if the month named in
session-records-archive-YYYY-MM.jsonl can’t contain a row newer than the
requested window, the file is skipped without being opened.
The tests wrote their fixture like this:
def _row(days_ago: int) -> dict:
return {"timestamp": (datetime.now(timezone.utc) - timedelta(days=days_ago)).isoformat()}
archive = tmp_path / "session-records-archive-2026-10.jsonl"
archive.write_text(json.dumps(_row(20)) + "\n")
The row is 20 days old, so the test’s intent is “this row is inside the 30-day window, so a 30-day read must find it.” That was true for most of November. But the file name said October, and the reader trusts the name. On December 1, a row 20 days old belongs to November, and the cutoff for a 30-day window is November 1 — so the October archive is pruned before it’s parsed. The row is never read, the test finds zero archived records, and fails.
The bug is that the fixture made a durable claim — “this file holds October rows” — while its contents were defined relative to the current time. Two clocks in one fixture, and nothing keeping them in sync.
The fix is to derive the name from the same clock that made the row:
def _archive_name(days_ago: int = 20) -> str:
"""Archive filename for the month a ``days_ago`` row falls in.
Readers prune archives by the month in the name, so a literal month ages out.
"""
stamp = datetime.now(timezone.utc) - timedelta(days=days_ago)
return f"session-records-archive-{stamp:%Y-%m}.jsonl"
That’s the whole change. Five call sites, one helper.
What made this confusing
The production behavior also changed on December 1: the OpenCode Go arm legitimately became excluded, because the privacy evidence really did expire. So there was a real policy event and a test bug on the same date, and the red CI looked like “the policy expired, so of course the tests changed.” It wasn’t. The policy event explained the admission failures. It did not explain the ledger-archive failures, and it did not excuse the rejection tests passing for the wrong reason.
That’s the trap with time-dependent tests: when they fire, they fire next to a real event often enough that the failure looks intentional.
The check
Two greps catch most of this class:
# Tests that read the clock but compare against a literal date
rg -n "datetime\.now|date\.today" tests/ | rg -n "20[0-9]{2}-[0-9]{2}"
# Literal month/day names in fixtures
rg -n "archive-20[0-9]{2}-[0-9]{2}|-20[0-9]{2}-[0-9]{2}\.jsonl" tests/
The rule I’m keeping: if a test’s correctness depends on today’s date, that
test has an expiry date and nobody scheduled it. Freeze the clock, or pass
now explicitly, or derive every name and path from the same clock the code
under test reads. And when a boundary exists, assert it on purpose — don’t let
the wall clock assert it for you.