





















@@ -6,11 +6,11 @@ import type { SkillSnapshot } from "../types.js";
6677const TEST_WORKSPACE_DIR = "/tmp/workspace";
889-function strippedSnapshot(skillName = "test"): SkillSnapshot {
9+function strippedSnapshot(skillName = "test", version = 1): SkillSnapshot {
1010return {
1111prompt: "skills prompt",
1212skills: [{ name: skillName }],
13-version: 0,
13+ version,
1414promptFormatVersion: WORKSPACE_SKILLS_PROMPT_FORMAT_VERSION,
1515};
1616}
@@ -27,8 +27,10 @@ const {
2727resolvedSkills: [] as unknown[],
2828})),
2929ensureSkillsWatcherMock: vi.fn(),
30-getSkillsSnapshotVersionMock: vi.fn(() => 0),
31-shouldRefreshSnapshotForVersionMock: vi.fn((_cached?: number, _next?: number) => false),
30+getSkillsSnapshotVersionMock: vi.fn(() => 1),
31+shouldRefreshSnapshotForVersionMock: vi.fn((cached = 0, next = 0) =>
32+next === 0 ? cached > 0 : cached < next,
33+),
3234}));
33353436vi.mock("../loading/workspace.js", () => ({
@@ -52,8 +54,10 @@ describe("resolveReusableWorkspaceSkillSnapshot", () => {
5254vi.clearAllMocks();
5355resetResolvedSkillsCacheForTests();
5456buildWorkspaceSkillSnapshotMock.mockReturnValue({ prompt: "", skills: [], resolvedSkills: [] });
55-getSkillsSnapshotVersionMock.mockReturnValue(0);
56-shouldRefreshSnapshotForVersionMock.mockReturnValue(false);
57+getSkillsSnapshotVersionMock.mockReturnValue(1);
58+shouldRefreshSnapshotForVersionMock.mockImplementation((cached = 0, next = 0) =>
59+next === 0 ? cached > 0 : cached < next,
60+);
5761});
58625963it("reuses cached resolvedSkills across calls with the same workspace, version, and filter", () => {
@@ -97,26 +101,59 @@ describe("resolveReusableWorkspaceSkillSnapshot", () => {
97101});
9810299103it("reads the skills snapshot version after watcher-side invalidation", () => {
100-getSkillsSnapshotVersionMock.mockReturnValue(0);
104+getSkillsSnapshotVersionMock.mockReturnValue(1);
101105ensureSkillsWatcherMock.mockImplementation(() => {
102106getSkillsSnapshotVersionMock.mockReturnValue(5);
103107});
104-shouldRefreshSnapshotForVersionMock.mockImplementation((cached = 0, next = 0) => cached < next);
105108106109resolveReusableWorkspaceSkillSnapshot({
107110workspaceDir: TEST_WORKSPACE_DIR,
108111config: { skills: { load: { extraDirs: ["/tmp/shared-skills"] } } },
109-existingSnapshot: strippedSnapshot(),
112+existingSnapshot: strippedSnapshot("test", 1),
110113});
111114112-expect(shouldRefreshSnapshotForVersionMock).toHaveBeenCalledWith(0, 5);
115+expect(shouldRefreshSnapshotForVersionMock).toHaveBeenCalledWith(1, 5);
113116expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledTimes(1);
114117const [[, snapshotParams]] = buildWorkspaceSkillSnapshotMock.mock.calls as unknown as Array<
115118[string, { snapshotVersion?: number }]
116119>;
117120expect(snapshotParams.snapshotVersion).toBe(5);
118121});
119122123+it("refreshes persisted version-0 snapshots after process restart", () => {
124+const result = resolveReusableWorkspaceSkillSnapshot({
125+workspaceDir: TEST_WORKSPACE_DIR,
126+config: {},
127+existingSnapshot: strippedSnapshot("test", 0),
128+});
129+130+expect(result.shouldRefresh).toBe(true);
131+expect(shouldRefreshSnapshotForVersionMock).toHaveBeenCalledWith(0, 1);
132+expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledTimes(1);
133+const [[, snapshotParams]] = buildWorkspaceSkillSnapshotMock.mock.calls as unknown as Array<
134+[string, { snapshotVersion?: number }]
135+>;
136+expect(snapshotParams.snapshotVersion).toBe(1);
137+});
138+139+it("refreshes persisted timestamp-version snapshots from earlier processes", () => {
140+getSkillsSnapshotVersionMock.mockReturnValue(10_000);
141+142+const result = resolveReusableWorkspaceSkillSnapshot({
143+workspaceDir: TEST_WORKSPACE_DIR,
144+config: {},
145+existingSnapshot: strippedSnapshot("test", 9_999),
146+});
147+148+expect(result.shouldRefresh).toBe(true);
149+expect(shouldRefreshSnapshotForVersionMock).toHaveBeenCalledWith(9_999, 10_000);
150+expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledTimes(1);
151+const [[, snapshotParams]] = buildWorkspaceSkillSnapshotMock.mock.calls as unknown as Array<
152+[string, { snapshotVersion?: number }]
153+>;
154+expect(snapshotParams.snapshotVersion).toBe(10_000);
155+});
156+120157it("invalidates cached resolvedSkills when non-skills config gates change", () => {
121158buildWorkspaceSkillSnapshotMock.mockImplementation((_workspaceDir, opts) => {
122159const config = (opts as { config?: { channels?: { discord?: { token?: string } } } }).config;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。