|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { spawnSync } from "node:child_process"; |
| 3 | +import { cpSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 4 | +import { tmpdir } from "node:os"; |
| 5 | +import { dirname, join } from "node:path"; |
| 6 | +import { test } from "node:test"; |
| 7 | +import { fileURLToPath } from "node:url"; |
| 8 | + |
| 9 | +const skillSource = fileURLToPath(new URL("../../templates/skills/bundled/skill-digester/", import.meta.url)); |
| 10 | + |
| 11 | +for (const type of ["module", "commonjs"]) { |
| 12 | + test(`skill-digester's documented helper finds skills inside a ${type} package`, () => { |
| 13 | + const root = mkdtempSync(join(tmpdir(), "deepcode-skill-digester-")); |
| 14 | + try { |
| 15 | + const project = join(root, "project"); |
| 16 | + const home = join(root, "home"); |
| 17 | + const installed = join(project, ".agents", "skills", "skill-digester"); |
| 18 | + cpSync(skillSource, installed, { recursive: true }); |
| 19 | + mkdirSync(home); |
| 20 | + writeFileSync(join(project, "package.json"), JSON.stringify({ type })); |
| 21 | + const target = join(project, ".agents", "skills", "work-log", "SKILL.md"); |
| 22 | + mkdirSync(dirname(target), { recursive: true }); |
| 23 | + writeFileSync(target, '---\nname: worklog\ndescription: "Project work log"\n---\n# Work Log\n'); |
| 24 | + const instructions = readFileSync(join(installed, "SKILL.md"), "utf8"); |
| 25 | + const documentedScript = instructions.match(/scripts\/find-skill\.(?:cjs|js)/)?.[0]; |
| 26 | + assert.ok(documentedScript, "the skill must document its helper entry point"); |
| 27 | + |
| 28 | + const result = spawnSync(process.execPath, [join(installed, documentedScript), "worklog", project], { |
| 29 | + cwd: project, |
| 30 | + encoding: "utf8", |
| 31 | + timeout: 10000, |
| 32 | + env: { ...process.env, HOME: home, USERPROFILE: home, NODE_PATH: "" }, |
| 33 | + }); |
| 34 | + |
| 35 | + assert.equal(result.status, 0, result.stderr); |
| 36 | + const output = JSON.parse(result.stdout); |
| 37 | + assert.equal(output.found, true); |
| 38 | + assert.equal(output.activeMatches.length, 1); |
| 39 | + assert.equal(output.activeMatches[0].path, target); |
| 40 | + assert.equal(output.activeMatches[0].description, "Project work log"); |
| 41 | + assert.equal( |
| 42 | + output.activeMatches[0].digestTarget.path, |
| 43 | + join(project, ".deepcode", "skills", "work-log", "SKILL.md") |
| 44 | + ); |
| 45 | + } finally { |
| 46 | + rmSync(root, { recursive: true, force: true }); |
| 47 | + } |
| 48 | + }); |
| 49 | +} |
0 commit comments