


























@@ -37,7 +37,7 @@ const {
3737})),
3838ensureSkillsWatcherMock: vi.fn(),
3939getSkillsSnapshotVersionMock: vi.fn(() => 0),
40-shouldRefreshSnapshotForVersionMock: vi.fn(() => false),
40+shouldRefreshSnapshotForVersionMock: vi.fn((_cached?: number, _next?: number) => false),
4141getRemoteSkillEligibilityMock: vi.fn(() => ({
4242platforms: [],
4343hasBin: () => false,
@@ -59,6 +59,9 @@ vi.mock("../../agents/skills.js", () => ({
59596060vi.mock("../../agents/skills/refresh.js", () => ({
6161ensureSkillsWatcher: ensureSkillsWatcherMock,
62+}));
63+64+vi.mock("../../agents/skills/refresh-state.js", () => ({
6265getSkillsSnapshotVersion: getSkillsSnapshotVersionMock,
6366shouldRefreshSnapshotForVersion: shouldRefreshSnapshotForVersionMock,
6467}));
@@ -197,6 +200,31 @@ describe("ensureSkillSnapshot", () => {
197200expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledTimes(2);
198201});
199202203+it("reads the skills snapshot version after watcher-side invalidation", async () => {
204+vi.stubEnv("OPENCLAW_TEST_FAST", "0");
205+getSkillsSnapshotVersionMock.mockReturnValue(0);
206+ensureSkillsWatcherMock.mockImplementation(() => {
207+getSkillsSnapshotVersionMock.mockReturnValue(5);
208+});
209+shouldRefreshSnapshotForVersionMock.mockImplementation((cached = 0, next = 0) => cached < next);
210+211+await ensureSkillSnapshot({
212+sessionEntry: testSessionEntry("sess-1", strippedSnapshot()),
213+sessionStore: {},
214+sessionKey: "main",
215+isFirstTurnInSession: false,
216+workspaceDir: TEST_WORKSPACE_DIR,
217+cfg: { skills: { load: { extraDirs: ["/tmp/shared-skills"] } } },
218+});
219+220+expect(shouldRefreshSnapshotForVersionMock).toHaveBeenCalledWith(0, 5);
221+expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledTimes(1);
222+const [[, snapshotParams]] = buildWorkspaceSkillSnapshotMock.mock.calls as unknown as Array<
223+[string, { snapshotVersion?: number }]
224+>;
225+expect(snapshotParams.snapshotVersion).toBe(5);
226+});
227+200228it("invalidates cache when non-skills config gates change", async () => {
201229vi.stubEnv("OPENCLAW_TEST_FAST", "0");
202230此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。