Skip to content

Keep test settings out of ~/Library/Preferences - #5

Merged
hollandcloud merged 1 commit into
mainfrom
fix/test-defaults-leak
Oct 19, 2026
Merged

hollandcloud merged 1 commit into
mainfrom
fix/test-defaults-leak

Conversation

@hollandcloud

Copy link
Copy Markdown
Owner

Summary

ScratchSettings gave each test its own ClearedTests.<UUID> defaults suite and called removePersistentDomain in deinit. 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, and deinit deletes the file.

Why not delete the leftover plist in teardown?

I checked this on macOS 27.0.1. Deleting ~/Library/Preferences/<suite>.plist after removePersistentDomain is racy: the preferences daemon recreated the file in one of two runs while it still had the domain cached. defaults delete won'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/file relies 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/Preferences held 651 files before and after the run, with no ClearedTests.*

🤖 Generated with Claude Code

https://claude.ai/code/session_01ExCvUisv1HRzoGqhBztmCk

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
@hollandcloud
hollandcloud merged commit 56a72f4 into main Oct 19, 2026
2 checks passed
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.

1 participant