branchout
branchoutv0.2.0MIT
Runs a Ruby method on concrete inputs and reports branch arms that are still uncovered. An agent reads that frontier and proposes the next inputs. Branchout does not collect or solve symbolic path constraints.
Install
gem install branchout- Source on GitHub
- Used by: holdfast
A coding agent that adds tests can see that a branch was missed and still not know which comparison failed, or which input came closest. branchout runs a Ruby method on many inputs under branch coverage and prints that frontier: each arm no input took, the condition that selects it, and the nearest input that reached it. The agent copies the nearest input, changes it as the line says, and runs again. branchout then writes examples that pin what the method returns now.
Features
Section titled “Features”- A frontier to close. Each line under
FRONTIERnames an arm at its file, line, and column, such asapp/models/loan.rb:8:4 makes `amount_cents > 10_000` true, andnearestis the input to start from. - What coverage cannot see.
RETURNEDlists the value each input returned,OPERATORSnames each&&and||whose sides coverage does not count, andBOUNDARIESlists each comparison to try at its edge. - Inputs from three strategies.
--strategyruns yourinputs, literal mutations of them (mutate), andrandomsamples, in that order. The same inputs, flags, and CRuby give the same output. - Tests that pin the current behavior.
--emit-tests PATHwrites Minitest or RSpec examples (--format rspec) for every input.--pin-keyspins only the named keys of a returned Hash. - Inside the test suite.
Branchout.explore("Loan#approve", within: self, inputs: [...])runs in a spec, so each input reaches the suite’s factories and helpers. With Active Record, each input runs in a savepoint that is rolled back. - Reports for a machine.
--jsonand--json-out PATHwrite the report as JSON, and--md-out PATHwrites it as Markdown.
How an agent uses it
Section titled “How an agent uses it”- Pick a method with a few
if,unless, orcasearms that returns a value. - Run
branchout explore <file> <entry>orBranchout.explorein a spec with one input. - For each
FRONTIERline, add an input likenearest, changed as the line says, and run again. - Compare each
RETURNEDvalue with what the method should return, then write the examples with--emit-tests.
The gem ships a branchout skill for the agent.
Getting started
Section titled “Getting started”branchout needs Ruby 3.3 or newer. It uses Coverage, Prism, and json from the standard library.
gem install branchout rspecbranchout explore shipping.rb Shipping.fee --emit-tests shipping_spec.rbIn a Rails app, add gem "branchout", group: :test, require: false to the Gemfile and call Branchout.explore from a spec.
Works with
Section titled “Works with”- The examples branchout writes can be candidates for jitcatch. Write them with
--require-by-nameon a checkout of the base revision, so each side loads its own code.