test: cover the least-tested modules (timemachine, purgeable, docker, homebrew, dns, config) - #81
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
Conversation
…ebrew, dns, config) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
What does this PR do?
Adds unit tests for the modules with the lowest coverage. Overall coverage goes from 83.09% statements / 71.56% branches to 93.52% / 84.6%, and the thresholds in
vitest.config.tsare raised to 90/90/80/90 to lock that in.Per-module before → after (statements):
maintenance/timemachine.tsscanners/homebrew.tsscanners/docker.tsmaintenance/purgeable.tsutils/clipboard.tsmaintenance/dns-cache.tsutils/hash.tsutils/config.tsThe recurring problem in the existing tests was that the
child_processandfs/promisesmocks were fixed for the whole file (accessalways rejected,spawnalways closed with code 0), so the interesting paths — brew/docker actually installed, sudo available, a command failing — were unreachable and several assertions were tautological (expect(typeof result.success).toBe('boolean')).The new tests use a per-test scriptable
spawnmock plus a recorded call log, so a test can decide what each invocation does and assert the exact argv:That makes the security-relevant behavior testable and now covered: snapshot dates are only accepted when they match the strict date regex,
sudo -nis used and reported viarequiresSudowhen passwordless sudo is unavailable,brew --cacheoutput outside the expected prefixes is rejected, unknowndocker system dfresource types are skipped,docker system prunenever gets--volumes, and configextraPathsoutside home//Users//Volumesare dropped and the list is capped at 50.config.test.tsnow mocksos.homedir()to a temp directory.config.tsbuildsCONFIG_PATHSfromhomedir()at import time, so coveringinitConfig()/configExists()otherwise means writing~/.maccleanerrc— i.e. clobbering the real config of whoever runs the suite.Type of change
Checklist
bun run lintpassesbun run testpasses (no regressions) — 392 tests, 42 filesbun run buildsucceedschild_process/fs, so they are platform independent)Notes for reviewer
No production code changed — tests and coverage thresholds only.
Link to Devin session: https://app.devin.ai/sessions/4a8526474f4a4c3fba300a24439718de
Requested by: @guhcostan