Repository navigation
Keep test settings out of ~/Library/Preferences - #5
Merged
Merged
Conversation
ScratchSettings gave every test its own ClearedTests.<UUID> defaults suite and called removePersistentDomain in deinit. That empties the domain but leaves a 42-byte plist behind in ~/Library/Preferences, so each test run added one file per test (72 had piled up). Name the suite with an absolute path in the temporary directory instead. CFPreferences stores such a domain as a plain plist at that path, so nothing reaches ~/Library/Preferences, and deinit deletes the file. Deleting a leaked plist from ~/Library/Preferences in teardown is not reliable: the preferences daemon can write it back while the domain is still cached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ExCvUisv1HRzoGqhBztmCk
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.
Summary
ScratchSettingsgave each test its ownClearedTests.<UUID>defaults suite and calledremovePersistentDomainindeinit. That empties the domain but leaves a 42-byte plist in~/Library/Preferences, so every test run added one file per test. 72 had piled up by Oct 13.The suite is now named with an absolute path in the temporary directory. CFPreferences stores such a domain as a plain plist at that path, so nothing reaches
~/Library/Preferences, anddeinitdeletes the file.Why not delete the leftover plist in teardown?
I checked this on macOS 27.0.1. Deleting
~/Library/Preferences/<suite>.plistafterremovePersistentDomainis racy: the preferences daemon recreated the file in one of two runs while it still had the domain cached.defaults deletewon't help either, since it reports an emptied domain as "not found". A path-based suite never touches that folder.Path-based suite names aren't documented for
UserDefaults(suiteName:), but CFPreferences has long supported them (defaults read /path/to/filerelies on this). I confirmed values,register(defaults:)and reads through a second instance all work.Test plan
xcodebuild … -scheme Cleared -destination 'platform=macOS' test: 79 tests in 16 suites passed~/Library/Preferencesheld 651 files before and after the run, with noClearedTests.*🤖 Generated with Claude Code
https://claude.ai/code/session_01ExCvUisv1HRzoGqhBztmCk