Skip to content

Add karva snapshot prune command#453

Merged
MatthewMckee4 merged 1 commit intomainfrom
add-snapshot-prune-command
Feb 10, 2026
Merged

Add karva snapshot prune command#453
MatthewMckee4 merged 1 commit intomainfrom
add-snapshot-prune-command

Conversation

@MatthewMckee4
Copy link
Member

@MatthewMckee4 MatthewMckee4 commented Feb 10, 2026

Summary

  • Add karva snapshot prune subcommand that detects and removes .snap files whose source test function no longer exists
  • Uses static analysis (no Python/PyO3 needed): parses each snapshot's source metadata field to extract the test file and function name, then checks if they still exist on disk
  • Supports --dry-run flag to preview which snapshots would be removed without deleting them
  • Supports optional path filtering to scope pruning to specific directories or files
  • Handles parametrized snapshots, numbered snapshots, inline snapshots, and class-prefixed test methods

Test plan

  • 12 unit tests in karva_snapshot covering parse_source, base_function_name, find_snapshots, find_unreferenced_snapshots, and remove_snapshot
  • 7 integration tests covering: basic prune, dry-run, nothing to prune, test file deleted, parametrized snapshots, path filtering, no snapshots directory
  • just test — all 545 tests pass
  • prek run -a — all pre-commit checks pass

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 10, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 1 untouched benchmark


Comparing add-snapshot-prune-command (89cd92f) with main (6add357)

Open in CodSpeed

Add a new subcommand that detects and removes `.snap` files whose
source test function no longer exists. Uses static analysis: parses
each snapshot's `source` metadata to extract the test file and function
name, then checks if they still exist on disk.

Supports `--dry-run` to preview removals and optional path filtering.
@MatthewMckee4 MatthewMckee4 force-pushed the add-snapshot-prune-command branch from e3a38d3 to 89cd92f Compare February 10, 2026 14:13
@MatthewMckee4 MatthewMckee4 added the snapshot-testing Related to snapshot testing label Feb 10, 2026
@MatthewMckee4 MatthewMckee4 merged commit 077f038 into main Feb 10, 2026
9 checks passed
@MatthewMckee4 MatthewMckee4 deleted the add-snapshot-prune-command branch February 10, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot-testing Related to snapshot testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant