Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
36 changes: 25 additions & 11 deletions Tests/kithTests/CommandIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading