Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

peel writes names from other apps' bundles as plain text

Țugui Dragoș22e900127417
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 2d5ca78a..9d7e9cf0 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -178,7 +178,7 @@ struct LeftoversCommand: AsyncParsableCommand {
Output.note(Output.fullDiskAccessNote)
}
for location in uninstallation.scan.cutShortLocations {
- Output.note("There are more folders in \(Output.path(location.url)) than Peel looks inside, so something of this app's may be in a folder Peel didn't reach.")
+ Output.note("There are more folders in \(Output.plain(Output.path(location.url))) than Peel looks inside, so something of this app's may be in a folder Peel didn't reach.")
}
}
}
@@ -328,7 +328,8 @@ struct UninstallCommand: AsyncParsableCommand {
private static func refuseWhileRunning(_ target: InstalledApp, among apps: [InstalledApp]) async throws {
let running = await RunningCopies.belonging(to: target, among: RunningCopies.current, installedApps: apps)
guard running.isEmpty else {
- throw CommandFailure("Quit \(target.name) first. Still running: \(Set(running.map(\.bundleIdentifier)).sorted().joined(separator: ", ")).")
+ let identifiers = Set(running.map(\.bundleIdentifier)).sorted().map(Output.plain)
+ throw CommandFailure("Quit \(Output.plain(target.name)) first. Still running: \(identifiers.joined(separator: ", ")).")
}
}
@@ -344,14 +345,14 @@ struct UninstallCommand: AsyncParsableCommand {
/// anything is listed: skipping the reset quietly would remove the app and leave its permissions on record.
static func refuseIfPrivacyCannotBeReset(_ target: InstalledApp) throws {
guard !PrivacyReset.isAllowed(bundleIdentifier: target.bundleIdentifier) else { return }
- throw CommandFailure("Peel never resets privacy permissions for \(target.name). Leave out --reset-privacy to remove it anyway.")
+ throw CommandFailure("Peel never resets privacy permissions for \(Output.plain(target.name)). Leave out --reset-privacy to remove it anyway.")
}
/// Returns the line that reports the privacy reset, and whether the command fails because of it.
static func privacyOutcome(_ result: PrivacyReset.Result, app: InstalledApp) -> (line: String, failed: Bool) {
result == .reset
- ? ("Reset \(app.name)'s privacy permissions.", false)
- : ("\(app.name)'s privacy permissions weren't reset: \(result.summary).", true)
+ ? ("Reset \(Output.plain(app.name))'s privacy permissions.", false)
+ : ("\(Output.plain(app.name))'s privacy permissions weren't reset: \(result.summary).", true)
}
func run() async throws {
@@ -359,7 +360,7 @@ struct UninstallCommand: AsyncParsableCommand {
let target = try AppLookup.app(matching: app, in: apps)
try Self.refuseIfItIsPeel(target)
guard !target.isSystemProtected else {
- throw CommandFailure("macOS protects \(target.name), so it can't be removed.")
+ throw CommandFailure("macOS protects \(Output.plain(target.name)), so it can't be removed.")
}
if resetPrivacy {
try Self.refuseIfPrivacyCannotBeReset(target)
@@ -368,7 +369,7 @@ struct UninstallCommand: AsyncParsableCommand {
try AppLookup.refuseIfExcluded(target, by: exclusions)
let service = TrashService(exclusions: exclusions)
guard !service.isInsideATrash(target.url) else {
- throw CommandFailure("\(target.name) is already in the Trash. Empty it, or put it back first.")
+ throw CommandFailure("\(Output.plain(target.name)) is already in the Trash. Empty it, or put it back first.")
}
try await Self.refuseWhileRunning(target, among: apps)
let homebrew = await CaskLookup.evidence(for: target)
@@ -380,7 +381,7 @@ struct UninstallCommand: AsyncParsableCommand {
receipts: homebrew.receipts
)
guard !uninstallation.appRequiresPrivileges else {
- throw CommandFailure("Moving \(target.name) to the Trash needs administrator access. Remove it with the Peel app.")
+ throw CommandFailure("Moving \(Output.plain(target.name)) to the Trash needs administrator access. Remove it with the Peel app.")
}
if let note = UnreadableHistory.note() {
@@ -389,7 +390,7 @@ struct UninstallCommand: AsyncParsableCommand {
// The removal guard judges each item before printing, so the list shows what the move will really do.
let plan = UninstallPlan.make(uninstallation, keepLeftovers: keepLeftovers, refusal: service.refusal(of:))
if let refusal = plan.appStays {
- throw CommandFailure("Peel won't move \(Output.path(target.url)): \(refusal.summary). Nothing of \(target.name) was touched.")
+ throw CommandFailure("Peel won't move \(Output.plain(Output.path(target.url))): \(refusal.summary). Nothing of \(Output.plain(target.name)) was touched.")
}
let unreadable = uninstallation.scan.unreadableLocations
if !output.json {
@@ -464,7 +465,7 @@ struct UninstallCommand: AsyncParsableCommand {
notes.append(Output.fullDiskAccessNote)
}
notes += scan.cutShortLocations.map {
- "There are more folders in \(Output.path($0.url)) than Peel looks inside, so something of this app's may be in a folder Peel didn't reach."
+ "There are more folders in \(Output.plain(Output.path($0.url))) than Peel looks inside, so something of this app's may be in a folder Peel didn't reach."
}
if plan.needsAdministrator > 0 {
let them = plan.needsAdministrator == 1 ? "it" : "them"
@@ -478,9 +479,9 @@ struct UninstallCommand: AsyncParsableCommand {
}
static func whatFailed(_ result: TrashResult, plan: UninstallPlan, app: InstalledApp) -> [String] {
- var notes = result.failures.map { "Couldn't move \(Output.path($0.url)): \($0.reason.summary)" }
+ var notes = result.failures.map { "Couldn't move \(Output.plain(Output.path($0.url))): \($0.reason.summary)" }
if result.trashed.isEmpty, plan.moving.count > 1 {
- notes.append("\(app.name) stayed, so its files were left where they are.")
+ notes.append("\(Output.plain(app.name)) stayed, so its files were left where they are.")
}
// macOS refuses to move another developer's app without App Management, and it names no permission.
if AppManagement.state(after: result, appBundles: [plan.app]) == .missing {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
index 960f397c..92824def 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
@@ -93,7 +93,7 @@ struct ExclusionsCommand: AsyncParsableCommand {
}
let broad = paths.map(URL.init(argument:)).filter { Exclusions.isTooBroad($0) }
guard broad.isEmpty else {
- throw ValidationError("\(broad.map(Output.path).joined(separator: ", ")): too broad to exclude. Name a folder inside it.")
+ throw ValidationError("\(broad.map { Output.plain(Output.path($0)) }.joined(separator: ", ")): too broad to exclude. Name a folder inside it.")
}
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index 2f88ed48..4fa660fa 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -131,7 +131,7 @@ struct OrphansCommand: AsyncParsableCommand {
}
let items = group.items.filter { $0.heldBack == nil }
// Nobody asked for a held back file on its own, so it is said here and never recorded as refused.
- let staying = group.items.compactMap { item in item.heldBack.map { "\(Output.path(item.url)) stays: \($0.summary)" } }
+ let staying = group.items.compactMap { item in item.heldBack.map { "\(Output.plain(Output.path(item.url))) stays: \($0.summary)" } }
guard !items.isEmpty else {
Output.line("Every file of \(group.identifier) is one Peel leaves alone. See `peel orphans`.")
staying.forEach(Output.note)
@@ -291,7 +291,7 @@ struct CachesCommand: AsyncParsableCommand {
}
private static func quitFirst(_ environment: DeveloperEnvironment) -> String {
- "Quit \(environment.runningApp ?? environment.name) first: \(environment.name)'s caches stay while it runs."
+ "Quit \(Output.plain(environment.runningApp ?? environment.name)) first: \(environment.name)'s caches stay while it runs."
}
}
@@ -347,7 +347,7 @@ struct ProjectsCommand: AsyncParsableCommand {
func validate() throws {
try removal.validate(with: output)
let refused = folders.map(URL.init(argument:)).compactMap { root in
- ProjectArtifacts.refusal(for: root).map { "\(Output.path(root)): \($0.summary)" }
+ ProjectArtifacts.refusal(for: root).map { "\(Output.plain(Output.path(root))): \($0.summary)" }
}
guard refused.count < folders.count else {
throw ValidationError((refused.isEmpty ? ["No folders to look in."] : refused).joined(separator: "\n"))
@@ -359,7 +359,7 @@ struct ProjectsCommand: AsyncParsableCommand {
// Each folder that can't be searched gets a note, so it isn't mistaken for one with nothing built in it.
for root in roots {
if let refusal = ProjectArtifacts.refusal(for: root) {
- Output.note("\(Output.path(root)): \(refusal.summary)")
+ Output.note("\(Output.plain(Output.path(root))): \(refusal.summary)")
}
}
let scan = await ProjectArtifacts.scan(roots: roots, exclusions: UnreadableExclusions.load())
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
index 67f0f1a3..e96e4800 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
@@ -271,7 +271,7 @@ struct RestoreCommand: AsyncParsableCommand {
}
guard failures.isEmpty else {
for (record, failure) in failures {
- Output.note("Couldn't put \(Output.path(record.originalURL)) back: \(failure.summary)")
+ Output.note("Couldn't put \(Output.plain(Output.path(record.originalURL))) back: \(failure.summary)")
}
throw ExitCode.failure
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift b/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift
index 585f6419..309d9d41 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift
@@ -37,6 +37,25 @@ public struct PeelCommand: AsyncParsableCommand {
Output.note("Don't run `peel` with `sudo`. What needs administrator access is removed by the Peel app, which has the checks for it.")
Darwin.exit(1)
}
- await main()
+ do {
+ var command = try await asyncParseAsRoot()
+ if var asynchronous = command as? any AsyncParsableCommand {
+ try await asynchronous.run()
+ } else {
+ try command.run()
+ }
+ } catch {
+ guard report(error) else { exit(withError: error) }
+ Darwin.exit(EXIT_FAILURE)
+ }
+ }
+
+ /// Writes a failure of Peel's own as a note, where every control character is shown as `?`: its message names
+ /// apps and paths from other people's bundles. Any other error is left for ArgumentParser to print.
+ @discardableResult
+ static func report(_ error: any Error) -> Bool {
+ guard error is CommandFailure || error is AppLookup.Failure else { return false }
+ Output.note("Error: \(error)")
+ return true
}
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
index d0df1f94..89307a0d 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
@@ -12,15 +12,15 @@ enum AppLookup {
var description: String {
switch self {
case .notFound(let query):
- "No installed app matches \"\(query)\". Run `peel apps` to see installed apps."
+ "No installed app matches \"\(Output.plain(query))\". Run `peel apps` to see installed apps."
case .ambiguous(let query, let paths):
- "Several apps match \"\(query)\". Use one of these paths:\n" + paths.map { " \($0)" }.joined(separator: "\n")
+ "Several apps match \"\(Output.plain(query))\". Use one of these paths:\n" + paths.map { " \(Output.plain($0))" }.joined(separator: "\n")
case .notAnApp(let path):
- "\(path) isn't an app."
+ "\(Output.plain(path)) isn't an app."
case .excluded(let name):
- "\(name) is excluded in Peel's settings, so Peel leaves it alone."
+ "\(Output.plain(name)) is excluded in Peel's settings, so Peel leaves it alone."
case .exclusionsUnreadable(let path):
- "Peel couldn't read your exclusions at \(path), so it left everything alone. Open Peel and click Start Over in Settings > Exclusions."
+ "Peel couldn't read your exclusions at \(Output.plain(path)), so it left everything alone. Open Peel and click Start Over in Settings > Exclusions."
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
index 931d5df1..12443aa8 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
@@ -114,7 +114,7 @@ struct Cleanup {
}
guard result.failures.isEmpty else {
for failure in result.failures {
- Output.note("\(Output.path(failure.url)) stayed: \(failure.reason.summary)")
+ Output.note("\(Output.plain(Output.path(failure.url))) stayed: \(failure.reason.summary)")
}
throw ExitCode.failure
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index e72bc3aa..f56e15a0 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -45,16 +45,9 @@ enum Output {
write(plain(text) + "\n")
}
- /// Replaces every control character with `?`. Names and paths come from other people's bundles: a newline in
- /// one would make a script read one row as two, and an escape sequence could rewrite on screen the list the
- /// user is asked to confirm.
+ /// Replaces every control character with `?` (`PlainText`), for names and paths from other people's bundles.
static func plain(_ text: String) -> String {
- guard text.unicodeScalars.contains(where: isControl) else { return text }
- return String(text.unicodeScalars.map { isControl($0) ? "?" : Character($0) })
- }
-
- private static func isControl(_ scalar: Unicode.Scalar) -> Bool {
- scalar.value <= 0x1F || (0x7F...0x9F).contains(scalar.value)
+ PlainText.of(text)
}
/// Returns `name` so the reader can paste it into a command: in single quotes when it contains a space.
@@ -214,7 +207,7 @@ extension RestoreFailure {
case .alreadyThere: "something is there already"
case .needsHelper: "it needs administrator access, so put it back with the Peel app"
case .notAllowed: "Peel won't write there"
- case .failed(let message): message
+ case .failed(let message): Output.plain(message)
}
}
}
@@ -222,7 +215,7 @@ extension RestoreFailure {
extension RemovalLogProblem {
var summary: String {
switch self {
- case .damaged(let setAside): "History was damaged, so it was kept as \(Output.path(setAside)) and started again."
+ case .damaged(let setAside): "History was damaged, so it was kept as \(Output.plain(Output.path(setAside))) and started again."
case .unreadable: "History couldn't be read, so Peel moves nothing until you start it over in the Peel app's History."
case .couldNotRecord: "History couldn't be saved, so the last removal isn't in it."
case .couldNotUpdate: "History couldn't be saved, so what was put back is still listed in it."
@@ -298,9 +291,9 @@ extension OrphanConfidence {
case .running: "something with this identifier is running now"
case .leadsIntoAnAppThatIsGone: "these links lead into an app that is no longer there"
case .writtenRecently(let date): "something wrote here on \(Output.day(date))"
- case .writtenAfterItLeft(let name, let written): "something wrote here on \(Output.day(written)), after Peel last saw \(name) installed"
+ case .writtenAfterItLeft(let name, let written): "something wrote here on \(Output.day(written)), after Peel last saw \(Output.plain(name)) installed"
case .sameMakerStillInstalled: "an app from the same maker is still installed"
- case .appLeft(let name, let lastSeen): "Peel last saw \(name) installed on \(Output.day(lastSeen))"
+ case .appLeft(let name, let lastSeen): "Peel last saw \(Output.plain(name)) installed on \(Output.day(lastSeen))"
case .untouched(let months): "\(months) months since anything wrote here"
case .nothingClaimsIt, nil: "nothing installed claims these"
}
@@ -322,8 +315,8 @@ extension PrivacyReset.Result {
case .reset: "reset"
case .notKnownToTheSystem: "macOS couldn't find the app"
case .refused: "Peel never resets them for this app"
- case .failed(let message): message.isEmpty ? "macOS didn't say why" : "macOS reported: \(message)"
- case .couldNotAsk(let message): message
+ case .failed(let message): message.isEmpty ? "macOS didn't say why" : "macOS reported: \(Output.plain(message))"
+ case .couldNotAsk(let message): Output.plain(message)
}
}
}
@@ -338,9 +331,9 @@ extension TrashFailure.Reason {
case .notPermitted: "not permitted"
case .needsHelper: "needs administrator access"
case .movedWithoutATrace: "in the Trash where macOS didn't say, so only Finder can put it back"
- case .somethingElseMoved(let name): "something else was at that path; it is in the Trash as \(name)"
+ case .somethingElseMoved(let name): "something else was at that path; it is in the Trash as \(Output.plain(name))"
case .historyUnreadable: "History can't be read"
- case .failed(let message): message
+ case .failed(let message): Output.plain(message)
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableExclusions.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableExclusions.swift
index 3b8fbef1..9211aa84 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableExclusions.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableExclusions.swift
@@ -6,7 +6,7 @@ import PeelCore
enum UnreadableExclusions {
static func note(for exclusions: Exclusions, savedAt url: URL = ExclusionStore.defaultURL) -> String? {
guard exclusions.isUnreadable else { return nil }
- return "Peel couldn't read your exclusions at \(url.path(percentEncoded: false)), so this may list what you asked it to leave alone, and nothing will be moved. Open Peel and click Start Over in Settings > Exclusions."
+ return "Peel couldn't read your exclusions at \(Output.plain(url.path(percentEncoded: false))), so this may list what you asked it to leave alone, and nothing will be moved. Open Peel and click Start Over in Settings > Exclusions."
}
static func load(from store: ExclusionStore = ExclusionStore()) async -> Exclusions {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableHistory.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableHistory.swift
index 79a71769..1050b64a 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableHistory.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/UnreadableHistory.swift
@@ -6,6 +6,6 @@ import PeelCore
enum UnreadableHistory {
static func note(at url: URL = RemovalHistory.defaultURL) -> String? {
guard !RemovalLog.canBeRead(at: url) else { return nil }
- return "Peel couldn't read its History at \(url.path(percentEncoded: false)), so nothing will be moved. Open Peel and click Start Over in History."
+ return "Peel couldn't read its History at \(Output.plain(url.path(percentEncoded: false))), so nothing will be moved. Open Peel and click Start Over in History."
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/Inventory.swift b/Packages/PeelCore/Sources/PeelCore/Apps/Inventory.swift
index 06a4eaf5..1657f24d 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/Inventory.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/Inventory.swift
@@ -143,18 +143,21 @@ public struct Inventory: Sendable {
entry.lastOpened.map { Self.day($0) } ?? "",
]
}
- return ([header] + rows).map { $0.map(Self.escaped).joined(separator: ",") }.joined(separator: "\n") + "\n"
+ return ([header] + rows)
+ .map { $0.map { Self.escaped(PlainText.of($0)) }.joined(separator: ",") }
+ .joined(separator: "\n") + "\n"
}
+ /// A line per app. Its name and version come from the app's own bundle, so each is shown plain (`PlainText`).
private func text() -> String {
entries.map { entry in
- var line = entry.name
+ var line = PlainText.of(entry.name)
if let version = entry.version {
- line += " \(version)"
+ line += " \(PlainText.of(version))"
}
line += ", \(entry.source)"
if let detail = entry.sourceDetail, entry.source == "Homebrew" {
- line += " (\(detail))"
+ line += " (\(PlainText.of(detail)))"
}
return line
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/PlainText.swift b/Packages/PeelCore/Sources/PeelCore/Support/PlainText.swift
new file mode 100644
index 00000000..ea3a02b9
--- /dev/null
+++ b/Packages/PeelCore/Sources/PeelCore/Support/PlainText.swift
@@ -0,0 +1,14 @@
+/// Text from someone else's bundle made safe to show: a name, a version or a path can hold any character, and a
+/// line end in one would make a script read one row as two, while an escape sequence could rewrite on screen the
+/// list the user is asked to confirm.
+public enum PlainText {
+ /// `text` with every control character replaced with `?`.
+ public static func of(_ text: String) -> String {
+ guard text.unicodeScalars.contains(where: isControl) else { return text }
+ return String(text.unicodeScalars.map { isControl($0) ? "?" : Character($0) })
+ }
+
+ static func isControl(_ scalar: Unicode.Scalar) -> Bool {
+ scalar.value <= 0x1F || (0x7F...0x9F).contains(scalar.value)
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 621644df..35f57c86 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -155,6 +155,47 @@ struct CommandLineTests {
}
}
+ /// A name or a version comes from someone else's bundle, so the text and CSV inventory show it plain: an escape
+ /// sequence there would change the terminal's title or clear its screen, and a line end would split a row. JSON
+ /// escapes both by itself.
+ @Test func writesTheInventoryWithoutControlCharacters() throws {
+ let app = InstalledApp(
+ url: URL(filePath: "/Applications/Evil.app", directoryHint: .isDirectory),
+ bundleIdentifier: "org.example.evil",
+ name: "Evil\u{1B}]0;pwned\u{07}\nApp",
+ version: "1\u{1B}[2J"
+ )
+ let inventory = Inventory.build(apps: [app])
+ for format in [Inventory.Format.text, .csv] {
+ let written = try inventory.written(as: format)
+ #expect(!written.unicodeScalars.contains { $0.value == 0x1B || $0.value == 0x07 }, "\(format)")
+ #expect(written.contains("Evil?]0;pwned??App"), "\(format)")
+ }
+ #expect(try inventory.written(as: .json).contains("\\u001b"))
+ }
+
+ /// An error names apps and paths from other people's bundles, and reaches the terminal as a note does: every
+ /// control character is shown as `?`.
+ @Test func writesAnErrorWithoutControlCharacters() {
+ let collected = Output.Collected()
+ Output.$collected.withValue(collected) {
+ PeelCommand.report(CommandFailure("Quit Evil\u{1B}[2J first."))
+ }
+ #expect(collected.notes == "Error: Quit Evil?[2J first.\n")
+ #expect(PeelCommand.report(ValidationError("not ours")) == false)
+ }
+
+ /// A line end the message writes stays, while one inside a path it names is shown as `?`, so each path the
+ /// reader is offered is one line.
+ @Test func keepsAnErrorsOwnLinesButNotThoseOfAPath() {
+ let collected = Output.Collected()
+ Output.$collected.withValue(collected) {
+ PeelCommand.report(AppLookup.Failure.ambiguous("Evil", ["/Applications/Evil\n.app", "/Applications/Evil.app"]))
+ }
+ let expected = "Error: Several apps match \"Evil\". Use one of these paths:\n /Applications/Evil?.app\n /Applications/Evil.app\n"
+ #expect(collected.notes == expected)
+ }
+
@Test func spellsAPathTheSameWayAsTheInventory() {
let app = InstalledApp(url: URL(filePath: NSHomeDirectory() + "/Applications/Editor.app", directoryHint: .isDirectory), bundleIdentifier: "com.example.editor", name: "Editor")
let inventoried = Inventory.build(apps: [app]).entries[0].path