Skip to content

Add end-to-end flows for check-unused-dependencies --auto-correct - #90

Draft
corsonknowles wants to merge 2 commits into
rubyatscale:mainfrom
corsonknowles:test/auto-correct-integration-flows
Draft

corsonknowles wants to merge 2 commits into
rubyatscale:mainfrom
corsonknowles:test/auto-correct-integration-flows

Conversation

@corsonknowles

Copy link
Copy Markdown

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.rs runs check-unused-dependencies --auto-correct end 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, check and validate.

Flows

Test Proves
removes_one_unused_dependency_from_a_documented_package_yml The packwerk init / pks create template, 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_covers A comment separated by blank lines goes with its only entry.
edits_every_pack_with_unused_dependencies_and_no_other_file Several packs in one run: each is edited, and an already-tidy pack is not touched.
a_second_run_changes_nothing Running again is a no-op.
removing_the_last_dependency_keeps_the_key_while_comments_remain A commented-out entry and a comment for the next key that contains a - line survive. The key stays.
removing_the_last_dependency_removes_an_uncommented_block With no comments, the block goes, as serializing would do.
removing_dependencies_over_several_runs_matches_one_run Dropping usages one at a time over four runs gives the same file at every step as one run from the original.
leaves_other_lists_that_name_the_same_packs_alone ignored_dependencies, visible_to and a nested metadata.dependencies naming the removed pack are untouched.
preserves_crlf_line_endings_and_a_missing_final_newline Line endings and the lack of a trailing newline are kept.
falls_back_to_rewriting_only_the_files_it_cannot_edit A flow-style list is rewritten with a warning naming the removed dependencies in sorted order, while a block list in the same run is still edited in place.
without_auto_correct_reports_and_writes_nothing A plain check writes nothing.
never_removes_a_dependency_that_is_used Plain, double-quoted and single-quoted entries that are all used are left alone.

Checking the tests bite

cargo test (including with RUST_LOG=debug set), cargo clippy --all-targets -- -D warnings and cargo fmt --check pass.

🤖 Generated with Claude Code

corsonknowles and others added 2 commits November 3, 2026 15:52
`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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant