From ef63d081960c831a265fc687074c9e7c45478fc6 Mon Sep 17 00:00:00 2001 From: dxnnystyles Date: Fri, 23 Oct 2026 18:32:09 -0700 Subject: [PATCH 1/3] fix(cli): report unknown export options --- Sources/removemacai/SelfTest.swift | 4 ++++ Sources/removemacai/main.swift | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Sources/removemacai/SelfTest.swift b/Sources/removemacai/SelfTest.swift index 6873e4e..083be1f 100644 --- a/Sources/removemacai/SelfTest.swift +++ b/Sources/removemacai/SelfTest.swift @@ -13,6 +13,10 @@ func selfTest() -> Bool { return false } + check(unknownOption(in: ["RemoveMacAI.mobileconfig", "--bogus"]) == "--bogus" + && unknownOption(in: ["RemoveMacAI.mobileconfig", "analytics"]) == nil, + "export distinguishes unknown options from tweak names") + check(Set(Catalog.setsToRemove(keeping: [])) == Set(Catalog.availableModelSets.map(\.name)), "off removes every model set this macOS has") let keptWriting = Catalog.setsToRemove(keeping: ["writing-tools"]) diff --git a/Sources/removemacai/main.swift b/Sources/removemacai/main.swift index 1d3e243..d33e16f 100644 --- a/Sources/removemacai/main.swift +++ b/Sources/removemacai/main.swift @@ -47,6 +47,9 @@ func option(_ name: String) -> String? { args.removeSubrange(i...(i + 1)) return value } +func unknownOption(in args: [String]) -> String? { + args.first(where: { $0.hasPrefix("-") }) +} func presetOption() -> Preset? { guard let name = option("--preset") else { return nil } guard let preset = Preset(rawValue: name) else { @@ -102,13 +105,13 @@ case "apply": let preset = presetOption() let dryRun = flag("--dry-run") let yes = flag("--yes") || flag("-y") - if let bad = args.first(where: { $0.hasPrefix("-") }) { Term.fail("unknown option \(bad)") } + if let bad = unknownOption(in: args) { Term.fail("unknown option \(bad)") } exit(TweakCommands.apply(ids: args, preset: preset, dryRun: dryRun, yes: yes) ? 0 : 1) case "undo": args.removeFirst() let dryRun = flag("--dry-run") let yes = flag("--yes") || flag("-y") - if let bad = args.first(where: { $0.hasPrefix("-") }) { Term.fail("unknown option \(bad)") } + if let bad = unknownOption(in: args) { Term.fail("unknown option \(bad)") } exit(TweakCommands.undo(ids: args, dryRun: dryRun, yes: yes) ? 0 : 1) case "background": args.removeFirst() @@ -118,13 +121,14 @@ case "clean": args.removeFirst() let dryRun = flag("--dry-run") let yes = flag("--yes") || flag("-y") - if let bad = args.first(where: { $0.hasPrefix("-") }) { Term.fail("unknown option \(bad)") } + if let bad = unknownOption(in: args) { Term.fail("unknown option \(bad)") } exit(TweakCommands.clean(ids: args, dryRun: dryRun, yes: yes) ? 0 : 1) case "export": args.removeFirst() let preset = presetOption() let keep = Set((option("--keep") ?? "").split(separator: ",").map { String($0).trimmed }.filter { !$0.isEmpty }) let noAI = flag("--no-ai") + if let bad = unknownOption(in: args) { Term.fail("unknown option \(bad)") } guard let path = args.first else { Term.fail("name the file to write, for example: removemacai export RemoveMacAI.mobileconfig") } TweakCommands.export(path: path, ids: Array(args.dropFirst()), preset: preset, keepAI: keep, noAI: noAI) case "selftest": From d875aeafabb023ee3a080947f65eca784ccbd2a0 Mon Sep 17 00:00:00 2001 From: dxnnystyles Date: Fri, 23 Oct 2026 23:26:06 -0700 Subject: [PATCH 2/3] test(cli): cover unknown export options --- Sources/removemacai/SelfTest.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/removemacai/SelfTest.swift b/Sources/removemacai/SelfTest.swift index 083be1f..a94bc1c 100644 --- a/Sources/removemacai/SelfTest.swift +++ b/Sources/removemacai/SelfTest.swift @@ -16,6 +16,14 @@ func selfTest() -> Bool { check(unknownOption(in: ["RemoveMacAI.mobileconfig", "--bogus"]) == "--bogus" && unknownOption(in: ["RemoveMacAI.mobileconfig", "analytics"]) == nil, "export distinguishes unknown options from tweak names") + let invalidProfile = FileManager.default.temporaryDirectory + .appendingPathComponent("removemacai-export-selftest-\(UUID().uuidString).mobileconfig") + defer { try? FileManager.default.removeItem(at: invalidProfile) } + let executable = Bundle.main.executableURL?.path ?? CommandLine.arguments[0] + let invalidExport = Shell.run(executable, ["export", invalidProfile.path, "--bogus"]) + check(!invalidExport.ok && invalidExport.output.contains("error: unknown option --bogus") + && !FileManager.default.fileExists(atPath: invalidProfile.path), + "export rejects unknown options without writing a profile") check(Set(Catalog.setsToRemove(keeping: [])) == Set(Catalog.availableModelSets.map(\.name)), "off removes every model set this macOS has") From 3f92f46de9b0a5272512865201218d76da4b4515 Mon Sep 17 00:00:00 2001 From: dxnnystyles Date: Sat, 24 Oct 2026 01:53:32 -0700 Subject: [PATCH 3/3] test(cli): normalize colored export errors --- Sources/removemacai/SelfTest.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/removemacai/SelfTest.swift b/Sources/removemacai/SelfTest.swift index a94bc1c..614d94d 100644 --- a/Sources/removemacai/SelfTest.swift +++ b/Sources/removemacai/SelfTest.swift @@ -21,7 +21,9 @@ func selfTest() -> Bool { defer { try? FileManager.default.removeItem(at: invalidProfile) } let executable = Bundle.main.executableURL?.path ?? CommandLine.arguments[0] let invalidExport = Shell.run(executable, ["export", invalidProfile.path, "--bogus"]) - check(!invalidExport.ok && invalidExport.output.contains("error: unknown option --bogus") + let invalidExportOutput = invalidExport.output.replacingOccurrences( + of: #"\x1B\[[0-9;]*m"#, with: "", options: .regularExpression) + check(!invalidExport.ok && invalidExportOutput.contains("error: unknown option --bogus") && !FileManager.default.fileExists(atPath: invalidProfile.path), "export rejects unknown options without writing a profile")