mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 21:11:37 +00:00
test: move skills-cli integration coverage to e2e lane
This commit is contained in:
85
src/cli/skills-cli.e2e.test.ts
Normal file
85
src/cli/skills-cli.e2e.test.ts
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import fs from "node:fs";
|
||||||
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||||
|
import type { SkillEntry } from "../agents/skills.js";
|
||||||
|
import { buildWorkspaceSkillStatus } from "../agents/skills-status.js";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
|
import { formatSkillInfo, formatSkillsCheck, formatSkillsList } from "./skills-cli.format.js";
|
||||||
|
|
||||||
|
describe("skills-cli (e2e)", () => {
|
||||||
|
let tempWorkspaceDir = "";
|
||||||
|
let tempBundledDir = "";
|
||||||
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
envSnapshot = captureEnv(["OPENCLAW_BUNDLED_SKILLS_DIR"]);
|
||||||
|
tempWorkspaceDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-skills-test-"));
|
||||||
|
tempBundledDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-bundled-skills-test-"));
|
||||||
|
process.env.OPENCLAW_BUNDLED_SKILLS_DIR = tempBundledDir;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
if (tempWorkspaceDir) {
|
||||||
|
fs.rmSync(tempWorkspaceDir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
if (tempBundledDir) {
|
||||||
|
fs.rmSync(tempBundledDir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
envSnapshot.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
function 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", () => {
|
||||||
|
const entries = createEntries();
|
||||||
|
const report = buildWorkspaceSkillStatus(tempWorkspaceDir, {
|
||||||
|
managedSkillsDir: "/nonexistent",
|
||||||
|
entries,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(report.skills.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
const listOutput = formatSkillsList(report, {});
|
||||||
|
expect(listOutput).toContain("Skills");
|
||||||
|
|
||||||
|
const checkOutput = formatSkillsCheck(report, {});
|
||||||
|
expect(checkOutput).toContain("Total:");
|
||||||
|
|
||||||
|
const jsonOutput = formatSkillsList(report, { json: true });
|
||||||
|
const parsed = JSON.parse(jsonOutput);
|
||||||
|
expect(parsed.skills).toBeInstanceOf(Array);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("formats info for a real bundled skill (peekaboo)", () => {
|
||||||
|
const entries = createEntries();
|
||||||
|
const report = buildWorkspaceSkillStatus(tempWorkspaceDir, {
|
||||||
|
managedSkillsDir: "/nonexistent",
|
||||||
|
entries,
|
||||||
|
});
|
||||||
|
|
||||||
|
const peekaboo = report.skills.find((s) => s.name === "peekaboo");
|
||||||
|
if (!peekaboo) {
|
||||||
|
throw new Error("peekaboo fixture skill missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = formatSkillInfo(report, "peekaboo", {});
|
||||||
|
expect(output).toContain("peekaboo");
|
||||||
|
expect(output).toContain("Details:");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,10 +1,5 @@
|
|||||||
import fs from "node:fs";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import os from "node:os";
|
|
||||||
import path from "node:path";
|
|
||||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
||||||
import type { SkillStatusEntry, SkillStatusReport } from "../agents/skills-status.js";
|
import type { SkillStatusEntry, SkillStatusReport } from "../agents/skills-status.js";
|
||||||
import type { SkillEntry } from "../agents/skills.js";
|
|
||||||
import { captureEnv } from "../test-utils/env.js";
|
|
||||||
import { formatSkillInfo, formatSkillsCheck, formatSkillsList } from "./skills-cli.format.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.
|
// Unit tests: don't pay the runtime cost of loading/parsing the real skills loader.
|
||||||
@@ -216,87 +211,4 @@ describe("skills-cli", () => {
|
|||||||
expect(parsed.summary.total).toBe(2);
|
expect(parsed.summary.total).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("integration: loads real skills from bundled directory", () => {
|
|
||||||
let tempWorkspaceDir = "";
|
|
||||||
let tempBundledDir = "";
|
|
||||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
|
||||||
let buildWorkspaceSkillStatus: typeof import("../agents/skills-status.js").buildWorkspaceSkillStatus;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
envSnapshot = captureEnv(["OPENCLAW_BUNDLED_SKILLS_DIR"]);
|
|
||||||
tempWorkspaceDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-skills-test-"));
|
|
||||||
tempBundledDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-bundled-skills-test-"));
|
|
||||||
process.env.OPENCLAW_BUNDLED_SKILLS_DIR = tempBundledDir;
|
|
||||||
({ buildWorkspaceSkillStatus } = await import("../agents/skills-status.js"));
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
if (tempWorkspaceDir) {
|
|
||||||
fs.rmSync(tempWorkspaceDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
if (tempBundledDir) {
|
|
||||||
fs.rmSync(tempBundledDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
envSnapshot.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
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 entries = createEntries();
|
|
||||||
const report = buildWorkspaceSkillStatus(tempWorkspaceDir, {
|
|
||||||
managedSkillsDir: "/nonexistent",
|
|
||||||
entries,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should have loaded some skills
|
|
||||||
expect(report.skills.length).toBeGreaterThan(0);
|
|
||||||
|
|
||||||
// Format should work without errors
|
|
||||||
const listOutput = formatSkillsList(report, {});
|
|
||||||
expect(listOutput).toContain("Skills");
|
|
||||||
|
|
||||||
const checkOutput = formatSkillsCheck(report, {});
|
|
||||||
expect(checkOutput).toContain("Total:");
|
|
||||||
|
|
||||||
// JSON output should be valid
|
|
||||||
const jsonOutput = formatSkillsList(report, { json: true });
|
|
||||||
const parsed = JSON.parse(jsonOutput);
|
|
||||||
expect(parsed.skills).toBeInstanceOf(Array);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("formats info for a real bundled skill (peekaboo)", async () => {
|
|
||||||
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) {
|
|
||||||
throw new Error("peekaboo fixture skill missing");
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = formatSkillInfo(report, "peekaboo", {});
|
|
||||||
expect(output).toContain("peekaboo");
|
|
||||||
expect(output).toContain("Details:");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user