mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 18:20:22 +00:00
Merged via squash.
Prepared head SHA: 6f60779a57
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
123 lines
3.6 KiB
TypeScript
123 lines
3.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { resolveSkillsPromptForRun } from "./skills.js";
|
|
import { createCanonicalFixtureSkill } from "./skills.test-helpers.js";
|
|
import type { SkillEntry } from "./skills/types.js";
|
|
|
|
describe("resolveSkillsPromptForRun", () => {
|
|
it("prefers snapshot prompt when available", () => {
|
|
const prompt = resolveSkillsPromptForRun({
|
|
skillsSnapshot: { prompt: "SNAPSHOT", skills: [] },
|
|
workspaceDir: "/tmp/openclaw",
|
|
});
|
|
expect(prompt).toBe("SNAPSHOT");
|
|
});
|
|
it("builds prompt from entries when snapshot is missing", () => {
|
|
const entry: SkillEntry = {
|
|
skill: createFixtureSkill({
|
|
name: "demo-skill",
|
|
description: "Demo",
|
|
filePath: "/app/skills/demo-skill/SKILL.md",
|
|
baseDir: "/app/skills/demo-skill",
|
|
source: "openclaw-bundled",
|
|
}),
|
|
frontmatter: {},
|
|
};
|
|
const prompt = resolveSkillsPromptForRun({
|
|
entries: [entry],
|
|
workspaceDir: "/tmp/openclaw",
|
|
});
|
|
expect(prompt).toContain("<available_skills>");
|
|
expect(prompt).toContain("/app/skills/demo-skill/SKILL.md");
|
|
});
|
|
|
|
it("inherits agents.defaults.skills when rebuilding prompt for an agent", () => {
|
|
const visible: SkillEntry = {
|
|
skill: createFixtureSkill({
|
|
name: "github",
|
|
description: "GitHub",
|
|
filePath: "/app/skills/github/SKILL.md",
|
|
baseDir: "/app/skills/github",
|
|
source: "openclaw-workspace",
|
|
}),
|
|
frontmatter: {},
|
|
};
|
|
const hidden: SkillEntry = {
|
|
skill: createFixtureSkill({
|
|
name: "hidden-skill",
|
|
description: "Hidden",
|
|
filePath: "/app/skills/hidden-skill/SKILL.md",
|
|
baseDir: "/app/skills/hidden-skill",
|
|
source: "openclaw-workspace",
|
|
}),
|
|
frontmatter: {},
|
|
};
|
|
|
|
const prompt = resolveSkillsPromptForRun({
|
|
entries: [visible, hidden],
|
|
config: {
|
|
agents: {
|
|
defaults: {
|
|
skills: ["github"],
|
|
},
|
|
list: [{ id: "writer" }],
|
|
},
|
|
},
|
|
workspaceDir: "/tmp/openclaw",
|
|
agentId: "writer",
|
|
});
|
|
|
|
expect(prompt).toContain("/app/skills/github/SKILL.md");
|
|
expect(prompt).not.toContain("/app/skills/hidden-skill/SKILL.md");
|
|
});
|
|
|
|
it("uses agents.list[].skills as a full replacement for defaults", () => {
|
|
const inheritedEntry: SkillEntry = {
|
|
skill: createFixtureSkill({
|
|
name: "weather",
|
|
description: "Weather",
|
|
filePath: "/app/skills/weather/SKILL.md",
|
|
baseDir: "/app/skills/weather",
|
|
source: "openclaw-workspace",
|
|
}),
|
|
frontmatter: {},
|
|
};
|
|
const explicitEntry: SkillEntry = {
|
|
skill: createFixtureSkill({
|
|
name: "docs-search",
|
|
description: "Docs",
|
|
filePath: "/app/skills/docs-search/SKILL.md",
|
|
baseDir: "/app/skills/docs-search",
|
|
source: "openclaw-workspace",
|
|
}),
|
|
frontmatter: {},
|
|
};
|
|
|
|
const prompt = resolveSkillsPromptForRun({
|
|
entries: [inheritedEntry, explicitEntry],
|
|
config: {
|
|
agents: {
|
|
defaults: {
|
|
skills: ["weather"],
|
|
},
|
|
list: [{ id: "writer", skills: ["docs-search"] }],
|
|
},
|
|
},
|
|
workspaceDir: "/tmp/openclaw",
|
|
agentId: "writer",
|
|
});
|
|
|
|
expect(prompt).not.toContain("/app/skills/weather/SKILL.md");
|
|
expect(prompt).toContain("/app/skills/docs-search/SKILL.md");
|
|
});
|
|
});
|
|
|
|
function createFixtureSkill(params: {
|
|
name: string;
|
|
description: string;
|
|
filePath: string;
|
|
baseDir: string;
|
|
source: string;
|
|
}): SkillEntry["skill"] {
|
|
return createCanonicalFixtureSkill(params);
|
|
}
|