71 lines
3.1 KiB
TypeScript
71 lines
3.1 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import packageJson from "../../package.json" with { type: "json" };
|
|
import {
|
|
EMBEDDED_SKILL_ALL_PATHS,
|
|
EMBEDDED_SKILL_ASSETS,
|
|
EMBEDDED_SKILL_FILES,
|
|
EMBEDDED_SKILL_VERSION,
|
|
getSkillContent,
|
|
installSkillFiles,
|
|
parseSkillVersion,
|
|
readInstalledSkillVersion
|
|
} from "./embedded-skill.js";
|
|
|
|
describe("embedded-skill", () => {
|
|
test("embeds skill text and asset files", () => {
|
|
expect(EMBEDDED_SKILL_FILES["SKILL.md"]).toBeDefined();
|
|
expect(EMBEDDED_SKILL_FILES["SKILL.md"]).toContain("name: seal-use");
|
|
expect(EMBEDDED_SKILL_FILES["references/cli.md"]).toBeDefined();
|
|
expect(EMBEDDED_SKILL_FILES["references/enterprise-onboarding.md"]).toContain("# Enterprise Onboarding");
|
|
expect(EMBEDDED_SKILL_FILES["references/first-time-user.md"]).toContain("复制 → 以 cURL 格式复制");
|
|
expect(EMBEDDED_SKILL_ASSETS["assets/hose-curl-copy-as-curl.png"]).toBeDefined();
|
|
expect(EMBEDDED_SKILL_ALL_PATHS).toContain("assets/hose-curl-copy-as-curl.png");
|
|
expect(getSkillContent()).toContain("name: seal-use");
|
|
});
|
|
|
|
test("installSkillFiles writes all embedded files to target directory", () => {
|
|
const tmp = mkdtempSync(join(tmpdir(), "skill-test-"));
|
|
try {
|
|
const res = installSkillFiles(tmp);
|
|
expect(res.targetDir).toBe(tmp);
|
|
expect(res.files.length).toBeGreaterThan(5);
|
|
expect(existsSync(join(tmp, "SKILL.md"))).toBe(true);
|
|
expect(existsSync(join(tmp, "references", "cli.md"))).toBe(true);
|
|
expect(existsSync(join(tmp, "references", "enterprise-onboarding.md"))).toBe(true);
|
|
expect(existsSync(join(tmp, "references", "first-time-user.md"))).toBe(true);
|
|
expect(existsSync(join(tmp, "assets", "hose-curl-copy-as-curl.png"))).toBe(true);
|
|
expect([...res.files].sort()).toEqual([...EMBEDDED_SKILL_ALL_PATHS].sort());
|
|
for (const path of EMBEDDED_SKILL_ALL_PATHS) {
|
|
expect(readFileSync(join(tmp, path))).toEqual(readFileSync(join(import.meta.dir, "../../skills/seal-use", path)));
|
|
}
|
|
} finally {
|
|
rmSync(tmp, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("embedded-skill version contract", () => {
|
|
test("the skill's version matches the package version", () => {
|
|
expect(EMBEDDED_SKILL_VERSION).toBe(packageJson.version);
|
|
});
|
|
|
|
test("parses the version out of SKILL.md front matter", () => {
|
|
expect(parseSkillVersion("---\nname: seal-use\nversion: 1.2.3\n---\n")).toBe("1.2.3");
|
|
expect(parseSkillVersion("# no front matter here")).toBeUndefined();
|
|
});
|
|
|
|
test("reads back the version of an installed skill", () => {
|
|
const tmp = mkdtempSync(join(tmpdir(), "skill-version-"));
|
|
try {
|
|
const res = installSkillFiles(tmp);
|
|
expect(readInstalledSkillVersion(join(res.targetDir, "SKILL.md"))).toBe(EMBEDDED_SKILL_VERSION);
|
|
expect(readInstalledSkillVersion(join(tmp, "missing.md"))).toBeUndefined();
|
|
} finally {
|
|
rmSync(tmp, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|