skill-dir-manager.test.js
2.11 KB
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
/**
* Unit Tests — skill-dir-manager.js
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import fs from 'fs';
import path from 'path';
describe('skill-dir-manager', () => {
let dirManager;
const TEST_CODE_DIR = '/tmp/test-sdm-code';
const TEST_DATA_DIR = '/tmp/test-sdm-data';
beforeAll(() => {
fs.mkdirSync(TEST_CODE_DIR, { recursive: true });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
fs.mkdirSync(path.join(TEST_DATA_DIR, 'my-test-skill'), { recursive: true });
fs.writeFileSync(path.join(TEST_DATA_DIR, 'my-test-skill', 'SKILL.md'), '# Test');
process.env.SKILLS_CODE_DIR = TEST_CODE_DIR;
process.env.SKILLS_DATA_DIR = TEST_DATA_DIR;
delete require.cache[require.resolve('../../config')];
delete require.cache[require.resolve('../../services/skill-dir-manager')];
dirManager = require('../../services/skill-dir-manager');
});
afterAll(() => {
try { fs.rmSync(TEST_CODE_DIR, { recursive: true }); } catch {}
try { fs.rmSync(TEST_DATA_DIR, { recursive: true }); } catch {}
});
describe('resolveSkillDir', () => {
it('should resolve a skill directory that exists in data dir', () => {
const dir = dirManager.resolveSkillDir('my-test-skill');
expect(dir).toBeDefined();
expect(dir).toContain('my-test-skill');
});
it('should return null for non-existent skill', () => {
const dir = dirManager.resolveSkillDir('nonexistent_skill_xyz_abc');
expect(dir).toBeNull();
});
});
describe('exported functions', () => {
it('should export resolveSkillDir', () => {
expect(typeof dirManager.resolveSkillDir).toBe('function');
});
it('should export isCodeSkill', () => {
expect(typeof dirManager.isCodeSkill).toBe('function');
});
it('should export getTargetDir', () => {
expect(typeof dirManager.getTargetDir).toBe('function');
});
it('should export initSkillDir', () => {
expect(typeof dirManager.initSkillDir).toBe('function');
});
it('should export ensureDataDirs', () => {
expect(typeof dirManager.ensureDataDirs).toBe('function');
});
});
});