|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { StandardResourceCatalog } from "../src/v3/resource-catalog/standardResourceCatalog.js"; |
| 3 | + |
| 4 | +describe("StandardResourceCatalog — skills", () => { |
| 5 | + it("registers and lists a skill manifest", () => { |
| 6 | + const catalog = new StandardResourceCatalog(); |
| 7 | + catalog.setCurrentFileContext("trigger/chat.ts", "chat"); |
| 8 | + |
| 9 | + catalog.registerSkillMetadata({ id: "pdf-processing", sourcePath: "./skills/pdf-processing" }); |
| 10 | + |
| 11 | + const manifests = catalog.listSkillManifests(); |
| 12 | + expect(manifests).toHaveLength(1); |
| 13 | + expect(manifests[0]).toMatchObject({ |
| 14 | + id: "pdf-processing", |
| 15 | + sourcePath: "./skills/pdf-processing", |
| 16 | + filePath: "trigger/chat.ts", |
| 17 | + entryPoint: "chat", |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + it("getSkillManifest returns the registered skill", () => { |
| 22 | + const catalog = new StandardResourceCatalog(); |
| 23 | + catalog.setCurrentFileContext("trigger/chat.ts", "chat"); |
| 24 | + catalog.registerSkillMetadata({ id: "a", sourcePath: "./skills/a" }); |
| 25 | + |
| 26 | + expect(catalog.getSkillManifest("a")?.sourcePath).toBe("./skills/a"); |
| 27 | + expect(catalog.getSkillManifest("missing")).toBeUndefined(); |
| 28 | + }); |
| 29 | + |
| 30 | + it("skips registration without a file context", () => { |
| 31 | + const catalog = new StandardResourceCatalog(); |
| 32 | + |
| 33 | + catalog.registerSkillMetadata({ id: "pdf", sourcePath: "./skills/pdf" }); |
| 34 | + |
| 35 | + expect(catalog.listSkillManifests()).toHaveLength(0); |
| 36 | + }); |
| 37 | + |
| 38 | + it("warns and ignores when the same id is registered with a different path", () => { |
| 39 | + const catalog = new StandardResourceCatalog(); |
| 40 | + catalog.setCurrentFileContext("trigger/chat.ts", "chat"); |
| 41 | + |
| 42 | + const warn = vi.spyOn(console, "warn").mockImplementation(() => {}); |
| 43 | + |
| 44 | + catalog.registerSkillMetadata({ id: "pdf", sourcePath: "./skills/pdf" }); |
| 45 | + catalog.registerSkillMetadata({ id: "pdf", sourcePath: "./skills/other-pdf" }); |
| 46 | + |
| 47 | + const manifests = catalog.listSkillManifests(); |
| 48 | + expect(manifests).toHaveLength(1); |
| 49 | + expect(manifests[0]?.sourcePath).toBe("./skills/pdf"); |
| 50 | + expect(warn).toHaveBeenCalledWith(expect.stringContaining("defined twice")); |
| 51 | + |
| 52 | + warn.mockRestore(); |
| 53 | + }); |
| 54 | + |
| 55 | + it("re-registering the same id + path is idempotent", () => { |
| 56 | + const catalog = new StandardResourceCatalog(); |
| 57 | + catalog.setCurrentFileContext("trigger/chat.ts", "chat"); |
| 58 | + |
| 59 | + catalog.registerSkillMetadata({ id: "pdf", sourcePath: "./skills/pdf" }); |
| 60 | + catalog.registerSkillMetadata({ id: "pdf", sourcePath: "./skills/pdf" }); |
| 61 | + |
| 62 | + expect(catalog.listSkillManifests()).toHaveLength(1); |
| 63 | + }); |
| 64 | + |
| 65 | + it("registers multiple distinct skills", () => { |
| 66 | + const catalog = new StandardResourceCatalog(); |
| 67 | + catalog.setCurrentFileContext("trigger/chat.ts", "chat"); |
| 68 | + |
| 69 | + catalog.registerSkillMetadata({ id: "pdf", sourcePath: "./skills/pdf" }); |
| 70 | + catalog.registerSkillMetadata({ id: "researcher", sourcePath: "./skills/researcher" }); |
| 71 | + |
| 72 | + expect(catalog.listSkillManifests().map((s) => s.id).sort()).toEqual(["pdf", "researcher"]); |
| 73 | + }); |
| 74 | +}); |
0 commit comments