Commit d1fdb1b
Test that
`rbs collection clean` built a `Collection::Cleaner` and never called
`#clean` on it, so the command walked away with exit status 0 while
leaving every directory in place. The bug dates back to 38fd8b2, the
commit that introduced `rbs collection`, so the command had never once
removed anything.
`test/rbs/collection/cleaner_test.rb` exercises `Cleaner#clean`
directly, which is why the missing call went unnoticed for so long.
This test goes through `RBS::CLI#run` instead, so it covers the wiring
between the subcommand and the cleaner.
The lockfile lists `ast 2.4`. The collection directory also holds
`ast 2.3` and `rainbow 3.0`, covering both reasons `Cleaner#needed?`
rejects a directory: a gem locked at another version, and a gem absent
from the lockfile. `ast/2.4/ast.rbs` is written so that the assertion
on the version that survives shows its RBS files are left alone rather
than only that a directory still exists.
The collection is named with `--collection` rather than by changing the
working directory. `Config.find_config_path` walks from the working
directory up to the filesystem root, so a `Dir.chdir` based test stays
inside its temporary directory only as long as the config file is
written before `cli.run`. With `TMPDIR` pointed inside a real project, a
reordering would let the search reach an ancestor's lockfile and delete
that project's `.gem_rbs_collection`. `--collection` expands the path it
is given and skips the search.
The config file is written empty. `clean` reads `path` and `gems` from
the lockfile and never opens the config, and `path` appears in both
files, so giving the config a `path` of its own would suggest that the
command consults it. Its one remaining job is to be what `--collection`
names and what the lockfile path is derived from, which is why the
lockfile is written through `Config.to_lockfile_path` instead of a
hardcoded name that happens to match.
The `source` block in the lockfile stays even though `Cleaner#needed?`
does not read it. `Lockfile.from_lockfile` passes `gem["source"]` to
`Sources.from_config_entry`, so a lockfile without it raises
`NoMethodError` when read through `Lockfile` rather than `Config`.
#3127
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HSq3kKMB8ULhZrnL5urD7yrbs collection clean removes unneeded directories1 parent a6b1e04 commit d1fdb1b
1 file changed
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1734 | 1734 | | |
1735 | 1735 | | |
1736 | 1736 | | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
1737 | 1773 | | |
1738 | 1774 | | |
1739 | 1775 | | |
| |||
0 commit comments