cmd: add corpus clean command to remove invalid sequences#777
Merged
cmd: add corpus clean command to remove invalid sequences#777
Conversation
After contract refactoring, the corpus may contain many invalid sequences that cannot be executed. This adds a new `medusa corpus clean` command to remove these invalid sequences from disk. The command: - Compiles contracts and sets up a test chain - Loads and validates each call sequence in the corpus - Removes sequences that fail to execute (contract resolution failures, ABI mismatches, or execution errors) - Supports --dry-run to preview what would be deleted - Reports statistics on valid/invalid sequences Fixes #743 Co-Authored-By: Claude Opus 4.5 <[email protected]>
6010ae3 to
83dfd8a
Compare
Move CorpusCleaner to fuzzing/corpus/ package to improve separation of concerns and match the organizational pattern of corpus_pruner.go. Changes: - Create fuzzing/corpus/corpus_cleaner.go with refactored CorpusCleaner that receives dependencies as parameters (no *Fuzzer dependency) - Update fuzzing/corpus_cleaner.go to be a thin wrapper that sets up dependencies and delegates to corpus.CorpusCleaner - Follows same pattern as corpus_pruner.go for consistency Benefits: - Better separation of concerns (corpus package independent of Fuzzer) - More testable (CorpusCleaner can be tested with mocked dependencies) - Consistent architecture within the corpus package Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
…ze architecture - Remove --dry-run flag completely (invalid sequences are always deleted) - Add CreateTestChainForCleaning() public helper to Fuzzer for CLI use - Delete fuzzing/corpus_cleaner.go wrapper (CLI now calls corpus package directly) - Standardize flag handling by creating cmd/corpus_flags.go - Move all cleaning logic to corpus package (no Fuzzer dependency) - Follow corpus_pruner pattern for clean separation of concerns Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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.
Summary
medusa corpus cleancommand to remove invalid sequences from the on-disk corpus--dry-runoption to preview changes)Usage
Example output:
Implementation Details
cmd/corpus.go: New CLI command using Cobra, similar to existing fuzz/init commandsfuzzing/corpus_cleaner.go: CorpusCleaner type that reuses fuzzer infrastructurefuzzing/corpus/corpus.go: AddedCleanInvalidSequences()methodfuzzing/corpus/corpus_files.go: AddedremoveFileFromDisk()methodTest plan
go build ./...)go fmt ./...)go test -v ./fuzzing/corpus/...)Fixes #743
Generated with Claude Code