ai newsMi., 25. Nov.
EilmeldungCan Claude’s storage webhooks miss an hour-long outage?

How to fix failing tests with an AI agent (without it deleting the tests)

In short Tell the agent which command must pass and that it must fix the code, not the tests. Mel reads the test command from AGENTS.md and uses it to check its work. For a big red suite, ask for one cause at a time or let a lead agent split the work. Read every test change on the approval card bef

dev.toDienstag 20:47 · 24.11.6 Min. Lesezeit
Bild: dev.to

Posted on Nov 24 • Originally published at openmel.dev

To fix failing tests with an AI agent, tell it which command must pass and what it may not touch, then let it run that command itself. In Mel – the agentic terminal (openmel.dev), put your test command in AGENTS.md or MEL.md, attach the failing output with Ctrl+↑ (⌃↑ on a Mac), and write a finish line such as "make pytest pass without skipping or deleting a test". Mel's agent reads the failing tests and the code, changes what it needs, and runs the tests again before it says it is done. You approve each edit and command that changes something, unless your settings allow it.

This guide covers the one rule that stops an agent from "fixing" tests the wrong way, how to set up your project once, the step-by-step in Mel, and how to handle a whole red test suite.

A failing test is one of the best tasks you can give an agent, because it comes with its own finish line. The agent does not have to guess what "done" means: the same command that failed must pass. It can run that command, read the exact error, change the code and run it again, as many times as it needs. A chat window cannot do that loop, because it cannot run anything; you would be copying errors back and forth by hand.

Three things decide whether the loop ends well:

The fastest way to make a test pass is to change the test. An agent with no limits will sometimes do exactly that: loosen an assertion, skip the test, or delete it. Say what is off limits in every task:

Make `pytest` pass. Fix the code, not the tests. Don't skip, delete or loosen any test. If a test itself is wrong, stop and tell me why before changing it. Enter fullscreen mode Exit fullscreen mode That last line matters. Sometimes the test really is wrong, and you want to decide that, not the agent.

Mel's agent reads the rules files in your repository on every turn: AGENTS.md and CLAUDE.md, then MEL.md for rules meant only for Mel. If AGENTS.md names a test command, Mel uses it as the check to run before it says it is done.

## Tests - Run tests with `pnpm test`. Run one file with `pnpm test path/to/file`. - Fix the code, not the tests. Never skip or delete a test. - Never edit files under `fixtures/`. Enter fullscreen mode Exit fullscreen mode Write it once and every task in that project follows it, for you and for your teammates.

A hundred failing tests usually have a few causes. Don't ask for all of them at once.

For a big suite, a lead agent can split the work. Type /orchestrate-cli or /orchestrate-agent and Mel's lead gives each worker its own files, then checks the combined result and runs the tests on disk.

Name the exact command. These are the usual ones, from each tool's own docs; your project may wrap them in a script:

Running one test first is faster and cheaper: the agent sees a short output instead of a whole suite, and each run is quick. Ask it to run the single failing test while it works, then the whole suite once at the end.

`pytest tests/test_cart.py::test_total` fails (output attached). Fix the code, not the test. Run that test until it passes, then run the whole suite once and tell me the result. Enter fullscreen mode Exit fullscreen mode Tests broke after an upgrade

We upgraded React from 18 to 19 and 14 tests fail (output attached). Make them pass on 19. Don't pin back, don't skip tests. Group the failures by cause before you change anything. Enter fullscreen mode Exit fullscreen mode A flaky test

`test_checkout_timeout` fails about one run in five. Find why. Don't add retries or longer sleeps. Show it is fixed by running it 20 times in a row. Enter fullscreen mode Exit fullscreen mode Fails in CI, passes locally

The CI log is attached. CI runs on Ubuntu with Node 20; I am on macOS with Node 22. Find what differs, fix the code, and tell me how you checked it. Enter fullscreen mode Exit fullscreen mode How Mel checks that "done" means done An agent saying "the tests pass" is a claim. Mel treats it as one:

The same agent runs outside the app with mel agent, on the folder you run it in:

mel agent "make npm test pass without skipping or deleting a test" Enter fullscreen mode Exit fullscreen mode The answer streams to your terminal, and each command the agent runs or file it changes is printed on its own line. On macOS, set up the mel command once first: from v0.1.68, choose Install the mel command in the command palette. Approvals still apply; read the docs before you run it unattended.

Leave the model on auto and Mel picks one for each turn, or choose a mode: Cost-efficient for a simple assertion error, Genius for a hard bug that spans several files. If one model gets stuck, pick another from the model menu and send the same task; a fresh model often sees what the first one missed. On your own provider key, the turns cost 0 Mel credits.

Can an AI agent fix failing tests? Yes, when it can run them. Mel's agent runs your test command, reads the output, changes the code and runs the tests again until they pass or it reports what is left.

How do I stop the agent from deleting tests? Say so in the task and in AGENTS.md: "Fix the code, not the tests. Never skip or delete a test." Every edit also shows its diff on an approval card before it is written.

Where do I tell Mel my test command? In AGENTS.md, CLAUDE.md or MEL.md in your repository. If AGENTS.md names a test command, Mel uses it as the check.

What if the agent can't fix it? A task that stops making progress ends with a report of what was done and what is left. Narrow the task, add a fact, or try another model from the model menu.

Can I undo the agent's changes? Yes. In the code review panel, Undo takes back one change and ↩ Discard reverts one file.

Should I run one test or the whole suite? One test while the agent works, the whole suite once at the end. It is faster and costs less.

Can I fix tests from CI with Mel? Yes, with mel agent "..." in the project folder. Read the approvals section of the mel agent docs first.

Is it free? The terminal is free, and Mel's agent is free with your own API key. Paid plans start at $20 a month.

Download Mel from openmel.dev, add one line with your test command to AGENTS.md, run the tests, and hand the red block to the agent.

Originally published on the Mel blog. pytest, Go, Rust, Cargo, Maven, npm and React are trademarks of their owners. Mel is not affiliated with or endorsed by them.

Quelle: dev.to (dev.to). Original öffnen