Location params on best_local_bid / latest_prices (zip / GPS + radius)
Thread zip/lat/lng/radius_miles through the client and both tools; friendly guard for the zip-XOR-gps rule. Formatters surface distance, the searched center, and the nearest-source hint when nothing is in range. - client: best()/latest() take zip/lat/lng/radius_miles - server: location params + docstrings (note Ohio-concentrated coverage) - format: distance column + center/nearest rendering - README + CHANGELOG + advisor prompt library updated - tests: location formatting cases Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,60 @@ def test_fmt_best_no_winner():
|
||||
assert "wheat" in out
|
||||
|
||||
|
||||
def test_fmt_best_with_location_shows_distance():
|
||||
payload = {
|
||||
"commodity": "corn", "today": "2026-05-20",
|
||||
"center": {"lat": 40.78, "lng": -83.81, "zip": "45810", "source": "zip"},
|
||||
"radius_miles": 50.0,
|
||||
"best": {
|
||||
"source_name": "Heritage Cooperative — Ada", "city": "Ada", "state": "OH",
|
||||
"delivery": "May 2026", "bid_cents": 486, "basis_cents": 20,
|
||||
"futures_contract": "ZCN26", "distance_miles": 2.3,
|
||||
"fetched_at": "2026-05-20T15:00:00+00:00",
|
||||
},
|
||||
}
|
||||
out = fmt.fmt_best("corn", payload)
|
||||
assert "(Ada, OH)" in out
|
||||
assert "2.3 mi" in out
|
||||
assert "within 50 mi of ZIP 45810" in out
|
||||
|
||||
|
||||
def test_fmt_best_out_of_range_reports_nearest():
|
||||
payload = {
|
||||
"commodity": "corn", "today": "2026-05-20", "best": None,
|
||||
"center": {"lat": 42.0, "lng": -93.6, "zip": "50010", "source": "zip"},
|
||||
"radius_miles": 50.0,
|
||||
"nearest": {"source_name": "Heritage Cooperative — Ada", "city": "Ada",
|
||||
"state": "OH", "distance_miles": 513.5},
|
||||
}
|
||||
out = fmt.fmt_best("corn", payload)
|
||||
assert "No current-month corn bids within 50 mi of ZIP 50010" in out
|
||||
assert "Nearest tracked elevator" in out
|
||||
assert "513.5 mi" in out
|
||||
|
||||
|
||||
def test_fmt_latest_with_location_adds_distance_column():
|
||||
payload = {
|
||||
"center": {"lat": 40.78, "lng": -83.81, "zip": "45810", "source": "zip"},
|
||||
"radius_miles": 50.0,
|
||||
"rows": [
|
||||
{"source_name": "Heritage Cooperative — Ada", "commodity": "corn",
|
||||
"display_name": "Corn", "commodity_kind": "grain", "delivery": "May 2026",
|
||||
"bid_cents": 486, "basis_cents": 20, "futures_contract": "ZCN26",
|
||||
"distance_miles": 2.3, "fetched_at": "2026-05-20T15:00:00+00:00"},
|
||||
],
|
||||
}
|
||||
out = fmt.fmt_latest(payload)
|
||||
assert "Distance" in out and "2.3 mi" in out
|
||||
assert "within 50 mi of ZIP 45810" in out
|
||||
|
||||
|
||||
def test_fmt_latest_location_no_rows():
|
||||
payload = {"center": {"zip": "50010", "source": "zip"}, "radius_miles": 50.0, "rows": []}
|
||||
out = fmt.fmt_latest(payload)
|
||||
assert "No sources within 50 mi of ZIP 50010" in out
|
||||
|
||||
|
||||
def test_fmt_futures_with_changes():
|
||||
payload = {
|
||||
"commodity": "corn", "delivery": "Jul 2026", "contract": "ZCN26",
|
||||
|
||||
Reference in New Issue
Block a user