43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { mkdtemp, readFile, stat } from "node:fs/promises";
|
|
import { spawnSync } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
const project = await mkdtemp(path.resolve("test-results/skill-consumer-"));
|
|
const install = () =>
|
|
spawnSync(
|
|
process.execPath,
|
|
["scripts/install-skill.mjs", "--project", project],
|
|
{ encoding: "utf8", windowsHide: true },
|
|
);
|
|
const first = install();
|
|
assert.equal(first.status, 0, first.stderr);
|
|
const skill = path.join(project, ".agents/skills/anidev-design-system");
|
|
await stat(path.join(skill, "SKILL.md"));
|
|
const pkg = path.join(skill, "assets/anidev"),
|
|
manifest = JSON.parse(
|
|
await readFile(path.join(pkg, "manifest.json"), "utf8"),
|
|
);
|
|
for (const [file, hash] of Object.entries(manifest.files))
|
|
assert.equal(
|
|
createHash("sha256")
|
|
.update(await readFile(path.join(pkg, file)))
|
|
.digest("hex"),
|
|
hash,
|
|
file,
|
|
);
|
|
const api = await import(pathToFileURL(path.join(pkg, "runtime/index.js")));
|
|
for (const name of [
|
|
"mountMarkdown",
|
|
"mountCodeEditor",
|
|
"mountChart",
|
|
"mountMiniLog",
|
|
"mountMobileDock",
|
|
])
|
|
assert.equal(typeof api[name], "function");
|
|
assert.equal(install().status, 1, "Must refuse an implicit overwrite");
|
|
console.log(
|
|
"Skill portability: temporary project install, bundled hashes/runtime and overwrite protection passed",
|
|
);
|