mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
refactor(skills): use chokidar all events
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user