diff --git a/Package.resolved b/Package.resolved index 059b5a8..ce39eac 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,13 +1,13 @@ { - "originHash" : "aa3b610661f9638121002a4550886729c9cdb511e05d0f5e55fb94244dce0b65", + "originHash" : "6207f2cd9f8f1fd4388e4ca0ae04db9938553925e1e8ec10c2dee489b7a8dc6e", "pins" : [ { "identity" : "phonenumberkit", "kind" : "remoteSourceControl", "location" : "https://github.com/PhoneNumberKit/PhoneNumberKit.git", "state" : { - "revision" : "ab06a8333394f4a4fb6eecca447dae0aa06c1eca", - "version" : "5.0.4" + "revision" : "faf1703e6fc71c699e911ff0e306c58ad7c756c0", + "version" : "5.0.11" } }, { diff --git a/Package.swift b/Package.swift index 69cb5e5..61ba0f1 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.8.2"), .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.16.0"), - .package(url: "https://github.com/PhoneNumberKit/PhoneNumberKit.git", from: "5.0.4"), + .package(url: "https://github.com/PhoneNumberKit/PhoneNumberKit.git", from: "5.0.11"), .package(url: "https://github.com/trilemma-dev/SecureXPC.git", from: "0.8.0"), ], targets: [ diff --git a/Tests/kithTests/CommandIntegrationTests.swift b/Tests/kithTests/CommandIntegrationTests.swift index b3f4b28..45d7518 100644 --- a/Tests/kithTests/CommandIntegrationTests.swift +++ b/Tests/kithTests/CommandIntegrationTests.swift @@ -76,18 +76,32 @@ struct CommandIntegrationTests { #expect(result.stdout.contains("anyOf")) } - @Test("--color flag overrides env (always vs never)") + @Test("--color flag overrides env on a missing local DB error") func colorFlagOverride() throws { - // --color always with NO_COLOR set should still color. - let always = try run(["doctor"], env: ["NO_COLOR": "1"]) - // doctor's exit will be 5 because we don't have full perms in CI; - // but we just care about stderr/stdout content here. - let alwaysOutput = always.stdout + always.stderr - // Without --color always, NO_COLOR wins → no escape codes. - #expect(!alwaysOutput.contains("\u{1B}[")) - let forced = try run(["doctor", "--color", "always"], env: ["NO_COLOR": "1"]) - let forcedOutput = forced.stdout + forced.stderr - #expect(forcedOutput.contains("\u{1B}[")) + let fixtureDir = FileManager.default.temporaryDirectory + .appendingPathComponent("kith-color-\(UUID().uuidString)", isDirectory: true) + try FileManager.default.createDirectory(at: fixtureDir, withIntermediateDirectories: false) + defer { try? FileManager.default.removeItem(at: fixtureDir) } + let missingDB = fixtureDir.appendingPathComponent("missing.db").path + let env = ["KITH_DB_PATH": missingDB, "KITH_COLOR": "auto", "NO_COLOR": "1"] + #expect(!FileManager.default.fileExists(atPath: missingDB)) + + // A read-only open fails before the local pipeline constructs ContactsStore. + let plain = try run(["chats"], env: env) + #expect(plain.code == 6) + #expect(plain.stderr.contains("kith: error:")) + #expect(!plain.stderr.contains("\u{1B}[")) + + let forced = try run(["chats", "--color", "always"], env: env) + #expect(forced.code == 6) + #expect(forced.stderr.contains("\u{1B}[1;31m")) + + let machine = try run(["chats", "--jsonl"], env: env) + #expect(machine.code == 6) + let error = try JSONSerialization.jsonObject(with: Data(machine.stderr.utf8)) as? [String: Any] + #expect(error?["code"] as? String == "DB_UNAVAILABLE") + #expect(error?["exit"] as? Int == 6) + #expect(!FileManager.default.fileExists(atPath: missingDB)) } @Test("kith tools help dumps every command's help in one stream")