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