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:
javis-bot
2026-11-16 15:27:57 +09:00
parent 1cdfbf5151
commit cbe898d3d0
25 changed files with 879 additions and 30 deletions

View File

@@ -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)

View File

@@ -376,3 +376,73 @@ def test_speakers_who_leave_free_their_place_and_finish_their_utterance():
finals = [m for m in seen if m.get("type") == "final"]
assert [m["speaker"] for m in finals] == [f"user{i}" for i in range(len(finals))]
assert len(finals) > MAX_SPEAKERS and all(m["text"] == "level 0.9" for m in finals)
def _index(root):
import pathlib
days = [d for d in pathlib.Path(root).iterdir() if d.is_dir()]
assert len(days) == 1
lines = [json.loads(x) for x in (days[0] / "index.jsonl").read_text(encoding="utf-8").splitlines()]
return days[0], lines
@pytest.mark.unit
def test_with_recordings_on_each_utterance_and_spoken_answer_is_kept_as_a_wav_with_its_text(tmp_path):
import wave
from voice_worker.recordings import Recorder
recorder = Recorder(tmp_path)
async def body(url):
async with connect(url) as ws:
await hello(ws, stt={"partials": False})
await ws.send(json.dumps({"type": "member_join", "user": "alice", "name": "Alice"}))
await stream(ws, "alice", 0.9, 600)
await ws.send(json.dumps({"type": "speaking_end", "speaker": "alice"}))
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "final")
await ws.send(json.dumps({"type": "tts", "id": "r1", "text": "오늘은 맑아요. 기온은 17.5도예요."}))
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
asyncio.run(with_worker(body, tts=FakeTts(), recorder=recorder))
recorder.close()
day, lines = _index(tmp_path)
said, spoke = lines
assert (said["kind"], said["who"], said["text"]) == ("said", "alice", "level 0.9")
assert (spoke["kind"], spoke["text"], spoke["cancelled"]) == ("spoke", "오늘은 맑아요. 기온은 17.5도예요.", False)
with wave.open(str(day / said["file"])) as w:
assert (w.getframerate(), w.getnchannels()) == (16000, 1)
assert 500 <= w.getnframes() * 1000 // 16000 <= 900
with wave.open(str(day / spoke["file"])) as w:
# Mono at the session's TTS rate; FakeTts makes 10 samples per character of each sentence.
assert (w.getframerate(), w.getnchannels()) == (24000, 1)
assert w.getnframes() == (len("오늘은 맑아요.") + len("기온은 17.5도예요.")) * 10
@pytest.mark.unit
def test_without_a_recorder_nothing_is_written(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
async def body(url):
async with connect(url) as ws:
await hello(ws, stt={"partials": False})
await stream(ws, "alice", 0.9, 600)
await ws.send(json.dumps({"type": "speaking_end", "speaker": "alice"}))
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "final")
asyncio.run(with_worker(body, tts=FakeTts()))
assert list(tmp_path.iterdir()) == []
@pytest.mark.unit
def test_recordings_older_than_the_keep_days_are_removed_at_start(tmp_path):
from datetime import date, datetime, timedelta
from voice_worker.recordings import KEEP_DAYS, Recorder
today = date(2026, 11, 16)
keep = [today - timedelta(days=i) for i in range(KEEP_DAYS)]
old = today - timedelta(days=KEEP_DAYS)
for d in keep + [old]:
(tmp_path / d.isoformat()).mkdir()
(tmp_path / "notes").mkdir() # not a day folder: left alone
Recorder(tmp_path, now=datetime(2026, 11, 16, 12).timestamp()).close()
assert sorted(p.name for p in tmp_path.iterdir()) == sorted([d.isoformat() for d in keep] + ["notes"])

View File

@@ -73,3 +73,13 @@ def test_master_off_never_uses_browser_even_if_live(monkeypatch):
def test_master_off_no_signal_uses_gemini(monkeypatch):
assert _route(monkeypatch, False, None) == "gemini"
def test_a_query_given_as_query_instead_of_search_query_still_searches(monkeypatch):
# Live 2026-11-16: the planner wrote "webSearch query='...'" and the model passed `query`;
# both searches failed with "Please provide a search query".
seen = []
monkeypatch.setattr(rs, "gemini_cli_search", lambda q, *a, **k: seen.append(q) or "GEMINI_RESULT")
monkeypatch.setattr(rs, "gemini_search", lambda q, *a, **k: seen.append(q) or "GEMINI_RESULT")
res = WebSearchTool().run({"query": "안강 산책 코스"}, _ctx(False, None))
assert res.reply_text == "GEMINI_RESULT" and seen[:1] == ["안강 산책 코스"]