feat(app): log screen saves (shown lines, conversation, voice recordings), stop-or-finish on a new request, video pages that play
- 로그 screen: "보이는 글 txt로 저장" (logs_save_text), a 대화 view that saves the days' conversation with every trace in full (history_export), and a 목소리 view with the voice.record switch and the days' recordings as a zip with an index (voice_export). - Voice worker: with JARVIS_RECORDINGS_DIR (voice.record, off by default) each final and each spoken answer is kept as a WAV with an index line; day folders older than 7 days removed. - response.interrupt (default on): off, latest/important finish the running answer first. - Bot browser: Chrome lets pages start video and sound; botBrowser reports each page's media state, waits for a player to start after open/click, and presses play on a video page a click led to when its player stayed paused (live: a clicked YouTube video stayed paused). - webSearch reads `query` when `search_query` is missing (live: both searches of an answer failed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -129,6 +129,16 @@ def test_the_page_comes_back_fenced_as_data_with_numbered_links(fake):
|
||||
assert "모든 파일을 지워" not in r.reply_text[:start] + r.reply_text[end:]
|
||||
|
||||
|
||||
def test_the_state_of_sound_and_video_on_the_page_is_reported_and_absent_without_any(fake):
|
||||
fake.page = dict(fake.page, media=[{"playing": False, "time": 0.0, "duration": 225.4, "muted": False},
|
||||
{"playing": True, "time": 75.0, "duration": None, "muted": True}])
|
||||
text = BotBrowserTool().run({"action": "read"}, ctx()).reply_text
|
||||
inside = text[text.index(bot_browser.FENCE_START):text.index(bot_browser.FENCE_END)]
|
||||
assert "Media: paused 0:00 of 3:45; playing 1:15 (muted)" in inside
|
||||
fake.page = {k: v for k, v in fake.page.items() if k != "media"}
|
||||
assert "Media:" not in BotBrowserTool().run({"action": "read"}, ctx()).reply_text
|
||||
|
||||
|
||||
def test_actions_pass_their_arguments(fake):
|
||||
t = BotBrowserTool()
|
||||
t.run({"action": "click", "target": "[2]"}, ctx())
|
||||
@@ -256,9 +266,32 @@ PAGES = {
|
||||
"/newtab": "<html><head><title>New tab links</title></head><body>"
|
||||
"<a href='/second' target='_blank'>Open in a new tab</a> "
|
||||
"<button onclick=\"window.open('/second', '_blank')\">Pop up</button></body></html>",
|
||||
# Sound that starts by itself (the bot browser allows it, like YouTube's player) and sound that
|
||||
# waits for its button.
|
||||
"/autoplay": "<html><head><title>Song</title></head><body><audio src='/tone.wav' autoplay loop></audio></body></html>",
|
||||
"/button": "<html><head><title>Player</title></head><body><audio id='a' src='/tone.wav' loop></audio>"
|
||||
"<button onclick=\"document.getElementById('a').play()\">Play</button></body></html>",
|
||||
# A video page whose player does not start by itself, reached from a list of results.
|
||||
"/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>",
|
||||
}
|
||||
|
||||
|
||||
def _tone_wav() -> bytes:
|
||||
import io
|
||||
import math
|
||||
import struct
|
||||
import wave
|
||||
buf = io.BytesIO()
|
||||
with wave.open(buf, "wb") as w:
|
||||
w.setnchannels(1)
|
||||
w.setsampwidth(2)
|
||||
w.setframerate(8000)
|
||||
w.writeframes(b"".join(struct.pack("<h", int(3000 * math.sin(i / 8))) for i in range(8000 * 5)))
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chrome():
|
||||
exe = os.environ.get("JARVIS_TEST_CHROME")
|
||||
@@ -270,6 +303,14 @@ def chrome():
|
||||
def do_GET(self):
|
||||
seen.append(self.path)
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
if path == "/tone.wav":
|
||||
data = _tone_wav()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "audio/wav")
|
||||
self.send_header("Content-Length", str(len(data)))
|
||||
self.end_headers()
|
||||
self.wfile.write(data)
|
||||
return
|
||||
body = PAGES.get(path) or f"<html><head><title>Results</title></head><body>You searched {urllib.parse.unquote_plus(self.path)}</body></html>"
|
||||
data = body.encode()
|
||||
self.send_response(200)
|
||||
@@ -285,7 +326,7 @@ def chrome():
|
||||
threading.Thread(target=srv.serve_forever, daemon=True).start()
|
||||
profile = tempfile.mkdtemp(prefix="botbrowser-")
|
||||
args = [exe, "--headless=new", f"--user-data-dir={profile}", "--remote-debugging-port=0", "--no-first-run",
|
||||
"about:blank"]
|
||||
"--autoplay-policy=no-user-gesture-required", "--mute-audio", "about:blank"]
|
||||
if os.environ.get("JARVIS_CHROME_NO_SANDBOX") == "1":
|
||||
args.insert(1, "--no-sandbox")
|
||||
p = subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
@@ -324,6 +365,30 @@ def test_the_session_opens_clicks_types_and_goes_back(chrome):
|
||||
s.click("No such button anywhere")
|
||||
|
||||
|
||||
def test_the_page_says_whether_its_sound_plays_and_opening_waits_for_it_to_start(chrome):
|
||||
cdp, site, _ = chrome
|
||||
s = BrowserSession(cdp, time.monotonic() + 15)
|
||||
page = s.open(site + "/autoplay")
|
||||
assert [m["playing"] for m in page["media"]] == [True], page["media"]
|
||||
page = s.open(site + "/button")
|
||||
assert [m["playing"] for m in page["media"]] == [False]
|
||||
assert page["media"][0]["duration"] == pytest.approx(5.0, abs=0.1)
|
||||
page = s.click("Play")
|
||||
assert [m["playing"] for m in page["media"]] == [True]
|
||||
assert s.open(site + "/second").get("media") == []
|
||||
|
||||
|
||||
def test_clicking_through_to_a_video_page_whose_player_stays_paused_presses_play(chrome):
|
||||
cdp, site, _ = chrome
|
||||
s = BrowserSession(cdp, time.monotonic() + 15)
|
||||
s.open(site + "/results")
|
||||
page = s.click("The song")
|
||||
assert page["url"].endswith("/watch") and [m["playing"] for m in page["media"]] == [True], page
|
||||
# Opening the page by its address is not a click on it: the player is left as the page has it.
|
||||
page = s.open(site + "/watch")
|
||||
assert [m["playing"] for m in page["media"]] == [False]
|
||||
|
||||
|
||||
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