holdfast
holdfastv0.2.0MIT
holdfast turns each suspicion an agent writes about a Rails app (a bug, a race, an effect on another area) into a spec built with the app's factories, runs it on base and head, and answers confirmed, refuted, or could_not_run. It also checks a change against its base and hunts with random sequences of the app's entry points when nothing changed.
Install
gem install holdfastA coding agent that reads code and has to say what it found often leaves a suspicion read but not run.
holdfast runs it.
The agent writes each suspicion (a bug, a race between two actions, an effect on another area) as a few lines of YAML.
holdfast check builds the world with the app’s own factories, runs the action on base and head, and answers confirmed with a failing spec to keep, refuted with what it observed, or could_not_run with the exact error.
Features
Section titled “Features”- Suspicions in YAML.
givenmakes one record per key from the factory of that name,dois Ruby, andexpectis what must be true afterwards.--suspect YAMLpasses one suspicion on the command line. - Races.
race:holds the first action at a pause point while the second runs, then the reverse, and also runs both serial orders. A race is confirmed only when the held order ends in a state that no serial order reaches. - A spec to keep. Each confirmed row names a spec under
spec/holdfast/<branch>/that fails until the code is fixed, and arepro:command that runs it. - Checking a change. On a branch, each suspicion runs on the base and on the working tree, and the row says whether the change brought it in or removed it.
holdfast runchecks a change with no suspicions: each changed method gets a row such asunintended_changeorintended_change. - Hunting when nothing changed.
holdfast rundrafts one sequence definition per write area of the app (routes, Grape endpoints, jobs) and runs random orders of their actions under invariants. A failure is shrunk, and the log holds anitblock that replays it. - Test databases of its own. Base and head, and two apps on one server, get their own database names through
DATABASE_URL. On SQLite each side gets its own file under.holdfast/db/.
How an agent uses it
Section titled “How an agent uses it”- Read the code, and write down each thing that looks wrong as a suspicion.
- Run
bundle exec holdfast check suspicions.yml. - For a
confirmedrow, keep the spec it names, fix the code, and run the spec until it passes. For arefutedrow, read what was observed. - When there is no suspicion yet, run
holdfast runand turn each suspected bug it prints into a suspicion to confirm withholdfast check.
Exit status 2 means a row was confirmed, 1 a usage error, and 0 that nothing was confirmed.
The gem ships a holdfast skill with the loop an agent follows and every form a suspicion can take.
Getting started
Section titled “Getting started”holdfast needs Ruby 3.4 or newer, git, and an app whose specs run with RSpec and FactoryBot against a test database on PostgreSQL or SQLite.
group :test do gem "holdfast", require: falseendbundle installbundle exec holdfast check suspicions.ymlAdd .holdfast/ to the app’s .gitignore, and commit the specs you keep.
Works with
Section titled “Works with”- The part of
holdfast runthat checks a change runs on jitcatch and branchout, which come with holdfast. - The hunt uses hegel-ruby (the hegeltest gem), which holdfast depends on.