fix(weather): fall back to met.no when the open-meteo forecast does not answer

Live 2026-11-18 the open-meteo forecast timed out three times (geocoding
worked) and every weather question ended in 'service unavailable'. The
forecast now waits 6s instead of 10s and then asks met.no (no key),
mapping its symbol to the WMO code the Korean sentence uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-18 01:59:49 +09:00
parent c51e5b2f68
commit 680d4fbdc1
2 changed files with 105 additions and 5 deletions

View File

@@ -404,6 +404,52 @@ class TestWeatherTool:
kw in result.reply_text.lower() for kw in ("location", "city")
)
@patch('requests.get')
def test_when_open_meteo_does_not_answer_met_no_gives_the_weather(self, mock_get):
"""Live 2026-11-18: the open-meteo forecast timed out (geocoding had worked) and the
answer was that the weather service was unavailable."""
geo = Mock(status_code=200, raise_for_status=Mock())
geo.json.return_value = {"results": [{"latitude": 37.57, "longitude": 126.98,
"name": "서울", "country": "대한민국"}]}
met = Mock(status_code=200, raise_for_status=Mock())
met.json.return_value = {"properties": {"timeseries": [{"data": {
"instant": {"details": {"air_temperature": 8.6, "relative_humidity": 96.0,
"wind_speed": 2.2}},
"next_1_hours": {"summary": {"symbol_code": "lightrainshowers_night"}}}}]}}
def get(url, *a, **k):
if "geocoding" in url:
return geo
if "open-meteo" in url:
raise requests.exceptions.Timeout("timed out")
assert "met.no" in url
return met
mock_get.side_effect = get
result = self.tool.run({"location": "서울"}, self.context)
assert result.success is True
assert "서울" in result.reply_text
assert WMO_CODES_KO[80] in result.reply_text
assert str(round(8.6)) in result.reply_text
@patch('requests.get')
def test_when_both_weather_services_fail_the_answer_says_so(self, mock_get):
geo = Mock(status_code=200, raise_for_status=Mock())
geo.json.return_value = {"results": [{"latitude": 37.57, "longitude": 126.98,
"name": "서울", "country": "대한민국"}]}
def get(url, *a, **k):
if "geocoding" in url:
return geo
raise requests.exceptions.Timeout("timed out")
mock_get.side_effect = get
result = self.tool.run({"location": "서울"}, self.context)
assert result.success is False
assert "unavailable" in result.reply_text.lower()
@patch('requests.get')
def test_run_network_timeout(self, mock_get):
"""Test weather with network timeout."""