Skip to content

test: cover the twilight API with astral-generated fixture data - #84

Open
ceeK wants to merge 1 commit into
mainfrom
chowell/fix-fixture-city-name-encoding
Open

test: cover the twilight API with astral-generated fixture data#84
ceeK wants to merge 1 commit into
mainfrom
chowell/fix-fixture-city-name-encoding

Conversation

@ceeK

@ceeK ceeK commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Summary

The six twilight properties — civilSunrise/Sunset, nauticalSunrise/Sunset, astronomicalSunrise/Sunset — had no coverage; only official sunrise/sunset were tested, leaving three quarters of the public date API unverified.

This adds the six columns to all 237 cities in CorrectResults.json and six parameterized tests mirroring the existing ones, at the same 5-minute accuracy.

Where the expected values come from

Generated with the astral package — an independent NOAA-based implementation — never from Solar itself, so the tests verify the zenith constants are astronomically right rather than merely self-consistent.

The source was validated before being trusted: regenerating the existing sunrise/sunset columns with astral reproduced the committed values to a max of 173s (median 29s), comfortably inside the 5-minute tolerance.

Two things worth a reviewer's attention

The fixture stores events on the local solar day, not the UTC day. For far-eastern/western cities (Wellington, Mexico City) the committed timestamps sit on the neighbouring UTC date, matching Solar's shouldBeYesterday/shouldBeTomorrow shift. I reproduced this by picking the occurrence nearest local mean noon, derived from longitude alone, rather than copying Solar's own heuristic — otherwise a bug in that heuristic would be baked into the fixture meant to test it.

No nulls were needed. All 237 capitals get all three twilights on 2017-02-09, so City uses non-optional Dates consistent with the existing fields. Adding a polar city later would need optionals; it currently fatalErrors with a message naming the missing key.

Verification

  • swift test: 20 tests pass, including 1,422 new city assertions — no extra tolerance needed, even at Nuuk and Reykjavík.
  • The JSON serialiser was proven byte-identical to the committed fixture before writing, so the diff is purely additive: 0 pre-existing field values changed and the city names repaired in fix(tests): repair mojibake'd city names in CorrectResults.json #83 are byte-for-byte intact.

🤖 Generated with Claude Code

The six twilight properties -- civil, nautical and astronomical sunrise and
sunset -- had no coverage at all; only official sunrise/sunset were tested,
leaving three quarters of the public date API unverified.

Adds the six columns to all 237 cities in CorrectResults.json, generated from
the astral package (an independent NOAA-based implementation) rather than from
Solar itself, so the tests verify the zeniths are astronomically correct and
not merely self-consistent.

Regenerating the existing sunrise/sunset columns with astral reproduced the
committed values to within 173s (median 29s), validating the source before it
was trusted for the new columns. No pre-existing field value changed.

Twilight events are stored on the local solar day, matching the fixture's
existing convention, by selecting the occurrence nearest local mean noon
derived from longitude alone -- rather than copying Solar's own +/-1 day
heuristic, which would have baked that heuristic into the fixture meant to
test it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PYPBCzQiXBvadC3y6Ae6FH
@ceeK
ceeK force-pushed the chowell/fix-fixture-city-name-encoding branch from d6fc2a2 to 2efa319 Compare August 31, 2026 15:50
@ceeK ceeK changed the title test: repair fixture city names and cover the twilight API test: cover the twilight API with astral-generated fixture data Aug 31, 2026
@ceeK
ceeK marked this pull request as ready for review August 31, 2026 15:53
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