Add first test suite; fix Timer resume, scraper silent failure
- backend/services/auth_test.go: token-version normalisation, the revocation rule, GenerateJWT/VerifyJWT claim handling. The happy path of AuthenticateTokenWithClaims still needs a DB driver we don't have. - python/tests: travelodge.py's pure functions and the NDJSON event contract. pytest is a commented-out dev dep so the image stays slim. - Timer.vue: the Paused screen now offers Resume, reaching pauseTimer's previously unreachable un-pause branch. - travelodge.py: warn when upstream parses but yields nothing usable, so a field rename is distinguishable from sold-out inventory. - CoverLetters.vue moved out of views/unused/ — it is live on /cv. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -58,6 +58,7 @@ Time budgets
|
||||
instead of the whole request dying at the nginx 300s proxy timeout.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import math
|
||||
import os
|
||||
import threading
|
||||
@@ -68,6 +69,11 @@ from datetime import date, datetime, timedelta
|
||||
|
||||
import requests
|
||||
|
||||
# Every upstream field is read tolerantly, so a Travelodge schema change would
|
||||
# otherwise be indistinguishable from genuinely sold-out inventory. This logger
|
||||
# is the only signal that the difference exists - see `hotels_for`.
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
TL_API = "https://www.travelodge.co.uk/api/v2/hotel"
|
||||
TL_SITE = "https://www.travelodge.co.uk"
|
||||
TFL_API = "https://api.tfl.gov.uk/Journey/JourneyResults/{frm}/to/{to}"
|
||||
@@ -432,7 +438,27 @@ def hotels_for(location, checkin, checkout, rooms, deadline=None):
|
||||
# The fetch deliberately happens outside any cache lock: a slow upstream
|
||||
# must not block other threads reading the cache. Two threads racing on the
|
||||
# same key both fetch and the second write wins, which is harmless.
|
||||
hotels = [normalise_hotel(h) for h in fetch_hotels(location, checkin, checkout, rooms, deadline=deadline)]
|
||||
raw = fetch_hotels(location, checkin, checkout, rooms, deadline=deadline)
|
||||
hotels = [normalise_hotel(h) for h in raw]
|
||||
|
||||
# A response that parsed but yielded nothing usable is the fingerprint of a
|
||||
# renamed upstream field: the tolerant .get()s in `normalise_hotel` turn a
|
||||
# schema change into "no hotels available", which looks exactly like a
|
||||
# sold-out search. Genuine sold-out inventory still carries names and codes,
|
||||
# so warn only when the shape itself came back empty.
|
||||
if raw and not any(h["code"] and h["name"] for h in hotels):
|
||||
log.warning(
|
||||
"Travelodge returned %d hotels for %r (%s..%s) but none had a usable "
|
||||
"code/name - upstream field names may have changed",
|
||||
len(raw), location, checkin, checkout,
|
||||
)
|
||||
elif raw and not any(h["available"] and h["room_price"] is not None for h in hotels):
|
||||
log.warning(
|
||||
"Travelodge returned %d hotels for %r (%s..%s) but none were priced "
|
||||
"and available - sold out, or minPrice/hasAvailability renamed",
|
||||
len(raw), location, checkin, checkout,
|
||||
)
|
||||
|
||||
_tl_cache.set(key, hotels)
|
||||
return hotels
|
||||
|
||||
|
||||
Reference in New Issue
Block a user