The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: trim the reused-final tests to the invariants; tighten comments
kshitijk4poor15cf1417e4c5
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts b/apps/desktop/src/app/session/hooks/use-message-stream/index.tsindex eabba2cfdbb..90707a010e2 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/index.ts@@ -773,12 +773,9 @@ export function useMessageStream({: undefinedconst replaceTextPart = (parts: ChatMessagePart[], interim: boolean) => {- // The backend names this final a response the turn already delivered- // (it streamed before the bubble's last tool, or was sealed as an- // interim): every word is on screen. Settle as is; a text merge- // bounded at the last tool row would paint it a second time. Only- // when this bubble does hold it — a bubble that lost those deltas- // (reconnect) still takes the text through the normal merge.+ // The backend says every word of this final is already on screen; a+ // merge bounded at the last tool row would paint it twice. A bubble+ // that missed those deltas (reconnect) still merges.if (reusedResponse && normalizeWs(partsText(parts)).includes(normalizeWs(finalText))) {return parts}diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/reused-final-after-tool.test.tsx b/apps/desktop/src/app/session/hooks/use-message-stream/reused-final-after-tool.test.tsxindex e2d7a9dd5e0..5e2a4dc3d99 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/reused-final-after-tool.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-message-stream/reused-final-after-tool.test.tsx@@ -56,16 +56,3 @@ it('a reused final whose deltas never reached this window still paints the reply// would leave the bubble without the reply.expect(await texts([...toolRound('m', 'todo_list'), ['message.complete', reused]])).toEqual([ANSWER])})--it('the same words in a second response are not a reused final: both stay', async () => {- const all = (- await texts([- ['message.delta', { text: 'Done.' }],- ...toolRound('t', 'terminal'),- ['message.delta', { text: '\n\nDone.' }],- ['message.complete', { text: 'Done.' }]- ])- ).join('\n')-- expect(all.split('Done.').length - 1).toBe(2)-})diff --git a/tests/agent/test_empty_response_recovery_persistence.py b/tests/agent/test_empty_response_recovery_persistence.pyindex 5f93b1e73ed..bd21c666c53 100644--- a/tests/agent/test_empty_response_recovery_persistence.py+++ b/tests/agent/test_empty_response_recovery_persistence.py@@ -180,11 +180,12 @@ def _response(content="", finish_reason="stop", tool_calls=None):return SimpleNamespace(id="chatcmpl-test", choices=[choice], model="test/model", usage=None)+def _call(name, args, call_id):+ return SimpleNamespace(id=call_id, type="function", function=SimpleNamespace(name=name, arguments=json.dumps(args)))++def _write_file_call(path):- return SimpleNamespace(- id="call_write", type="function",- function=SimpleNamespace(name="write_file", arguments=json.dumps({"path": str(path), "content": "PAYMENT #1 SENT\n"})),- )+ return _call("write_file", {"path": str(path), "content": "PAYMENT #1 SENT\n"}, "call_write")@pytest.fixture@@ -269,10 +270,6 @@ def test_stop_during_empty_response_recovery_keeps_the_executed_tool_call_live(rassert result["messages"][-1]["content"] == result["final_response"]-def _call(name, args, call_id):- return SimpleNamespace(id=call_id, type="function", function=SimpleNamespace(name=name, arguments=json.dumps(args)))--def test_housekeeping_fallback_names_its_final_a_reused_response(real_loop):"""The empty follow-up after a housekeeping tool ends the turn on the answer the model sentBEFORE that tool. The result says so, so a client settles the answer it already showsdiff --git a/tests/tui_gateway/test_turn_payload_reused_final.py b/tests/tui_gateway/test_turn_payload_reused_final.pyindex fc67f346c7e..245819e04c3 100644--- a/tests/tui_gateway/test_turn_payload_reused_final.py+++ b/tests/tui_gateway/test_turn_payload_reused_final.py@@ -4,26 +4,20 @@ The housekeeping-tool fallback (turn_empty_response, ``fallback_prior_turn_conteturn on the answer the model streamed BEFORE its tool call. The renderer bounds "the currentresponse" at the bubble's last tool row, so without an identity it appended that answer again:the same reply twice in one bubble, nothing between the copies when the tool is silent-(``todo_list``). ``response_reused`` is set where the reuse happens, never inferred from equal-text: a model that says the same words in two responses keeps both.+(``todo_list``)."""import contextlibfrom types import SimpleNamespaceimport tui_gateway.server as srv-from agent.stream_delivery import StreamDeliveryMixin---class _Agent(StreamDeliveryMixin):- _session_title_hint = "Scratch"def _payload(monkeypatch, result):monkeypatch.setattr(srv, "_get_usage", lambda _agent: {})monkeypatch.setattr(srv, "render_message", lambda _text, _cols: None)monkeypatch.setattr(srv, "_clear_inflight_turn", lambda _session: None)- agent = _Agent()+ agent = SimpleNamespace(_session_title_hint="Scratch")session = {"pending_title": None, "session_key": "k", "history_lock": contextlib.nullcontext(), "agent": agent}st = SimpleNamespace(result=result, agent=agent, terminal_callback=None, receipt_committed=True, receipt_attempted=False,@@ -38,7 +32,3 @@ def test_reused_final_is_named_on_the_wire(monkeypatch):"response_reused": True})assert payload["response_reused"] is Trueassert srv._event_frame("message.complete", "sid", payload)["params"]["payload"]["response_reused"] is True---def test_a_fresh_final_is_not_named_reused(monkeypatch):- assert "response_reused" not in _payload(monkeypatch, {"final_response": "Here is the answer."})