-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnotify.test.ts
More file actions
43 lines (36 loc) · 1.3 KB
/
notify.test.ts
File metadata and controls
43 lines (36 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { describe, it, afterEach, mock } from "bun:test"
import { expect } from "bun:test"
import fs from "fs"
const writeSpy = mock(() => {})
mock.module("fs", () => ({
...fs,
writeFileSync: writeSpy,
}))
const { warpNotify } = await import("../src/notify")
describe("warpNotify", () => {
const originalVersion = process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
afterEach(() => {
writeSpy.mockClear()
if (originalVersion === undefined) {
delete process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
} else {
process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = originalVersion
}
})
it("skips when WARP_CLI_AGENT_PROTOCOL_VERSION is not set", () => {
delete process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
warpNotify("title", "body")
expect(writeSpy).not.toHaveBeenCalled()
})
it("writes OSC 777 sequence when Warp declares protocol support", () => {
process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = "1"
warpNotify("warp://cli-agent", '{"event":"stop"}')
expect(writeSpy).toHaveBeenCalledTimes(1)
const [path, data] = writeSpy.mock.calls[0] as [string, string]
expect(path).toBe("/dev/tty")
expect(data).toContain("warp://cli-agent")
expect(data).toContain('{"event":"stop"}')
expect(data).toMatch(/^\x1b\]777;notify;/)
expect(data).toMatch(/\x07$/)
})
})