Skip to content

Commit 50c1a49

Browse files
committed
fix: make interactive-selector tests resilient to ~/.ma files
Tests now filter to only relevant sources (cwd, test PATH dirs) instead of expecting exact file counts, since ~/.ma may contain user's agent files during test runs.
1 parent 79332b5 commit 50c1a49

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

src/interactive-selector.test.ts

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ describe("findAgentFiles", () => {
4646

4747
const files = await findAgentFiles();
4848

49-
expect(files.length).toBe(2);
50-
expect(files.map(f => f.name).sort()).toEqual(["agent1.md", "agent2.md"]);
51-
expect(files.every(f => f.source === "cwd")).toBe(true);
49+
// Filter to only cwd files (ignoring ~/.ma files that may exist on user's system)
50+
const cwdFiles = files.filter(f => f.source === "cwd");
51+
expect(cwdFiles.length).toBe(2);
52+
expect(cwdFiles.map(f => f.name).sort()).toEqual(["agent1.md", "agent2.md"]);
5253
});
5354

5455
test("finds .md files in PATH directories", async () => {
@@ -67,9 +68,11 @@ describe("findAgentFiles", () => {
6768

6869
const files = await findAgentFiles();
6970

70-
expect(files.length).toBe(1);
71-
expect(files[0].name).toBe("global-agent.md");
72-
expect(files[0].source).toBe(pathDir);
71+
// Filter to only PATH files (ignoring ~/.ma files that may exist)
72+
const pathFiles = files.filter(f => f.source === pathDir);
73+
expect(pathFiles.length).toBe(1);
74+
expect(pathFiles[0].name).toBe("global-agent.md");
75+
expect(pathFiles[0].source).toBe(pathDir);
7376
});
7477

7578
test("deduplicates files that appear in both cwd and PATH", async () => {
@@ -81,13 +84,16 @@ describe("findAgentFiles", () => {
8184

8285
const files = await findAgentFiles();
8386

87+
// Filter to files from cwd or PATH only (ignoring ~/.ma files)
88+
const relevantFiles = files.filter(f => f.source === "cwd" || f.source === testDir);
89+
8490
// Should only appear once (from cwd, since we scan that first)
85-
expect(files.length).toBe(1);
86-
expect(files[0].name).toBe("shared-agent.md");
87-
expect(files[0].source).toBe("cwd");
91+
expect(relevantFiles.length).toBe(1);
92+
expect(relevantFiles[0].name).toBe("shared-agent.md");
93+
expect(relevantFiles[0].source).toBe("cwd");
8894
});
8995

90-
test("returns empty array when no .md files exist", async () => {
96+
test("returns empty array when no .md files exist in cwd or PATH", async () => {
9197
// Empty directory
9298
const emptyDir = join(testDir, "empty");
9399
mkdirSync(emptyDir, { recursive: true });
@@ -97,7 +103,9 @@ describe("findAgentFiles", () => {
97103

98104
const files = await findAgentFiles();
99105

100-
expect(files).toEqual([]);
106+
// Filter out ~/.ma and .ma files - test only checks cwd and PATH are empty
107+
const cwdOrPathFiles = files.filter(f => f.source === "cwd");
108+
expect(cwdOrPathFiles).toEqual([]);
101109
});
102110

103111
test("handles non-existent PATH directories gracefully", async () => {
@@ -110,7 +118,9 @@ describe("findAgentFiles", () => {
110118

111119
// Should not throw
112120
const files = await findAgentFiles();
113-
expect(files).toEqual([]);
121+
// Filter out ~/.ma and .ma files - test only checks non-existent PATH is handled
122+
const cwdOrPathFiles = files.filter(f => f.source === "cwd");
123+
expect(cwdOrPathFiles).toEqual([]);
114124
});
115125

116126
test("combines files from cwd and multiple PATH directories", async () => {
@@ -132,13 +142,18 @@ describe("findAgentFiles", () => {
132142

133143
const files = await findAgentFiles();
134144

135-
expect(files.length).toBe(3);
136-
expect(files.map(f => f.name).sort()).toEqual(["global1.md", "global2.md", "local.md"]);
145+
// Filter to only cwd and our test PATH directories (ignoring ~/.ma files)
146+
const relevantFiles = files.filter(f =>
147+
f.source === "cwd" || f.source === pathDir1 || f.source === pathDir2
148+
);
149+
150+
expect(relevantFiles.length).toBe(3);
151+
expect(relevantFiles.map(f => f.name).sort()).toEqual(["global1.md", "global2.md", "local.md"]);
137152

138153
// Verify sources
139-
const localFile = files.find(f => f.name === "local.md");
140-
const global1File = files.find(f => f.name === "global1.md");
141-
const global2File = files.find(f => f.name === "global2.md");
154+
const localFile = relevantFiles.find(f => f.name === "local.md");
155+
const global1File = relevantFiles.find(f => f.name === "global1.md");
156+
const global2File = relevantFiles.find(f => f.name === "global2.md");
142157

143158
expect(localFile?.source).toBe("cwd");
144159
expect(global1File?.source).toBe(pathDir1);
@@ -154,8 +169,10 @@ describe("findAgentFiles", () => {
154169

155170
// Should not throw
156171
const files = await findAgentFiles();
157-
expect(files.length).toBe(1);
158-
expect(files[0].name).toBe("agent.md");
172+
// Filter to only cwd files (ignoring ~/.ma files)
173+
const cwdFiles = files.filter(f => f.source === "cwd");
174+
expect(cwdFiles.length).toBe(1);
175+
expect(cwdFiles[0].name).toBe("agent.md");
159176
});
160177
});
161178

0 commit comments

Comments
 (0)