sqlite: add SQLite persistence for projects, runs, and mutants#35
Merged
sqlite: add SQLite persistence for projects, runs, and mutants#35
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11