Skip to content

Cover the code that deletes, and make the suite runnable - #5

Merged
Jarvis322 merged 2 commits into
Jarvis322:mainfrom
peechycreation:pr/tests
Sep 6, 2026
Merged

Jarvis322 merged 2 commits into
Jarvis322:mainfrom
peechycreation:pr/tests

Conversation

@peechycreation

Copy link
Copy Markdown
Contributor

Two changes to the test target.

Reclaimer had no test. It is the only code in the app that removes anything, so this pins the behaviour the UI promises: emptyDirectories keeps the directory itself, prune keeps files newer than the cutoff and removes only the directories it emptied, steps stops at the first failure instead of carrying on down the list, and deleting a path the user already removed by hand is a no-op rather than an error that would stop a batch halfway. Everything happens inside a temporary directory the suite creates and removes.

The machine-wide scan is now opt-in. itemsAreWellFormed and jsonInventoryIsWellFormed each walk the whole disk and measure every file. On a developer Mac that is over 20 minutes for the pair, with no output until they finish, which is not something anyone runs before a commit — I could not get either to complete while working on this.

They are worth keeping, so they stay one variable away:

SYSDATA_SCAN_TESTS=1 swift test

and they now carry a time limit. What is left runs in 8 ms, so swift test is worth running again.

Happy to split these if you would rather take one.

Reclaimer is the only place in the app that removes anything, and it was
the only service without a test. These pin the behaviour the UI promises:
emptyDirectories keeps the directory itself, prune keeps files newer than
the cutoff and removes only the directories it emptied, steps stops at
the first failure instead of carrying on down the list, and a delete of a
path the user already removed by hand is a no-op rather than an error
that would stop a batch halfway.

Everything happens inside a temporary directory the suite creates and
removes; the whole suite runs in 6 ms.
itemsAreWellFormed and jsonInventoryIsWellFormed each walk $HOME,
/Library, /private/var, /opt, /usr/local and /Users/Shared and measure
every file under them. On a developer Mac that is over 20 minutes for the
pair, with no output until they finish, so `swift test` is not something
anyone runs before a commit.

Put them behind SYSDATA_SCAN_TESTS and give them a time limit. The
remaining suite is 9 tests in 8 ms; the inventory is still one variable
away, and a CI runner starts empty enough to enable it there.
@Jarvis322
Jarvis322 merged commit 7528f87 into Jarvis322:main Sep 6, 2026
Jarvis322 added a commit that referenced this pull request Sep 6, 2026
Making the scan opt-in in #5 was right — 21 tests in ten milliseconds is a
suite people will actually run — but it left nothing running the scan
automatically. The release script is the one place it has to happen, and the
comment saying CI enables them was describing a workflow that does not.
@Jarvis322

Copy link
Copy Markdown
Owner

Merged. Reclaimer having no test was the worst gap in the project: it is the only code that deletes, and it had just shipped a bug where a cancelled password prompt let the rest of a batch delete anyway.

21 tests in ten milliseconds is a suite people will actually run before committing, which the old one was not.

One thing your change left open, fixed in a follow-up: nothing ran the disk-walking tests automatically any more. scripts/release.sh now sets SYSDATA_SCAN_TESTS=1, so no version ships without them. I also corrected the comment saying CI enables them — the workflow in #6 deliberately does not.

@peechycreation
peechycreation deleted the pr/tests branch September 7, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants