mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 12:51:37 +00:00
perf(cli): split skills formatting
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildWorkspaceSkillStatus,
|
||||
type SkillStatusEntry,
|
||||
type SkillStatusReport,
|
||||
} from "../agents/skills-status.js";
|
||||
import { formatSkillInfo, formatSkillsCheck, formatSkillsList } from "./skills-cli.js";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import type { SkillStatusEntry, SkillStatusReport } from "../agents/skills-status.js";
|
||||
import type { SkillEntry } from "../agents/skills.js";
|
||||
import { formatSkillInfo, formatSkillsCheck, formatSkillsList } from "./skills-cli.format.js";
|
||||
|
||||
// Unit tests: don't pay the runtime cost of loading/parsing the real skills loader.
|
||||
vi.mock("@mariozechner/pi-coding-agent", () => ({
|
||||
loadSkillsFromDir: () => ({ skills: [] }),
|
||||
formatSkillsForPrompt: () => "",
|
||||
}));
|
||||
|
||||
function createMockSkill(overrides: Partial<SkillStatusEntry> = {}): SkillStatusEntry {
|
||||
return {
|
||||
@@ -227,25 +229,29 @@ describe("skills-cli", () => {
|
||||
}
|
||||
});
|
||||
|
||||
function resolveBundledSkillsDir(): string | undefined {
|
||||
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const root = path.resolve(moduleDir, "..", "..");
|
||||
const candidate = path.join(root, "skills");
|
||||
if (fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
it("loads bundled skills and formats them", () => {
|
||||
const bundledDir = resolveBundledSkillsDir();
|
||||
if (!bundledDir) {
|
||||
// Skip if skills dir not found (e.g., in CI without skills)
|
||||
return;
|
||||
}
|
||||
const createEntries = (): SkillEntry[] => {
|
||||
const baseDir = path.join(tempWorkspaceDir, "peekaboo");
|
||||
return [
|
||||
{
|
||||
skill: {
|
||||
name: "peekaboo",
|
||||
description: "Capture UI screenshots",
|
||||
source: "openclaw-bundled",
|
||||
filePath: path.join(baseDir, "SKILL.md"),
|
||||
baseDir,
|
||||
} as SkillEntry["skill"],
|
||||
frontmatter: {},
|
||||
metadata: { emoji: "📸" },
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
it("loads bundled skills and formats them", async () => {
|
||||
const { buildWorkspaceSkillStatus } = await import("../agents/skills-status.js");
|
||||
const entries = createEntries();
|
||||
const report = buildWorkspaceSkillStatus(tempWorkspaceDir, {
|
||||
managedSkillsDir: "/nonexistent",
|
||||
entries,
|
||||
});
|
||||
|
||||
// Should have loaded some skills
|
||||
@@ -264,21 +270,18 @@ describe("skills-cli", () => {
|
||||
expect(parsed.skills).toBeInstanceOf(Array);
|
||||
});
|
||||
|
||||
it("formats info for a real bundled skill (peekaboo)", () => {
|
||||
const bundledDir = resolveBundledSkillsDir();
|
||||
if (!bundledDir) {
|
||||
return;
|
||||
}
|
||||
|
||||
it("formats info for a real bundled skill (peekaboo)", async () => {
|
||||
const { buildWorkspaceSkillStatus } = await import("../agents/skills-status.js");
|
||||
const entries = createEntries();
|
||||
const report = buildWorkspaceSkillStatus(tempWorkspaceDir, {
|
||||
managedSkillsDir: "/nonexistent",
|
||||
entries,
|
||||
});
|
||||
|
||||
// peekaboo is a bundled skill that should always exist
|
||||
const peekaboo = report.skills.find((s) => s.name === "peekaboo");
|
||||
if (!peekaboo) {
|
||||
// Skip if peekaboo not found
|
||||
return;
|
||||
throw new Error("peekaboo fixture skill missing");
|
||||
}
|
||||
|
||||
const output = formatSkillInfo(report, "peekaboo", {});
|
||||
|
||||
Reference in New Issue
Block a user