Skip to content

sqlite: add SQLite persistence for projects, runs, and mutants#35

Merged
brunoerg merged 5 commits intomainfrom
2026-02-sqlite
Mar 3, 2026
Merged

sqlite: add SQLite persistence for projects, runs, and mutants#35
brunoerg merged 5 commits intomainfrom
2026-02-sqlite

Conversation

@brunoerg
Copy link
Owner

@brunoerg brunoerg commented Feb 28, 2026

Fixes #11

brunoerg and others added 5 commits February 28, 2026 10:53
Introduce --sqlite[=<path>] flag (default: mutation.db) on both the
mutate and analyze subcommands, backed by a new db module.

mutate:
- Opens/creates the database, applies schema (projects, runs, mutants
  with indexes and CHECK constraints), and seeds the Bitcoin Core
  project row via INSERT OR IGNORE.
- Creates a runs row capturing commit_hash, tool_version, and optional
  pr_number before generation begins.
- mutate_file now returns Vec<MutantData> (unified diff, SHA-256
  patch_hash, file_path, operator) alongside the existing file writes.
- Mutants are batch-inserted in chunks of 100 within transactions;
  duplicate (run_id, patch_hash) pairs are silently ignored.

analyze:
- New --sqlite <path> + --run_id <id> flags trigger DB-based analysis.
- Reads all mutants for the run, applies each diff via `git apply`
  (temp file), runs the supplied --command, updates status to
  killed/survived/error, then restores the file with git restore.
- --command is required in DB mode; --run_id without --sqlite is
  rejected with a clear error.

Other:
- get_commit_hash() added to git_changes (git rev-parse HEAD).
- MutationError gains a Rusqlite(#[from] rusqlite::Error) variant.
- rusqlite 0.32 (bundled) and sha2 0.10 added as dependencies.
- Running without --sqlite preserves existing behaviour exactly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a config_json TEXT column to the runs table. When --range is
supplied together with --sqlite, the range bounds are written as
{"range":[start,end]} into that column, making the exact scope of
every run reproducible and queryable.

Schema migration: ensure_schema now issues
  ALTER TABLE runs ADD COLUMN config_json TEXT
after the CREATE TABLE statement and silently ignores the
"duplicate column name" error so existing databases are upgraded
non-destructively without requiring a full schema recreation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
restore_file discarded the bool returned by run_command, so a failed
`git restore` was silently ignored and left the file in a mutated state.
All subsequent mutants targeting the same file then failed with
"patch does not apply" because the `-` line in their diff no longer
matched the actual file content.

Two fixes:
- restore_file now returns an error when `git restore` exits non-zero.
- run_db_analysis resets the file to HEAD at the start of each mutant
  iteration (soft pre-restore with a warning on failure) so a single
  bad restore cannot poison the rest of the run.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the hand-crafted minimal diff in generate_diff with an actual
`git diff --no-index` invocation against a temp file. This produces a
proper unified diff with 3 context lines that `git apply` can reliably
locate and apply, fixing silent patch failures during DB-based analysis.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Allows narrowing a run's mutants to a single source file, enabling
per-file analysis with different test commands on multi-file PRs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@brunoerg brunoerg merged commit 9b28987 into main Mar 3, 2026
1 check passed
@brunoerg brunoerg deleted the 2026-02-sqlite branch March 3, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite persistence (--sqlite)

1 participant