Trim comments to the non-obvious why
Test and deploy / test (push) Successful in 28s
Test and deploy / deploy (push) Successful in 31s

Drop narration, history and restated-code comments across the repo,
keep short ones for security boundaries, upstream quirks and ordering
constraints, and record the convention in CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 20:49:03 +00:00
co-authored by Claude Opus 5.5
parent effddd2794
commit 4530cb8dc4
222 changed files with 1173 additions and 5423 deletions
+3 -12
View File
@@ -124,8 +124,7 @@ def test_ndjson_frames_one_json_object_per_line():
def test_ndjson_omits_none_fields():
# The reader treats an absent key as null, so exclude_none is part of the
# contract rather than only a size optimisation.
# The reader treats absent as null, so exclude_none is contract.
body = read_lines(main._ndjson(iter([main.HotelSearchEvent(event="error", detail="boom")])))
payload = json.loads(body.strip())
assert payload == {"event": "error", "cached": False, "detail": "boom"}
@@ -134,8 +133,6 @@ def test_ndjson_omits_none_fields():
def test_ndjson_headers_defeat_proxy_buffering():
response = main._ndjson(iter([]))
assert response.media_type == "application/x-ndjson"
# Without X-Accel-Buffering an nginx-style proxy holds the whole response
# and the stream is pointless. (Caddy streams it regardless.)
assert response.headers["x-accel-buffering"] == "no"
assert response.headers["cache-control"] == "no-cache"
@@ -240,8 +237,6 @@ def test_a_cached_result_replays_as_the_opening_event_plus_done():
assert len(calls) == 1 # the upstream generator was not run again
assert [e.event for e in replay] == ["hotels", "done"]
assert all(e.cached for e in replay)
# The replay carries the finished rows on both lines, so a streaming reader
# needs no special case for a cache hit.
assert replay[0].rows == replay[1].rows
@@ -267,8 +262,7 @@ def test_search_and_scan_caches_cannot_collide():
def test_an_unfinished_stream_is_not_cached():
# Only "done" writes the cache, so a stream that errored part-way must be
# re-run rather than replayed as if it had completed.
# Only "done" writes the cache.
def gen():
yield "hotels", search_summary(), []
raise travelodge.UpstreamError("Travelodge search failed")
@@ -301,8 +295,6 @@ def test_upstream_failures_become_a_final_error_event(exc, want_detail):
def test_a_failure_while_binding_the_generator_is_also_an_error_event():
# make_gen is called inside the guard precisely so this is a stream event
# rather than a 500 from the endpoint.
def gen():
raise ValueError("bad request")
@@ -333,8 +325,7 @@ def test_the_search_slot_is_released_after_a_failure():
def test_an_abandoned_stream_releases_the_search_slot():
# The frontend closes the connection when the user navigates away, so the
# generator is closed part-way; the finally in _guarded must still run.
# The frontend aborts on navigation; the guard's finally must still run.
def gen():
yield "hotels", search_summary(), []
yield "done", search_summary(), []
+2 -12
View File
@@ -23,8 +23,7 @@ from app import travelodge as tl
(101, 100),
(102, 100),
(103, 105),
# Banker's rounding at the exact half-step: 21.5 and 22.5 both round to
# 22, i.e. 110p. Documented as an ignored sub-penny discrepancy.
# Banker's rounding at the half-step: an accepted sub-penny discrepancy.
(107.5, 110),
(112.5, 110),
# The real use: 1/3 off a rail fare must land on TfL's 5p grid.
@@ -37,8 +36,6 @@ def test_round_5p_snaps_to_the_5p_grid(pence, want):
def test_round_5p_returns_an_int():
# Fares are integer pence everywhere upstream of the final /100, so this
# must not leak a float back into the arithmetic.
assert isinstance(tl.round_5p(103.0), int)
@@ -68,8 +65,7 @@ def test_parse_guests(spec, want):
def test_parse_guests_preserves_room_order():
# Room order is the rooms[i][...] index in the Travelodge query, so it is
# part of the request rather than cosmetic.
# Room order is part of the query.
assert tl.parse_guests("3+1,1,2+2") == [(3, 1), (1, 0), (2, 2)]
@@ -115,8 +111,6 @@ def test_haversine_km_matches_a_known_london_distance():
def test_haversine_km_one_degree_of_latitude_is_about_111km():
# A degree of latitude is the same everywhere, so this pins the radius
# constant independently of any London coordinate.
assert tl.haversine_km((0.0, 0.0), (1.0, 0.0)) == pytest.approx(111.19, abs=0.05)
@@ -153,8 +147,6 @@ def test_sort_rows_orders_by_total_and_sorts_in_place():
def test_sort_rows_puts_unpriced_rows_last():
# An unpriced row must not sort as if it were free, which is what the
# `total is None` leading key prevents.
rows = [row("unpriced", None, 10.0), row("priced", 99.0, 99.0)]
tl.sort_rows(rows)
assert [r["code"] for r in rows] == ["priced", "unpriced"]
@@ -173,8 +165,6 @@ def test_sort_rows_orders_unpriced_rows_among_themselves_by_room_price():
def test_sort_rows_handles_a_zero_total():
# `or 0` collapses a genuine 0.0 total onto the None fallback value, so a
# free row must still sort ahead of an unpriced one.
rows = [row("unpriced", None, 5.0), row("free", 0.0, 0.0)]
tl.sort_rows(rows)
assert [r["code"] for r in rows] == ["free", "unpriced"]