-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathskill-config-loader.test.js
More file actions
149 lines (138 loc) · 5.02 KB
/
Copy pathskill-config-loader.test.js
File metadata and controls
149 lines (138 loc) · 5.02 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
import yaml from 'js-yaml';
import { loadSkillsConfig } from '../skill-generator.js';
function createFixture(tree, baseDir) {
for (const [name, content] of Object.entries(tree)) {
const fullPath = join(baseDir, name);
if (typeof content === 'string') {
writeFileSync(fullPath, content);
} else {
mkdirSync(fullPath, { recursive: true });
createFixture(content, fullPath);
}
}
}
describe('loadSkillsConfig', () => {
let tmpDir;
beforeEach(() => {
tmpDir = mkdtempSync(join(tmpdir(), 'skills-test-'));
mkdirSync(join(tmpDir, 'skills'));
});
afterEach(() => rmSync(tmpDir, { recursive: true, force: true }));
it('discovers a flat config with variants', () => {
createFixture({
skills: {
integration: {
'config.yaml': yaml.dump({
type: 'example',
template: 'description.md',
variants: [{ id: 'django', display_name: 'Django' }],
}),
},
},
}, tmpDir);
const config = loadSkillsConfig(tmpDir);
expect(Object.keys(config)).toEqual(['integration']);
expect(config['integration'].variants).toHaveLength(1);
expect(config['integration'].type).toBe('example');
});
it('skips configs without variants', () => {
createFixture({
skills: {
'no-variants': {
'config.yaml': yaml.dump({
type: 'docs-only',
tags: ['test'],
}),
},
},
}, tmpDir);
const config = loadSkillsConfig(tmpDir);
expect(Object.keys(config)).toEqual([]);
});
it('discovers nested configs independently (no inheritance)', () => {
createFixture({
skills: {
'feature-flags': {
'config.yaml': yaml.dump({
type: 'docs-only',
tags: ['feature-flags'],
}),
installation: {
'config.yaml': yaml.dump({
type: 'docs-only',
tags: ['feature-flags', 'installation'],
variants: [{ id: 'react', display_name: 'React' }],
}),
},
},
},
}, tmpDir);
const config = loadSkillsConfig(tmpDir);
expect(Object.keys(config)).toEqual(['feature-flags/installation']);
const leaf = config['feature-flags/installation'];
expect(leaf.type).toBe('docs-only');
expect(leaf.tags).toEqual(['feature-flags', 'installation']);
expect(leaf.variants).toHaveLength(1);
});
it('discovers configs at arbitrary depth', () => {
createFixture({
skills: {
a: {
b: { c: { d: {
'config.yaml': yaml.dump({
type: 'docs-only',
variants: [{ id: 'deep', display_name: 'Deep' }],
}),
}}},
},
},
}, tmpDir);
const config = loadSkillsConfig(tmpDir);
expect(Object.keys(config)).toEqual(['a/b/c/d']);
expect(config['a/b/c/d'].type).toBe('docs-only');
});
it('ignores directories without config.yaml', () => {
createFixture({
skills: {
'empty-dir': {},
'has-config': {
'config.yaml': yaml.dump({
variants: [{ id: 'x', display_name: 'X' }],
}),
},
},
}, tmpDir);
const config = loadSkillsConfig(tmpDir);
expect(Object.keys(config)).toEqual(['has-config']);
});
it('handles flat and nested siblings', () => {
createFixture({
skills: {
integration: {
'config.yaml': yaml.dump({
type: 'example',
variants: [{ id: 'django', display_name: 'Django' }],
}),
},
'feature-flags': {
installation: {
'config.yaml': yaml.dump({
type: 'docs-only',
tags: ['feature-flags', 'installation'],
variants: [{ id: 'react', display_name: 'React' }],
}),
},
},
},
}, tmpDir);
const config = loadSkillsConfig(tmpDir);
expect(Object.keys(config).sort()).toEqual([
'feature-flags/installation',
'integration',
]);
});
});