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)
|
||||
|
||||
Reference in New Issue
Block a user