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.
51 lines
1.8 KiB
Swift
51 lines
1.8 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import NotifierCore
|
|
|
|
struct HookEventParserTests {
|
|
private func parse(_ json: String, point: String) throws -> NotifyEvent {
|
|
try HookEventParser.parse(Data(json.utf8), hookPoint: point, cwd: "/work")
|
|
}
|
|
|
|
@Test func permissionRequestedNamesTheTool() throws {
|
|
let event = try parse(#"{"Other":{"tool":"bash","phase":"requested"}}"#, point: "PermissionRequested")
|
|
#expect(event.kind == .permission)
|
|
#expect(event.message.contains("bash"))
|
|
#expect(event.cwd == "/work")
|
|
}
|
|
|
|
@Test func agentEndMeansWaitingOnYou() throws {
|
|
let event = try parse(#"{"Other":{"effective_context_percent":12.5}}"#, point: "AgentEnd")
|
|
#expect(event.kind == .turnEnded)
|
|
}
|
|
|
|
@Test func errorCarriesTheMessage() throws {
|
|
let event = try parse(#"{"Other":{"message":"provider timed out"}}"#, point: "Error")
|
|
#expect(event.kind == .error)
|
|
#expect(event.message == "provider timed out")
|
|
}
|
|
|
|
@Test func hookPointMatchingIsLooseLikeLuxe() throws {
|
|
#expect(try parse("{}", point: "permission_requested").kind == .permission)
|
|
}
|
|
|
|
@Test func unknownHookPointIsKeptAsGenericNotDropped() throws {
|
|
let event = try parse("{}", point: "SessionStart")
|
|
#expect(event.kind == .generic)
|
|
#expect(event.message.contains("SessionStart"))
|
|
}
|
|
|
|
@Test func malformedJSONIsRejectedWithAReason() {
|
|
do {
|
|
_ = try parse("not json", point: "AgentEnd")
|
|
Issue.record("expected a parse error")
|
|
} catch {
|
|
#expect("\(error)".contains("not valid JSON"))
|
|
}
|
|
}
|
|
|
|
@Test func nonObjectJSONIsRejected() {
|
|
#expect(throws: HookParseError.notAnObject) { try parse("[1,2]", point: "AgentEnd") }
|
|
}
|
|
}
|