Files
luxe-macos-tray-notifier/Tests/NotifierCoreTests/TerminalLocatorTests.swift
cottongin ced6a44ed0 Add luxe Notifier: macOS menu bar app that tells you when luxe needs you
A luxe hook runs luxe-notify, which sends one JSON line over a Unix socket to
a SwiftUI menu bar app. The app shows a banner, keeps a badge count and
history, and brings the terminal forward when you click a banner.

Notifies on approvals (PermissionRequested), question prompts
(BeforeToolUse, matched to the question tool), errors, and turns that run at
least --min-seconds (default 30, timed from BeforeAgentStart to AgentEnd).

The menu warns when macOS has notifications blocked for the app. The app
writes status.txt beside its socket for debugging.

Known limits are in README.md and PLAN.md: a crowded menu bar can hide the
icon, and the first test build after a change can fail with a TestingMacros
error under Command Line Tools, which make test retries once.
2026-10-24 22:41:42 -04:00

42 lines
1.7 KiB
Swift

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)
}
}