@@ -0,0 +1,105 @@
1+import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3+import { tmpdir } from "node:os";
4+import { join } from "node:path";
5+import { loadMarkdownConfigs } from "./load-markdown-configs.ts";
6+
7+let dir: string;
8+
9+beforeEach(() => {
10+ dir = mkdtempSync(join(tmpdir(), "mc-load-markdown-configs-test-"));
11+});
12+
13+afterEach(() => {
14+ rmSync(dir, { recursive: true, force: true });
15+});
16+
17+function writeFileAt(parts: string[], content: string): void {
18+ const filePath = join(dir, ...parts);
19+ mkdirSync(join(filePath, ".."), { recursive: true });
20+ writeFileSync(filePath, content);
21+}
22+
23+function createDirAt(parts: string[]): void {
24+ mkdirSync(join(dir, ...parts), { recursive: true });
25+}
26+
27+function nextName(prefix: string): string {
28+ return `${prefix}-${Math.random().toString(36).slice(2)}`;
29+}
30+
31+describe("loadMarkdownConfigs", () => {
32+ test("ignores local .claude dirs when disabled", () => {
33+ const name = nextName("flat-disabled");
34+ writeFileAt([".claude", "commands", `${name}.md`], "from claude");
35+
36+ const configs = loadMarkdownConfigs({
37+ type: "commands",
38+ strategy: "flat",
39+ cwd: dir,
40+ includeClaudeDirs: false,
41+ mapConfig: ({ body, source }) => ({ body, source }),
42+ });
43+
44+ expect(configs.get(name)).toBeUndefined();
45+ });
46+
47+ test("prefers local .agents over local .claude with the same name", () => {
48+ const name = nextName("flat-precedence");
49+ writeFileAt([".claude", "commands", `${name}.md`], "from claude");
50+ writeFileAt([".agents", "commands", `${name}.md`], "from agents");
51+
52+ const configs = loadMarkdownConfigs({
53+ type: "commands",
54+ strategy: "flat",
55+ cwd: dir,
56+ includeClaudeDirs: true,
57+ mapConfig: ({ body, source }) => ({ body, source }),
58+ });
59+
60+ expect(configs.get(name)).toEqual({ body: "from agents", source: "local" });
61+ });
62+
63+ test("uses frontmatter name for nested configs", () => {
64+ const folderName = nextName("folder");
65+ const configName = nextName("skill");
66+ writeFileAt(
67+ [".agents", "skills", folderName, "SKILL.md"],
68+ `---\nname: ${configName}\ndescription: Test skill\n---\n\nBody`,
69+ );
70+
71+ const configs = loadMarkdownConfigs({
72+ type: "skills",
73+ strategy: "nested",
74+ nestedFileName: "SKILL.md",
75+ cwd: dir,
76+ includeClaudeDirs: false,
77+ mapConfig: ({ name, body, source }) => ({ name, body, source }),
78+ });
79+
80+ expect(configs.has(folderName)).toBe(false);
81+ expect(configs.get(configName)).toEqual({
82+ name: configName,
83+ body: "Body",
84+ source: "local",
85+ });
86+ });
87+
88+ test("skips directory entries that look like markdown files", () => {
89+ const badName = `${nextName("bad")}.md`;
90+ const goodName = nextName("good");
91+ createDirAt([".agents", "commands", badName]);
92+ writeFileAt([".agents", "commands", `${goodName}.md`], "ok");
93+
94+ const configs = loadMarkdownConfigs({
95+ type: "commands",
96+ strategy: "flat",
97+ cwd: dir,
98+ includeClaudeDirs: false,
99+ mapConfig: ({ body }) => body,
100+ });
101+
102+ expect(configs.get(goodName)).toBe("ok");
103+ expect(configs.has(badName.slice(0, -3))).toBe(false);
104+ });
105+});