Inspiration

A green test suite does not mean your code is safe. It only means your tests did not notice anything wrong. We wanted a tool that proves it: change the code on purpose, and see whether any test complains.

What it does

Stake hunts for blind spots in Python test suites.

  1. Mutate. It makes small deliberate bugs in your code (flip >= to >, swap + for -, tweak a number, negate a condition).
  2. Run. It runs your existing tests against every mutant.
  3. Generate. For each mutant that survives, Gemini writes a new test aimed at that exact bug.
  4. Verify. A strict gate accepts a generated test only if it passes on the original code, fails on the mutant with a real assertion failure (not a crash or import error), stays stable across 3 runs, and actually calls the target function with a real assert.
  5. Report. Results go to report.json and a static "Graveyard" page where every killed mutant gets a tombstone.

Mutants are labelled killed_by_existing, killed_by_stake, survived, or possibly_equivalent, so a bug that no test can ever see is not counted as a failure.

Results

On a tiny demo function (is_adult(age): return age >= 18) with one weak test, a live Gemini run took the mutation score from 0.0% to 66.7%. The generated tests caught the boundary bug that the original test missed. The project's own suite has 320 passing tests.

Real-library check

We also ran Stake with live Gemini on three functions from open-source libraries (7 mutants in total):

  • boltons asciify: 1 mutant, score 0% to 100%
  • simpleeval safe_power: 4 mutants, score 25% to 25%
  • more-itertools matmul (upstream test_recipes.py): 2 mutants, score 0% to 0%

Across the 7 mutants, existing tests killed 1, Stake's verified tests killed 1, 2 survived (flagged as possibly equivalent) and 3 ended as unresolved because the mutant crashed the tests with an exception. Our verifier counts only assertion failures as kills, which is stricter than classic mutation testing.

This is a very small sample. One new kill out of seven is a modest result, and we do not claim it generalizes.

How we built it

Python, pytest, Hypothesis, the Gemini API over REST, and plain HTML/JS for the Graveyard.

  • Mutator: Python AST based, 4 operators.
  • Runner and CLI: stake hunt <file> --tests --timeout --attempts --function.
  • Generator: Gemini with a disk cache and a mock mode for offline tests.
  • Verifier: runs candidate tests in a stripped subprocess environment, so secrets never reach generated code.
  • Reporter and Graveyard: report.json plus a static page.

The Frankenstein part: we stitched together three things that normally live apart: classic mutation testing (old and academic), LLM test generation (new and unreliable), and a hard verification gate that stops the LLM from lying to us.

How we used Kiro

We wrote specs first in .kiro/specs for the runner/CLI and the AI test generator, kept project rules in steering (.kiro/steering/stake.md), and added a hook that checks for leaked secrets. Kiro also helped us write property-based tests with Hypothesis.

AI assistance

We used Kiro and Claude while building, and Gemini is part of the product itself. All code was reviewed and run by the team, and every claim in this write-up comes from runs we did ourselves.

Challenges we ran into

  • Gemini 503 overload errors. We switched to a lighter model and added a disk cache.
  • Equivalent mutants. Some mutants change nothing observable, so no test can kill them. We label them possibly_equivalent instead of pretending.
  • A function with zero mutants. One function we picked had no supported operators, which taught us to count mutants before choosing a target.
  • Windows. The verifier broke on a stripped environment and on dotted module names. We fixed both and added regression tests.
  • A false positive in our own verifier. An independent audit by a teammate found that an exception whose message contained the word "assertion" was accepted as a valid kill. We fixed it and added regression tests.

Accomplishments that we're proud of

  • A verifier that rejects fake or weak tests instead of trusting the LLM, and a team that audited it and fixed its own bug.
  • A Graveyard report that makes test gaps easy to see.
  • Three people in two countries shipping one tested codebase in days.

What we learned

Asking an LLM for tests is easy. Making it prove each test is worth keeping is the hard and useful part.

Limitations (honest)

4 mutation operators only, Python only, single-file targets, a standalone copy of the verifier, a Latin-1 limitation, and tested mainly on Windows. Mutants that crash the existing tests are reported as unresolved, not as kills, so our scores are conservative.

What's next for Stake: Bury Weak Tests

More operators, multi-file projects, smarter detection of equivalent mutants, and an option to count crash-type kills.

Code: https://github.com/ailanasirai/stake

Built With

Share this project:

Updates

Submission history