Compare commits
7 Commits
app-v0.1.3
...
app-v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e428aad58a | ||
|
|
a665dd8d21 | ||
|
|
a5afdbb221 | ||
|
|
9199ccbd0e | ||
|
|
2a95f58a0e | ||
|
|
81d1e26f61 | ||
|
|
88ee5ec2cb |
2
app/Cargo.lock
generated
2
app/Cargo.lock
generated
@@ -1520,7 +1520,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jarvis-app"
|
name = "jarvis-app"
|
||||||
version = "0.1.30"
|
version = "0.1.33"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "jarvis-app"
|
name = "jarvis-app"
|
||||||
version = "0.1.30"
|
version = "0.1.33"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.85"
|
rust-version = "1.85"
|
||||||
description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels"
|
description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels"
|
||||||
|
|||||||
4
app/shell/Cargo.lock
generated
4
app/shell/Cargo.lock
generated
@@ -2637,7 +2637,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jarvis-app"
|
name = "jarvis-app"
|
||||||
version = "0.1.30"
|
version = "0.1.33"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
@@ -2666,7 +2666,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jarvis-shell"
|
name = "jarvis-shell"
|
||||||
version = "0.1.30"
|
version = "0.1.33"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jarvis-app",
|
"jarvis-app",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "jarvis-shell"
|
name = "jarvis-shell"
|
||||||
version = "0.1.30"
|
version = "0.1.33"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.85"
|
rust-version = "1.85"
|
||||||
description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)"
|
description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)"
|
||||||
|
|||||||
@@ -35,3 +35,13 @@ def debug_log(message: str, category: str = "debug") -> None:
|
|||||||
print(f"[{category:^10}] {message}", file=sys.stderr)
|
print(f"[{category:^10}] {message}", file=sys.stderr)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def notice(message: str, category: str = "debug") -> None:
|
||||||
|
"""A line that is written also without debug logging, to the process's original stderr, so it
|
||||||
|
still reaches the app's log while the voice worker mutes the reply engine's output. It must carry
|
||||||
|
no question, answer, place or other text from the conversation."""
|
||||||
|
try:
|
||||||
|
print(f"[{category:^10}] {message}", file=sys.__stderr__, flush=True)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from datetime import datetime, timedelta, timezone
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
from typing import Dict, Any, Optional
|
from typing import Dict, Any, Optional
|
||||||
from ...debug import debug_log
|
from ...debug import debug_log, notice
|
||||||
from ...utils.location import get_location_info
|
from ...utils.location import get_location_info
|
||||||
from ..base import Tool, ToolContext
|
from ..base import Tool, ToolContext
|
||||||
from ..types import ToolExecutionResult
|
from ..types import ToolExecutionResult
|
||||||
@@ -674,8 +674,8 @@ class WeatherTool(Tool):
|
|||||||
rest = [off for off in offsets if off not in days]
|
rest = [off for off in offsets if off not in days]
|
||||||
if rest:
|
if rest:
|
||||||
days.update(_open_meteo_days(lat, lon, rest))
|
days.update(_open_meteo_days(lat, lon, rest))
|
||||||
debug_log(f" 🌤️ forecast days {first}-{last}: {from_kma} from KMA, "
|
# Which service gave the answer, in the app's log (no place: it comes from the question).
|
||||||
f"{len(days) - from_kma} from open-meteo", "tools")
|
notice(f"weather days {first}-{last}: {from_kma} from KMA, {len(days) - from_kma} from open-meteo", "llm")
|
||||||
place = location_display.split(",")[0].strip() or location_display
|
place = location_display.split(",")[0].strip() or location_display
|
||||||
return [_day_sentence(off, days[off], place, detail) for off in offsets if off in days]
|
return [_day_sentence(off, days[off], place, detail) for off in offsets if off in days]
|
||||||
|
|
||||||
@@ -863,12 +863,12 @@ class WeatherTool(Tool):
|
|||||||
}
|
}
|
||||||
|
|
||||||
current: Dict[str, Any] = {}
|
current: Dict[str, Any] = {}
|
||||||
|
source = "KMA"
|
||||||
kma_key = _kma_key_now()
|
kma_key = _kma_key_now()
|
||||||
if kma_key and country_code == "KR":
|
if kma_key and country_code == "KR":
|
||||||
current = _kma_current(lat, lon, kma_key)
|
current = _kma_current(lat, lon, kma_key)
|
||||||
if current:
|
|
||||||
debug_log(" 🌤️ current weather from KMA", "tools")
|
|
||||||
if not current:
|
if not current:
|
||||||
|
source = "open-meteo"
|
||||||
try:
|
try:
|
||||||
weather_response = requests.get(weather_url, params=weather_params,
|
weather_response = requests.get(weather_url, params=weather_params,
|
||||||
timeout=_OPEN_METEO_TIMEOUT_SEC)
|
timeout=_OPEN_METEO_TIMEOUT_SEC)
|
||||||
@@ -877,12 +877,14 @@ class WeatherTool(Tool):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Live 2026-11-18: the forecast server stopped answering while geocoding worked.
|
# Live 2026-11-18: the forecast server stopped answering while geocoding worked.
|
||||||
debug_log(f"open-meteo forecast failed ({type(e).__name__}); trying met.no", "tools")
|
debug_log(f"open-meteo forecast failed ({type(e).__name__}); trying met.no", "tools")
|
||||||
|
source = "met.no"
|
||||||
current = _met_no_current(lat, lon)
|
current = _met_no_current(lat, lon)
|
||||||
if not current:
|
if not current:
|
||||||
return ToolExecutionResult(
|
return ToolExecutionResult(
|
||||||
success=False,
|
success=False,
|
||||||
reply_text=f"Weather data temporarily unavailable for {location_display}."
|
reply_text=f"Weather data temporarily unavailable for {location_display}."
|
||||||
)
|
)
|
||||||
|
notice(f"weather now: {source}", "llm")
|
||||||
|
|
||||||
# Extract current weather values
|
# Extract current weather values
|
||||||
temp_c = current.get("temperature_2m")
|
temp_c = current.get("temperature_2m")
|
||||||
|
|||||||
@@ -298,7 +298,9 @@ which carry Discord's own time.
|
|||||||
highest chance of rain), then 중기예보 for the nearest of the KMA cities in `weather.py` and its region (중기기온,
|
highest chance of rain), then 중기예보 for the nearest of the KMA cities in `weather.py` and its region (중기기온,
|
||||||
중기육상). Days KMA does not give, and every KMA failure, come from open-meteo (now: then
|
중기육상). Days KMA does not give, and every KMA failure, come from open-meteo (now: then
|
||||||
met.no; later days: open-meteo's daily forecast only). The key is in KMA's URLs, so a failure is
|
met.no; later days: open-meteo's daily forecast only). The key is in KMA's URLs, so a failure is
|
||||||
logged by its kind only. `detail` (only when the user asks for more detail) adds the
|
logged by its kind only. Which service answered is printed without debug logging (category
|
||||||
|
`llm`, no place and no key): `weather now: KMA` (or `open-meteo`, `met.no`) and
|
||||||
|
`weather days <first>-<last>: <n> from KMA, <m> from open-meteo`. `detail` (only when the user asks for more detail) adds the
|
||||||
humidity, the wind in m/s and the rain amount: now the last hour's rain (KMA 초단기실황 RN1,
|
humidity, the wind in m/s and the rain amount: now the last hour's rain (KMA 초단기실황 RN1,
|
||||||
open-meteo `precipitation`; none from met.no), a 단기예보 day its mean humidity and strongest
|
open-meteo `precipitation`; none from met.no), a 단기예보 day its mean humidity and strongest
|
||||||
wind, an open-meteo day its strongest wind and rain total; 중기예보 has none of these. A dry
|
wind, an open-meteo day its strongest wind and rain total; 중기예보 has none of these. A dry
|
||||||
|
|||||||
@@ -433,6 +433,29 @@ class TestWeatherTool:
|
|||||||
assert WMO_CODES_KO[80] in result.reply_text
|
assert WMO_CODES_KO[80] in result.reply_text
|
||||||
assert str(round(8.6)) in result.reply_text
|
assert str(round(8.6)) in result.reply_text
|
||||||
|
|
||||||
|
@patch('requests.get')
|
||||||
|
def test_the_log_names_met_no_when_it_gave_the_weather_now(self, mock_get, capfd):
|
||||||
|
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}},
|
||||||
|
"next_1_hours": {"summary": {"symbol_code": "cloudy"}}}}]}}
|
||||||
|
|
||||||
|
def get(url, *a, **k):
|
||||||
|
if "geocoding" in url:
|
||||||
|
return geo
|
||||||
|
if "open-meteo" in url:
|
||||||
|
raise requests.exceptions.Timeout("timed out")
|
||||||
|
return met
|
||||||
|
mock_get.side_effect = get
|
||||||
|
|
||||||
|
self.tool.run({"location": "Seoul"}, self.context)
|
||||||
|
|
||||||
|
err = capfd.readouterr().err
|
||||||
|
assert "weather now: met.no" in err and "서울" not in err
|
||||||
|
|
||||||
@pytest.mark.parametrize("symbol", ["lightsleet", "sleet_day", "heavysleetshowers_night"])
|
@pytest.mark.parametrize("symbol", ["lightsleet", "sleet_day", "heavysleetshowers_night"])
|
||||||
def test_met_no_sleet_stays_sleet_not_freezing_rain(self, symbol):
|
def test_met_no_sleet_stays_sleet_not_freezing_rain(self, symbol):
|
||||||
from src.jarvis.tools.builtin.weather import _met_no_wmo
|
from src.jarvis.tools.builtin.weather import _met_no_wmo
|
||||||
@@ -722,6 +745,23 @@ class TestKmaWeather:
|
|||||||
assert len(kma) == 2 and all(p["authKey"] == self.KEY for p in kma)
|
assert len(kma) == 2 and all(p["authKey"] == self.KEY for p in kma)
|
||||||
assert all((p["nx"], p["ny"]) == (60, 127) for p in kma)
|
assert all((p["nx"], p["ny"]) == (60, 127) for p in kma)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("key, source", [(True, "KMA"), (False, "open-meteo")])
|
||||||
|
@patch('requests.get')
|
||||||
|
def test_the_log_names_the_service_that_gave_the_weather_now_and_not_the_place(
|
||||||
|
self, mock_get, key, source, monkeypatch, capfd):
|
||||||
|
"""Live 2026-11-18: "흐림" could have come from either service, and nothing said which."""
|
||||||
|
if key:
|
||||||
|
monkeypatch.setenv("JARVIS_KMA_API_KEY", self.KEY)
|
||||||
|
else:
|
||||||
|
monkeypatch.delenv("JARVIS_KMA_API_KEY", raising=False)
|
||||||
|
mock_get.side_effect = self._routes()
|
||||||
|
|
||||||
|
self.tool.run({"location": "Seoul"}, self.context)
|
||||||
|
|
||||||
|
err = capfd.readouterr().err
|
||||||
|
assert f"weather now: {source}" in err
|
||||||
|
assert "Seoul" not in err and self.KEY not in err
|
||||||
|
|
||||||
@patch('requests.get')
|
@patch('requests.get')
|
||||||
def test_precipitation_wins_over_the_sky(self, mock_get, monkeypatch):
|
def test_precipitation_wins_over_the_sky(self, mock_get, monkeypatch):
|
||||||
monkeypatch.setenv("JARVIS_KMA_API_KEY", self.KEY)
|
monkeypatch.setenv("JARVIS_KMA_API_KEY", self.KEY)
|
||||||
@@ -1053,6 +1093,15 @@ class TestForecast:
|
|||||||
assert "강수확률 80%" in result.reply_text
|
assert "강수확률 80%" in result.reply_text
|
||||||
assert not any(self.KEY in str(c) for c in log.call_args_list)
|
assert not any(self.KEY in str(c) for c in log.call_args_list)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("fail_kma, counts", [(False, "1 from KMA, 0 from open-meteo"),
|
||||||
|
(True, "0 from KMA, 1 from open-meteo")])
|
||||||
|
def test_the_log_says_how_many_forecast_days_each_service_gave(self, fail_kma, counts, monkeypatch, capfd):
|
||||||
|
self._run({"days_ahead": 1}, monkeypatch, fail_kma=fail_kma)
|
||||||
|
|
||||||
|
err = capfd.readouterr().err
|
||||||
|
assert f"weather days 1-1: {counts}" in err
|
||||||
|
assert "Seoul" not in err and self.KEY not in err
|
||||||
|
|
||||||
def test_outside_korea_the_forecast_is_open_meteos_daily_one(self, monkeypatch):
|
def test_outside_korea_the_forecast_is_open_meteos_daily_one(self, monkeypatch):
|
||||||
result, calls = self._run({"days_ahead": 1}, monkeypatch, country_code="JP")
|
result, calls = self._run({"days_ahead": 1}, monkeypatch, country_code="JP")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user