fix(tests): date the settled snapshot fixture on the CT clock - #223
Merged
Merged
Conversation
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.
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/test_positions_api.py::test_superseded_live_only_row_is_absent_while_a_current_one_is_servedhas 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_positionsetas_of_date=date.today(), which reads the processtimezone.
is_overlay_supersededcompares that date againstct_date(fetched_at)inAmerica/Chicago. Between 19:00 CT and midnight CTthose 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), thelive overlay taken at that same instant is superseded, dropped, and the row the
assertion looks for is
None.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_dateoverride for tests that need one. The overlay logic was right; thefixture 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 quietlygoing missing.
Verification
TZ=UTCreproduces the CI failure exactly onmain— that is what identifiedit. All three timezones pass with this change; before it, the first two fail
and the third does not.
Additional notes
ngv-trader-bjr.PRs), both of which inherited the red check from
main.src/api/routers/positions.py:167computes DTEwith
date.today(), the same process-clock assumption in production code.Left alone here — it deserves its own change.