import { describe, expect, test } from "bun:test" import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" import { getDefaultGlobalSkillDir, getSkillVersionStatus, GLOBAL_SKILL_DIR_ENV, parseSkillVersion } from "./skill-version.js" describe("lightweight Skill version inspection", () => { test("compares release generations without mistaking a development suffix for drift", () => { const dir = mkdtempSync(join(tmpdir(), "seal-skill-version-")) const file = join(dir, "SKILL.md") try { expect(getSkillVersionStatus("1.2.3", file).status).toBe("missing") const content = "---\nname: seal-use\nmetadata:\n version: \"1.2.3\"\n---\n" writeFileSync(file, content) expect(getSkillVersionStatus("1.2.3-dev.6+abc.dirty", file)).toMatchObject({ status: "matched", installedVersion: "1.2.3", nextAction: null }) expect(getSkillVersionStatus("1.2.2", file)).toMatchObject({ status: "skill_newer", nextAction: "seal-use update" }) expect(getSkillVersionStatus("1.2.4", file)).toMatchObject({ status: "cli_newer", nextAction: "seal-use skill install" }) expect(readFileSync(file, "utf8")).toBe(content) writeFileSync(file, "# invalid metadata\nversion: 1.2.3\n") expect(getSkillVersionStatus("1.2.3", file).status).toBe("unknown") expect(parseSkillVersion("---\r\nmetadata:\r\n version: '2.0.0'\r\n---\r\n")).toBe("2.0.0") } finally { rmSync(dir, { recursive: true, force: true }) } }) test("getDefaultGlobalSkillDir respects GLOBAL_SKILL_DIR_ENV override", () => { const prev = process.env[GLOBAL_SKILL_DIR_ENV] try { process.env[GLOBAL_SKILL_DIR_ENV] = "/tmp/custom-agents-skill" expect(getDefaultGlobalSkillDir()).toBe("/tmp/custom-agents-skill") } finally { if (prev !== undefined) process.env[GLOBAL_SKILL_DIR_ENV] = prev else delete process.env[GLOBAL_SKILL_DIR_ENV] } }) })