/** * Unit tests for generate-skills.mjs — RED phase of TDD. * * Tests cover: * - detectFileType: classification of files by extension * - applyHeader: insertion per file-type-aware policy * - makePackageJsonContent: unique name + private:true * - getGeneratedRoots: returns the canonical generated-root list */ import assert from "node:assert/strict"; import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises"; import crypto from "node:crypto"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const SCRIPTS_DIR = path.resolve(__dirname, ".."); const { detectFileType, applyHeader, makePackageJsonContent, getGeneratedRoots, buildManifest, } = await import(`${SCRIPTS_DIR}/generate-skills.mjs`); // ── detectFileType ──────────────────────────────────────────────────────── test("detectFileType: .md files → markdown", () => { assert.equal(detectFileType("SKILL.md"), "markdown"); assert.equal(detectFileType("templates/milestone-plan.md"), "markdown"); assert.equal(detectFileType("README.md"), "markdown"); }); test("detectFileType: .sh files → shell", () => { assert.equal(detectFileType("run-review.sh"), "shell"); assert.equal(detectFileType("scripts/install.sh"), "shell"); }); test("detectFileType: .ts and .d.ts files → ts", () => { assert.equal(detectFileType("src/cli.ts"), "ts"); assert.equal(detectFileType("turndown-plugin-gfm.d.ts"), "ts"); assert.equal(detectFileType("auth.ts"), "ts"); }); test("detectFileType: .js files → js", () => { assert.equal(detectFileType("check-install.js"), "js"); assert.equal(detectFileType("extract.js"), "js"); }); test("detectFileType: .json files → json", () => { assert.equal(detectFileType("package.json"), "json"); assert.equal(detectFileType("tsconfig.json"), "json"); }); test("detectFileType: .yaml and .yml files → yaml", () => { assert.equal(detectFileType("pnpm-lock.yaml"), "yaml"); assert.equal(detectFileType("other.yml"), "yaml"); }); test("detectFileType: .jsonc files → jsonc", () => { assert.equal(detectFileType(".markdownlint.jsonc"), "jsonc"); }); test("detectFileType: unknown extension → unknown", () => { assert.equal(detectFileType("Makefile"), "unknown"); assert.equal(detectFileType("somefile"), "unknown"); }); // ── applyHeader ─────────────────────────────────────────────────────────── test("applyHeader: markdown with YAML front matter inserts HTML comment after closing ---", () => { const content = "---\nname: create-plan\n---\n\n# Create Plan\n\nBody.\n"; const result = applyHeader(content, "markdown", "skills/create-plan/_source/claude-code/SKILL.md"); // Front matter block preserved verbatim at start assert.ok(result.startsWith("---\nname: create-plan\n---\n"), "front matter at start"); // HTML comment present assert.ok(result.includes("