46 lines
2.3 KiB
Swift
46 lines
2.3 KiB
Swift
import HelderCore
|
|
import Testing
|
|
|
|
@Suite struct AgentReferenceTests {
|
|
@Test func formatsFileLineAndRange() {
|
|
#expect(AgentReference(path: "src/A.php").description == "src/A.php")
|
|
#expect(AgentReference(path: "src/A.php", startLine: 42).description == "src/A.php:42")
|
|
#expect(AgentReference(path: "src/A.php", lines: 42...58).description == "src/A.php:42-58")
|
|
#expect(AgentReference(path: "src/A.php", lines: 7...7).description == "src/A.php:7")
|
|
}
|
|
|
|
@Test func composesPassOnText() {
|
|
#expect(PassOn.compose(note: "", reference: "a.php:3") == "a.php:3")
|
|
#expect(PassOn.compose(note: " fix this ", reference: "a.php:3") == "fix this => a.php:3")
|
|
#expect(PassOn.compose(note: "why", reference: "a.php:3-4", code: "x\ny") == "why a.php:3-4\n```\nx\ny\n```")
|
|
}
|
|
|
|
@Test func wrapsInBracketedPaste() {
|
|
#expect(BracketedPaste.wrap("a.php:1", composerHasText: false) == "\u{1b}[200~a.php:1\u{1b}[201~")
|
|
#expect(BracketedPaste.wrap("a.php:1", composerHasText: true) == "\u{1b}[200~\na.php:1\u{1b}[201~")
|
|
}
|
|
|
|
@Test func pastedTextCannotEndThePasteAndSubmit() {
|
|
let hostile = "note\u{1b}[201~\rrm -rf ~\r\u{1b}[200~ \u{9b}201~tail"
|
|
let wrapped = BracketedPaste.wrap(hostile, composerHasText: false)
|
|
#expect(wrapped == "\u{1b}[200~note[201~\rrm -rf ~\r[200~ 201~tail\u{1b}[201~")
|
|
#expect(wrapped.unicodeScalars.filter { $0 == "\u{1b}" }.count == 2)
|
|
}
|
|
|
|
@Test func terminalEnvironmentFillsTheGuiGaps() {
|
|
let env = TerminalLaunch.environment(from: ["npm_config_prefix": "/opt/homebrew", "PATH": "/usr/bin"])
|
|
#expect(env["npm_config_prefix"] == nil)
|
|
#expect(env["LANG"] == "en_US.UTF-8")
|
|
#expect(env["COLORTERM"] == "truecolor")
|
|
#expect(TerminalLaunch.environment(from: ["LC_ALL": "nl_NL.UTF-8"])["LANG"] == nil)
|
|
}
|
|
|
|
@Test func agentRunsTheCommandThroughAnInteractiveShell() {
|
|
let launch = TerminalLaunch.make(kind: .agent, config: .defaults, projectRoot: "/p", environment: ["SHELL": "/bin/bash"])
|
|
#expect(launch.executable == "/bin/bash")
|
|
#expect(launch.arguments == ["-i", "-c", "claude"])
|
|
#expect(launch.workingDirectory == "/p")
|
|
#expect(TerminalLaunch.make(kind: .shell, config: .defaults, projectRoot: nil, environment: [:]).arguments.isEmpty)
|
|
}
|
|
}
|