Skip to content

Commit d9fdf7b

Browse files
committed
test(cli): isolate skill removal cache fixtures
1 parent 5e41ad4 commit d9fdf7b

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

tests/unit/cli/skill-removal.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import { join } from 'node:path';
55
import { load, dump } from 'js-yaml';
66
import { removeInstalledSkill } from '../../../src/cli/skill-removal.js';
77
import type { WorkspaceConfig } from '../../../src/models/workspace-config.js';
8-
import type { SkillInfo } from '../../../src/core/skills.js';
8+
import {
9+
getAllSkillsFromPlugins,
10+
type SkillInfo,
11+
} from '../../../src/core/skills.js';
912
import { resetFetchCache } from '../../../src/core/plugin.js';
13+
import { stubHomeDir } from '../../helpers/env.js';
1014

1115
describe('removeInstalledSkill', () => {
1216
let tmpDir: string;
@@ -164,8 +168,8 @@ describe('removeInstalledSkill', () => {
164168
});
165169

166170
it('removes a single-skill GitHub source instead of leaving an empty allowlist', async () => {
167-
const originalHome = process.env.HOME;
168171
const fakeHome = join(tmpDir, 'home');
172+
const restoreHomeDir = stubHomeDir(fakeHome);
169173
const pluginDir = join(
170174
fakeHome,
171175
'.allagents/plugins/marketplaces/NousResearch-hermes-agent@main/skills/research/llm-wiki',
@@ -185,10 +189,16 @@ describe('removeInstalledSkill', () => {
185189
};
186190
await writeFile(join(tmpDir, '.allagents/workspace.yaml'), dump(config), 'utf-8');
187191

188-
process.env.HOME = fakeHome;
189192
resetFetchCache();
190193

191194
try {
195+
const discoveredSkills = await getAllSkillsFromPlugins(tmpDir);
196+
expect(
197+
discoveredSkills.map(({ name, pluginSource, path }) => ({ name, pluginSource, path })),
198+
).toEqual([
199+
{ name: 'llm-wiki', pluginSource: source, path: pluginDir },
200+
]);
201+
192202
const result = await removeInstalledSkill({
193203
targetSkill: {
194204
name: 'llm-wiki',
@@ -206,7 +216,7 @@ describe('removeInstalledSkill', () => {
206216
const updated = load(content) as WorkspaceConfig;
207217
expect(updated.plugins).toEqual([]);
208218
} finally {
209-
process.env.HOME = originalHome;
219+
restoreHomeDir();
210220
resetFetchCache();
211221
}
212222
});

tests/unit/core/skills.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { mkdtemp, rm, mkdir, writeFile, symlink } from 'node:fs/promises';
33
import { tmpdir } from 'node:os';
44
import { join } from 'node:path';
55
import { dump } from 'js-yaml';
6+
import { stubHomeDir } from '../../helpers/env.js';
67
import {
78
getAllSkillsFromPlugins,
89
discoverNestedSkillEntries,
910
type SkillInfo,
1011
} from '../../../src/core/skills.js';
12+
import { resetFetchCache } from '../../../src/core/plugin.js';
1113
import { getPluginCachePath } from '../../../src/utils/plugin-path.js';
1214

1315
describe('getAllSkillsFromPlugins', () => {
@@ -224,23 +226,33 @@ describe('getAllSkillsFromPlugins', () => {
224226
});
225227

226228
it('skips GitHub URL entries whose subpath no longer exists in cache', async () => {
227-
const originalHome = process.env.HOME;
228-
process.env.HOME = tmpDir;
229+
const restoreHomeDir = stubHomeDir(tmpDir);
230+
resetFetchCache();
229231
try {
230232
const cachePath = getPluginCachePath('owner', 'repo', 'main');
231-
await mkdir(cachePath, { recursive: true });
233+
const siblingPath = join(cachePath, 'available');
234+
await mkdir(siblingPath, { recursive: true });
235+
await writeFile(join(siblingPath, 'SKILL.md'), '# Cached sibling');
236+
237+
const missingSource = 'https://github.com/owner/repo/tree/main/missing/path';
238+
const siblingSource = 'https://github.com/owner/repo/tree/main/available';
232239

233240
const config = {
234241
repositories: [],
235-
plugins: ['https://github.com/owner/repo/tree/main/missing/path'],
242+
plugins: [missingSource, siblingSource],
236243
clients: ['claude'],
237244
};
238245
await writeFile(join(tmpDir, '.allagents/workspace.yaml'), dump(config));
239246

240247
const skills = await getAllSkillsFromPlugins(tmpDir);
241-
expect(skills).toEqual([]);
248+
expect(
249+
skills.map(({ name, pluginSource, path }) => ({ name, pluginSource, path })),
250+
).toEqual([
251+
{ name: 'available', pluginSource: siblingSource, path: siblingPath },
252+
]);
242253
} finally {
243-
process.env.HOME = originalHome;
254+
restoreHomeDir();
255+
resetFetchCache();
244256
}
245257
});
246258
});

0 commit comments

Comments
 (0)