{"slug": "how-to-build-a-coding-agent-that-fixes-a-failing-test", "title": "How to build a coding agent that fixes a failing test", "summary": "A tutorial published on getfloo.com shows how to build a coding agent that repairs a failing test by giving the model a reproduced failure and a single file to edit, rather than repository write access. The example uses a shipping-fee bug in which an order of exactly 5,000 cents should charge 0 but the function returns 599, and the agent's proposed fix changes `subtotal > 5000` to `subtotal >= 5000`, after which the check prints \"3 cases passed\". The host requires a failure with the expected three values before asking the model to edit anything, allows two failed proposals before ending the run, and returns a unified diff for human review.", "body_md": "## TL;DR\n\nAn order for exactly $50 qualifies for free shipping. The checkout still adds $5.99. Give a coding agent a way to reproduce that single failure and verify the change it proposes.\n\n- Keep the original source and the three test cases on the host.\n- Send the model the observed failure and let it propose a source edit.\n- Run the check again and return a diff for review.\n\n## Put the boundary in the test\n\nThe fixture uses integer cents. Shipping is 599 cents below the threshold and zero from 5,000 cents up. The bug is easy to miss in a demo because orders on either side already work.\n\n``` python\ndef shipping_cents(subtotal):\n    return 0 if subtotal > 5000 else 599\n```\n\nTest 4,999, 5,000, and 5,001 cents. The middle case distinguishes “at least” from “more than.” The case immediately below it prevents a superficially successful fix that makes shipping free for everyone. [Repair agent source](https://getfloo.com/examples/sandbox-agents/repair_agent.py) · [Host helper](https://getfloo.com/examples/sandbox-agents/agent_tools.py)\n\n## Run the repair\n\nUse Python 3.10 or later, a signed-in Claude Code CLI, and a floo account with sandbox credits. Sign in with the floo CLI or set FLOO_API_KEY in your shell. Run these commands in an empty directory.\n\n```\npython3 -m venv .venv\n. .venv/bin/activate\npython -m pip install floo-sandbox==0.2.0\nexport FLOO_API_KEY=\"${FLOO_API_KEY:-$(floo auth token)}\"\nbase=https://getfloo.com/examples/sandbox-agents\ncurl -fsSLO \"$base/agent_tools.py\"\ncurl -fsSLO \"$base/repair_agent.py\"\npython repair_agent.py\n```\n\nThe script writes `shipping.py` and `check.py` into one sandbox. It runs the original code first. The host requires a failure with the expected three values before it asks the model to edit anything.\n\n```\nReproduced: AssertionError: (5000, 0, 599)\n```\n\nRead the tuple as input, expected fee, and actual fee. A missing interpreter or a broken import produces a different failure. Sending that to a model as evidence of a shipping bug would send it after the wrong problem.\n\n## Give the agent one file to change\n\nThe host sends Claude the pricing rule, original function, test, and captured failure. Claude returns replacement Python. The host writes the candidate to the workspace and invokes the same check with bytecode caching disabled. That detail matters for tiny edits made within the same second: the next test should load the bytes the agent just wrote.\n\nIf a proposal fails, the second attempt sees the candidate and its error. Two failed proposals end the run. On a pass the host computes a unified diff against the original source. Here's the change from our run:\n\n```\n-    return 0 if subtotal > 5000 else 599\n+    return 0 if subtotal >= 5000 else 599\n```\n\nThe check printed `3 cases passed`. A reviewer can connect that one character to a business rule, three inputs, and an observed failure. Nothing in this example grants the model repository write access.\n\n## Adapt it to an actual bug\n\nPick one failing test in your project and copy the smallest source tree and dependency lockfile that reproduce it. Record the exact command and expected failure. Replace the toy fixture only after that command fails for the same reason in the sandbox and in your normal test environment.\n\nThe tutorial checks one behavior. Before accepting a patch to your project, apply the diff to a clean checkout and run your usual suite in CI. A model proposal and its sandbox output are inputs to the review. The independent checkout is what verifies the patch you would merge. [Sandbox execution guide](https://getfloo.com/docs/guides/sandboxes)", "url": "https://wpnews.pro/news/how-to-build-a-coding-agent-that-fixes-a-failing-test", "canonical_source": "https://getfloo.com/blog/build-a-coding-agent-that-fixes-failing-tests", "published_at": "2026-11-26 00:00:00+00:00", "updated_at": "2026-12-01 20:45:49.040319+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models"], "entities": ["getfloo.com", "floo-sandbox 0.2.0", "Claude Code CLI", "Claude", "Python 3.10"], "also_reported_by": [], "takeaway": "Gate the repair loop on a reproduced failure with the expected values (here the tuple 5000, 0, 599) and run the check with bytecode caching disabled so the next test loads the bytes the agent just wrote.", "recommendation": {"advice": "Reproduce the exact failing test before letting the agent edit, give it one file, cap retries at two, and apply the returned diff to a clean checkout and run CI before merging.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/how-to-build-a-coding-agent-that-fixes-a-failing-test", "markdown": "https://wpnews.pro/news/how-to-build-a-coding-agent-that-fixes-a-failing-test.md", "text": "https://wpnews.pro/news/how-to-build-a-coding-agent-that-fixes-a-failing-test.txt", "jsonld": "https://wpnews.pro/news/how-to-build-a-coding-agent-that-fixes-a-failing-test.jsonld"}}