Files
Ra3ModXmlExt/test/agentSkill.test.mjs
T
2026-09-10 19:18:15 +02:00

104 lines
4.2 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import {
SKILL_MARKER_FILE,
installSkillToDirectories,
readSkillInstallRecord,
uninstallSkillFromDirectory,
writeSkillTo,
} from "../out/agent/skill.js";
test("writeSkillTo creates SKILL.md and avoids project-doc noise", async () => {
const dir = mkdtempSync(join(tmpdir(), "ra3-skill-test-"));
try {
const skillDir = join(dir, "ra3-mod-xml");
await writeSkillTo(skillDir, "0.1.25");
assert.ok(existsSync(join(skillDir, "SKILL.md")));
assert.ok(existsSync(join(skillDir, "references", "query-guide.md")));
assert.ok(existsSync(join(skillDir, SKILL_MARKER_FILE)));
const content = readFileSync(join(skillDir, "SKILL.md"), "utf8");
assert.ok(content.includes("find_asset"));
assert.ok(!content.includes("codebase-navigation-guide"));
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test("SKILL.md scopes itself to SAGE/RA3 projects and warns off others", async () => {
const dir = mkdtempSync(join(tmpdir(), "ra3-skill-scope-"));
try {
const skillDir = join(dir, "ra3-mod-xml");
await writeSkillTo(skillDir, "0.1.25");
const content = readFileSync(join(skillDir, "SKILL.md"), "utf8");
// Must state its applicability and list concrete positive signals.
assert.match(content, /When this skill applies/);
assert.ok(content.includes("Data/Mod.xml"));
assert.ok(content.includes("babproj"));
assert.ok(content.includes("AssetDeclaration"));
// Must give an explicit negative rule and a cheap probe.
assert.match(content, /Do \*\*not\*\* use these tools for unrelated repositories/);
assert.ok(content.includes("get_status"));
assert.ok(content.includes("projectDir"));
// The CnC3 red herring is called out explicitly.
assert.ok(content.includes("CnC3Types.xsd"));
assert.ok(content.includes("C&C3"));
// Second-phase capability must be documented.
assert.ok(content.includes("get_asset_references"));
assert.ok(content.includes("definedIn"));
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test("SKILL.md explains how to reach the index without MCP", async () => {
const dir = mkdtempSync(join(tmpdir(), "ra3-skill-reach-"));
try {
const skillDir = join(dir, "ra3-mod-xml");
await writeSkillTo(skillDir, "0.1.25");
const content = readFileSync(join(skillDir, "SKILL.md"), "utf8");
assert.match(content, /## Reaching the index/);
// The discovery manifest is the stable entry point.
assert.ok(content.includes("~/.ra3modxml/index.json"));
// The launcher and the bundled CLI are both mentioned.
assert.ok(content.includes("ra3-mod-xml-mcp"));
assert.ok(content.includes("cli.js"));
// The stdio escape hatch must be shown, since it needs no setup at all.
assert.ok(content.includes("tools/call"));
// It must not pretend configuring a client takes effect immediately.
assert.ok(content.includes("new session"));
// And it must refuse to invent results.
assert.match(content, /Never fabricate index results/);
// Instructions must not send it looking for project-specific docs.
assert.equal(content.includes("codebase-navigation-guide"), false);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test("installSkillToDirectories records managed copies and uninstall removes them", async () => {
const home = mkdtempSync(join(tmpdir(), "ra3-skill-home-"));
const dir = mkdtempSync(join(tmpdir(), "ra3-skill-target-"));
try {
const target = join(dir, "ra3-mod-xml");
const succeeded = await installSkillToDirectories([target], "0.1.25", home);
assert.deepEqual(succeeded, [target]);
const record = await readSkillInstallRecord(home);
assert.equal(record.length, 1);
assert.equal(record[0].path, target);
await uninstallSkillFromDirectory(target, home);
assert.equal(existsSync(target), false);
assert.equal((await readSkillInstallRecord(home)).length, 0);
} finally {
rmSync(home, { recursive: true, force: true });
rmSync(dir, { recursive: true, force: true });
}
});