feat(worker): answer traces stored from the question on and filled in as the answer is made
A trace is now kept the moment the request arrives (at the time it was asked, ms -1), its steps are stored as the engine adds each one, and it ends with the answer. Traces a killed run left unfinished are closed at start. The 대화 screen reads a trace still being made as pending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -244,6 +244,32 @@ def test_each_answer_keeps_how_it_was_made_with_the_records_it_was_given(store):
|
||||
assert (task.via, task.channel_id, task.answer) == ("task", None, "answer for task")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_trace_is_stored_from_the_request_on_and_fills_in_while_the_answer_is_made(store):
|
||||
import time
|
||||
during = []
|
||||
|
||||
def answer(user, text):
|
||||
during.append((store.traces_of(user), time.time())) # the engine has added its steps
|
||||
return "answer"
|
||||
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws)
|
||||
await send(ws, type="voice_join", channel="vc1")
|
||||
await send(ws, type="reply", id="r1", user="100", text="q", via="voice", speak=False)
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "r1")
|
||||
|
||||
asyncio.run(with_worker(body, store=store, brain=FakeBrain(answer)))
|
||||
[(traces, answering_at)] = during
|
||||
[t] = traces
|
||||
assert (t.question, t.answer, t.ms) == ("q", "", -1) # -1: still being made
|
||||
assert [s["kind"] for s in t.steps] == ["records", "tools"]
|
||||
assert t.ts <= answering_at
|
||||
[t] = store.traces_of("100")
|
||||
assert (t.answer, t.ms >= 0, t.ts) == ("answer", True, traces[0].ts)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_without_a_brain_reply_is_an_error():
|
||||
async def body(url):
|
||||
@@ -337,15 +363,16 @@ def test_presence_left_open_by_a_previous_run_is_closed_at_start(store):
|
||||
def test_traces_older_than_thirty_days_are_removed_at_start(store):
|
||||
import time
|
||||
now = time.time()
|
||||
store.add_trace("voice", "vc1", "100", "old", "a", [], ms=1, ts=now - 31 * 86400)
|
||||
store.add_trace("voice", "vc1", "100", "new", "a", [], ms=1, ts=now - 29 * 86400)
|
||||
store.finish_trace(store.start_trace("voice", "vc1", "100", "old", ts=now - 31 * 86400), "a", [], ms=1)
|
||||
store.finish_trace(store.start_trace("voice", "vc1", "100", "new", ts=now - 29 * 86400), "a", [], ms=1)
|
||||
store.start_trace("voice", "vc1", "100", "cut off", ts=now - 60) # a killed run never finished it
|
||||
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws)
|
||||
|
||||
asyncio.run(with_worker(body, store=store))
|
||||
assert [t.question for t in store.traces_of("100")] == ["new"]
|
||||
assert [(t.question, t.ms >= 0) for t in store.traces_of("100")] == [("new", True), ("cut off", True)]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
Reference in New Issue
Block a user