Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Tests that take permissions away do not run as root
Țugui Dragoș41fccfe2e3d7
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppMemoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppMemoryTests.swiftindex c0b5843b..1327888b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AppMemoryTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppMemoryTests.swift@@ -105,7 +105,7 @@ struct AppMemoryTests {}/// A file that is there and cannot be read says nothing about what it holds, so it is never written over.- @Test func leavesAFileItCannotReadAlone() async throws {+ @Test(.permissionsHold) func leavesAFileItCannotReadAlone() async throws {let directory = try TemporaryDirectory()let url = directory.url.appending(path: "apps.json")let memory = AppMemory(url: url)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swiftindex 5427db9e..38de8a68 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift@@ -417,7 +417,7 @@ struct AttackRemovalGuardTests {/// The guard refuses what is inside a container's `Data/Documents`, where a sandboxed app keeps what its/// user made. An uninstall lists the container around it, so the container is refused too while that folder/// holds anything or cannot be read.- @Test func theContainerAroundSomebodysDocuments() throws {+ @Test(.permissionsHold) func theContainerAroundSomebodysDocuments() throws {let directory = try TemporaryDirectory()let home = directory.url.appending(path: "home", directoryHint: .isDirectory)try directory.file("home/Library/Containers/com.example.notes/Data/Documents/thesis.txt")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swiftindex 99fc5350..ee2fbc39 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CleanupTests.swift@@ -39,7 +39,7 @@ struct CleanupTests {}/// While History cannot be read nothing moves, and the command says so above the list, with the way out.- @Test func saysSoWhenHistoryCannotBeRead() async throws {+ @Test(.permissionsHold) func saysSoWhenHistoryCannotBeRead() async throws {let directory = try TemporaryDirectory()let cache = try directory.file("home/Library/Caches/com.example.editor/blob", bytes: 20)let history = try directory.file("Peel/removals.json", contents: Data("[]".utf8))diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swiftindex 8597f8aa..1854271a 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift@@ -120,7 +120,7 @@ struct CloudStorageTests {/// Without Full Disk Access, iCloud Drive cannot be read. The scan then says so, rather than reporting/// nothing to free.- @Test func saysWhenICloudDriveCouldNotBeRead() async throws {+ @Test(.permissionsHold) func saysWhenICloudDriveCouldNotBeRead() async throws {let directory = try TemporaryDirectory()try directory.directory("Library/Mobile Documents")try directory.setPermissions(0o000, of: "Library/Mobile Documents")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swiftindex 5785409a..21f6e791 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift@@ -25,7 +25,7 @@ struct DeveloperCachesTests {/// A folder macOS would not let Peel open is not one that took too long: both are unknown and never selected/// for the user, and the page says which of the two it was.- @Test func tellsAFolderMacOSRefusedFromOneThatDidNotAnswer() async throws {+ @Test(.permissionsHold) func tellsAFolderMacOSRefusedFromOneThatDidNotAnswer() async throws {let directory = try TemporaryDirectory()try directory.file(".npm/_cacache/content/data", bytes: 80_000)try directory.file(".npm/_npx/package/index.js", bytes: 8_000)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swiftindex 0d9e3d8e..d0adfdf1 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift@@ -118,7 +118,7 @@ struct DuplicateFinderTests {/// A folder locked by ordinary file permissions is not one Full Disk Access would open, so the scan does not/// ask for it. Only macOS's privacy refusal does, and a test cannot stage that.- @Test func aFolderLockedByPermissionsDoesNotAskForFullDiskAccess() async throws {+ @Test(.permissionsHold) func aFolderLockedByPermissionsDoesNotAskForFullDiskAccess() async throws {let directory = try TemporaryDirectory()try directory.file("home/Documents/locked/inside.txt", contents: Data("hello".utf8))try directory.setPermissions(0o000, of: "home/Documents/locked")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swiftindex d65fff91..d010cbd2 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift@@ -142,11 +142,11 @@ struct ExclusionCommandTests {#expect(try Data(contentsOf: store.url) == Data("not json".utf8))}- @Test func saysSoWhenItCannotWrite() async throws {+ @Test(.permissionsHold) func saysSoWhenItCannotWrite() async throws {let directory = try TemporaryDirectory()let folder = try directory.directory("Peel")let store = store(in: directory)- try FileManager.default.setAttributes([.posixPermissions: 0o500], ofItemAtPath: folder.path(percentEncoded: false))+ try directory.setPermissions(0o500, of: folder)defer { try? FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: folder.path(percentEncoded: false)) }await #expect(throws: CommandFailure.self) {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swiftindex 7e4bcc9f..09b4ab83 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionsTests.swift@@ -186,13 +186,13 @@ struct ExclusionsTests {}/// A change that cannot be written says what the list would have been, so the app can keep it until it quits.- @Test func aChangeThatCannotBeWrittenSaysWhatItWouldHaveSaved() async throws {+ @Test(.permissionsHold) func aChangeThatCannotBeWrittenSaysWhatItWouldHaveSaved() async throws {let directory = try TemporaryDirectory()let folder = directory.url.appending(path: "Peel", directoryHint: .isDirectory)try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)let store = ExclusionStore(url: folder.appending(path: "exclusions.json"))await store.save(Exclusions(paths: [URL(filePath: "/Users/x/Kept")]))- try FileManager.default.setAttributes([.posixPermissions: 0o500], ofItemAtPath: folder.path(percentEncoded: false))+ try directory.setPermissions(0o500, of: folder)defer { try? FileManager.default.setAttributes([.posixPermissions: 0o700], ofItemAtPath: folder.path(percentEncoded: false)) }let outcome = await store.change { $0.paths.insert(URL(filePath: "/Users/x/Added")) }@@ -214,7 +214,7 @@ struct ExclusionsTests {}/// A list that is there and cannot be read is not an empty list: what was excluded is unknown.- @Test func doesNotReadAListItCannotUnderstandAsEmpty() async throws {+ @Test(.permissionsHold) func doesNotReadAListItCannotUnderstandAsEmpty() async throws {let directory = try TemporaryDirectory()let broken = try directory.file("broken.json", contents: Data(#"{"paths":["file:///Users/x/Vault/""#.utf8))let locked = try directory.file("locked.json", contents: Data(#"{"paths":[]}"#.utf8))diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swiftindex 0f48216e..1a059298 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift@@ -116,7 +116,7 @@ struct FileSizeTests {/// A folder macOS will not open has no known size. Read as zero, it would fall under Space's size floor and/// never be shown.- @Test func knowsNoSizeForAFolderItCannotOpen() async throws {+ @Test(.permissionsHold) func knowsNoSizeForAFolderItCannotOpen() async throws {let directory = try TemporaryDirectory()let folder = try directory.directory("closed")try directory.file("closed/a.bin", bytes: 100_000)@@ -129,7 +129,7 @@ struct FileSizeTests {/// A folder inside that macOS will not open leaves the walk short: its size, and whatever wallet or repository/// it holds, were never seen. So the folder around it is not known either.- @Test func knowsNoSizeForAFolderItCannotReadToTheEnd() async throws {+ @Test(.permissionsHold) func knowsNoSizeForAFolderItCannotReadToTheEnd() async throws {let directory = try TemporaryDirectory()let folder = try directory.directory("Vendor")try directory.file("Vendor/settings.plist", bytes: 100_000)@@ -163,7 +163,7 @@ struct FileSizeTests {/// An item whose own attributes macOS will not give, because the folder around it cannot be searched, is not/// known either, and never reads as zero. An item that is not there at all holds nothing.- @Test func knowsNoSizeForAnItemItCannotLookAt() async throws {+ @Test(.permissionsHold) func knowsNoSizeForAnItemItCannotLookAt() async throws {let directory = try TemporaryDirectory()let file = try directory.file("closed/a.bin", bytes: 100_000)let folder = try directory.directory("closed/inner")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swiftindex 7540ef2f..d7523733 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift@@ -160,7 +160,7 @@ struct HistoryCommandTests {}/// A removal whose items Peel cannot look at in the Trash is not called gone: nobody knows yet.- @Test func aRemovalPeelCannotLookAtIsNotCalledGone() throws {+ @Test(.permissionsHold) func aRemovalPeelCannotLookAtIsNotCalledGone() throws {let directory = try TemporaryDirectory()let trashed = try directory.file("home/.Trash/report.pdf")let record = RemovalRecord(@@ -251,11 +251,11 @@ struct HistoryCommandTests {}/// A History file that cannot be read is reported as an error, never shown as an empty History.- @Test func refusesToListAHistoryItCannotRead() async throws {+ @Test(.permissionsHold) func refusesToListAHistoryItCannotRead() async throws {let directory = try TemporaryDirectory()let logs = logs(in: directory)let file = try directory.file("Peel/removals.json", contents: Data("not json".utf8))- try FileManager.default.setAttributes([.posixPermissions: 0], ofItemAtPath: file.path(percentEncoded: false))+ try directory.setPermissions(0, of: file)defer { try? FileManager.default.setAttributes([.posixPermissions: 0o644], ofItemAtPath: file.path(percentEncoded: false)) }await #expect(throws: CommandFailure.self) {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swiftindex 2b3c5727..12fe691e 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift@@ -76,7 +76,7 @@ struct DeviceInfoTests {struct AccessTests {/// A privacy (TCC) refusal reads as `EPERM`. Plain permissions read as `EACCES`, which says nothing about/// Full Disk Access: a `.Trash` that `sudo` left owned by root is one example.- @Test func tellsApartReadableFoldersFromRefusedOnes() throws {+ @Test(.permissionsHold) func tellsApartReadableFoldersFromRefusedOnes() throws {let directory = try TemporaryDirectory()let readable = try directory.directory("readable")let refused = try directory.directory("refused")@@ -90,7 +90,7 @@ struct AccessTests {/// The probes are tried in turn, and an unknown answer moves on to the next: a `.Trash` nobody can list must/// not keep the Safari folders from being asked.- @Test func keepsAskingWhenAProbeSaysNothing() async throws {+ @Test(.permissionsHold) func keepsAskingWhenAProbeSaysNothing() async throws {let directory = try TemporaryDirectory()let home = try directory.directory("home")try directory.directory("home/.Trash")@@ -132,7 +132,7 @@ struct AccessTests {}/// A refusal where the account cannot write is about ownership, not App Management.- @Test func aRefusalInAFolderThatCannotBeWrittenSaysNothing() throws {+ @Test(.permissionsHold) func aRefusalInAFolderThatCannotBeWrittenSaysNothing() throws {let directory = try TemporaryDirectory()let bundle = try directory.directory("Locked/Example.app")try directory.setPermissions(0o555, of: "Locked")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swiftindex 6b218ef3..4e05d131 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift@@ -312,7 +312,7 @@ struct LeftoverScannerTests {#expect(try #require(emptied.leftovers.first { $0.kind == .containers }).match.isRecommended)}- @Test func reportsUnreadableLocations() async throws {+ @Test(.permissionsHold) func reportsUnreadableLocations() async throws {let directory = try TemporaryDirectory()try directory.file("home/Library/Logs/Tunewell/log.txt")try directory.setPermissions(0o000, of: "home/Library/Logs")@@ -324,7 +324,7 @@ struct LeftoverScannerTests {#expect(scan.unreadableLocations.map(\.kind) == [.logs])}- @Test func flagsItemsInReadOnlyLocationsAsRequiringPrivileges() async throws {+ @Test(.permissionsHold) func flagsItemsInReadOnlyLocationsAsRequiringPrivileges() async throws {let directory = try TemporaryDirectory()try directory.file("root/Library/LaunchDaemons/net.example.client.helper.plist")try directory.file("home/Library/Preferences/net.example.client.plist")@@ -562,11 +562,11 @@ struct LeftoverScannerTests {/// A folder macOS will not open would read as empty, and an empty folder of the app's own would be selected./// From macOS 27, access to another team's container is denied outright rather than prompted for.- @Test func aLeftoverThatCannotBeReadIsNeverSelectedAndHasNoSize() async throws {+ @Test(.permissionsHold) func aLeftoverThatCannotBeReadIsNeverSelectedAndHasNoSize() async throws {let directory = try TemporaryDirectory()let container = try directory.directory("home/Library/Containers/net.example.client")try directory.file("home/Library/Containers/net.example.client/Data/Library/Caches/blob", bytes: 64_000)- try FileManager.default.setAttributes([.posixPermissions: 0o000], ofItemAtPath: container.path(percentEncoded: false))+ try directory.setPermissions(0o000, of: container)defer { try? FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: container.path(percentEncoded: false)) }let scan = await LeftoverScanner(environment: environment(in: directory)).scan(tunewell, installedApps: [tunewell])@@ -579,7 +579,7 @@ struct LeftoverScannerTests {/// A folder inside the leftover that macOS will not open may hold what nothing brings back, as a helper's own/// `Private` folder with a wallet in it, so the leftover is not read to the end and is never selected.- @Test func aLeftoverNotReadToTheEndIsNeverSelected() async throws {+ @Test(.permissionsHold) func aLeftoverNotReadToTheEndIsNeverSelected() async throws {let directory = try TemporaryDirectory()try directory.file("home/Library/Application Support/net.example.client/settings.plist", bytes: 4_096)try directory.file("home/Library/Application Support/net.example.client/Private/wallet.dat", bytes: 4_096)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swiftindex 8f0be7dd..c5d39d10 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift@@ -85,7 +85,7 @@ struct OrphanScannerTests {/// A crash reporter keeps a folder for each app inside its own. When macOS will not let Peel list that folder,/// what it holds is not known, so it is not reported as nobody's, the same as a folder that did not answer.- @Test func aFolderThatCannotBeListedIsNotNobodys() async throws {+ @Test(.permissionsHold) func aFolderThatCannotBeListedIsNotNobodys() async throws {let directory = try TemporaryDirectory()try directory.file("home/Library/Application Support/com.vendor.reports/com.installed.app/report.log")try directory.setPermissions(0, of: "home/Library/Application Support/com.vendor.reports")@@ -98,13 +98,13 @@ struct OrphanScannerTests {/// An item that needs an administrator, in a place the helper does not serve, is left alone rather than/// offered and then refused.- @Test func whatTheHelperMayNotMoveIsLeftAlone() async throws {+ @Test(.permissionsHold) func whatTheHelperMayNotMoveIsLeftAlone() async throws {let directory = try TemporaryDirectory()let served = try directory.directory("root/Library/Application Support/com.gone.app")let beyond = try directory.directory("root/Users/Shared/com.gone.app")try directory.file("root/Users/Shared/com.gone.app/wallet.dat")for folder in [served, beyond] {- try FileManager.default.setAttributes([.posixPermissions: 0o555], ofItemAtPath: folder.path(percentEncoded: false))+ try directory.setPermissions(0o555, of: folder)}defer {for folder in [served, beyond] {@@ -373,7 +373,7 @@ struct OrphanScannerTests {}/// A file that cannot be read is not called a leftover on its name; one that is no job at all still is.- @Test func aJobThatCannotBeReadIsNotCalledALeftover() async throws {+ @Test(.permissionsHold) func aJobThatCannotBeReadIsNotCalledALeftover() async throws {let directory = try TemporaryDirectory()try directory.file("home/Library/LaunchAgents/org.example.closed.plist", contents: job("org.example.closed", runs: ["/bin/sh"]))try directory.setPermissions(0o000, of: "home/Library/LaunchAgents/org.example.closed.plist")@@ -500,12 +500,12 @@ struct OrphanScannerTests {/// In root's `/usr/local/bin`, a link into an app that is gone leads nowhere, which is the one kind of item the/// helper takes from there, so it is offered like anything else the helper can move.- @Test func aLinkIntoAnAppThatIsGoneIsWithinTheHelpersReach() async throws {+ @Test(.permissionsHold) func aLinkIntoAnAppThatIsGoneIsWithinTheHelpersReach() async throws {let directory = try TemporaryDirectory()let bin = try directory.directory("root/usr/local/bin")let link = bin.appending(path: "docker")try FileManager.default.createSymbolicLink(atPath: link.path(percentEncoded: false), withDestinationPath: "../../../Applications/Gone.app/Contents/MacOS/docker")- try FileManager.default.setAttributes([.posixPermissions: 0o555], ofItemAtPath: bin.path(percentEncoded: false))+ try directory.setPermissions(0o555, of: bin)defer { try? FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: bin.path(percentEncoded: false)) }let items = await scanner(in: directory).scan(installedApps: installed).groups.flatMap(\.items)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swiftindex 0e55f323..2e367799 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift@@ -337,7 +337,7 @@ struct PackageReceiptsTests {/// An item that needs an administrator is left alone when the helper would refuse it. The helper refuses/// items outside the folders it serves, anything in `/Applications` that is not an app, and, in a folder/// command-line tools are linked into, anything but a link that leads nowhere.- @Test func leavesAloneWhatTheHelperWouldRefuse() async throws {+ @Test(.permissionsHold) func leavesAloneWhatTheHelperWouldRefuse() async throws {let directory = try TemporaryDirectory()let volume = PathPattern.canonical(directory.url).path(percentEncoded: false)let served = PathPattern.canonical(try directory.directory("root/Library/Application Support/Example"))@@ -348,7 +348,7 @@ struct PackageReceiptsTests {try FileManager.default.createSymbolicLink(atPath: bin.appending(path: "linked").path(percentEncoded: false), withDestinationPath: "tool")try FileManager.default.createSymbolicLink(atPath: bin.appending(path: "gone").path(percentEncoded: false), withDestinationPath: "/Applications/Gone.app/Contents/MacOS/gone")for folder in [served, vendor, tools, bin] {- try FileManager.default.setAttributes([.posixPermissions: 0o555], ofItemAtPath: folder.path(percentEncoded: false))+ try directory.setPermissions(0o555, of: folder)}defer {for folder in [served, vendor, tools, bin] {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PermissionsHold.swift b/Packages/PeelCore/Tests/PeelCoreTests/PermissionsHold.swiftnew file mode 100644index 00000000..866bbd49--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/PermissionsHold.swift@@ -0,0 +1,9 @@+import Darwin+import Testing++extension Trait where Self == ConditionTrait {+ /// For a test that takes permissions away. Root ignores them, so under root such a test would check nothing.+ static var permissionsHold: Self {+ .disabled(if: geteuid() == 0, "root ignores file permissions, which this test takes away")+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PrivilegedPathPolicyTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PrivilegedPathPolicyTests.swiftindex fe072e78..e20d5c5b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/PrivilegedPathPolicyTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/PrivilegedPathPolicyTests.swift@@ -211,7 +211,7 @@ struct PrivilegedPathPolicyTests {/// Without Full Disk Access, macOS refuses to open `~/.Trash` for reading, the helper included, but allows/// opening it for search. Moving an item in needs no reading, so a Trash that can be entered but not listed/// stands in for it here.- @Test func movesIntoATrashItMayNotRead() throws {+ @Test(.permissionsHold) func movesIntoATrashItMayNotRead() throws {let directory = try TemporaryDirectory()let policy = try policy(in: directory)try directory.directory("home/.Trash")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swiftindex cd0d8e39..1f4acd2c 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift@@ -40,7 +40,7 @@ struct ProjectArtifactsTests {#expect(ProjectArtifacts.markableForBackups([modules], excludedFromAbove: [modules.url]).isEmpty)}- @Test func doesNotBlameFullDiskAccessForOrdinaryPermissions() async throws {+ @Test(.permissionsHold) func doesNotBlameFullDiskAccessForOrdinaryPermissions() async throws {let directory = try TemporaryDirectory()try directory.file("Code/app/package.json", bytes: 16)try directory.setPermissions(0, of: "Code")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swiftindex 8fe2d0fb..2450b5f6 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift@@ -114,11 +114,11 @@ struct RefusalLogTests {}/// The file is the only copy of what was refused, so when it cannot be read it is never written over.- @Test func whatCannotBeReadIsKept() async throws {+ @Test(.permissionsHold) func whatCannotBeReadIsKept() async throws {let directory = try TemporaryDirectory()let url = try directory.directory("Peel").appending(path: "refusals.json")try Data("[]".utf8).write(to: url)- try FileManager.default.setAttributes([.posixPermissions: 0], ofItemAtPath: url.path(percentEncoded: false))+ try directory.setPermissions(0, of: url)defer { try? FileManager.default.setAttributes([.posixPermissions: 0o644], ofItemAtPath: url.path(percentEncoded: false)) }await RefusalLog(url: url).add([failure("/Users/me/a", .lastCopy)], source: "Editor", tool: "applications")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swiftindex fc92f556..39b6e19c 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift@@ -277,7 +277,7 @@ struct RemovalHistoryTests {/// A full disk is when people run a cleaner, and also when the record cannot be written. History opens by/// reading the older, healthy file, and that read must not clear the notice.- @Test func aRemovalThatCouldNotBeRecordedStaysSaidUntilOneIs() async throws {+ @Test(.permissionsHold) func aRemovalThatCouldNotBeRecordedStaysSaidUntilOneIs() async throws {let directory = try TemporaryDirectory()let url = try directory.file("Peel/removals.json", contents: Data("[]".utf8))let log = RemovalLog(url: url)@@ -293,7 +293,7 @@ struct RemovalHistoryTests {/// A Put Back that cannot update the log reports `couldNotUpdate`, not `couldNotRecord`: nothing was/// removed, and the items have left the Trash.- @Test func aPutBackThatCouldNotBeWrittenDownSaysSo() async throws {+ @Test(.permissionsHold) func aPutBackThatCouldNotBeWrittenDownSaysSo() async throws {let directory = try TemporaryDirectory()let log = RemovalLog(url: directory.url.appending(path: "Peel/removals.json"))let record = Self.record(batch: UUID())@@ -305,7 +305,7 @@ struct RemovalHistoryTests {}/// A file that cannot even be read cannot be copied out of the way, so nothing is written at all.- @Test func leavesAnUnreadableFileAlone() async throws {+ @Test(.permissionsHold) func leavesAnUnreadableFileAlone() async throws {let directory = try TemporaryDirectory()let url = try directory.file("Peel/removals.json", contents: Data("[]".utf8))try directory.setPermissions(0, of: "Peel/removals.json")@@ -319,7 +319,7 @@ struct RemovalHistoryTests {/// Whether History can be read is known without reading it, so a removal can be refused before anything moves:/// a History not written yet can be, one Peel cannot open, or in a folder Peel cannot search, cannot.- @Test func whetherHistoryCanBeReadIsKnownBeforeAMove() throws {+ @Test(.permissionsHold) func whetherHistoryCanBeReadIsKnownBeforeAMove() throws {let directory = try TemporaryDirectory()let url = directory.url.appending(path: "Peel/removals.json")#expect(RemovalLog.canBeRead(at: url), "a History not written yet")@@ -337,7 +337,7 @@ struct RemovalHistoryTests {}/// Starting over keeps a History Peel cannot read beside the new one, under another name, and records again.- @Test func startingOverKeepsAHistoryItCannotReadAside() async throws {+ @Test(.permissionsHold) func startingOverKeepsAHistoryItCannotReadAside() async throws {let directory = try TemporaryDirectory()let url = try directory.file("Peel/removals.json", contents: Data("[]".utf8))try directory.setPermissions(0, of: "Peel/removals.json")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swiftindex ff954bf2..9f0d0860 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift@@ -165,7 +165,7 @@ struct RemovalHygieneTests {}/// A container that cannot be read may hold the settings, so the domain is left alone.- @Test func keepsTheDomainOfAContainerItCannotRead() throws {+ @Test(.permissionsHold) func keepsTheDomainOfAContainerItCannotRead() throws {let directory = try TemporaryDirectory()let home = directory.url.appending(path: "home", directoryHint: .isDirectory)let stray = try directory.file("home/Library/Preferences/com.example.app.plist")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalJournalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalJournalTests.swiftindex 33f3a5ae..a635d242 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalJournalTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalJournalTests.swift@@ -121,7 +121,7 @@ struct RemovalJournalTests {/// While History cannot be read nothing moves, since what moved could not be listed for Put Back. An item the/// guard refuses keeps that reason, and Peel's own files, which History never lists, still go.- @Test func nothingMovesWhileHistoryCannotBeRead() async throws {+ @Test(.permissionsHold) func nothingMovesWhileHistoryCannotBeRead() async throws {let directory = try TemporaryDirectory()let history = try directory.file("home/Library/Application Support/Peel/removals.json", contents: Data("[]".utf8))try directory.setPermissions(0, of: "home/Library/Application Support/Peel/removals.json")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceInventoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceInventoryTests.swiftindex 0272112b..eaf0a45d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceInventoryTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceInventoryTests.swift@@ -50,7 +50,7 @@ struct SpaceInventoryTests {}/// Without Full Disk Access some areas are refused, and a refused one is kept like one that ran out of time.- @Test func keepsAFolderItCannotOpen() async throws {+ @Test(.permissionsHold) func keepsAFolderItCannotOpen() async throws {let directory = try TemporaryDirectory()try directory.file("Library/Logs/big.log", bytes: 400_000)try directory.setPermissions(0, of: "Library/Logs")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TemporaryDirectory.swift b/Packages/PeelCore/Tests/PeelCoreTests/TemporaryDirectory.swiftindex 7cc4ba5d..376590b9 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/TemporaryDirectory.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/TemporaryDirectory.swift@@ -1,4 +1,5 @@import Foundation+import Testingstruct TemporaryDirectory: ~Copyable {let url: URL@@ -53,6 +54,16 @@ struct TemporaryDirectory: ~Copyable {}func setPermissions(_ permissions: Int, of path: String) throws {- try FileManager.default.setAttributes([.posixPermissions: permissions], ofItemAtPath: url.appending(path: path).path(percentEncoded: false))+ try setPermissions(permissions, of: url.appending(path: path))+ }++ /// Root ignores permissions, so a test that takes the owner's read or write away carries `.permissionsHold`,+ /// and one that does not fails under root rather than passing for the wrong reason.+ func setPermissions(_ permissions: Int, of item: URL) throws {+ if geteuid() == 0, permissions & 0o600 != 0o600 {+ Issue.record("this test takes permissions away, which root ignores, so it needs .permissionsHold")+ }+ let path = item.path(percentEncoded: false)+ try FileManager.default.setAttributes([.posixPermissions: permissions], ofItemAtPath: path)}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashMoverTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashMoverTests.swiftindex 825388ae..73259e5b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashMoverTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashMoverTests.swift@@ -91,7 +91,7 @@ struct TrashMoverTests {/// was being put back to keeps an empty stand-in. exFAT refuses no permission, so no rename there can be made to/// fail at that moment: here the startup disk plays exFAT, answering `ENOTSUP` for a free name, and a folder/// that cannot be changed makes the rename fail.- @Test func aMoveThatFailsLeavesNothingBehind() throws {+ @Test(.permissionsHold) func aMoveThatFailsLeavesNothingBehind() throws {let directory = try TemporaryDirectory()let file = try directory.file("locked/notes.txt")let project = try directory.directory("Project/inside")diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swiftindex c18f4dba..cc606339 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift@@ -265,7 +265,7 @@ struct TrashServiceTests {/// An item is gone from the Trash only when the disk says nothing is there, or another item is. When macOS won't/// let Peel look, whether it is there is not known, and never read as gone, since gone records can be forgotten.- @Test func whatPeelCannotSeeInTheTrashIsNotKnownRatherThanGone() throws {+ @Test(.permissionsHold) func whatPeelCannotSeeInTheTrashIsNotKnownRatherThanGone() throws {let directory = try TemporaryDirectory()let trashed = try directory.file("home/.Trash/report.pdf")let item = TrashedItem(diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swiftindex 547dcc45..03b54cbf 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift@@ -150,14 +150,14 @@ struct UninstallationTests {/// Leftovers move before the app. If the helper then refused the app, it would stay without them, so an app/// the helper may not move is never offered. Neither is an app macOS keeps, wherever it sits.- @Test func anAppTheHelperMayNotMoveIsNeverOffered() async throws {+ @Test(.permissionsHold) func anAppTheHelperMayNotMoveIsNeverOffered() async throws {let directory = try TemporaryDirectory()try directory.file("root/Applications/Scribbler.app/Contents/Info.plist", bytes: 4_096)try directory.file("root/Volumes/Other/Applications/Scribbler.app/Contents/Info.plist", bytes: 4_096)let inReach = directory.url.appending(path: "root/Applications/Scribbler.app")let beyond = directory.url.appending(path: "root/Volumes/Other/Applications/Scribbler.app")for bundle in [inReach, beyond] {- try FileManager.default.setAttributes([.posixPermissions: 0o555], ofItemAtPath: bundle.path(percentEncoded: false))+ try directory.setPermissions(0o555, of: bundle)}defer {for bundle in [inReach, beyond] {@@ -218,7 +218,7 @@ struct UninstallationTests {}/// An app bundle macOS will not let Peel read has no known size: its row reads "Unknown", never zero.- @Test func anAppBundleThatCannotBeReadIsNotMeasured() async throws {+ @Test(.permissionsHold) func anAppBundleThatCannotBeReadIsNotMeasured() async throws {let directory = try TemporaryDirectory()let home = try directory.directory("home")let bundle = try directory.directory("home/Applications/Example.app")@@ -284,14 +284,14 @@ struct UninstallationTests {/// A command-line tool's link in root's `/usr/local/bin` that leads into the app goes with it, through the/// helper, which takes it once the app has moved and the link leads nowhere.- @Test func aToolsLinkInRootsFolderGoesWithTheApp() async throws {+ @Test(.permissionsHold) func aToolsLinkInRootsFolderGoesWithTheApp() async throws {let directory = try TemporaryDirectory()let app = InstalledApp(url: directory.url.appending(path: "root/Applications/Scribbler.app"), bundleIdentifier: "com.example.scribbler", name: "Scribbler")try directory.file("root/Applications/Scribbler.app/Contents/MacOS/scribble")let bin = try directory.directory("root/usr/local/bin")let link = bin.appending(path: "scribble")try FileManager.default.createSymbolicLink(at: link, withDestinationURL: app.url.appending(path: "Contents/MacOS/scribble"))- try FileManager.default.setAttributes([.posixPermissions: 0o555], ofItemAtPath: bin.path(percentEncoded: false))+ try directory.setPermissions(0o555, of: bin)defer { try? FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: bin.path(percentEncoded: false)) }let environment = SearchEnvironment(homeDirectory: directory.url.appending(path: "home"), rootDirectory: directory.url.appending(path: "root"))@@ -305,14 +305,14 @@ struct UninstallationTests {/// A folder the helper would refuse to move, such as root's `/Library/Developer` matched on the name of an/// app called Developer, is held back and cannot be selected, so it never reaches the helper to be refused.- @Test func whatTheHelperMayNotMoveIsNeverOffered() async throws {+ @Test(.permissionsHold) func whatTheHelperMayNotMoveIsNeverOffered() async throws {let directory = try TemporaryDirectory()let app = InstalledApp(url: directory.url.appending(path: "root/Applications/Scribbler.app"), bundleIdentifier: "com.example.scribbler", name: "Scribbler")let served = try directory.directory("root/Library/Application Support/com.example.scribbler")let named = try directory.directory("root/Library/Scribbler")let identified = try directory.directory("root/Library/com.example.scribbler")for folder in [served, named, identified] {- try FileManager.default.setAttributes([.posixPermissions: 0o555], ofItemAtPath: folder.path(percentEncoded: false))+ try directory.setPermissions(0o555, of: folder)}defer {for folder in [served, named, identified] {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swiftindex 4d6610ea..f682c0c8 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift@@ -366,7 +366,7 @@ struct TeamRegistryTests {/// A registry that cannot be read is never written over. Rebuilt from today's apps, it would hide for good a/// change of signer made since it was last read.- @Test func leavesARegistryItCannotReadAlone() async throws {+ @Test(.permissionsHold) func leavesARegistryItCannotReadAlone() async throws {let directory = try TemporaryDirectory()let url = directory.url.appending(path: "teams.json")_ = await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111")])@@ -415,7 +415,7 @@ struct TeamRegistryTests {/// A registry that cannot be saved has not recorded what the check learned, so it says so rather than let the/// next launch start again from the apps as they are then.- @Test func saysWhenTheRegistryCannotBeSaved() async throws {+ @Test(.permissionsHold) func saysWhenTheRegistryCannotBeSaved() async throws {let directory = try TemporaryDirectory()_ = try directory.directory("Peel")let url = directory.url.appending(path: "Peel/teams.json")