On macOS, watching deep dependency trees can exhaust file descriptors and lead to spawn EBADF failures. The skills watcher only needs to observe skill changes, so ignore dotfiles, node_modules, and dist by default. Adds regression coverage.
30 lines
975 B
TypeScript
30 lines
975 B
TypeScript
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);
|
|
});
|
|
});
|