fix: play on YouTube in one step, Korea as the default location, searches in the user's language
- botBrowser `play`: searches YouTube for the words as said, opens the first video (not an ad, without the playlist) and starts it, in one call (an address given opens that page); `type` also takes `query`. Live 0.1.19: the model stopped on YouTube's home page or the results, a retry was refused as a third call, and the answer still said the video played. - `brain.location` (기본 위치, default 대한민국) goes to the brain as `location_name`: the time line says it without GeoIP (no database on the game PC), and getWeather without a place uses it. - Planner and webSearch keep search words in the user's language (never translated into English), so recommendations fit where the user is. Evals (qwen3:8b, 3 runs): play ending on a playing video found with the words as said 0/6 -> 5/6; Korean searches for Korean requests 6/9 -> 8/9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,10 @@ class FakeSession:
|
||||
self.calls.append(("back",))
|
||||
return self.page
|
||||
|
||||
def play(self, results_url):
|
||||
self.calls.append(("play", results_url))
|
||||
return self.page
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake(monkeypatch):
|
||||
@@ -176,6 +180,25 @@ def test_actions_pass_their_arguments(fake):
|
||||
assert not t.run({"action": "dance"}, ctx()).success
|
||||
|
||||
|
||||
def test_play_searches_youtube_for_the_words_as_said_in_one_call(fake):
|
||||
t = BotBrowserTool()
|
||||
assert t.run({"action": "play", "query": "뉴진스 하입보이"}, ctx()).success
|
||||
assert fake.calls == [("play", "https://www.youtube.com/results?search_query="
|
||||
"%EB%89%B4%EC%A7%84%EC%8A%A4+%ED%95%98%EC%9E%85%EB%B3%B4%EC%9D%B4")]
|
||||
assert not t.run({"action": "play"}, ctx()).success # nothing to play
|
||||
# An address to play opens that page (whose player starts as on any video page opened).
|
||||
fake.calls.clear()
|
||||
t.run({"action": "play", "query": "https://www.youtube.com/watch?v=x"}, ctx())
|
||||
t.run({"action": "play", "url": "www.youtube.com/watch?v=y"}, ctx())
|
||||
assert fake.calls == [("open", "https://www.youtube.com/watch?v=x"), ("open", "https://www.youtube.com/watch?v=y")]
|
||||
|
||||
|
||||
def test_typing_takes_the_words_also_as_query(fake):
|
||||
# Live 2026-11-16: the model wrote query instead of text and the search never ran.
|
||||
BotBrowserTool().run({"action": "type", "query": "아이유 신곡", "submit": True}, ctx())
|
||||
assert fake.calls == [("type", "아이유 신곡", None, True)]
|
||||
|
||||
|
||||
class Broken(FakeSession):
|
||||
"""A session whose connection breaks during `breaks` (after the action may have gone out)."""
|
||||
|
||||
@@ -300,6 +323,15 @@ PAGES = {
|
||||
"/results": "<html><head><title>Results</title></head><body><a href='/watch'>The song</a></body></html>",
|
||||
"/watch": "<html><head><title>Watch</title></head><body>"
|
||||
"<video src='/tone.wav' style='width:90vw;height:300px'></video></body></html>",
|
||||
# Search results with an ad first, then a video (on YouTube the links carry ?v= and more).
|
||||
"/yt": "<html><head><title>Results</title></head><body>"
|
||||
"<div is-ad><a href='/watch?v=ad1'>An ad</a></div>"
|
||||
"<a href='/watch?v=abc&list=RDabc&start_radio=1'>The song</a></body></html>",
|
||||
# Results that show their first video only a moment after the page loaded.
|
||||
"/slow": "<html><head><title>Results</title></head><body><script>setTimeout(() => {"
|
||||
"const a = document.createElement('a'); a.href = '/watch?v=late'; a.textContent = 'Late song';"
|
||||
"document.body.appendChild(a); }, 1500)</script></body></html>",
|
||||
"/none": "<html><head><title>Results</title></head><body>No results</body></html>",
|
||||
# A video page whose player cannot play (its file is missing).
|
||||
"/broken": "<html><head><title>Broken</title></head><body>"
|
||||
"<video src='/missing.mp4' style='width:90vw;height:300px'></video></body></html>",
|
||||
@@ -425,6 +457,20 @@ def test_a_video_page_whose_player_stays_paused_gets_play_pressed_when_clicked_t
|
||||
assert "not playing" in bot_browser._render(page)
|
||||
|
||||
|
||||
def test_play_opens_the_first_video_of_the_results_not_an_ad_and_starts_it(chrome):
|
||||
cdp, site, seen = chrome
|
||||
s = BrowserSession(cdp, time.monotonic() + 25)
|
||||
page = s.play(site + "/yt?search_query=x")
|
||||
assert page["url"] == site + "/watch?v=abc", page["url"]
|
||||
assert [m["playing"] for m in page["media"]] == [True], page
|
||||
assert "/watch?v=ad1" not in seen
|
||||
s.deadline = time.monotonic() + 25
|
||||
assert s.play(site + "/slow")["url"] == site + "/watch?v=late"
|
||||
s.deadline = time.monotonic() + 3
|
||||
with pytest.raises(bot_browser.BrowserError):
|
||||
s.play(site + "/none")
|
||||
|
||||
|
||||
def test_links_that_would_open_a_new_tab_open_in_the_same_tab(chrome):
|
||||
cdp, site, _ = chrome
|
||||
s = BrowserSession(cdp, time.monotonic() + 15)
|
||||
|
||||
@@ -111,3 +111,33 @@ def test_auto_detect_rejects_private_ip_from_opendns():
|
||||
patch("jarvis.utils.location._resolve_public_ip_via_opendns", return_value="192.168.1.1"):
|
||||
result = _get_external_ip_automatically()
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_a_place_set_in_the_settings_is_the_location_and_detection_is_not_tried():
|
||||
"""brain.location (default 대한민국) reaches the brain as location_name: the time line says it,
|
||||
without GeoIP (which has no database on the game PC: "Location: Unknown" before)."""
|
||||
from jarvis.reply import engine
|
||||
with patch.object(engine, "get_location_context_with_timezone") as detect:
|
||||
line = engine._live_time_location_string(types.SimpleNamespace(location_enabled=True, location_name="대한민국"))
|
||||
assert "Location: 대한민국" in line and "Current local time" in line
|
||||
detect.assert_not_called()
|
||||
# Location turned off still wins; no place set means detection as before.
|
||||
off = engine._live_time_location_string(types.SimpleNamespace(location_enabled=False, location_name="대한민국"))
|
||||
assert "Location: Disabled" in off
|
||||
with patch.object(engine, "get_location_context_with_timezone", return_value=("Location: Seoul", None)) as detect:
|
||||
assert "Location: Seoul" in engine._live_time_location_string(types.SimpleNamespace(location_enabled=True, location_name=None))
|
||||
detect.assert_called_once()
|
||||
|
||||
|
||||
def test_the_settings_file_carries_the_place():
|
||||
import json
|
||||
import tempfile
|
||||
from jarvis.config import load_settings
|
||||
with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False) as f:
|
||||
json.dump({"location_name": " 대한민국 "}, f)
|
||||
with patch.dict("os.environ", {"JARVIS_CONFIG_PATH": f.name}):
|
||||
assert load_settings().location_name == "대한민국"
|
||||
with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False) as f:
|
||||
json.dump({"location_name": None}, f)
|
||||
with patch.dict("os.environ", {"JARVIS_CONFIG_PATH": f.name}):
|
||||
assert load_settings().location_name is None
|
||||
|
||||
@@ -253,6 +253,28 @@ class TestWeatherTool:
|
||||
# Verify location detection was called (fallback was attempted)
|
||||
mock_location.assert_called_once()
|
||||
|
||||
@patch('requests.get')
|
||||
@patch('src.jarvis.tools.builtin.weather.get_location_info')
|
||||
def test_without_a_place_the_place_set_in_the_settings_is_used(self, mock_location, mock_get):
|
||||
"""Live 2026-11-16: detection failed on the game PC and "날씨 어때" got "tell me the city";
|
||||
the place set in the settings (brain.location, default 대한민국) is the answer instead."""
|
||||
self.context.cfg.location_name = "South Korea"
|
||||
geo = Mock(raise_for_status=Mock())
|
||||
geo.json.return_value = {"results": [{"latitude": 36.5, "longitude": 127.75, "name": "South Korea",
|
||||
"country": "South Korea"}]}
|
||||
weather = Mock(raise_for_status=Mock())
|
||||
weather.json.return_value = {"current": {"temperature_2m": 12.0, "apparent_temperature": 12.0,
|
||||
"weather_code": 0}}
|
||||
mock_get.side_effect = [geo, weather]
|
||||
result = self.tool.run({}, self.context)
|
||||
assert result.success, result.reply_text
|
||||
assert mock_get.call_args_list[0].kwargs["params"]["name"] == "South Korea"
|
||||
mock_location.assert_not_called()
|
||||
# A place the person asked about still wins over the set one.
|
||||
mock_get.side_effect = [geo, weather]
|
||||
self.tool.run({"location": "Busan"}, self.context)
|
||||
assert mock_get.call_args_list[2].kwargs["params"]["name"] == "Busan"
|
||||
|
||||
@patch('src.jarvis.tools.builtin.weather.get_location_info')
|
||||
def test_run_no_args_uses_fallback(self, mock_location):
|
||||
"""Test weather with no arguments uses user's detected location as fallback."""
|
||||
|
||||
Reference in New Issue
Block a user