Repository navigation
Add end-to-end flows for check-unused-dependencies --auto-correct - #90
Draft
corsonknowles wants to merge 2 commits into
Draft
corsonknowles wants to merge 2 commits into
corsonknowles wants to merge 2 commits into
Conversation
`check-unused-dependencies --auto-correct` rewrote every package.yml it touched by serializing the pack, which deleted its comments and reordered its keys. It now removes the unused entries from the `dependencies:` list as text and leaves the rest of the file as it was, line endings included. A comment covers the entries below it, up to the next blank line or comment, and is removed only when all of those entries are. A commented-out entry, and any comment directly above one, is always kept. When no entries remain, the `dependencies:` key stays, with nothing under it, while a comment is on it, directly above it or still under it; otherwise the whole block is removed. pks and packwerk both read a key with no entries as an empty list. Removing entries one at a time gives the same file as removing them together, which a test checks for every subset of every list of up to five lines. The edited text must parse back to the original pack minus exactly the removed dependencies. When it doesn't, as for a flow-style list, the file is rewritten as before and a warning names the file and the dependencies removed, in sorted order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each test builds a small project in a temporary directory, runs pks the way a developer would, and compares every file before and after, so it fails both when an intended edit is missing and when any other file or line changes. The flows cover a documented package.yml, several packs in one run, a second run, emptying a list with and without comments, removing over several runs, lists that name the same packs under other keys, CRLF and a missing final newline, the flow-style fallback, a check without --auto-correct, and a pack whose dependencies are all used. After each correction the project must pass check-unused-dependencies, check and validate. Co-Authored-By: Claude Opus 5.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.
Stacked on #60. This branch contains #60's commit (1df54a4) plus one more, 83eba89. Please review only 83eba89 here; once #60 merges, this PR's diff shrinks to just that commit.
What this adds
tests/auto_correct_unused_dependencies_flows_test.rsrunscheck-unused-dependencies --auto-correctend to end against small projects built in a temporary directory. Each project has four library packs that define modules, plus consumer packs whose code references some of them, so whether a dependency is "unused" comes from real references, not stubs.Every test snapshots every file in the project before and after the run and compares them whole. A test therefore fails when an intended edit is missing, and also when any other line or any other file changes. After each correction, the project must pass
check-unused-dependencies,checkandvalidate.Flows
removes_one_unused_dependency_from_a_documented_package_ymlpackwerk init/pks createtemplate, with comments filled in, loses one entry and nothing else. A comment that still covers a kept entry stays.removes_a_comment_with_the_only_entry_it_coversedits_every_pack_with_unused_dependencies_and_no_other_filea_second_run_changes_nothingremoving_the_last_dependency_keeps_the_key_while_comments_remain-line survive. The key stays.removing_the_last_dependency_removes_an_uncommented_blockremoving_dependencies_over_several_runs_matches_one_runleaves_other_lists_that_name_the_same_packs_aloneignored_dependencies,visible_toand a nestedmetadata.dependenciesnaming the removed pack are untouched.preserves_crlf_line_endings_and_a_missing_final_newlinefalls_back_to_rewriting_only_the_files_it_cannot_editwithout_auto_correct_reports_and_writes_nothingnever_removes_a_dependency_that_is_usedChecking the tests bite
main's auto-correct, which serializes the pack, 10 of the 12 fail. The two that pass are the no-write and all-used guards, which should pass with or without Preserve comments when auto-correcting unused dependencies #60.dependency_removal.rsandchecker.rs, exactly the two flows from the last review fail: emptying a list that has comments, and removing over several runs.cargo test(including withRUST_LOG=debugset),cargo clippy --all-targets -- -D warningsandcargo fmt --checkpass.🤖 Generated with Claude Code