40 lines
1.5 KiB
Swift
40 lines
1.5 KiB
Swift
|
|
import Foundation
|
||
|
|
import Testing
|
||
|
|
@testable import NotifierCore
|
||
|
|
|
||
|
|
struct QuestionEventTests {
|
||
|
|
private func parse(_ json: String) throws -> NotifyEvent {
|
||
|
|
try HookEventParser.parse(Data(json.utf8), hookPoint: "BeforeToolUse", cwd: "/work")
|
||
|
|
}
|
||
|
|
|
||
|
|
private let questionPayload = #"{"ToolUse":{"tool_name":"question","args":{"prompt":"Restart luxe now?","options":[]}}}"#
|
||
|
|
|
||
|
|
@Test func aQuestionToolCallBecomesAQuestionEvent() throws {
|
||
|
|
let event = try parse(questionPayload)
|
||
|
|
#expect(event.kind == .question)
|
||
|
|
#expect(event.message == "Restart luxe now?")
|
||
|
|
#expect(event.title == "luxe has a question")
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func aQuestionWithNoPromptStillNotifiesWithAFallback() throws {
|
||
|
|
let event = try parse(#"{"ToolUse":{"tool_name":"question","args":{}}}"#)
|
||
|
|
#expect(event.kind == .question)
|
||
|
|
#expect(!event.message.isEmpty)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func aVeryLongPromptIsTruncatedForTheBanner() throws {
|
||
|
|
let long = String(repeating: "x", count: 500)
|
||
|
|
let event = try parse(#"{"ToolUse":{"tool_name":"question","args":{"prompt":"\#(long)"}}}"#)
|
||
|
|
#expect(event.message.count <= 200)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func otherToolsAreNotTurnedIntoQuestions() throws {
|
||
|
|
let event = try parse(#"{"ToolUse":{"tool_name":"bash","args":{"command":"ls"}}}"#)
|
||
|
|
#expect(event.kind == .generic)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test func aToolUsePayloadWithoutAToolNameIsNotAQuestion() throws {
|
||
|
|
#expect(try parse(#"{"ToolUse":{"args":{"prompt":"hi"}}}"#).kind == .generic)
|
||
|
|
}
|
||
|
|
}
|