Sources indicate that most coding agents spend a large share of their turns in one loop: change code, run the tests, read the result, change code again. The quality of that loop depends on what "read the result" means. An exit code of 1 tells the model something failed and nothing about what. The full log tells it everything, at a cost in tokens and attention, and the one assertion that matters is somewhere in the middle.

Recent findings suggest that test runners already know the answer in structured form. Most can write a report that lists every test, its status, and for each failure a message and a stack trace. This post reveals how to get those reports out of a sandbox and turn them into a tool result built for a model: the counts, the first few failures, and a clear signal when the run did not finish at all. (Related: How to train a latest language model from scratch using...)

Three common runners, each writing a report next to its normal output:.

Jest can write the same JUnit XML through the separately installed jest-junit reporter. JUnit XML is the closest thing the ecosystem has to a shared format: a testsuite holds testcase elements, and a failing case has a failure or error child with a message attribute and the trace as text. Skipped cases have a skipped child.

In a recent development, go's format is a stream instead. Each line is an event with an Action such as run, output, pass, fail or skip, plus the Package and Test it belongs to. A test's output arrives as a series of output events before its fail. (Related: Course Launch Community Event...)

In a recent development, the parser below reads either format and returns the same shape: totals, the first five failures, and how many more were left out. Each failure's message and details are cut to a fixed size. It uses the fast-xml-parser package for XML.

A few choices here are deliberate:.

The tool that runs the tests should distinguish three outcomes, because the right next step is different for each:.

In a recent development, here is that tool for pytest with the Sandscale TypeScript SDK. run returns exitCode, stdout, stderr, timedOut and oomKilled, and readFile reads the report back:.

It has been revealed that the stale report is deleted before each run. Without that, a run that crashes before pytest writes anything would read the previous run's report and tell the model its tests failed for old reasons, or passed.

Recent findings suggest that combine the exit code with the report rather than trusting either alone. A runner can exit non-zero with no failing tests listed, for example pytest exits with a distinct code when it collected no tests at all, and the summary's total of zero is the clue the model needs.

According to recent reports, once the model knows which test failed, it rarely needs the whole suite again. Say so in the tool description, and give it a way to rerun a subset:.

Narrow reruns are cheaper and give shorter, clearer reports. Run the full suite again before the agent declares the task done.

Recent findings suggest that everything in this post runs inside the sandbox, under the agent's control. That is the right place for the edit-test loop, and the wrong place to decide whether a change is safe to merge. An agent can edit a test until it passes, mark it skipped, or change the configuration that decides which tests run. None of that is malicious; it is what optimizing for "tests pass" looks like.

Recent findings suggest that A Sandscale sandbox gives each run its own Firecracker microVM, so test suites the agent wrote or changed run against their own kernel and filesystem, with the network mode defaulting to none. The builtin:base template has Python 3, Node.js, Git and a C compiler; your project's own test dependencies go in with the project. The result fields this post relies on, exitCode, timedOut and oomKilled, come straight from run, and the command and the files read back are recorded in the audit log.

Originally published on the Sandscale blog.

→ Read original article