HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
"""The aider backend (Aider-AI/aider, Apache-2.0, pinned to 0.86.2).
aider is the only backend here driven IN PROCESS, and every test below pins one of the reasons why.
The reason that decided it: on stdout, model prose beginning `litellm.AuthenticationError:` is
BYTE-IDENTICAL to a real 401 — same stream, same exit code 0 — so a text-parsing normaliser would
turn ordinary answers into provider failures. In process the channels are separate at the source.
Source anchors (all 0.86.2):
return_coder / forced yes_always aider/main.py:451, 546-547
the ONE explicit_yes_required site aider/coders/base_coder.py handle_shell_commands
shell extraction, diff format only aider/coders/editblock_coder.py get_edits
shell output is not reflected aider/coders/base_coder.py:1609-1614
MODEL_ALIASES (21 rewrites) aider/models.py:87-111
TAGS_CACHE_DIR, no CLI flag aider/repomap.py:43
"""
import json
import os
import pathlib
import sys
import tempfile
import subprocess
import types
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
import aider_driver # noqa: E402
from server import (Auth, BACKENDS, _AIDER_SESSION_NAME, _aider_eof, # noqa: E402
_aider_mcp_block,
_aider_to_claude, _agent_doc_path, _build_aider, _resume_lost)
# ── the policy gate: what makes tool_enforcement "hard" true rather than asserted ──
def test_an_ordinary_command_is_approved_and_named_shell():
g = aider_driver._Gate([])
assert g.decide("python3 stamp.py") == (True, "Shell", "")
def test_disabling_shell_refuses_the_command_the_model_proposed():
g = aider_driver._Gate(["Shell"])
approved, tool, reason = g.decide("python3 stamp.py")
assert approved is False and tool == "Shell"
assert "disabled shell commands" in reason
def test_an_mcp_call_is_named_for_the_tool_it_invokes():
"""The bridge's call form. Naming the call after the MCP tool is what lets the support matrix
measure `mcp_called` from a command that actually ran — aider itself has no MCP client at all
(zero source hits across the 0.86.2 tree)."""
g = aider_driver._Gate([])
assert g.mcp_calls_in("hr-mcp call deepwiki read_wiki_structure --params {}") == \
[("deepwiki", "read_wiki_structure")]
approved, tool, _ = g.decide("hr-mcp call deepwiki read_wiki_structure --params {}")
assert approved is True and tool == "deepwiki.read_wiki_structure"
def test_disabling_an_mcp_tool_refuses_it_by_its_own_name():
g = aider_driver._Gate(["read_wiki_structure"])
approved, tool, reason = g.decide("hr-mcp call deepwiki read_wiki_structure --params {}")
assert approved is False and tool == "deepwiki.read_wiki_structure"
assert "read_wiki_structure" in reason
def test_a_disabled_tool_is_refused_wherever_the_call_stands_in_a_compound_command():
"""gpt-5.4, with probe_sse disabled, proposed `hr-mcp tools probe && hr-mcp call probe
probe_sse` and a gate that read argv[0..3] saw a discovery and let the call through (hr-test,
2026-09-18). The whole command is scanned; the bridge refuses the same name itself."""
g = aider_driver._Gate(["probe_sse"])
assert g.decide("hr-mcp tools probe && hr-mcp call probe probe_sse --params '{}'")[0] is False
assert g.decide("cd x; .harness/bin/hr-mcp call probe probe_sse")[0] is False
assert g.decide("echo | hr-mcp call probe probe_sse")[0] is False
ok, name, _ = g.decide("hr-mcp call probe other_tool")
assert ok and name == "probe.other_tool"
# the bridge's own refusal, by bare name and by server.tool
cfg = {"mcpServers": {"probe": {"url": "https://x/sse"}}, "disabledTools": ["probe_sse"]}
assert aider_mcp_bridge._refused(cfg, "probe", "probe_sse").startswith("hr-mcp: the harness disabled")
assert aider_mcp_bridge._refused({"disabledTools": ["probe.probe_sse"]}, "probe", "probe_sse")
assert aider_mcp_bridge._refused(cfg, "probe", "other") == ""
# and the runner writes the names beside the servers
_, d, _, _ = _build(tools_disabled=["probe_sse"], mcp_servers=[{"name": "probe", "url": "https://x/sse", "transport": "sse"}])
doc = json.loads(pathlib.Path(d, ".harness", "aider-mcp.json").read_text())
assert doc["disabledTools"] == ["probe_sse"] and "probe" in doc["mcpServers"]
def test_a_command_that_merely_mentions_hr_mcp_is_not_an_mcp_call():
"""`hr-mcp` in prose, or a bare `hr-mcp tools <server>` discovery call, is a shell command —
only the four-part `call` form names a tool, and treating anything else as one would invent an
MCP call in the turn record."""
g = aider_driver._Gate([])
assert g.mcp_calls_in("echo hr-mcp call x y") == []
assert g.mcp_calls_in("hr-mcp tools deepwiki") == []
def test_an_unparseable_command_does_not_crash_the_gate():
g = aider_driver._Gate([])
assert g.mcp_calls_in('hr-mcp call "unclosed') == []
assert g.decide('hr-mcp call "unclosed')[1] == "Shell"
# ── the normalizer ───────────────────────────────────────────────────────────────
def _norm(events):
state: dict = {}
out = []
for e in events:
out += _aider_to_claude(e, state)
return [e for e in out if e.get("subtype") != "init"], state
def test_an_error_the_turn_recovered_from_does_not_fail_it():
"""gpt-5.4 wrote an edit aider refused ("not in the subpath"), was told, wrote it again and
aider applied it; the driver said ok and the normaliser said failed on the earlier error.
The driver's verdict is the verdict; the error text is the reason only when it says not ok."""
state: dict = {"_aider_init": True}
_aider_to_claude({"m": "error", "p": {"text": "The LLM did not conform to the edit format."}}, state)
_aider_to_claude({"m": "edits", "p": {"files": ["deck.md"]}}, state)
ev = _aider_to_claude({"m": "result", "p": {"ok": True, "final": "The deck outline is in deck.md."}}, state)[0]
assert ev["is_error"] is False and ev["result"] == "The deck outline is in deck.md."
state = {"_aider_init": True}
_aider_to_claude({"m": "error", "p": {"text": "litellm.AuthenticationError: bad key"}}, state)
ev = _aider_to_claude({"m": "result", "p": {"ok": False, "final": ""}}, state)[0]
assert ev["is_error"] is True and ev["result"] == "litellm.AuthenticationError: bad key"
def test_a_failure_on_the_error_channel_is_not_rendered_as_the_answer():
"""The whole point of the driver. io.tool_error is reachable only by aider itself; the model's
prose cannot reach it. The text becomes the turn's reason and never its result."""
out, state = _norm([
{"m": "text", "p": {"text": "Here is what I found about the error handling."}},
{"m": "error", "p": {"text": "litellm.AuthenticationError: Incorrect API key provided"}},
{"m": "result", "p": {"ok": False, "final": ""}},
])
rendered = [e for e in out if e.get("type") == "assistant"]
assert len(rendered) == 1 # the prose rendered
res = out[-1]
assert res["is_error"] is True
assert "AuthenticationError" in res["result"]
def test_aiders_advice_about_its_own_chat_commands_is_cut_from_the_reason():
"""show_exhausted_error ends with `- Use /tokens …`, `- Use /drop …`, `- Use /clear …`: in-chat
commands this product never shows. Same rule kimi's resume hint earned."""
state: dict = {"_aider_init": True}
text = ("Model openai/gpt-5.4 has hit a token limit!\n\nInput tokens: ~300,000 of 272,000 "
"-- possibly exhausted context window!\n\nTo reduce input tokens:\n"
"- Use /tokens to see token usage.\n- Use /drop to remove unneeded files from the chat "
"session.\n- Use /clear to clear the chat history.\n- Break your code into smaller source files.\n")
_aider_to_claude({"m": "error", "p": {"text": text}}, state)
reason = state["_aider_error"]
assert "Use /" not in reason
assert "hit a token limit" in reason and "Break your code into smaller source files." in reason
ev = _aider_to_claude({"m": "result", "p": {"ok": False, "final": ""}}, state)[0]
assert ev["is_error"] and "Use /" not in ev["result"]
def test_prose_that_merely_mentions_an_error_still_succeeds():
"""The case an anchored stdout regex cannot get right, and the driver gets right for free."""
out, _ = _norm([
{"m": "text", "p": {"text": "litellm.AuthenticationError: is raised when the key is bad."}},
{"m": "result", "p": {"ok": True, "final": "litellm.AuthenticationError: is raised when the key is bad."}},
])
assert out[-1]["is_error"] is False
assert out[-1]["subtype"] == "success"
def test_an_approved_command_renders_as_a_call_and_its_real_result():
out, _ = _norm([
{"m": "shell_decision", "p": {"command": "python3 stamp.py", "tool": "Shell",
"approved": True, "reason": ""}},
{"m": "shell_result", "p": {"tool": "Shell", "command": "python3 stamp.py",
"output": "STAMP-OK"}},
])
call = out[0]["message"]["content"][0]
res = out[1]["message"]["content"][0]
assert call["type"] == "tool_use" and call["name"] == "Shell"
assert call["input"] == {"command": "python3 stamp.py"}
assert res["type"] == "tool_result" and res["tool_use_id"] == call["id"]
assert res["is_error"] is False and res["content"] == "STAMP-OK"
def test_a_refused_command_is_a_complete_pair_with_the_policy_as_its_result():
"""Nothing ran, so the policy IS the result — and the reader sees the refusal rather than a
call that silently never finished."""
out, _ = _norm([{"m": "shell_decision", "p": {"command": "rm -rf /", "tool": "Shell",
"approved": False,
"reason": "the harness disabled shell commands"}}])
assert len(out) == 2
res = out[1]["message"]["content"][0]
assert res["is_error"] is True and "disabled shell commands" in res["content"]
def test_usage_is_empty_rather_than_aiders_own_numbers():
"""aider fills the real field names with a tiktoken ESTIMATE when streaming (587 against a true
595, measured) and reads cache under names an OpenAI response never carries. Per the 2026-09-13
decision the relay supplies these, and no harness PR builds its own usage pipeline."""
out, _ = _norm([{"m": "result", "p": {"ok": True, "final": "done"}}])
assert out[0]["usage"] == {}
def test_eof_only_speaks_when_the_driver_never_reached_its_result():
assert _aider_eof({"final": "x"}, 0)[0]["subtype"] == "success"
assert _aider_eof({"_aider_error": "boom"}, 1)[0]["result"] == "boom"
def test_backend_is_registered_with_its_eof():
assert BACKENDS["aider"]["normalize"] is _aider_to_claude
assert getattr(BACKENDS["aider"]["normalize"], "eof", None) is _aider_eof
# ── argv, environment and the bridge ─────────────────────────────────────────────
def _build(**kw):
d = tempfile.mkdtemp()
env: dict = {}
cmd = _build_aider("openai-api", Auth(api_key="sk-t", base_url="https://up.example/v1"),
"gemini-2.5-pro", "do it", d, env, **kw)
return cmd, d, env, json.loads(cmd[-1])
def test_the_model_id_is_prefixed_so_aiders_alias_table_cannot_rewrite_it():
"""MODEL_ALIASES rewrites 21 BARE ids, `gemini-2.5-pro` among them — an id this catalog also
serves. The openai/ prefix routes through litellm verbatim and skips that table, which is the
same class of silent substitution that pruned the gemini catalog."""
_, _, _, job = _build()
assert job["model"] == "openai/gemini-2.5-pro"
def test_the_real_key_never_reaches_aider():
_, _, env, _ = _build()
assert env["OPENAI_API_KEY"].startswith("hr-relay-")
assert env["OPENAI_API_BASE"] != "https://up.example/v1"
def test_the_bridge_actually_reaches_the_model_and_is_runnable():
"""The defect this pins: the block was generated by a function nobody called, so the bridge
existed and the model was never told it did — MCP was dead code that unit-testing the generator
in isolation could not see. Assert the whole chain instead: config written, shim on PATH and
executable, and the instructions appended to the doc the driver puts into the system message."""
d = tempfile.mkdtemp()
doc = pathlib.Path(d, "AGENTS.md")
doc.write_text("# harness contract\n")
env: dict = {}
_build_aider("openai-api", Auth(api_key="sk-t", base_url="https://up.example/v1"),
"gpt-5.4", "do it", d, env,
mcp_servers=[{"name": "deepwiki", "url": "https://mcp.deepwiki.com/mcp"}])
cfg = json.loads(pathlib.Path(d, ".harness", "aider-mcp.json").read_text())
assert cfg == {"mcpServers": {"deepwiki": {"url": "https://mcp.deepwiki.com/mcp"}}, "disabledTools": []}
shim = pathlib.Path(d, ".harness", "bin", "hr-mcp")
assert shim.is_file() and shim.stat().st_mode & 0o111 # executable
assert str(shim.parent) in env["PATH"].split(":")
text = doc.read_text()
assert "# harness contract" in text # appended, not overwritten
assert "hr-mcp call" in text and "deepwiki" in text
assert "```bash" in text # the only surface aider can propose a tool through
def test_no_bridge_is_advertised_when_no_server_is_declared():
d = tempfile.mkdtemp()
doc = pathlib.Path(d, "AGENTS.md"); doc.write_text("# harness contract\n")
_build_aider("openai-api", Auth(api_key="sk-t", base_url="https://up.example/v1"),
"gpt-5.4", "do it", d, {}, mcp_servers=[])
text = doc.read_text()
assert text.startswith("# harness contract\n")
assert "hr-mcp" not in text and "## MCP servers" not in text
assert _aider_mcp_block({}) == ""
def test_the_doc_tells_the_model_how_this_workspace_works_and_names_the_skills_by_relative_path():
"""aider's own prompt says the USER adds files and may run the suggested commands; here the
driver does both, and a model that was not told behaved as aider's prompt says (guessed a
skill's token, declared itself unable to run a tool, invented a result). The block names each
SKILL.md as a `cat` the model can run on any turn; aider's own file-mention route adds only
files git already tracks, which a first turn's skill files are not."""
d = tempfile.mkdtemp()
sk = pathlib.Path(d, ".harness", "skills", "plugin-probe"); sk.mkdir(parents=True)
sk.joinpath("SKILL.md").write_text("---\nname: plugin-probe\n---\n")
doc = pathlib.Path(d, "AGENTS.md"); doc.write_text("# harness contract\n")
_build_aider("openai-api", Auth(api_key="sk-t", base_url="https://up.example/v1"),
"gpt-5.4", "do it", d, {}, mcp_servers=[])
text = doc.read_text()
assert "## How this workspace works for you" in text
assert "- `cat .harness/skills/plugin-probe/SKILL.md`" in text
assert "```bash" in text and "Report only output you were actually given" in text
assert "never by an absolute path" in text
assert "A new file is created by writing it" in text and "added to the chat first" in text
# written fresh each turn on top of the doc the turn wrote: no growth across turns
doc.write_text("# harness contract\n")
_build_aider("openai-api", Auth(api_key="sk-t", base_url="https://up.example/v1"),
"gpt-5.4", "do it", d, {}, mcp_servers=[])
assert doc.read_text().count("## How this workspace works for you") == 1
def test_edit_blocks_are_stripped_from_the_answer_and_the_edits_render_as_cards():
"""The SEARCH/REPLACE markup is aider's wire format for an edit; the console showed it raw as
the reply ("hello.py ```python <<<<<<< SEARCH ======= print(...) >>>>>>> REPLACE ```",
hr-test 2026-09-18). The prose is the answer; each edited file is a card, as on every base."""
text = ("I will create the file.\n\nhello.py\n```python\n<<<<<<< SEARCH\n=======\n"
"print(\"aider\")\n>>>>>>> REPLACE\n```\n\nDONE-FILE")
assert aider_driver.strip_edit_blocks(text) == "I will create the file.\n\n\nDONE-FILE"
# the file name inside the fence, the shape gpt-5.5 writes and aider's parser also takes
inside = ("Deck builder:\n```python\nbuild_sfo.py\n<<<<<<< SEARCH\n=======\nfrom pptx import "
"Presentation\n>>>>>>> REPLACE\n```\nRun it with `python3 build_sfo.py`.")
assert aider_driver.strip_edit_blocks(inside) == "Deck builder:\nRun it with `python3 build_sfo.py`."
# fences of four backticks, which aider's parser takes and gpt-5.4 writes: nothing is left
# behind (a stripper that took exactly three left "`" as the whole answer, hosted 2026-09-19)
four = ("````python\nbuild.py\n<<<<<<< SEARCH\n=======\nx = 1\n>>>>>>> REPLACE\n````\n"
"````bash\npython3 build.py\n````\n")
assert aider_driver.strip_edit_blocks(four) == ""
assert aider_driver.strip_edit_blocks("````bash\nls\n````\nDone.") == "Done."
shell = "Run this:\n```bash\ncat SKILL.md\n```"
assert aider_driver.strip_edit_blocks(shell) == "Run this:" # the command renders as a card
# a fence the model closed and kept writing on ("```An improved…") closes the block for aider
# (editblock_coder.py:478) and the sentence is prose
assert aider_driver.strip_edit_blocks("```bash\nofficecli view a.pptx\n```An improved style.\nDone.") == "An improved style.\nDone."
state: dict = {"_aider_init": True}
evs = _aider_to_claude({"m": "edits", "p": {"files": ["hello.py", "b.txt"]}}, state)
calls = [c for e in evs for c in e["message"]["content"] if c["type"] == "tool_use"]
results = [c for e in evs for c in e["message"]["content"] if c["type"] == "tool_result"]
assert [c["name"] for c in calls] == ["Edit", "Edit"]
assert [c["input"]["file_path"] for c in calls] == ["hello.py", "b.txt"]
assert [r["tool_use_id"] for r in results] == [c["id"] for c in calls]
# the result event's text is what the gateway stores as the answer: stripped there too, or
# the markup comes back through the other door (measured: the text event was clean and the
# stored answer still carried the block)
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert 'final = strip_edit_blocks(coder.partial_response_content or "")' in src
def test_a_path_line_aiders_lookback_takes_is_stripped_with_its_block():
"""gpt-5.4 answered just "hello.txt" (1 of 3 follow-up probes, hosted, 2026-10-19): it set the
path line off from the fence — a blank line between them, or a trailing space on the name —
and aider still applied the edit, because find_filename reads the 3 lines before
`<<<<<<< SEARCH` and strips each one (editblock_coder.py:492, 538-569; strip_filename:408),
while the strip's path group took only a bare \\S+ line DIRECTLY above the fence. The leftover
path then beat the edits sentence as the answer. The group now takes what the parser takes:
whitespace around the name, one blank line at most (the parser's 3-line window holds no more),
and still one token only, so a prose line is never swallowed."""
S = aider_driver.strip_edit_blocks
block = "```text\n<<<<<<< SEARCH\nhello\n=======\nhello\nworld\n>>>>>>> REPLACE\n```\n"
assert S("hello.txt\n\n" + block) == "" # path + blank line + fence (measured)
assert S("hello.txt \n" + block) == "" # trailing space on the path (measured)
assert S("hello.txt\t\n" + block) == ""
assert S(" hello.txt\n" + block) == "" # leading spaces: strip_filename strips
assert S("hello.txt \n \n" + block) == "" # a whitespace-only line is a blank one
assert S("Done.\n\nhello.txt\n\n" + block) == "Done." # prose above the path is kept
# a second blank line puts the path outside find_filename's window: it is not the block's
assert S("hello.txt\n\n\n" + block) == "hello.txt"
# a line with internal spaces is prose, never a path, whatever sits under it
assert S("I will edit hello.txt now.\n" + block) == "I will edit hello.txt now."
assert S("I will edit hello.txt now.\n\n" + block) == "I will edit hello.txt now."
# the name inside the fence tolerates the same whitespace, and the whole block still matches
inside = "```python\nbuild.py \n<<<<<<< SEARCH\n=======\nx = 1\n>>>>>>> REPLACE\n```\n"
assert S("Deck builder:\n" + inside) == "Deck builder:"
def test_a_turn_that_ended_on_a_command_says_so_rather_than_saying_nothing():
"""A response that was commands and nothing else leaves no answer once the blocks are cards;
the record then read as an empty reply (hosted, 2026-09-19: seven officecli attempts, no text,
no file). The sentence states what happened; a turn with an answer, an edit-only turn (no
commands) and a failed turn keep their own text."""
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert "if not final.strip() and not failed and (gate.calls or coder.aider_edited_files):" in src
assert "The task ended without a written answer after running commands." in src
# an edit-only turn says which files it changed (below), not that it wrote no answer
assert "The task ended without a written answer after editing files." not in src
assert "final = _edits_sentence(edited, before)" in src
def test_a_turn_that_only_wrote_edit_blocks_says_which_files_it_changed(tmp_path):
"""The model's whole reply was the edit block, without the "done" it was asked for (6 of 24 on
"Create a file named hello.txt containing hi, then say done.", 2026-10-19), and the answer read
"The task ended without a written answer". It now names what the turn changed, from the edits
themselves: created when the file was not in the workspace before the turn, edited when it
was. Nothing is said that the edits do not show."""
S = aider_driver._edits_sentence
assert S(["hello.txt"], set()) == "Created hello.txt."
assert S(["hello.txt"], {"hello.txt"}) == "Edited hello.txt."
assert S(["a.txt", "b.txt"], set()) == "Created a.txt and b.txt."
assert S(["hello.txt", "src/x.py", "y.md"], {"src/x.py", "y.md"}) == "Created hello.txt and edited src/x.py and y.md."
assert S(["a", "b", "c", "d"], {"c", "d"}) == "Created a and b, and edited c and d."
assert S(["a", "b", "c"], {"a", "b", "c"}) == "Edited 3 files."
assert S(["n1", "n2", "n3", "old"], {"old"}) == "Created 3 files and edited old."
assert S(["hello.txt"], None) == "Edited hello.txt." # no listing: every written file is edited
# created means absent before the turn, by path: a hello.txt elsewhere does not make it edited
(tmp_path / "src").mkdir()
(tmp_path / "src" / "hello.txt").write_text("x")
before = aider_driver._workspace_paths(str(tmp_path))
assert before == {"src/hello.txt"}
assert S(["hello.txt"], before) == "Created hello.txt."
assert "hello.txt" in aider_driver._workspace_names(str(tmp_path)) # the nudge's bare names stay
def test_a_reply_that_announces_work_and_does_none_is_nudged_once():
"""gpt-5.5 on "build a 1 pager ppt about SFO" wrote "I'll create a one-page PowerPoint deck
about SFO and save it in the workspace." with zero commands and the turn ended; at a terminal
the person types "go ahead". The nudge is that, once, only for a reply that reads as an
announcement; a plain answer, a reply that acted, and a second announcement get none."""
a = aider_driver._announces_without_acting
# the typographic apostrophe gpt-5.4 writes, a need stated instead of met, and a paragraph
# that says the task is not finished (three aider browser turns on hr-test 0.25.13, 2026-09-28)
assert a("I’ll open the page in the browser, click its only link, then report the destination URL.")
assert a("I need to use the browser for this, not edit any files.")
assert a("The browser output shows example.com loaded.\n\nTo complete the task, I still need to click the link.")
assert not a("Done. The page I’ll leave as it is; the file you need to edit is notes.csv.")
assert a("I'll create a one-page PowerPoint deck about SFO and save it in the workspace.")
assert a("Sure, I will build the deck now.") and a("Let me start by reading the skill.")
assert a("Okay. I'm going to write the outline first.") and a("Here's the plan:\n1. read")
assert not a("M1-gpt-5.4") and not a("The file I'll need is hello.py, which exists.")
assert not a("Done. The deck is at SFO.pptx.") and not a("")
class Coder:
def __init__(self, replies):
self.replies = list(replies); self.reflected_message = None
self.partial_response_content = ""; self.aider_edited_files = set(); self.max_reflections = 5
self.io = types.SimpleNamespace(user_input=lambda p: None); self.sent = []
def init_before_message(self): pass
def send_message(self, m):
self.sent.append(m); self.partial_response_content = self.replies.pop(0); return iter(())
gate = aider_driver._Gate([])
c = Coder(["I'll create the deck and save it in the workspace.", "I'll do it right away."])
aider_driver._run_turn(c, "build a deck", gate)
assert c.sent == ["build a deck", aider_driver.NUDGE] # nudged once, not twice
c = Coder(["M1-gpt-5.4"]); aider_driver._run_turn(c, "Reply with exactly: M1-gpt-5.4", gate)
assert c.sent == ["Reply with exactly: M1-gpt-5.4"] # an answer is not nudged
c = Coder(["I'll create it.\n\nsfo.md\n```md\n<<<<<<< SEARCH\n=======\n# SFO\n>>>>>>> REPLACE\n```"])
c.aider_edited_files = {"sfo.md"}; aider_driver._run_turn(c, "make sfo.md", gate)
assert c.sent == ["make sfo.md"] # it acted: no nudge
def test_a_request_that_names_a_file_to_write_is_told_apart_from_a_question():
"""#379: the request decides, not the reply. A create or write verb opening a clause, and a
file name with a lettered extension in the same sentence that does not exist yet; a question,
a version number, an abbreviation, an address, a file the request only reads from, a file that
exists and a file asked for in an earlier turn are none."""
d = tempfile.mkdtemp()
pathlib.Path(d, "notes.md").write_text("n\n"); pathlib.Path(d, "utils.py").write_text("x = 1\n")
pathlib.Path(d, "data.csv").write_text("a,b\n")
pathlib.Path(d, "src").mkdir(); pathlib.Path(d, "src", "app.py").write_text("x = 1\n")
pathlib.Path(d, "report.final.md").write_text("r\n")
f = lambda text: aider_driver._files_asked_for(text, d)
assert f("Create a file named hello-aider.txt containing exactly the word HELLO, then reply DONE.") == ["hello-aider.txt"]
assert f("Please write a short poem about autumn into poem.md") == ["poem.md"]
assert f("Read the notes, then write it to out/report.md") == ["out/report.md"]
assert f("Can you create `config.yaml` with a port of 8080?") == ["config.yaml"]
assert f("Write a summary of notes.md into summary.md") == ["summary.md"]
assert f("I want you to save the results in results.csv.") == ["results.csv"]
assert f("Create a.txt and b.txt, then reply DONE") == ["a.txt", "b.txt"]
assert f("what would a hello.txt contain?") == [] and f("how do I create config.yaml?") == []
assert f("Reply with exactly: M1-gpt-5.4") == [] and f("Summarize what changed in 0.29.0") == []
assert f("Make the tests pass for gpt-5.4-mini") == [] and f("Write a summary of ideas.md") == []
assert f("Write a summary of `ideas.md`") == [] and f('Write a summary from "ideas.md"') == []
assert f("Write a script, e.g. a bash one-liner, that prints the date") == []
assert f("Draft an email to [email protected] about the launch") == []
assert f("Write unit tests for utils.py") == [] and f("Export the table in data.csv to JSON") == []
assert f("Create a file. What is hello.txt?") == [] and f("") == [] and f(None) == []
assert f("Create notes.v2.txt") == ["notes.v2.txt"] # every dot kept
assert f("Write the output to ./out.txt, then reply DONE") == ["out.txt"]
# binary types are not asked for by edit block: a .pptx written as text is a corrupt file
assert f("Make a one-slide deck deck.pptx, then reply DONE") == [] and f("Create logo.png") == []
# what the requested program reads or produces is not a file to make now
assert f("Write a script that parses config.yaml") == []
# "and save results.csv" after it reads as the person's own ask, as in "fetch it and save
# results.csv", and is kept as one
assert f("Write a Python script to load input.json and save results.csv") == ["results.csv"]
assert f("Write a Python script that loads input.json and saves results.csv") == []
assert f("Save it to the file out.md") == ["out.md"] and f("Write it to out/report.md") == ["out/report.md"]
assert f("Create a project with main.py and utils2.py, then reply DONE") == ["main.py", "utils2.py"]
assert f("Create docker-compose.prod.yml for the app") == ["docker-compose.prod.yml"]
assert f("Create report.final.md with a title") == [] # it exists, whole name
assert f("Create .env with FOO=1") == [".env"] and f("Write a Dockerfile, then reply DONE") == ["Dockerfile"]
assert f("Write the result to ../out.txt") == [] # not in the workspace
assert f("Write a Node.js script that prints hi") == [] and f("Build a Next.js app") == []
assert f("Write a scraper for example.com") == []
# a site whose ending is also a file type (#499 review)
assert f("Write a scraper for wikipedia.org") == [] and f("Create a crawler for python.org that saves pages") == []
assert f("Build a checker for crates.rs") == [] and f("Write a tool for golang.go") == []
assert f("Write lib.rs and main.go") == ["lib.rs", "main.go"] and f("Create deploy.sh") == ["deploy.sh"]
assert f("Write a function that calls subprocess.run and prints the output") == []
assert f("Create a wrapper around requests.Session") == [] and f("Build a .NET console app") == []
assert f("Fix the parser and make sure the output goes to parsed.json") == []
assert f("Create .gitignore for node") == [".gitignore"] and f("Save it as poem.md.") == ["poem.md"]
# a name the scan's cut runs through is not taken as a shorter name
long = "Create " + "y" * 290 + " report.css" # the 300-character scan ends at "report.c"
assert f(long) == [] and f(long.replace("y" * 290, "y" * 280)) == ["report.css"]
assert f("Create App.js with a root component") == ["App.js"] # a file, not a framework
assert f("Make the header in app.py bold") == [] # src/app.py is that file
# the workspace's own list: git's in a repo of any size, and a list nobody could read counts
# every bare name as present
g = tempfile.mkdtemp(); pathlib.Path(g, "deep", "er").mkdir(parents=True)
pathlib.Path(g, "deep", "er", "util.py").write_text("x\n")
subprocess.run(["git", "init", "-q", g], check=True)
assert "util.py" in aider_driver._workspace_names(g) and "deep/er/util.py" in aider_driver._workspace_names(g)
assert aider_driver._files_asked_for("Write tests for util.py into test_util.py", g) == ["test_util.py"]
assert aider_driver._files_asked_for("Create new.py", "/nonexistent", None) == []
earlier = ("<conversation_so_far>\nThis is the conversation in this session so far. Continue it; "
"do not repeat it.\nuser: create a.txt\nassistant: done\n</conversation_so_far>\n\n")
assert f(earlier + "What is in it?") == []
assert f(earlier + "Now create b.md please") == ["b.md"]
assert f("make " + "x " * 5000 + "out.txt") == [] # the scan is bounded
def test_a_file_request_answered_with_a_word_and_no_edit_is_nudged_once():
"""gpt-5.4 answered the matrix's artifact request with "DONE" and no file, 4 of 4, and gpt-5.5
the same (#379). The nudge names the file and asks for the edit block; once per turn, shared
with the announcement nudge; never for a question, a reply that asks one, nor a turn that
edited or ran something."""
root = tempfile.mkdtemp()
class Coder:
def __init__(self, replies, edits=None, gate=None):
self.replies = list(replies); self.edits = list(edits or []); self.gate = gate
self.reflected_message = None; self.partial_response_content = ""; self.root = root
self.aider_edited_files = set(); self.max_reflections = 5
self.io = types.SimpleNamespace(user_input=lambda p: None); self.sent = []
def init_before_message(self): self.aider_edited_files = set()
def send_message(self, m):
self.sent.append(m); self.partial_response_content = self.replies.pop(0)
step = self.edits.pop(0) if self.edits else None
if step and step.startswith("edit"):
name = step.partition(":")[2] or "hello-aider.txt"
self.aider_edited_files.add(name); pathlib.Path(root, name).write_text("x\n")
elif step == "run": # the command writes the file, as echo would
self.gate.calls.append({"command": "echo HELLO > hello-aider.txt", "approved": True})
pathlib.Path(root, "hello-aider.txt").write_text("HELLO\n")
elif step == "read": # a command that writes nothing
self.gate.calls.append({"command": "cat SKILL.md", "approved": True})
return iter(())
ask = "Create a file named hello-aider.txt containing exactly the word HELLO, then reply DONE."
nudge = aider_driver._file_nudge(["hello-aider.txt"], "DONE") # the reply was the word
plain = aider_driver._file_nudge(["hello-aider.txt"]) # the reply was more than that
assert "`hello-aider.txt`" in nudge and "SEARCH/REPLACE" in nudge
assert "does not need to be added to the chat" in nudge
assert "`a.txt`, `b.txt`" in aider_driver._file_nudge(["a.txt", "b.txt"])
gate = aider_driver._Gate([])
c = Coder(["DONE", "DONE"], edits=[None, "edit"])
logged = []; c.io = types.SimpleNamespace(user_input=logged.append)
aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask, nudge] # nudged, then wrote it
# the history a recycled sandbox restores holds every message the model saw, the nudge too
assert logged == [ask, nudge]
pathlib.Path(root, "hello-aider.txt").unlink()
c = Coder(["DONE", "DONE"]); aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask, nudge] # once, not twice
c = Coder(["I'll create it now.", "I'll do it."]); aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask, plain] # one nudge, the specific one
c = Coder(["Paris."]); aider_driver._run_turn(c, "What is the capital of France?", gate)
assert c.sent == ["What is the capital of France?"] # a question is not nudged
c = Coder(["It would hold HELLO."]); aider_driver._run_turn(c, "what would a hello.txt contain?", gate)
assert len(c.sent) == 1
c = Coder(["Which port should it use?"]); aider_driver._run_turn(c, "Create config.yaml for the service", gate)
assert len(c.sent) == 1 # it asked the person something
c = Coder(["Which port should it use? Let me know."]); aider_driver._run_turn(c, "Create config.yaml", gate)
assert len(c.sent) == 1
c = Coder(["Which port should it listen on?\n\nLet me know and I'll write it."])
aider_driver._run_turn(c, "Create config.yaml", gate)
assert len(c.sent) == 1 # the question, then a sign-off
c = Coder(["DONE, it calls https://api.x.com/v1?id=1", "DONE"]); aider_driver._run_turn(c, ask, gate)
assert len(c.sent) == 2 # a URL's "?" asks nobody
c = Coder([""]); aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask] # a failed call is not repeated
g = aider_driver._Gate([])
g.calls.append({"command": "echo HELLO > hello-aider.txt", "approved": False})
c = Coder(["DONE", "DONE"]); aider_driver._run_turn(c, ask, g)
assert c.sent == [ask, nudge] # a refused command ran nothing
c = Coder(["DONE"], edits=["edit"]); aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask] # it wrote the file
pathlib.Path(root, "hello-aider.txt").unlink()
# two files asked for and one written: nudged for the other alone, once
two = "Create a.txt and b.txt, then reply DONE."
c = Coder(["DONE", "DONE"], edits=["edit:a.txt", "edit:b.txt"]); aider_driver._run_turn(c, two, gate)
assert c.sent == [two, aider_driver._file_nudge(["b.txt"], "DONE")]
assert "`a.txt`" not in c.sent[1] and "it is not written yet" in c.sent[1]
pathlib.Path(root, "hello-aider.txt").write_text("HELLO\n")
c = Coder(["DONE"]); aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask] # it is there already
pathlib.Path(root, "hello-aider.txt").unlink()
g = aider_driver._Gate([])
c = Coder(["DONE"], edits=["run"], gate=g); aider_driver._run_turn(c, ask, g)
assert c.sent == [ask] # it ran a command for it
pathlib.Path(root, "hello-aider.txt").unlink()
g = aider_driver._Gate([])
c = Coder(["DONE", "DONE"], edits=["read"], gate=g); aider_driver._run_turn(c, ask, g)
assert c.sent == [ask, nudge] # a command that made no file
# a command run on an earlier pass of the turn counts too: its output came back as a
# reflection and the next pass answered with the word
g = aider_driver._Gate([])
c = Coder(["```bash\necho HELLO > hello-aider.txt\n```", "DONE"], edits=["run"], gate=g)
real_send = c.send_message
def send(m):
out = real_send(m)
if len(c.sent) == 1:
c.reflected_message = "Output: \n\n" + aider_driver.REFLECT_ASK
return out
c.send_message = send
aider_driver._run_turn(c, ask, g)
assert len(c.sent) == 2 and c.sent[1] != nudge # the reflection, no nudge after
pathlib.Path(root, "hello-aider.txt").unlink()
# a pending reflection (a lint result to feed back) is never replaced by the nudge
c = Coder(["DONE", "DONE", "DONE"]); real = c.send_message
def pending(m):
out = real(m)
if len(c.sent) == 1:
c.reflected_message = "lint: fix this"
return out
c.send_message = pending
aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask, "lint: fix this", nudge]
def test_a_file_request_answered_with_the_requested_word_gets_the_block_to_write():
"""#513: a file request that comes after a few exact-reply turns ("Reply with exactly:
M1-gpt-5.4-mini", M2, M3) is answered by gpt-5.4-mini with the requested word and no file:
"Create a file named hello-aider.txt containing exactly the word HELLO, then reply DONE."
answered "DONE", 5 of 6, and answered "DONE" again after the nudge; a fresh session wrote the
file 3 of 3. The nudge a paragraph asks for does not lift the model out of the pattern, so a
reply that is nothing but a word of the request gets the block to write, with the path in it.
A reply that says more than that word keeps the plain nudge."""
root = tempfile.mkdtemp()
class Coder:
def __init__(self, replies):
self.replies = list(replies); self.reflected_message = None
self.partial_response_content = ""; self.root = root
self.aider_edited_files = set(); self.max_reflections = 5
self.io = types.SimpleNamespace(user_input=lambda p: None); self.sent = []
def init_before_message(self): pass
def send_message(self, m):
self.sent.append(m); self.partial_response_content = self.replies.pop(0)
return iter(())
gate = aider_driver._Gate([])
ask = "Create a file named hello-aider.txt containing exactly the word HELLO, then reply DONE."
c = Coder(["DONE", "DONE"]); aider_driver._run_turn(c, ask, gate)
assert len(c.sent) == 2
nudge = c.sent[1]
assert "'DONE' is not the answer" in nudge # the word is not the answer
assert "<<<<<<< SEARCH" in nudge and "hello-aider.txt\n```" in nudge # the block, path in it
assert "does not need to be added to the chat" in nudge
c = Coder(["I'll create it now.", "I'll do it."]); aider_driver._run_turn(c, ask, gate)
assert "<<<<<<< SEARCH" not in c.sent[1] # more than a word: the plain nudge
c = Coder(["Sure", "Sure"]); aider_driver._run_turn(c, ask, gate)
assert "<<<<<<< SEARCH" not in c.sent[1] # a word that is not the request's
repeats = aider_driver._repeats_a_word_of
assert repeats("DONE", ask) == "DONE" and repeats("done.", ask) == "done"
assert repeats("DONE\n\nDONE", ask) == "DONE" # the same word twice
assert repeats("I wrote DONE", ask) == "" and repeats("Sure", ask) == ""
assert repeats("", ask) == "" and repeats("DONE", "") == ""
# The release check of 0.35.13 (2026-10-21): a fresh session answered the same request with two
# NUL characters, a blank line and "DONE" (8 output tokens, no file). What has no letter or
# digit in it is not a word, so that reply is the word too.
assert repeats("\u0000\u0000\n\nDONE", ask) == "DONE"
assert repeats("he", "Write the file") == "" # a word of the request, not part of one
# rc.1 of 0.35.14 (2026-10-22): 2 of 6 primed runs answered with the word in a fenced block, twice.
# A fence and its language tag are formatting, not words.
assert repeats("```text\nDONE\n```\n\n```text\nDONE\n```", ask) == "DONE"
def test_a_request_for_words_back_answered_by_an_edit_alone_is_nudged_once():
"""The runner read-back on 0.35.3's driver (2026-10-18): "Create a file named hello.txt
containing hi, then say done." gpt-5.4-mini answered with the edit block and no other word (its
chat history), so hello.txt was written and the answer was "The task ended without a written
answer after editing files." A request that asks for words back gets one nudge for them, and
the nudged reply is the answer; a reply with words, a request that asks for none, a failed call
and a second wordless reply get none."""
root = tempfile.mkdtemp()
class Coder:
def __init__(self, replies, edits=None, gate=None):
self.replies = list(replies); self.edits = list(edits or []); self.gate = gate
self.reflected_message = None; self.partial_response_content = ""; self.root = root
self.aider_edited_files = set(); self.max_reflections = 5
self.io = types.SimpleNamespace(user_input=lambda p: None); self.sent = []
def init_before_message(self): self.aider_edited_files = set()
def send_message(self, m):
self.sent.append(m); self.partial_response_content = self.replies.pop(0)
step = self.edits.pop(0) if self.edits else None
if step == "edit":
self.aider_edited_files.add("hello.txt"); pathlib.Path(root, "hello.txt").write_text("hi\n")
elif step == "run": # a command that printed nothing: no reflection
self.gate.calls.append({"command": "touch hello.txt", "approved": True})
return iter(())
ask = "Create a file named hello.txt containing hi, then say done."
block = "hello.txt\n```text\n<<<<<<< SEARCH\n=======\nhi\n>>>>>>> REPLACE\n```\n" # the reply, verbatim
gate = aider_driver._Gate([])
c = Coder([block, "done"], edits=["edit"]); logged = []; c.io = types.SimpleNamespace(user_input=logged.append)
aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask, aider_driver.REPLY_NUDGE] and logged == [ask, aider_driver.REPLY_NUDGE]
assert aider_driver.strip_edit_blocks(c.partial_response_content) == "done" # what the result says
assert "do not write or run it again" in aider_driver.REPLY_NUDGE
c = Coder([block, block], edits=["edit"]); aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask, aider_driver.REPLY_NUDGE] # once, not twice
c = Coder([block + "\ndone"], edits=["edit"]); aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask] # it said the word
c = Coder([block], edits=["edit"]); aider_driver._run_turn(c, "Create a file named hello.txt containing hi.", gate)
assert len(c.sent) == 1 # no word asked for: the edit is the turn
c = Coder([""]); aider_driver._run_turn(c, ask, gate)
assert c.sent == [ask] # a failed call is not repeated
g = aider_driver._Gate([])
c = Coder(["```bash\ntouch hello.txt\n```", "done"], edits=["run"], gate=g); aider_driver._run_turn(c, ask, g)
assert c.sent == [ask, aider_driver.REPLY_NUDGE] # a command and no word, the same
a = aider_driver._asks_for_reply
assert a("Create a.txt and b.txt, then reply DONE.") and a("Reply with exactly: M1-gpt-5.4")
assert a("Fix the bug in app.py and tell me what it was") and a("Update notes.md. Confirm when done.")
assert not a("Create hello.txt containing hi") and not a("the answer is in notes.md")
assert not a("write an essay to essay.md") and not a("Make the report in report.md")
assert not a("<conversation_so_far>\nuser: say hi\n</conversation_so_far>\n\nCreate hello.txt")
def _answered_mention_coder(root):
"""A Coder whose send_message is ordered as 0.86.2 orders it: the display reaches
io.assistant_output during the send, then check_for_file_mentions runs, and an ANSWERED
mention sets the reflected message and ends the pass before any edit or command
(base_coder.py:1561-1567). `mentions` holds what the check returns, one entry per pass."""
class Coder:
def __init__(self, replies, mentions):
self.replies = list(replies); self.mentions = list(mentions)
self.reflected_message = None; self.partial_response_content = ""
self.aider_edited_files = set(); self.max_reflections = 5; self.root = root
self.io = types.SimpleNamespace(user_input=lambda p: None,
assistant_output=lambda m, pretty=None: None,
confirm_ask=lambda *a, **k: True,
tool_error=lambda m="", strip=True: None,
tool_warning=lambda m="", strip=True: None)
self.sent = []
def check_for_file_mentions(self, content):
# aider's own: an answered mention returns prompts.added_files, else None
return self.mentions.pop(0) if self.mentions else None
def init_before_message(self): pass
def send_message(self, m):
self.sent.append(m)
self.partial_response_content = self.replies.pop(0)
self.io.assistant_output(self.partial_response_content)
added = self.check_for_file_mentions(self.partial_response_content)
if added:
self.reflected_message = added
return iter(())
if "<<<<<<< SEARCH" in self.partial_response_content:
self.aider_edited_files.add("hello.txt")
pathlib.Path(self.root, "hello.txt").write_text("hello\nworld\n")
return iter(())
return Coder
def _run_installed(coder, prompt):
"""_install + _run_turn on one gate, with every event the turn emits captured."""
gate = aider_driver._Gate([])
emitted: list = []
real_emit = aider_driver._emit
aider_driver._emit = lambda m, p: emitted.append((m, p))
try:
aider_driver._install(coder, gate)
aider_driver._run_turn(coder, prompt, gate)
finally:
aider_driver._emit = real_emit
return gate, emitted
# what check_for_file_mentions returns once the driver has set prompts.added_files: the reflected
# message the driver feeds back IS this string (the shape tests below assert it in c.sent)
_ADDED = aider_driver.ADDED_FILES.format(fnames="hello.txt")
_BLOCK = "hello.txt\n```text\n<<<<<<< SEARCH\nhello\n=======\nhello\nworld\n>>>>>>> REPLACE\n```\n"
def test_a_pass_answered_by_the_automatic_file_add_is_not_part_of_the_reply(tmp_path):
"""MEASURED twice on the hosted service (gpt-5.4, QA org, 2026-10-19), then 9 of 12 across
gpt-5.4, gpt-5.5 and gpt-6-sol on 0.35.8: turn 2 of hello.txt ("add a second line, world, to
hello.txt") rendered (1) "Please add this file to the chat first so I can provide an exact
edit: - `hello.txt`" (2) the edit (3) an empty message. The first pass's words were answered
by the driver itself — check_for_file_mentions added the file and set the reflected message —
so the person read a request nobody needs to act on; the second pass was the edit block alone,
an empty message once the block is a card. The pass that spoke to the driver is not part of
the reply, an empty text is never emitted, and the answer is the sentence from the edits. The
add request's WORDING varies by model, so the detection is the mechanism (the check returned
its added-files message), never the words: a second wording must behave the same."""
Coder = _answered_mention_coder(str(tmp_path))
ask = "add a second line, world, to hello.txt"
c = Coder(["Please add this file to the chat first so I can provide an exact edit:\n- `hello.txt`",
_BLOCK], [_ADDED, None])
gate, emitted = _run_installed(c, ask)
assert c.sent == [ask, _ADDED] # the add was answered, aider's own loop ran
texts = [p["text"] for m, p in emitted if m == "text"]
assert texts == [] # no add-file text, and never an empty message
assert ("edits", {"files": ["hello.txt"]}) in emitted
assert aider_driver._turn_answer(c, gate, {"hello.txt"}, failed=False) == "Edited hello.txt."
# another wording of the same request (gpt-5.5 and gpt-6-sol write their own): the mechanism
# decides, so the words never matter
c = Coder(["I need to edit this existing file, which has not been added to the chat yet: hello.txt",
_BLOCK], [_ADDED, None])
gate, emitted = _run_installed(c, ask)
assert [p["text"] for m, p in emitted if m == "text"] == []
assert aider_driver._turn_answer(c, gate, {"hello.txt"}, failed=False) == "Edited hello.txt."
# off the send path too, an empty text is never emitted: a display of edit blocks alone is
# no message at all, not ""
assert _turn_texts(_BLOCK, "") == []
def test_the_last_pass_words_are_the_answer_and_win_over_the_edits_sentence(tmp_path):
"""The sentence is the fallback, not the answer: a last pass that wrote the edit AND words
answers with its words, and a request that asks for words back still gets its one REPLY_NUDGE
first — the nudged words are the answer, the sentence stays behind them."""
Coder = _answered_mention_coder(str(tmp_path))
ask = "add a second line, world, to hello.txt"
c = Coder(["Please add `hello.txt` to the chat so I can edit it.",
_BLOCK + "\nAdded the second line."], [_ADDED, None])
gate, emitted = _run_installed(c, ask)
assert [p["text"] for m, p in emitted if m == "text"] == ["Added the second line."]
assert aider_driver._turn_answer(c, gate, {"hello.txt"}, failed=False) == "Added the second line."
# asked for words back and the edit pass wrote none: one nudge, and the nudged word answers
asked = ask + ", then say done."
c = Coder(["Please add `hello.txt` to the chat so I can edit it.", _BLOCK, "done"],
[_ADDED, None, None])
gate, emitted = _run_installed(c, asked)
assert c.sent == [asked, _ADDED, aider_driver.REPLY_NUDGE]
assert [p["text"] for m, p in emitted if m == "text"] == ["done"]
assert aider_driver._turn_answer(c, gate, {"hello.txt"}, failed=False) == "done"
# a turn whose TAIL asked the driver for files (reflections spent) answers with what it did,
# never with that request; a failed turn keeps its empty answer for the error to speak
ns = types.SimpleNamespace(partial_response_content="Please add `notes.md` to the chat.",
aider_edited_files={"hello.txt"})
g = aider_driver._Gate([]); g.answered_by_file_add = True
assert aider_driver._turn_answer(ns, g, {"hello.txt"}, failed=False) == "Edited hello.txt."
assert aider_driver._turn_answer(ns, g, {"hello.txt"}, failed=True) == ""
g.calls.append({"command": "cat hello.txt", "tool": "Shell", "approved": True, "reason": ""})
assert aider_driver._turn_answer(ns, g, {"hello.txt"}, failed=False) == \
"Edited hello.txt. The commands and their output are above."
g.answered_by_file_add = False
assert aider_driver._turn_answer(ns, g, {"hello.txt"}, failed=False) == "Please add `notes.md` to the chat."
def test_mid_turn_words_that_no_file_add_answered_keep_their_message_and_their_place(tmp_path):
"""The words of every pass the file add did not answer stay what they are today: each pass its
own message, ahead of the cards it narrates (the gate flushes the parked words when a card
goes out). They remain narration — the turn's answer is still the LAST pass's words alone,
never a join of the passes."""
Coder = _answered_mention_coder(str(tmp_path))
class Narrating(Coder):
def send_message(self, m):
out = super().send_message(m)
if len(self.sent) == 1: # the first pass proposes a command, aider confirms it
self.io.confirm_ask("Run shell command?", subject="cat hello.txt",
explicit_yes_required=True)
self.reflected_message = "Output:\n\ntwo lines\n\n" + aider_driver.REFLECT_ASK
return out
c = Narrating(["Reading the file now.", "hello.txt has two lines."], [None, None])
gate, emitted = _run_installed(c, "how many lines does hello.txt have?")
order = [(m, p.get("text") or p.get("command")) for m, p in emitted
if m in ("text", "shell_decision")]
assert order == [("text", "Reading the file now."),
("shell_decision", "cat hello.txt"),
("text", "hello.txt has two lines.")]
assert aider_driver._turn_answer(c, gate, set(), failed=False) == "hello.txt has two lines."
def test_the_added_files_message_states_the_add_and_invites_no_answer():
"""aider's own added_files prompt ends "Let me know if there are others we should add." — an
invitation written for a person at the prompt. Reflected into the driver's loop it was
ANSWERED: gpt-6-sol opened the pass after the add with "No other files are needed." and that
narration became the turn's answer, in the future tense ("I'll add `there` after `hi`.",
rc.1 probe, 2026-10-19). The driver's message states the add and points back at the request —
no question, no invitation — and it lives on the aider.prompts MODULE, because that is where
check_for_file_mentions reads it (base_coder.py:31, 1781); the coder's gpt_prompts does not
carry it."""
assert aider_driver.ADDED_FILES.format(fnames="hello.txt") == \
"I added these files to the chat: hello.txt. Continue with the request."
msg = aider_driver.ADDED_FILES.format(fnames="a.txt, b.txt")
assert "a.txt, b.txt" in msg and "?" not in msg and "Let me know" not in msg
# the override lands where aider reads it, replacing aider's own wording
pkg = types.ModuleType("aider")
mod = types.ModuleType("aider.prompts")
mod.added_files = ("I added these files to the chat: {fnames}\nLet me know if there are others"
" we should add.")
pkg.prompts = mod
saved = {k: sys.modules.get(k) for k in ("aider", "aider.prompts")}
sys.modules.update({"aider": pkg, "aider.prompts": mod})
try:
aider_driver._added_files_without_invitation()
finally:
for k, v in saved.items():
sys.modules.pop(k, None) if v is None else sys.modules.__setitem__(k, v)
assert mod.added_files == aider_driver.ADDED_FILES
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert " _added_files_without_invitation()\n" in src # main sets it before the turn runs
# _ADDED above is this message, so the shape tests also pin that the reflected message the
# driver feeds back is the uninviting one
assert _ADDED == aider_driver.ADDED_FILES.format(fnames="hello.txt")
def test_a_chat_with_no_files_says_a_new_file_needs_no_adding():
"""aider's "I am not sharing any files that you can edit yet." made gpt-5.4-mini refuse to
create a file, even after a nudge (#379). The no-files message says a new file is written with
an empty SEARCH; the repo-map message keeps aider's text and gains that sentence; aider's
shared prompts object is left as it was."""
class Prompts:
files_no_full_files = "I am not sharing any files that you can edit yet."
files_no_full_files_with_repo_map = "Don't try and edit any existing code without asking me to add the files to the chat!\n"
files_no_full_files_with_repo_map_reply = "Ok, based on your requests I will suggest which files need to be edited and then stop and wait for your approval."
shared = Prompts()
coder = types.SimpleNamespace(gpt_prompts=shared)
aider_driver._new_files_need_no_add(coder)
p = coder.gpt_prompts
assert "not sharing" not in p.files_no_full_files and aider_driver.NEW_FILE_NOTE in p.files_no_full_files
# with a repo map: a new file is written directly; an existing one is still named and added
assert aider_driver.NEW_FILE_NOTE in p.files_no_full_files_with_repo_map
assert "name the ones that need changes and stop" in p.files_no_full_files_with_repo_map
assert "wait for your approval" not in p.files_no_full_files_with_repo_map_reply
assert "write it directly" in p.files_no_full_files_with_repo_map_reply
# conditional on a request for a file: a question about one is answered, not acted on (on
# 0.35.3-rc.2 an unconditional note made gpt-5.4, gpt-5.5 and gpt-6-sol create the file asked about)
assert "If the request asks for a new file" in aider_driver.NEW_FILE_NOTE
assert "A question about a file is answered in words" in aider_driver.NEW_FILE_NOTE
assert shared.files_no_full_files == "I am not sharing any files that you can edit yet."
assert shared.files_no_full_files_with_repo_map.startswith("Don't try")
# a coder whose prompts have no repo-map message (aider's ask and architect modes) keeps none
bare = types.SimpleNamespace(gpt_prompts=types.SimpleNamespace(
files_no_full_files="x", files_no_full_files_with_repo_map="", files_no_full_files_with_repo_map_reply=""))
aider_driver._new_files_need_no_add(bare)
assert bare.gpt_prompts.files_no_full_files_with_repo_map == ""
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert " _new_files_need_no_add(coder)\n" in src
def test_the_repo_map_follows_the_conversation():
"""With a file in the workspace aider's repo map and its canned "Ok, I won't try..." reply came
ahead of the conversation, and gpt-5.4 asked for the first message's word answered "Ok" 5 of 6
times (0.35.3-rc.4). The map now opens the files message after the conversation; nothing of it
is dropped, and a workspace with no map is left as it was."""
repo = [dict(role="user", content="Here are summaries of some files present in my git repository.\nhello-aider.txt"),
dict(role="assistant", content="Ok, I won't try and edit those files without asking first.")]
files = [dict(role="user", content="No files are in the chat yet."), dict(role="assistant", content="Ok.")]
coder = types.SimpleNamespace(get_repo_messages=lambda: list(repo), get_chat_files_messages=lambda: list(files))
aider_driver._repo_map_after_the_conversation(coder)
assert coder.get_repo_messages() == []
msgs = coder.get_chat_files_messages()
assert [m["role"] for m in msgs] == ["user", "assistant"]
assert msgs[0]["content"].startswith("Here are summaries") and msgs[0]["content"].endswith("No files are in the chat yet.")
assert "hello-aider.txt" in msgs[0]["content"] and msgs[1]["content"] == "Ok."
empty = types.SimpleNamespace(get_repo_messages=lambda: [], get_chat_files_messages=lambda: list(files))
aider_driver._repo_map_after_the_conversation(empty)
assert empty.get_chat_files_messages() == files # an empty workspace: as before
none = types.SimpleNamespace(get_repo_messages=lambda: list(repo), get_chat_files_messages=lambda: [])
aider_driver._repo_map_after_the_conversation(none)
assert none.get_chat_files_messages() == repo # no files message: the map alone
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert " _repo_map_after_the_conversation(coder)\n" in src
def test_agent_doc_is_written_as_agents_md_even_though_aider_reads_it_via_read():
assert _agent_doc_path("/ws", "aider").name == "AGENTS.md"
# ── a lost conversation must not answer from an empty history ────────────────────
def test_resume_lost_reads_the_history_file_because_there_is_no_session_id():
"""aider has no session id at all, and a missing history file resumes silently with no output
difference whatsoever. The store question is "does the history hold a message?"."""
d = tempfile.mkdtemp()
assert _resume_lost("aider", ["aider"], "s1", d) == "s1"
hist = pathlib.Path(d, ".harness", "aider", "chat.history.md")
hist.parent.mkdir(parents=True)
hist.write_text("# aider chat started at 2026-09-13\n\n") # a file, but no exchange
assert _resume_lost("aider", ["aider"], "s1", d) == "s1"
hist.write_text("# aider chat started\n\n#### do the thing\n\nok\n")
assert _resume_lost("aider", ["aider"], "s1", d) is None
# ── the in-turn loop the maintainer asked to be measured ─────────────────────────
class _FakeCoder:
"""Enough Coder to exercise the shell-reporting wrapper without aider installed."""
def __init__(self, output="STAMP-OK"):
self.shell_commands = ["python3 stamp.py"]
self.reflected_message = None
self.runs = 0
self._output = output
def run_shell_commands(self):
self.runs += 1
return "\n".join(f"Output from {c}\n{self._output}" for c in self.shell_commands)
def test_shell_output_is_fed_back_so_the_model_sees_it_in_the_same_turn():
"""aider stashes shell output for the NEXT user message and sets no reflection of its own
(base_coder.py:1609-1614), unlike its lint and test paths. Without this the model can never
report what its command printed, and every other backend here can. Measured against a stub with
the reflection on: two provider round trips and the answer carries the script's output; with it
off, one round trip and the answer is the ```bash block itself."""
c = _FakeCoder()
g = aider_driver._Gate([])
g.calls.append({"command": "python3 stamp.py", "tool": "Shell", "approved": True, "reason": ""})
aider_driver._run_shell_commands_reporting(c, g, reflect=True)
c.run_shell_commands()
assert c.reflected_message and "STAMP-OK" in c.reflected_message
# the output is followed by an ask, as aider's own reflections are, or the model answers "Ok"
assert c.reflected_message.endswith("\n\n" + aider_driver.REFLECT_ASK) and c.reflected_message.index("STAMP-OK") < c.reflected_message.index(aider_driver.REFLECT_ASK)
def test_a_reflection_does_not_re_run_the_command_it_reported():
"""The bug this wrapper introduced and this test pins: init_before_message() empties
shell_commands once per TURN, not per reflection, so with a reflection set the next pass
re-ran every command already executed. Measured before the fix: one proposed command ran four
times and the turn made four round trips instead of two, side effects repeated each time."""
c = _FakeCoder()
g = aider_driver._Gate([])
aider_driver._run_shell_commands_reporting(c, g, reflect=True)
c.run_shell_commands()
assert c.shell_commands == [] # cleared, so a reflection cannot replay it
c.reflected_message = None # _run_turn clears this at the top of every pass
c.run_shell_commands() # the reflection's pass
# nothing left to run, so no output, so no second reflection: the loop ends after one.
assert c.runs == 2 and c.reflected_message is None
def test_reflection_can_be_turned_off_and_then_aider_behaves_as_shipped():
c = _FakeCoder()
g = aider_driver._Gate([])
aider_driver._run_shell_commands_reporting(c, g, reflect=False)
c.run_shell_commands()
assert c.reflected_message is None
# ── the MCP bridge itself ────────────────────────────────────────────────────────
# These run without the `mcp` SDK installed: the SDK is imported inside _run, and everything below
# is argument handling and the shapes the bridge puts in front of the agent. The live half — list,
# call, a failing call and an unknown server, against public servers — was measured separately and
# is recorded in docs/support-matrix-notes.md.
import aider_mcp_bridge # noqa: E402
def test_an_unknown_server_names_the_ones_that_exist():
"""The agent reads stderr. "no such server" without the list is a dead end for it."""
cfg = pathlib.Path(tempfile.mkdtemp(), "m.json")
cfg.write_text(json.dumps({"mcpServers": {"deepwiki": {"url": "https://x/mcp"}}}))
servers = aider_mcp_bridge._load(str(cfg))
try:
aider_mcp_bridge._target(servers, "nope")
except SystemExit as e:
assert e.code == 2
else:
raise AssertionError("an unknown server must not be silently accepted")
def test_a_url_server_resolves_to_its_url():
"""No transport and no headers: the plain string, which the SDK dials as streamable HTTP."""
servers = {"deepwiki": {"url": "https://mcp.deepwiki.com/mcp"}}
assert aider_mcp_bridge._target(servers, "deepwiki") == "https://mcp.deepwiki.com/mcp"
def _stub_mcp_sdk(monkeypatch):
"""The bridge runs under the aider venv's SDK (mcp 2.x with httpx2), not the runner's (1.x, no
httpx2): the transports it builds do not import here. Stub the three modules by name so the
test checks the bridge's choice of transport, which is what the declaration bug was about."""
sse = types.ModuleType("mcp.client.sse")
sse.sse_client = lambda url, headers=None: ("sse", url, headers)
sh = types.ModuleType("mcp.client.streamable_http")
sh.streamable_http_client = lambda url, http_client=None: ("http", url, http_client)
hx = types.ModuleType("httpx2")
hx.AsyncClient = lambda headers=None, timeout=None: ("client", headers)
client = types.ModuleType("mcp.client")
pkg = types.ModuleType("mcp")
pkg.client = client
for name, mod in (("mcp", pkg), ("mcp.client", client), ("mcp.client.sse", sse),
("mcp.client.streamable_http", sh), ("httpx2", hx)):
monkeypatch.setitem(sys.modules, name, mod)
def test_the_declared_transport_decides_and_not_the_urls_spelling(monkeypatch):
_stub_mcp_sdk(monkeypatch)
"""MEASURED DEFECT this pins: `Client.__init__` sends a plain URL string to
`streamable_http_client` unconditionally (mcp 2.2.0, client.py:393-394) — there is no inference
and no SSE path — so a harness that declared `transport: sse` had its server dialled with the
wrong protocol. Same rule the maintainer set for kimi: the declaration decides, never the url.
A string result here would be that defect returning."""
sse = aider_mcp_bridge._target(
{"events": {"url": "https://example.test/events", "transport": "sse"}}, "events")
assert sse == ("sse", "https://example.test/events", None)
def test_declared_headers_reach_the_server_rather_than_the_config_file(monkeypatch):
"""They were written into the config and never read: the streamable path takes headers on an
httpx client, not on the call, so a plain URL string dropped every one of them."""
_stub_mcp_sdk(monkeypatch)
with_hdrs = aider_mcp_bridge._target(
{"api": {"url": "https://example.test/mcp", "headers": {"X-K": "v"}}}, "api")
assert with_hdrs == ("http", "https://example.test/mcp", ("client", {"X-K": "v"}))
def test_structured_content_wins_over_prose():
"""A tool that returns data should not be flattened into text for the agent to re-parse.
NOTE the field name: the 2.2.0 SDK is snake_case (structured_content / is_error /
input_schema), not the camelCase of older releases. The camelCase guess raised inside a
TaskGroup and surfaced as an unreadable "unhandled errors in a TaskGroup" — measured."""
class R:
structured_content = {"answer": 42}
content = []
assert json.loads(aider_mcp_bridge._render(R())) == {"answer": 42}
def test_text_blocks_are_joined_when_there_is_no_structured_content():
class Block:
def __init__(self, t): self.text = t
class R:
structured_content = None
content = [Block("one"), Block("two")]
assert aider_mcp_bridge._render(R()) == "one\ntwo"
def test_bad_params_json_is_rejected_before_any_connection():
rc = aider_mcp_bridge.main(["--config", "/nonexistent", "call", "s", "t",
"--params", "{not json"])
assert rc == 2
# ── conversation continuity: the bug the support matrix found ────────────────────
def test_the_turn_announces_a_session_id_even_though_aider_has_none():
"""MEASURED FAILURE this pins: aider has no conversation id of any kind, so the gateway never
recorded one, never treated a later turn as a follow-up, and every turn was a fresh thread. The
support matrix's recycle scenario failed on every aider row while first/follow-up/switch
passed — those three only check that a turn answers, never that it remembers."""
state: dict = {}
out = _aider_to_claude({"m": "text", "p": {"text": "hi"}}, state)
assert out[0]["type"] == "system" and out[0]["subtype"] == "init"
assert out[0]["session_id"] == _AIDER_SESSION_NAME
# once per turn, not once per event
again = _aider_to_claude({"m": "text", "p": {"text": "more"}}, state)
assert not [e for e in again if e.get("subtype") == "init"]
def test_the_chat_history_is_restored_on_every_turn():
"""aider's only continuation mechanism. It travels in the checkpoint under .harness/, which is
what lets a follow-up after a sandbox recycle still know what was said; on a first turn the file
does not exist and aider starts fresh."""
_, _, _, job = _build()
# the driver owns the argv; assert the flag it builds
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert '"--restore-chat-history"' in src
assert '"--chat-history-file", str(hist / "chat.history.md")' in src
# ── the Plugins sub-protocol (UHP 2026-09-12) ────────────────────────────────────
def test_a_plugins_stdio_server_reaches_the_bridge_as_command_and_args():
"""_plugin_launchers bakes env, cwd and the ${PLUGIN_ROOT}/${PLUGIN_DATA} placeholders into one
launcher script, so every writer sees the same {name, command, args}. aider has no MCP client of
its own, so "the writer" here is the bridge's server table plus the shim the turn builds."""
d = tempfile.mkdtemp()
pathlib.Path(d, "AGENTS.md").write_text("# contract\n")
env: dict = {}
_build_aider("openai-api", Auth(api_key="sk-t", base_url="https://up.example/v1"),
"gpt-5.4", "do it", d, env, mcp_servers=[
{"name": "probe", "command": "/ws/.harness/plugin-data/demo/.launch-probe.sh",
"args": ["--x", "1"]},
{"name": "vault", "url": "https://mcp.example.invalid/mcp"}])
cfg = json.loads(pathlib.Path(d, ".harness", "aider-mcp.json").read_text())["mcpServers"]
assert cfg["probe"] == {"command": "/ws/.harness/plugin-data/demo/.launch-probe.sh",
"args": ["--x", "1"]}
assert cfg["vault"]["url"].startswith("https://")
# both kinds are advertised to the model, and a stdio one is named as such
doc = pathlib.Path(d, "AGENTS.md").read_text()
assert "`probe` — stdio" in doc and "`vault` — streamable HTTP" in doc
def test_the_bridge_resolves_a_stdio_entry_to_stdio_server_parameters():
"""The half a config file cannot show. Verified live against a real stdio MCP server too: the
bridge listed its tool and called it, exit 0.
Skipped where the SDK is absent: `mcp` lives in AIDER's venv, not the runner's — deliberately,
because installing it beside the runner bumps starlette past what FastAPI 0.115.6 accepts."""
import pytest
pytest.importorskip("mcp", reason="the MCP SDK lives in aider's own venv")
servers = {"probe": {"command": "/bin/echo", "args": ["a", "b"], "env": {"K": "V"}}}
target = aider_mcp_bridge._target(servers, "probe")
assert target.command == "/bin/echo"
assert target.args == ["a", "b"]
assert target.env == {"K": "V"}
# The companion test that asserted membership of _STDIO_MCP_BACKENDS is gone with the set itself:
# upstream (#185) stopped declaring any transport missing, because the runner now hands every client
# one launcher shape and bridges SSE and streamable HTTP over stdio for the ones that cannot speak
# them. Nothing about aider changed — the bridge already resolved a stdio entry — so what is left to
# pin is the two tests above: the servers the turn writes, and the shape the bridge resolves them to.
def test_the_driver_bounds_every_api_call():
"""MEASURED FAILURE this pins: aider's --timeout defaults to None, so a provider that accepts
the connection and never finishes the stream leaves the call waiting forever. aider's own retry
loop cannot save it — that only fires on an exception, and is itself bounded at ~63s. In the
vercel column single scenarios ran 3,621s, 6,040s, 16,071s and 27,360s against 7-30s healthy,
and only the runner's 6-hour cap ended them."""
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert '"--timeout", os.environ.get("HR_AIDER_TIMEOUT", "300")' in src
def test_the_operators_step_budget_reaches_the_driver():
"""aider has no CLI flag for it — its loop is Coder.max_reflections, a class attribute — so the
budget travels in the job and the driver sets it on the object. Pinned here because the dispatch
passes it and a builder that did not accept it would TypeError on the first aider turn, which no
unit test exercises."""
_, _, _, job = _build(max_turns=7)
assert job["max_turns"] == 7
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert "coder.max_reflections = max(1, int(budget))" in src
# The dispatch is the link that was missing: the builder accepted the budget and turn() never
# handed it over, so every aider turn ran on aider's own default no matter what the harness
# said. Read off the source, since turn() needs a live workspace and a provider to run.
server_src = pathlib.Path(__file__).resolve().parents[1].joinpath("server.py").read_text()
dispatch = server_src[server_src.index('elif backend == "aider":'):]
dispatch = dispatch[:dispatch.index("elif backend ==", 10)]
assert "max_turns=req.max_turns" in dispatch
def test_only_the_agent_doc_rides_read_and_skills_are_reached_on_demand():
"""The PR passed every file of every installed skill bundle through --read on every turn:
27 files and 264 KB for the three built-in bundles on hr-test, 45,030 input tokens for a
one-line answer. The agent doc's skills block names the folders; the model reads a skill when
a task calls for it, through the shell command the driver feeds back or a file mention aider
adds itself."""
server_src = pathlib.Path(__file__).resolve().parents[1].joinpath("server.py").read_text()
dispatch = server_src[server_src.index('elif backend == "aider":'):]
dispatch = dispatch[:dispatch.index("elif backend ==", 10)]
assert "rglob" not in dispatch and "skills_read=aider_read" in dispatch
def _stub_aider_models(info):
"""`from aider.models import model_info_manager` without aider installed."""
pkg = types.ModuleType("aider")
mod = types.ModuleType("aider.models")
mod.model_info_manager = types.SimpleNamespace(get_model_info=lambda name: info(name))
pkg.models = mod
return {"aider": pkg, "aider.models": mod}
def test_the_prefixed_id_is_given_back_the_record_the_prefix_hides():
"""MEASURED FAILURE this pins: litellm falls back from `openai/<id>` to the bare id ONLY when
that id's own litellm_provider is openai (models.py:228-231). `openai/gpt-5.6-sol` keeps its
66-key record; every gemini, claude, grok and qwen id resolved to an EMPTY dict, and aider then
ran and REPORTED limits of 0 -- `Input tokens: ~45,356 of 0 -- possibly exhausted context
window!` about a 1,048,576-token model (google|aider|gemini-3-flash-preview, 2026-09-16).
The BARE id is what gets looked up, so aider's alias table is still never consulted."""
asked = []
stub = _stub_aider_models(lambda n: (asked.append(n), {"max_input_tokens": 1048576})[1])
with tempfile.TemporaryDirectory() as d:
pathlib.Path(d, ".harness", "aider").mkdir(parents=True)
saved = {k: sys.modules.get(k) for k in stub}
sys.modules.update(stub)
try:
out = aider_driver._write_model_metadata(d, "openai/gemini-3-flash-preview")
finally:
for k, v in saved.items():
sys.modules.pop(k, None) if v is None else sys.modules.__setitem__(k, v)
assert asked == ["gemini-3-flash-preview"]
written = json.loads(pathlib.Path(out).read_text())
# registered under the PREFIXED name: that is the key aider looks the running model up by
assert written == {"openai/gemini-3-flash-preview": {"max_input_tokens": 1048576}}
def test_an_id_litellm_does_not_know_writes_nothing():
"""claude-opus-4.8, grok-4.6, qwen3.8-max and kimi-k3 are absent from litellm's database even
bare, so there is nothing to hand over and the turn must run exactly as it does today."""
stub = _stub_aider_models(lambda n: {})
with tempfile.TemporaryDirectory() as d:
pathlib.Path(d, ".harness", "aider").mkdir(parents=True)
saved = {k: sys.modules.get(k) for k in stub}
sys.modules.update(stub)
try:
assert aider_driver._write_model_metadata(d, "openai/grok-4.6") is None
finally:
for k, v in saved.items():
sys.modules.pop(k, None) if v is None else sys.modules.__setitem__(k, v)
assert not pathlib.Path(d, ".harness", "aider", "model-metadata.json").exists()
def test_the_record_is_handed_to_aider_on_the_command_line():
"""A file written and never passed is the defect the MCP block already taught this backend."""
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert 'meta = _write_model_metadata(cwd, job["model"])' in src
assert 'argv += ["--model-metadata-file", meta]' in src
def test_the_conversation_is_kept_verbatim_rather_than_summarised_at_aiders_cap():
"""aider keeps at most 8k tokens of history (1k for an id litellm does not know) and
summarises the rest with a model call; after four short turns the fifth could not say what
the first asked (console matrix, hr-test 2026-09-18). Half the window when known, else a
budget that fits the catalog's smallest windows; and the flag reaches the command line."""
d = tempfile.mkdtemp()
meta = pathlib.Path(d, "meta.json")
meta.write_text(json.dumps({"openai/gpt-5.4": {"max_input_tokens": 400000}}))
assert aider_driver._history_budget(str(meta)) == 200000
meta.write_text(json.dumps({"openai/x": {"max_input_tokens": 8000}}))
assert aider_driver._history_budget(str(meta)) == 8192
assert aider_driver._history_budget(None) == 96000
meta.write_text("not json")
assert aider_driver._history_budget(str(meta)) == 96000
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert 'argv += ["--max-chat-history-tokens", str(_history_budget(meta))]' in src
def test_the_agent_doc_is_the_system_message_and_the_conversation_holds_only_the_users_turns():
"""--read sent the doc as a user message ("Here are some READ ONLY files, provided for your
reference") ahead of the conversation, and aider's few-shot examples were user/assistant turns
ahead of that: asked what the first message of the task said, gpt-5.4 answered "reference"
and, before, "Change" (hr-test, 2026-09-18). The doc rides aider's own system_prompt_prefix
hook and the examples fold into the system message; nothing of aider's precedes the user."""
_, _, _, job = _build(skills_read=["/w/AGENTS.md"])
assert job["system_files"] == ["/w/AGENTS.md"] and "read_files" not in job
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert '"--read"' not in src
assert "coder.main_model.system_prompt_prefix = (" in src
assert "coder.main_model.examples_as_sys_msg = True" in src
def test_no_temperature_is_sent_since_a_provider_that_retired_the_field_refuses_the_turn():
"""claude-fable-5-1 on TokenRouter: "`temperature` is deprecated for this model", turn dead
after 171 s of retries (console matrix, hr-test 2026-09-18). aider sends 0 for every id its
settings do not know; no other base sets one; aider's own switch leaves it out."""
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert "coder.main_model.use_temperature = False" in src
def test_the_harness_own_files_stay_out_of_the_repo_map():
""".harness/ holds the skill bundles, aider's state and the MCP shim; summarised into the
repo map they rode every request as the user's project. The driver hands aider an ignore
file for them, so the map describes the task's files alone."""
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert 'ignore.write_text(".harness/\\nAGENTS.md\\n.gitignore\\n")' in src
assert '"--aiderignore", str(ignore),' in src
def test_a_small_binary_file_is_not_taken_for_text():
"""The leeway for a character cut at the sniff boundary (decode all but the last four bytes)
also ran on a file read whole, so a file of four bytes or fewer, or one whose only invalid
UTF-8 was in its last bytes, was called text and failed in aider's UTF-8 read."""
d = tempfile.mkdtemp()
for name, data in (("bom16.txt", b"\xff\xfe"), ("tail.bin", b"hello\x80"), ("one.bin", b"\xc3")):
pathlib.Path(d, name).write_bytes(data)
assert aider_driver.is_text_file(os.path.join(d, name)) is False, name
# a head that fills the sniff and ends inside a multi-byte character is still text
big = pathlib.Path(d, "long.md")
big.write_bytes(b"a" * 65534 + "€".encode() + b"more") # the euro sign straddles byte 65536
assert aider_driver.is_text_file(str(big)) is True
pathlib.Path(d, "accents.md").write_text("café\n", encoding="utf-8")
assert aider_driver.is_text_file(os.path.join(d, "accents.md")) is True
pathlib.Path(d, "empty.md").write_bytes(b"")
assert aider_driver.is_text_file(os.path.join(d, "empty.md")) is True
def test_a_binary_file_the_model_names_is_refused_at_aiders_add_prompt():
"""Asked to restyle hello.pptx (hr-test, 2026-09-19), the model named it, aider added it, the
UTF-8 read failed ("Use --encoding…"), the file was dropped and added again on the next
mention: an error and a reflection each time, twelve commands, fifteen minutes. A binary
file is refused at aider's own "Add file to the chat?" prompt, which puts it on
ignore_mentions; text files still go in."""
d = tempfile.mkdtemp()
pathlib.Path(d, "deck.pptx").write_bytes(b"PK\x03\x04\xf7\x00binary")
pathlib.Path(d, "notes.md").write_text("# notes\n")
assert aider_driver.is_text_file(os.path.join(d, "deck.pptx")) is False
assert aider_driver.is_text_file(os.path.join(d, "notes.md")) is True
asked = []
io = types.SimpleNamespace(confirm_ask=lambda q, default="y", subject=None, explicit_yes_required=False, group=None, allow_never=False: asked.append(subject) or True,
assistant_output=lambda m, p=None: None, tool_error=lambda m="", strip=True: None,
tool_warning=lambda m="", strip=True: None)
coder = types.SimpleNamespace(io=io, root=d, partial_response_content="", reasoning_tag_name="think",
reflected_message=None)
gate = aider_driver._Gate([])
aider_driver._install(coder, gate)
assert io.confirm_ask("Add file to the chat?", subject="deck.pptx") is False
assert io.confirm_ask("Add file to the chat?", subject="notes.md") is True
assert asked == ["notes.md"] # the binary never reached aider's prompt
# the same for an edit block aimed at a binary the model never added (gpt-5.5 put its
# closing answer in a SEARCH/REPLACE block for the .pptx it had built; aider read the file
# as text and crashed on its own None content)
assert io.confirm_ask("Allow edits to file that has not been added to the chat?", subject="deck.pptx") is False
assert io.confirm_ask("Allow edits to file that has not been added to the chat?", subject="notes.md") is True
assert asked == ["notes.md", "notes.md"]
# nobody is at aider's prompt to say what to do instead, so the turn is told and goes on
assert "`deck.pptx` is a binary file" in coder.reflected_message and "```bash" in coder.reflected_message
def test_the_turn_fails_only_when_an_error_was_the_last_thing_that_happened():
"""The restyled .pptx and the edited hello.md were reported FAILED for a decode error twelve
commands earlier. An error followed by more of the model's work is a recovered error; an
error with nothing after it (a provider refusal) is the failure."""
io = types.SimpleNamespace(confirm_ask=lambda *a, **k: True, assistant_output=lambda m, p=None: None,
tool_error=lambda m="", strip=True: None, tool_warning=lambda m="", strip=True: None)
coder = types.SimpleNamespace(io=io, root="/tmp", partial_response_content="", reasoning_tag_name="think",
reflected_message=None)
gate = aider_driver._Gate([])
aider_driver._install(coder, gate)
assert gate.error_after_output is False
io.tool_error("x: 'utf-8' codec can't decode"); assert gate.error_after_output is True
io.assistant_output("I restyled the deck."); assert gate.error_after_output is False
io.tool_error("litellm.AuthenticationError"); assert gate.error_after_output is True
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert "failed = coder.usage_report is None or gate.error_after_output" in src
def test_each_text_pass_ends_with_a_paragraph_break():
"""The console joins consecutive text blocks as they come; a closing fence ran straight into
the next pass's first sentence and the rest of the turn rendered inside a code block."""
state: dict = {"_aider_init": True}
ev = _aider_to_claude({"m": "text", "p": {"text": "First pass.\n"}}, state)[0]
assert ev["message"]["content"][0]["text"] == "First pass.\n\n"
def _stub_reasoning_tags():
"""aider's `reasoning_tags` as the suite sees it: the suite runs without aider installed, so
the two display markers and the strip helper stand in here. The markers are aider 0.86.2's own
literals (reasoning_tags.py:8-11), copied so a reworded banner upstream shows as a red test."""
import re as _re
pkg = types.ModuleType("aider")
mod = types.ModuleType("aider.reasoning_tags")
mod.REASONING_START = "--------------\n► **THINKING**"
mod.REASONING_END = "------------\n► **ANSWER**"
mod.remove_reasoning_content = lambda res, tag: (
_re.sub(f"<{tag}>.*?</{tag}>", "", res, flags=_re.DOTALL).strip() if tag else res)
pkg.reasoning_tags = mod
return {"aider": pkg, "aider.reasoning_tags": mod}
def _turn_texts(display: str, content: str) -> list[str]:
"""What the driver emits as the turn's text for one aider response."""
class _IO:
def assistant_output(self, message, pretty=None): pass
def confirm_ask(self, *a, **k): return True
def tool_error(self, *a, **k): pass
def tool_warning(self, *a, **k): pass
coder = types.SimpleNamespace(io=_IO(), partial_response_content=content,
reasoning_tag_name="thinking-content-7bbeb8e1441453ad999a0bbba8a46d4b",
shell_commands=[])
stub = _stub_reasoning_tags()
emitted: list = []
real_emit = aider_driver._emit
saved = {k: sys.modules.get(k) for k in stub}
sys.modules.update(stub)
try:
aider_driver._emit = lambda m, p: emitted.append((m, p))
aider_driver._install(coder, aider_driver._Gate([]))
coder.io.assistant_output(display)
finally:
aider_driver._emit = real_emit
for k, v in saved.items():
sys.modules.pop(k, None) if v is None else sys.modules.__setitem__(k, v)
return [p["text"] for m, p in emitted if m == "text"]
def test_a_reply_of_reasoning_only_says_the_model_wrote_no_answer():
"""MEASURED FAILURE this pins (self-hosted, kimi-k3, 2026-10-05, #395): about one aider turn in
three the model returned reasoning and no content, the turn completed, and the answer the reader
got was aider's own display furniture — `--------------\\n► **THINKING**` and the chain of
thought — because an empty `partial_response_content` falls back to the display string, and
`remove_reasoning_content` only recognises the `<tag>` form the display string no longer holds."""
furniture = (_stub_reasoning_tags()["aider.reasoning_tags"].REASONING_START
+ "\n\nThe user wants me to call the MCP tool `probe_rows`. Let me first check"
" the tools available on the probe server.\n\n"
+ _stub_reasoning_tags()["aider.reasoning_tags"].REASONING_END + "\n\n")
texts = _turn_texts(furniture, "")
assert texts == [aider_driver.NO_ANSWER], texts
assert "THINKING" not in texts[0] and "►" not in texts[0]
# what the gateway stores is the result's text; the normaliser takes the last text pass when
# the driver's own `final` is empty, so the banner reached the record through that door too
state: dict = {"_aider_init": True}
_aider_to_claude({"m": "text", "p": {"text": texts[0]}}, state)
ev = _aider_to_claude({"m": "result", "p": {"ok": True, "final": ""}}, state)[0]
assert ev["is_error"] is False and ev["result"] == aider_driver.NO_ANSWER
def test_the_answer_behind_the_banner_is_what_the_reader_gets():
"""The other half of the same fallback: a content field that is empty does not mean the display
string holds nothing but reasoning — what follows aider's ANSWER marker is the answer."""
stub = _stub_reasoning_tags()["aider.reasoning_tags"]
display = (stub.REASONING_START + "\n\nthink think think\n\n" + stub.REASONING_END
+ "\n\nA one-pager is in sfo.pdf.\n")
assert _turn_texts(display, "") == ["A one-pager is in sfo.pdf."]
def test_a_display_string_with_no_furniture_is_reported_as_it_arrived():
"""The fallback exists for a call site off the send path, which passes plain prose; stripping
to nothing there would answer the reader with silence (the invariant in `_install`'s comment)."""
assert _turn_texts("I restyled the deck.", "") == ["I restyled the deck."]
def test_the_driver_takes_aiders_own_banner():
"""Handing the marker to the helper is the point: a pattern of ours would drift from aider's."""
src = pathlib.Path(__file__).resolve().parents[1].joinpath("aider_driver.py").read_text()
assert "from aider.reasoning_tags import REASONING_END" in src
assert "body or _after_answer_banner(str(message))" in src
def test_the_models_reasoning_is_not_rendered_as_its_answer():
"""MEASURED FAILURE this pins (vercel|aider|grok-4.20, 2026-09-18): the transcript showed the
model's chain of thought -- "(wait, no, that's not how it works)... So my response should be:"
-- because io.assistant_output receives aider's DISPLAY string, which base_coder.py:1882-1890
builds by prepending the reasoning and rewriting its tags into `► **THINKING**`/`► **ANSWER**`
furniture. The answer is partial_response_content, which is never decorated."""
class _IO:
def __init__(self):
self.seen = []
def assistant_output(self, message, pretty=None): self.seen.append(message)
def confirm_ask(self, *a, **k): return True
def tool_error(self, *a, **k): pass
def tool_warning(self, *a, **k): pass
class _Coder:
def __init__(self):
self.io = _IO()
self.reasoning_tag_name = "thinking-content-7bbeb8e1441453ad999a0bbba8a46d4b"
self.partial_response_content = "M1-grok-4.20"
self.shell_commands = []
coder = _Coder()
emitted = []
real_emit = aider_driver._emit
# the driver asks aider to strip, so aider is where the tag semantics stay; the suite runs
# without aider installed, so its helper stands in here
stub = _stub_reasoning_tags()
saved = {k: sys.modules.get(k) for k in stub}
sys.modules.update(stub)
try:
aider_driver._emit = lambda m, p: emitted.append((m, p))
aider_driver._install(coder, aider_driver._Gate([]))
# what aider would hand it for a reasoning model
coder.io.assistant_output(
"--------------\n► **THINKING**\n\nwait, no, that is not how it works\n\n"
"------------\n► **ANSWER**\n\nM1-grok-4.20")
finally:
aider_driver._emit = real_emit
for k, v in saved.items():
sys.modules.pop(k, None) if v is None else sys.modules.__setitem__(k, v)
texts = [p["text"] for m, p in emitted if m == "text"]
assert texts == ["M1-grok-4.20"], texts
assert "THINKING" not in texts[0]
def test_a_prose_line_that_starts_with_a_shells_name_is_kept():
"""Every line was read as if a fence opened it, so an answer line such as "bash build.sh" or a
lone "sh" opened a shell block and everything after it, usually the rest of the answer, was
cut from the reply."""
for text in ("I created build.sh. Run it with:\nbash build.sh\nIt writes report.pdf.",
"Which shell do you use? I recommend\nbash\nbecause it is everywhere.",
"Two options:\nsh run.sh\nzsh run.sh\nEither works."):
assert aider_driver.strip_edit_blocks(text) == text
# a real fence is still a block, prose around it kept
assert aider_driver.strip_edit_blocks("Run:\nbash build.sh\n```bash\nls\n```\nDone.") == "Run:\nbash build.sh\nDone."