All jobs

Write Unit Tests for a Rust Project

An agent writes inline Rust tests for five fd source files; 209 unit tests pass and line coverage rises from 87.64% to 92.75%.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent ran cargo llvm-cov --summary-only on the untouched clone of sharkdp/fd, where cargo test already passed 122 integration tests, and ranked files by line coverage. It skipped main.rs (74.7%) as binary wiring the integration suite exercises, and took output.rs (58.9%), dir_entry.rs (70.6%), exec/job.rs (75.6%), error.rs (76.9%) and fmt/mod.rs (83.2%).

The tests go in each file's own #[cfg(test)] module. To build a real Config and a real walker entry it added two test-only constructors, Config::for_test() in src/config.rs and DirEntry::for_test(), so release builds are unchanged. The exec/job.rs tests run sh and test, so they are gated to cfg(unix).

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Run the test suite with coverage, pick the five least-covered files that hold real logic, and write Rust tests for them that exercise behaviour, not implementation details. Do not change production code unless a test reveals a bug; if it does, say so in the description. Open a pull request with the coverage before and after.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

Tried on sharkdp/fd at cc4e40f: 6 files changed, 592 insertions(+), 1 deletion(-), all in src/. cargo test --bin fd ended test result: ok. 209 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s, the 122 integration tests still passed, and cargo clippy --all-targets and cargo fmt --check exited 0. Per file, output.rs reached 98.0% and exec/job.rs and error.rs 100%. The run copied the diff to /workspace/.rush/artifacts/, but capture keeps no .diff file, so it did not come back; the change is in the run's answer. No pull request was opened.

For the reviewer: FormatTemplate::parse("{{{}}}") yields {{}} where Rust's format! gives {x}. The run pinned only the clear case, a{}}b to a{}b, and left the parser alone. Decide too whether the two helpers belong inside each test module. Coverage was not re-measured after the last clippy fix, a one-line test change.

Run it on every night

An automation with a schedule trigger, cron 0 2 * * * and your timezone, runs this prompt in the Project's repository each night, each run on its own branch. The sandbox had no Rust toolchain, linker or coverage tool, so expect each night's run to install rustup, gcc and cargo-llvm-cov as this trial did.

The use case this job follows, with its automation and trigger: Write the missing tests.

Why run it on Rush?

With 122 integration tests green, fd's remaining gaps sat in units: output writing at 58.9%, the placeholder template parser, error reporting. Testing them directly surfaced an ambiguity in how fmt/mod.rs reads {{{}}}, which the run reported for a decision instead of changing parser behaviour on its own.

Frequently asked questions

Did production code change?

Only to add Config::for_test() and DirEntry::for_test(), both behind #[cfg(test)], so they compile into test builds alone. No new test exposed a bug.

How honest is the 92.75% total?

The run says it slightly flatters the result, because the new test code sits in the same files and counts toward the total. The per-file numbers, such as dir_entry.rs from 70.6% to 97.6%, are the fairer comparison.

More Rust jobs

The same job on other stacks

Keep reading