refactor(skills): use chokidar all events

This commit is contained in:
Peter Steinberger
2026-07-14 06:30:14 +01:00
parent 73cb408565
commit 1d02cc83dd
2 changed files with 7 additions and 11 deletions
+6 -6
View File
@@ -9,7 +9,7 @@ import {
type SkillsChangeEvent,
} from "./refresh-state.js";
type WatchEvent = "add" | "addDir" | "change" | "unlink" | "unlinkDir" | "raw" | "error";
type WatchEvent = "add" | "addDir" | "all" | "change" | "unlink" | "unlinkDir" | "raw" | "error";
type WatchCallback = (...args: unknown[]) => void;
function createMockWatcher() {
@@ -207,7 +207,7 @@ describe("ensureSkillsWatcher", () => {
expect(calls[firstIndex]?.[1]?.depth).toBe(7);
const changedPath = path.join(workspaceDir, "skills", "group", "demo", "SKILL.md");
createdWatchers[firstIndex]?.emit("change", changedPath);
createdWatchers[firstIndex]?.emit("all", "change", changedPath);
await vi.advanceTimersByTimeAsync(10);
expect(seen).toEqual([
@@ -714,7 +714,7 @@ describe("ensureSkillsWatcher", () => {
config: { skills: { load: { watchDebounceMs: 10 } } },
});
createdWatchers[0]?.emit(event, "/tmp/workspace/skills/demo/SKILL.md");
createdWatchers[0]?.emit("all", event, "/tmp/workspace/skills/demo/SKILL.md");
await vi.advanceTimersByTimeAsync(10);
expect(seen).toEqual([
@@ -794,7 +794,7 @@ describe("ensureSkillsWatcher", () => {
const sharedIndex = callPaths.findIndex((target) => target.includes("/tmp/shared"));
expect(sharedIndex).toBeGreaterThanOrEqual(0);
createdWatchers[sharedIndex]?.emit("change", "/tmp/shared/demo/SKILL.md");
createdWatchers[sharedIndex]?.emit("all", "change", "/tmp/shared/demo/SKILL.md");
await vi.advanceTimersByTimeAsync(10);
expect(seen).toContainEqual({
@@ -836,7 +836,7 @@ describe("ensureSkillsWatcher", () => {
const sharedIndex = callPaths.findIndex((target) => target.includes("/tmp/shared"));
expect(sharedIndex).toBeGreaterThanOrEqual(0);
createdWatchers[sharedIndex]?.emit("change", "/tmp/shared/demo/SKILL.md");
createdWatchers[sharedIndex]?.emit("all", "change", "/tmp/shared/demo/SKILL.md");
await vi.advanceTimersByTimeAsync(10);
expect(seen).toContainEqual({
@@ -970,7 +970,7 @@ describe("ensureSkillsWatcher", () => {
expect(callPaths2.filter((target) => target === "/tmp/shared/skills")).toHaveLength(2);
const liveSharedIndex = sharedIndices[sharedIndices.length - 1] ?? -1;
createdWatchers[liveSharedIndex]?.emit("change", "/tmp/shared/demo/SKILL.md");
createdWatchers[liveSharedIndex]?.emit("all", "change", "/tmp/shared/demo/SKILL.md");
await vi.advanceTimersByTimeAsync(50);
expect(seen).toContainEqual({
+1 -5
View File
@@ -554,11 +554,7 @@ function createSkillsPathWatcher(target: WatchTarget, debounceMs: number): Skill
.then(() => schedule(changedPath));
};
watcher.on("addDir", (p) => schedule(p));
watcher.on("add", (p) => schedule(p));
watcher.on("change", (p) => schedule(p));
watcher.on("unlink", (p) => schedule(p));
watcher.on("unlinkDir", (p) => schedule(p));
watcher.on("all", (_event, changedPath) => schedule(changedPath));
watcher.on("raw", (_eventName, rawPath, details) => {
const rawPathText = rawPathToString(rawPath);
if (!rawPathText) {