Skip to content

fix(tests): date the settled snapshot fixture on the CT clock - #223

Merged
westonplatter merged 1 commit into
mainfrom
fix/positions-test-utc-day-boundary
Aug 30, 2026
Merged

westonplatter merged 1 commit into
mainfrom
fix/positions-test-utc-day-boundary

Conversation

@westonplatter

Copy link
Copy Markdown
Owner

Summary

tests/test_positions_api.py::test_superseded_live_only_row_is_absent_while_a_current_one_is_served
has failed in CI on every run since #219 merged, while passing locally. It is
not flaky and it is not a timing race — it fails on any machine whose local
calendar date is ahead of the Chicago one, which is every UTC machine after
00:00 UTC. CI runs around 02:00 UTC.

Two lines of test-fixture change; src/ is untouched.

Fixes

make_position set as_of_date=date.today(), which reads the process
timezone. is_overlay_superseded compares that date against
ct_date(fetched_at) in America/Chicago. Between 19:00 CT and midnight CT
those two clocks name different days, so the fixture dated its settled snapshot
one day ahead of its own capture — a state the real FlexQuery sync cannot
produce.

The test then reads exactly as designed: with as_of > ct_date(capture), the
live overlay taken at that same instant is superseded, dropped, and the row the
assertion looks for is None.

E       TypeError: 'NoneType' object is not subscriptable
>       assert _row(payload, CON_ES)["source"] == "live"

The fixture now derives the trade date from the capture instant with ct_date
— the same helper production compares against — and accepts an explicit
as_of_date override for tests that need one. The overlay logic was right; the
fixture disagreed with it about which clock names a trade date.

Also adds one guard asserting that invariant directly, so a future
date.today() fails on the reason rather than on a downstream row quietly
going missing.

Verification

TZ=UTC          uv run --group dev --extra mcp pytest   # 246 passed
TZ=Asia/Tokyo   ...                                     # 246 passed
TZ=America/Denver (local)                               # 246 passed

TZ=UTC reproduces the CI failure exactly on main — that is what identified
it. All three timezones pass with this change; before it, the first two fail
and the third does not.

Additional notes

tests/test_positions_api.py::test_superseded_live_only_row_is_absent_while_a_current_one_is_served
has failed on main since #219, in CI only. Reproduces locally with TZ=UTC.

make_position set as_of_date=date.today(), which reads the *process*
timezone, while is_overlay_superseded compares that date against
ct_date(fetched_at) in America/Chicago. On a UTC machine after 00:00 UTC
-- 19:00 CT, and CI runs around 02:00 UTC -- the fixture dated the
settled snapshot one day ahead of its own capture, so a live overlay
taken at that same instant read as superseded and was dropped. The row
the test expects to be served went missing.

The fixture now derives the trade date from the capture instant with
ct_date, the same helper production compares against, and takes an
explicit as_of_date override. No src/ change: the overlay logic was
right, the fixture disagreed with it about which clock names a trade
date.

Adds a guard pinning that invariant directly, so a future date.today()
fails on the reason rather than on a downstream row going missing.

Verified: 246 passed under TZ=UTC, TZ=Asia/Tokyo, and local MDT; the
failure reproduces under TZ=UTC before the change.
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bf2bd41d-a0d0-457d-aebd-47533f15e405

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@westonplatter
westonplatter merged commit 6be2651 into main Aug 30, 2026
2 checks passed
@westonplatter
westonplatter deleted the fix/positions-test-utc-day-boundary branch August 30, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant