64 lines
2.6 KiB
TypeScript
64 lines
2.6 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { mkdtempSync, rmSync, existsSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import packageJson from "../../package.json" with { type: "json" };
|
|
import {
|
|
EMBEDDED_SKILL_FILES,
|
|
EMBEDDED_SKILL_VERSION,
|
|
getSkillContent,
|
|
installSkillFiles,
|
|
parseSkillVersion,
|
|
readInstalledSkillVersion
|
|
} from "./embedded-skill.js";
|
|
|
|
describe("embedded-skill", () => {
|
|
test("embeds SKILL.md and reference 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(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);
|
|
} finally {
|
|
rmSync(tmp, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("embedded-skill version contract", () => {
|
|
// A version-tagged document that nothing asserts on drifts silently: `seal-use update` shipped
|
|
// the previous release's skill for several versions, because "the file was written" looked like
|
|
// success from every angle. Keeping the skill and the package in step is a failing test now
|
|
// rather than a discovery.
|
|
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 });
|
|
}
|
|
});
|
|
});
|