From 6a1cf5d76a23035a776cb3ff5d588e452697d9d6 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:15:44 -0800 Subject: [PATCH] Fix kqueue file watcher test failing on macOS One kqueue watcher test briefly pauses file change notifications so it can control the order in which they arrive. On macOS, pausing or resuming a watch also resets the list of changes it reports, so the test must pass the watcher's full list each time. Without it, macOS stops reporting changes to the directory and the test times out on every run, which breaks macOS CI. FreeBSD keeps the existing list. --- tsc/internal/fswatch/kqueue.go | 7 +++++-- tsc/internal/fswatch/kqueue_test.go | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tsc/internal/fswatch/kqueue.go b/tsc/internal/fswatch/kqueue.go index 6376b1068e14b..1305e5199264a 100644 --- a/tsc/internal/fswatch/kqueue.go +++ b/tsc/internal/fswatch/kqueue.go @@ -112,6 +112,10 @@ func newKqueueIdentity[D ~int32 | ~uint32 | ~int64 | ~uint64](device D, inode ui return kqueueIdentity{device: uint64(device), inode: inode} } +// kqueueVnodeFflags lists the file and directory changes each watch reports. +const kqueueVnodeFflags = unix.NOTE_DELETE | unix.NOTE_WRITE | unix.NOTE_EXTEND | + unix.NOTE_ATTRIB | unix.NOTE_RENAME | unix.NOTE_REVOKE + // kqueueSubscription. type kqueueSubscription struct { dirWatch *dirWatch @@ -392,8 +396,7 @@ func (b *kqueueBackend) openEntryLocked(entry *dirEntry) error { } var ev unix.Kevent_t unix.SetKevent(&ev, fd, unix.EVFILT_VNODE, unix.EV_ADD|unix.EV_CLEAR|unix.EV_ENABLE) - ev.Fflags = unix.NOTE_DELETE | unix.NOTE_WRITE | unix.NOTE_EXTEND | - unix.NOTE_ATTRIB | unix.NOTE_RENAME | unix.NOTE_REVOKE + ev.Fflags = kqueueVnodeFflags if _, err := unix.Kevent(b.kq, []unix.Kevent_t{ev}, nil, nil); err != nil { unix.Close(fd) return err diff --git a/tsc/internal/fswatch/kqueue_test.go b/tsc/internal/fswatch/kqueue_test.go index a0dbbb8bd87c4..bf42e9e31b6df 100644 --- a/tsc/internal/fswatch/kqueue_test.go +++ b/tsc/internal/fswatch/kqueue_test.go @@ -298,11 +298,13 @@ func TestKqueueReplacementWatchBeforeParentDispatch(t *testing.T) { //nolint:par rootFD := kqueueTestDescriptor(t, root, int(lower.Fd())) childFD := kqueueTestDescriptor(t, child, int(lower.Fd())) - // Hold actual kernel delivery while the public API subscribes to the - // replacement. No backend subscription bookkeeping is modified. + // Pause kernel event delivery while the public API subscribes to the + // replacement. On macOS, EV_DISABLE and EV_ENABLE also set the watch's + // event mask, so both pass the backend's full mask. changes := make([]unix.Kevent_t, 2) for i, fd := range []int{rootFD, childFD} { unix.SetKevent(&changes[i], fd, unix.EVFILT_VNODE, unix.EV_DISABLE) + changes[i].Fflags = kqueueVnodeFflags } if _, err := unix.Kevent(impl.kq, changes, nil, nil); err != nil { t.Fatal(err) @@ -315,6 +317,7 @@ func TestKqueueReplacementWatchBeforeParentDispatch(t *testing.T) { //nolint:par } childRec, _ := subscribeFor(t, child, w) unix.SetKevent(&changes[0], rootFD, unix.EVFILT_VNODE, unix.EV_ENABLE) + changes[0].Fflags = kqueueVnodeFflags if _, err := unix.Kevent(impl.kq, changes[:1], nil, nil); err != nil { t.Fatal(err) }