import Foundation import Testing @testable import NotifierCore struct TerminalLocatorTests { @Test func theExportedBundleIdentifierWins() { let env = ["__CFBundleIdentifier": "com.mitchellh.ghostty", "TERM_PROGRAM": "iTerm.app"] #expect(TerminalLocator.bundleID(from: env) == "com.mitchellh.ghostty") } @Test func termProgramIsUsedWhenThereIsNoBundleIdentifier() { #expect(TerminalLocator.bundleID(from: ["TERM_PROGRAM": "iTerm.app"]) == "com.googlecode.iterm2") } @Test func anUnknownTermProgramReturnsNilInsteadOfGuessing() { #expect(TerminalLocator.bundleID(from: ["TERM_PROGRAM": "mystery-term"]) == nil) } @Test func anEmptyBundleIdentifierFallsThrough() { let env = ["__CFBundleIdentifier": "", "TERM_PROGRAM": "ghostty"] #expect(TerminalLocator.bundleID(from: env) == "com.mitchellh.ghostty") } @Test func noHintsAtAllReturnsNil() { #expect(TerminalLocator.bundleID(from: [:]) == nil) } } struct EventCompatibilityTests { @Test func anOlderEventWithoutTheTerminalFieldStillDecodes() throws { let line = Data(#"{"kind":"permission","title":"t","message":"m","timestamp":"2026-10-25T02:23:19Z"}"#.utf8) let event = try NotifySocket.decodeLine(line) #expect(event.terminalBundleID == nil) } @Test func theTerminalFieldSurvivesTheSocketEncoding() throws { let sent = NotifyEvent(kind: .permission, title: "t", message: "m", timestamp: Date(timeIntervalSince1970: 1_700_000_000), terminalBundleID: "com.mitchellh.ghostty") let line = try NotifySocket.encodeLine(sent) #expect(try NotifySocket.decodeLine(line.dropLast()) == sent) } }