Skip to content

Commit 2d29ab6

Browse files
committed
🔧 chore: revert notify.ts to writeFileSync implementation
Revert to writeFileSync for /dev/tty writes while keeping retry mechanism and error logging. The openSync/writeSync/closeSync approach caused complete notification failure in the current environment.
1 parent 4c29b59 commit 2d29ab6

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

‎src/notify.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { openSync, writeSync, closeSync } from "fs"
1+
import { writeFileSync } from "fs"
22

33
const MAX_OSC_LENGTH = 4096
44

@@ -14,9 +14,7 @@ function warpNotify(title: string, body: string): void {
1414
let lastError: Error | null = null
1515
for (let attempt = 0; attempt < 3; attempt++) {
1616
try {
17-
const fd = openSync("/dev/tty", "w")
18-
writeSync(fd, sequence)
19-
closeSync(fd)
17+
writeFileSync("/dev/tty", sequence)
2018
return
2119
} catch (err) {
2220
lastError = err as Error

‎tests/notify.test.ts‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ import { describe, it, afterEach, mock } from "bun:test"
22
import { expect } from "bun:test"
33
import fs from "fs"
44

5-
const writeSyncSpy = mock(() => {})
6-
const openSyncSpy = mock(() => 42)
7-
const closeSyncSpy = mock(() => {})
5+
const writeFileSyncSpy = mock(() => {})
86

97
mock.module("fs", () => ({
108
...fs,
11-
openSync: openSyncSpy,
12-
writeSync: writeSyncSpy,
13-
closeSync: closeSyncSpy,
9+
writeFileSync: writeFileSyncSpy,
1410
}))
1511

1612
const { warpNotify } = await import("../src/notify")
@@ -19,9 +15,7 @@ describe("warpNotify", () => {
1915
const originalVersion = process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
2016

2117
afterEach(() => {
22-
openSyncSpy.mockClear()
23-
writeSyncSpy.mockClear()
24-
closeSyncSpy.mockClear()
18+
writeFileSyncSpy.mockClear()
2519
if (originalVersion === undefined) {
2620
delete process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
2721
} else {
@@ -32,18 +26,16 @@ describe("warpNotify", () => {
3226
it("skips when WARP_CLI_AGENT_PROTOCOL_VERSION is not set", () => {
3327
delete process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
3428
warpNotify("title", "body")
35-
expect(openSyncSpy).not.toHaveBeenCalled()
29+
expect(writeFileSyncSpy).not.toHaveBeenCalled()
3630
})
3731

3832
it("writes OSC 777 sequence when Warp declares protocol support", () => {
3933
process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = "1"
4034
warpNotify("warp://cli-agent", '{"event":"stop"}')
41-
expect(openSyncSpy).toHaveBeenCalledTimes(1)
42-
expect(openSyncSpy).toHaveBeenCalledWith("/dev/tty", "w")
43-
expect(writeSyncSpy).toHaveBeenCalledTimes(1)
44-
expect(closeSyncSpy).toHaveBeenCalledTimes(1)
35+
expect(writeFileSyncSpy).toHaveBeenCalledTimes(1)
4536

46-
const [, data] = writeSyncSpy.mock.calls[0] as [number, string]
37+
const [path, data] = writeFileSyncSpy.mock.calls[0] as [string, string]
38+
expect(path).toBe("/dev/tty")
4739
expect(data).toContain("warp://cli-agent")
4840
expect(data).toContain('{"event":"stop"}')
4941
expect(data).toMatch(/^\x1b\]777;notify;/)

0 commit comments

Comments
 (0)