Merge pull request #1074 from roshanasingh4/fix/1056-ignore-heavy-watch-paths
Fix #1056: prevent macOS FD exhaustion by ignoring node_modules in skills watcher
This commit is contained in:
30
src/agents/skills/refresh.test.ts
Normal file
30
src/agents/skills/refresh.test.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
const watchMock = vi.fn(() => ({
|
||||||
|
on: vi.fn(),
|
||||||
|
close: vi.fn(async () => undefined),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("chokidar", () => {
|
||||||
|
return {
|
||||||
|
default: { watch: watchMock },
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ensureSkillsWatcher", () => {
|
||||||
|
it("ignores node_modules and dist by default", async () => {
|
||||||
|
const mod = await import("./refresh.js");
|
||||||
|
mod.ensureSkillsWatcher({ workspaceDir: "/tmp/workspace" });
|
||||||
|
|
||||||
|
expect(watchMock).toHaveBeenCalledTimes(1);
|
||||||
|
const opts = watchMock.mock.calls[0]?.[1] as { ignored?: unknown };
|
||||||
|
|
||||||
|
expect(Array.isArray(opts.ignored)).toBe(true);
|
||||||
|
const ignored = opts.ignored as RegExp[];
|
||||||
|
expect(ignored.some((re) => re.test("/tmp/workspace/skills/node_modules/pkg/index.js"))).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
expect(ignored.some((re) => re.test("/tmp/workspace/skills/dist/index.js"))).toBe(true);
|
||||||
|
expect(ignored.some((re) => re.test("/tmp/workspace/skills/.git/config"))).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -125,6 +125,13 @@ export function ensureSkillsWatcher(params: { workspaceDir: string; config?: Cla
|
|||||||
stabilityThreshold: debounceMs,
|
stabilityThreshold: debounceMs,
|
||||||
pollInterval: 100,
|
pollInterval: 100,
|
||||||
},
|
},
|
||||||
|
// Avoid FD exhaustion on macOS when a workspace contains huge trees.
|
||||||
|
// This watcher only needs to react to skill changes.
|
||||||
|
ignored: [
|
||||||
|
/(^|[\\/])\../, // dotfiles (includes .git)
|
||||||
|
/(^|[\\/])node_modules([\\/]|$)/,
|
||||||
|
/(^|[\\/])dist([\\/]|$)/,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const state: SkillsWatchState = { watcher, pathsKey, debounceMs };
|
const state: SkillsWatchState = { watcher, pathsKey, debounceMs };
|
||||||
|
|||||||
Reference in New Issue
Block a user