test(agent): give the Stop-during-recovery test teeth and drop its real backoff

The kept Stop test passed with the `abort_turn_on_interrupt` scaffold strip
reverted (gate mutation: 68/68 green) because it only checked "pair kept,
tail not tool". Assert the closing row carries the owner's own reason so
reverting that hunk goes red.

The `real_loop` fixture let the first empty response sleep its real 5-7.5 s
backoff; the give-up path is reached through the deterministic-empty guard,
not the wait, so stub `jittered_backoff` to 0 in the fixture (the Stop test
still overrides it). Also drop the never-taken `callable(pending[0])`
branch: every scripted response is a SimpleNamespace.
This commit is contained in:
kshitijk4poor
2026-09-24 14:41:50 +05:30
committed by kshitij
parent 53156ea725
commit 013dcadc10

View File

@@ -197,6 +197,9 @@ def real_loop(tmp_path, monkeypatch):
monkeypatch.setenv("no_proxy", "")
monkeypatch.setattr("agent.title_generator.maybe_auto_title", lambda *a, **k: None)
monkeypatch.setattr("agent.title_generator.start_title_upgrade", lambda *a, **k: None)
# The first empty response backs off 5-7.5 s for real; the give-up path is reached via the
# deterministic-empty guard, not the wait (``turn_empty_response`` imports this lazily).
monkeypatch.setattr("agent.retry_utils.jittered_backoff", lambda *a, **k: 0.0)
monkeypatch.chdir(tmp_path)
db = SessionDB(db_path=tmp_path / "state.db")
sid = "sess-empty-exit"
@@ -218,9 +221,7 @@ def real_loop(tmp_path, monkeypatch):
def run(script, user_message):
pending = list(script)
agent.client = MagicMock()
agent.client.chat.completions.create.side_effect = lambda **_kw: (
pending.pop(0)() if callable(pending[0]) else pending.pop(0)
)
agent.client.chat.completions.create.side_effect = lambda **_kw: pending.pop(0)
return agent.run_conversation(user_message)
yield SimpleNamespace(agent=agent, db=db, sid=sid, ledger=tmp_path / "ledger.txt", run=run)
@@ -267,3 +268,5 @@ def test_stop_during_empty_response_recovery_keeps_the_executed_tool_call_live(r
assert real_loop.ledger.read_text() == "PAYMENT #1 SENT\n"
assert result["interrupted"] is True
_assert_saved_tool_pairs_stay_live(result, real_loop.db, real_loop.sid)
# The Stop owner strips the nudge scaffold itself and closes with its own reason.
assert result["messages"][-1]["content"] == result["final_response"]