File size: 2,879 Bytes
031fd6d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import { describe, it, expect } from "vitest";
import { parsers } from "../src/parsers/index.js";
import { generateConfig, outputFileFor } from "../src/migrator/generate.js";
import type { Rule, AgentKind } from "../src/core/types.js";
const AGENTS = Object.keys(parsers) as AgentKind[];
/** Build one canonical rule set to migrate between every pair. */
function sampleRules(agent: AgentKind): Rule[] {
return [
{ id: "r1", category: "style", content: "Use TypeScript strict mode", scope: "project", source: { agent, file: "x" }, status: "active" },
{ id: "r2", category: "constraint", content: "Never commit secrets to the repository", scope: "project", source: { agent, file: "x" }, status: "active" },
{ id: "r3", category: "workflow", content: "Run tests before every commit", scope: "project", source: { agent, file: "x" }, status: "active" },
{ id: "r4", category: "tooling", content: "Use pnpm as the package manager", scope: "project", source: { agent, file: "x" }, status: "active" },
];
}
describe("full migration matrix — every agent pair produces valid output", () => {
for (const from of AGENTS) {
for (const to of AGENTS) {
it(`${from} → ${to}`, () => {
const rules = sampleRules(from);
const output = generateConfig(rules, to);
// Output must be non-empty and contain every rule body.
expect(output.trim().length).toBeGreaterThan(0);
for (const r of rules) {
expect(output).toContain(r.content);
}
// Every target resolves to a concrete file path.
const file = outputFileFor(to);
expect(file.length).toBeGreaterThan(0);
});
}
}
});
describe("round-trip: parse(output) recovers the same rule bodies", () => {
for (const from of AGENTS) {
for (const to of AGENTS) {
it(`${from} → ${to} → parse`, () => {
const rules = sampleRules(from);
const output = generateConfig(rules, to);
const file = outputFileFor(to);
const reparsed = parsers[to].parse(output, file);
const bodies = reparsed.map((r) => r.content);
for (const r of rules) {
expect(bodies.some((b) => b.includes(r.content) || r.content.includes(b))).toBe(true);
}
});
}
}
});
describe("output files per agent", () => {
it("shared AGENTS.md for codex/dsh/workbuddy/zcode/mimo", () => {
for (const a of ["codex", "dsh", "workbuddy", "zcode", "mimo"] as AgentKind[]) {
expect(outputFileFor(a)).toBe("AGENTS.md");
}
});
it("distinct files for claude/cursor/windsurf/copilot", () => {
expect(outputFileFor("claude")).toBe("CLAUDE.md");
expect(outputFileFor("cursor")).toBe(".cursor/rules/agentlens.mdc");
expect(outputFileFor("windsurf")).toBe(".windsurfrules");
expect(outputFileFor("copilot")).toBe(".github/copilot-instructions.md");
});
});
|