|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import type { OpenClawConfig } from "../../config/config.js"; |
| 3 | +import type { SkillEntry } from "./types.js"; |
| 4 | +import { shouldIncludeSkill } from "./config.js"; |
| 5 | + |
| 6 | +/** |
| 7 | + * Build a minimal SkillEntry for testing shouldIncludeSkill. |
| 8 | + */ |
| 9 | +function makeEntry(overrides?: { |
| 10 | + name?: string; |
| 11 | + source?: string; |
| 12 | + requiresBins?: string[]; |
| 13 | +}): SkillEntry { |
| 14 | + const name = overrides?.name ?? "test-skill"; |
| 15 | + return { |
| 16 | + skill: { |
| 17 | + name, |
| 18 | + description: "A test skill", |
| 19 | + filePath: `/skills/${name}/SKILL.md`, |
| 20 | + baseDir: `/skills/${name}`, |
| 21 | + source: overrides?.source ?? "user", |
| 22 | + disableModelInvocation: false, |
| 23 | + }, |
| 24 | + frontmatter: {}, |
| 25 | + metadata: overrides?.requiresBins |
| 26 | + ? { requires: { bins: overrides.requiresBins } } |
| 27 | + : undefined, |
| 28 | + }; |
| 29 | +} |
| 30 | + |
| 31 | +describe("shouldIncludeSkill", () => { |
| 32 | + it("returns false when enabled is explicitly false", () => { |
| 33 | + const entry = makeEntry(); |
| 34 | + const config: OpenClawConfig = { |
| 35 | + skills: { entries: { "test-skill": { enabled: false } } }, |
| 36 | + } as OpenClawConfig; |
| 37 | + expect(shouldIncludeSkill({ entry, config })).toBe(false); |
| 38 | + }); |
| 39 | + |
| 40 | + it("returns true when enabled is explicitly true, even with unmet requires.bins", () => { |
| 41 | + const entry = makeEntry({ requiresBins: ["nonexistent-binary-xyz"] }); |
| 42 | + const config: OpenClawConfig = { |
| 43 | + skills: { entries: { "test-skill": { enabled: true } } }, |
| 44 | + } as OpenClawConfig; |
| 45 | + expect(shouldIncludeSkill({ entry, config })).toBe(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it("returns true when enabled is explicitly true without any requires", () => { |
| 49 | + const entry = makeEntry(); |
| 50 | + const config: OpenClawConfig = { |
| 51 | + skills: { entries: { "test-skill": { enabled: true } } }, |
| 52 | + } as OpenClawConfig; |
| 53 | + expect(shouldIncludeSkill({ entry, config })).toBe(true); |
| 54 | + }); |
| 55 | + |
| 56 | + it("falls through to runtime eligibility when enabled is not set", () => { |
| 57 | + // A skill requiring a nonexistent binary should be excluded when |
| 58 | + // there is no explicit enabled override. |
| 59 | + const entry = makeEntry({ requiresBins: ["nonexistent-binary-xyz"] }); |
| 60 | + const config: OpenClawConfig = { |
| 61 | + skills: { entries: { "test-skill": {} } }, |
| 62 | + } as OpenClawConfig; |
| 63 | + expect(shouldIncludeSkill({ entry, config })).toBe(false); |
| 64 | + }); |
| 65 | + |
| 66 | + it("falls through to runtime eligibility when no skill config exists", () => { |
| 67 | + const entry = makeEntry({ requiresBins: ["nonexistent-binary-xyz"] }); |
| 68 | + expect(shouldIncludeSkill({ entry })).toBe(false); |
| 69 | + }); |
| 70 | +}); |
0 commit comments