@productbrain/cli 0.1.0-beta.11522 → 0.1.0-beta.11527
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/commands/scoreboard.d.ts +1 -1
- package/dist/commands/scoreboard.d.ts.map +1 -1
- package/dist/commands/scoreboard.js +3 -2
- package/dist/commands/scoreboard.js.map +1 -1
- package/dist/commands/scoreboard.test.d.ts +2 -0
- package/dist/commands/scoreboard.test.d.ts.map +1 -0
- package/dist/commands/scoreboard.test.js +54 -0
- package/dist/commands/scoreboard.test.js.map +1 -0
- package/dist/formatters/scoreboard.test.js +0 -1
- package/dist/formatters/scoreboard.test.js.map +1 -1
- package/dist/lib/ruleListRender.d.ts +0 -5
- package/dist/lib/ruleListRender.d.ts.map +1 -1
- package/dist/lib/ruleListRender.js +1 -26
- package/dist/lib/ruleListRender.js.map +1 -1
- package/dist/scoreboard/diagnose.d.ts +0 -6
- package/dist/scoreboard/diagnose.d.ts.map +1 -1
- package/dist/scoreboard/diagnose.js +1 -1
- package/dist/scoreboard/diagnose.js.map +1 -1
- package/dist/scoreboard/diagnose.test.js +0 -1
- package/dist/scoreboard/diagnose.test.js.map +1 -1
- package/package.json +1 -1
- package/dist/__tests__/adapters.test.d.ts +0 -2
- package/dist/__tests__/adapters.test.d.ts.map +0 -1
- package/dist/__tests__/adapters.test.js +0 -443
- package/dist/__tests__/adapters.test.js.map +0 -1
- package/dist/__tests__/batch-transformations.test.d.ts +0 -2
- package/dist/__tests__/batch-transformations.test.d.ts.map +0 -1
- package/dist/__tests__/batch-transformations.test.js +0 -239
- package/dist/__tests__/batch-transformations.test.js.map +0 -1
- package/dist/__tests__/hook-intents.test.d.ts +0 -2
- package/dist/__tests__/hook-intents.test.d.ts.map +0 -1
- package/dist/__tests__/hook-intents.test.js +0 -172
- package/dist/__tests__/hook-intents.test.js.map +0 -1
- package/dist/__tests__/manifest.test.d.ts +0 -6
- package/dist/__tests__/manifest.test.d.ts.map +0 -1
- package/dist/__tests__/manifest.test.js +0 -255
- package/dist/__tests__/manifest.test.js.map +0 -1
- package/dist/__tests__/perimeter.test.d.ts +0 -2
- package/dist/__tests__/perimeter.test.d.ts.map +0 -1
- package/dist/__tests__/perimeter.test.js +0 -165
- package/dist/__tests__/perimeter.test.js.map +0 -1
- package/dist/__tests__/personal-layer.test.d.ts +0 -11
- package/dist/__tests__/personal-layer.test.d.ts.map +0 -1
- package/dist/__tests__/personal-layer.test.js +0 -268
- package/dist/__tests__/personal-layer.test.js.map +0 -1
- package/dist/__tests__/surface-profiles.test.d.ts +0 -2
- package/dist/__tests__/surface-profiles.test.d.ts.map +0 -1
- package/dist/__tests__/surface-profiles.test.js +0 -233
- package/dist/__tests__/surface-profiles.test.js.map +0 -1
- package/dist/__tests__/surfaces.test.d.ts +0 -2
- package/dist/__tests__/surfaces.test.d.ts.map +0 -1
- package/dist/__tests__/surfaces.test.js +0 -45
- package/dist/__tests__/surfaces.test.js.map +0 -1
- package/dist/generators/adapters.d.ts +0 -77
- package/dist/generators/adapters.d.ts.map +0 -1
- package/dist/generators/adapters.js +0 -286
- package/dist/generators/adapters.js.map +0 -1
- package/dist/generators/adapters.test.d.ts +0 -2
- package/dist/generators/adapters.test.d.ts.map +0 -1
- package/dist/generators/adapters.test.js +0 -36
- package/dist/generators/adapters.test.js.map +0 -1
- package/dist/generators/boundary-manifest.d.ts +0 -29
- package/dist/generators/boundary-manifest.d.ts.map +0 -1
- package/dist/generators/boundary-manifest.js +0 -183
- package/dist/generators/boundary-manifest.js.map +0 -1
- package/dist/generators/boundary-manifest.test.d.ts +0 -2
- package/dist/generators/boundary-manifest.test.d.ts.map +0 -1
- package/dist/generators/boundary-manifest.test.js +0 -91
- package/dist/generators/boundary-manifest.test.js.map +0 -1
- package/dist/generators/briefing-projections.test.d.ts +0 -2
- package/dist/generators/briefing-projections.test.d.ts.map +0 -1
- package/dist/generators/briefing-projections.test.js +0 -71
- package/dist/generators/briefing-projections.test.js.map +0 -1
- package/dist/generators/manifest.d.ts +0 -115
- package/dist/generators/manifest.d.ts.map +0 -1
- package/dist/generators/manifest.js +0 -277
- package/dist/generators/manifest.js.map +0 -1
- package/dist/generators/noProjectionAssets.d.ts +0 -15
- package/dist/generators/noProjectionAssets.d.ts.map +0 -1
- package/dist/generators/noProjectionAssets.js +0 -6
- package/dist/generators/noProjectionAssets.js.map +0 -1
- package/dist/generators/portable-knowledge.d.ts +0 -142
- package/dist/generators/portable-knowledge.d.ts.map +0 -1
- package/dist/generators/portable-knowledge.js +0 -482
- package/dist/generators/portable-knowledge.js.map +0 -1
- package/dist/generators/portable-knowledge.test.d.ts +0 -2
- package/dist/generators/portable-knowledge.test.d.ts.map +0 -1
- package/dist/generators/portable-knowledge.test.js +0 -742
- package/dist/generators/portable-knowledge.test.js.map +0 -1
- package/dist/generators/region-projections.d.ts +0 -17
- package/dist/generators/region-projections.d.ts.map +0 -1
- package/dist/generators/region-projections.js +0 -51
- package/dist/generators/region-projections.js.map +0 -1
- package/dist/generators/region-projections.test.d.ts +0 -2
- package/dist/generators/region-projections.test.d.ts.map +0 -1
- package/dist/generators/region-projections.test.js +0 -58
- package/dist/generators/region-projections.test.js.map +0 -1
- package/dist/generators/region.d.ts +0 -24
- package/dist/generators/region.d.ts.map +0 -1
- package/dist/generators/region.js +0 -87
- package/dist/generators/region.js.map +0 -1
- package/dist/generators/region.test.d.ts +0 -2
- package/dist/generators/region.test.d.ts.map +0 -1
- package/dist/generators/region.test.js +0 -125
- package/dist/generators/region.test.js.map +0 -1
- package/dist/generators/surface-profiles.d.ts +0 -48
- package/dist/generators/surface-profiles.d.ts.map +0 -1
- package/dist/generators/surface-profiles.js +0 -98
- package/dist/generators/surface-profiles.js.map +0 -1
- package/dist/lib/frontmatter.d.ts +0 -55
- package/dist/lib/frontmatter.d.ts.map +0 -1
- package/dist/lib/frontmatter.js +0 -92
- package/dist/lib/frontmatter.js.map +0 -1
- package/dist/lib/frontmatter.test.d.ts +0 -15
- package/dist/lib/frontmatter.test.d.ts.map +0 -1
- package/dist/lib/frontmatter.test.js +0 -98
- package/dist/lib/frontmatter.test.js.map +0 -1
- package/dist/lib/hook-intents.d.ts +0 -56
- package/dist/lib/hook-intents.d.ts.map +0 -1
- package/dist/lib/hook-intents.js +0 -84
- package/dist/lib/hook-intents.js.map +0 -1
- package/dist/lib/writePerimeter.d.ts +0 -72
- package/dist/lib/writePerimeter.d.ts.map +0 -1
- package/dist/lib/writePerimeter.js +0 -128
- package/dist/lib/writePerimeter.js.map +0 -1
- package/dist/surfaces/__tests__/adapter.test.d.ts +0 -2
- package/dist/surfaces/__tests__/adapter.test.d.ts.map +0 -1
- package/dist/surfaces/__tests__/adapter.test.js +0 -86
- package/dist/surfaces/__tests__/adapter.test.js.map +0 -1
- package/dist/surfaces/__tests__/claude-skill-pointer-drift.test.d.ts +0 -2
- package/dist/surfaces/__tests__/claude-skill-pointer-drift.test.d.ts.map +0 -1
- package/dist/surfaces/__tests__/claude-skill-pointer-drift.test.js +0 -180
- package/dist/surfaces/__tests__/claude-skill-pointer-drift.test.js.map +0 -1
- package/dist/surfaces/__tests__/telemetry.test.d.ts +0 -2
- package/dist/surfaces/__tests__/telemetry.test.d.ts.map +0 -1
- package/dist/surfaces/__tests__/telemetry.test.js +0 -44
- package/dist/surfaces/__tests__/telemetry.test.js.map +0 -1
- package/dist/surfaces/adapter.d.ts +0 -70
- package/dist/surfaces/adapter.d.ts.map +0 -1
- package/dist/surfaces/adapter.js +0 -2
- package/dist/surfaces/adapter.js.map +0 -1
- package/dist/surfaces/adapters/claude.d.ts +0 -3
- package/dist/surfaces/adapters/claude.d.ts.map +0 -1
- package/dist/surfaces/adapters/claude.js +0 -72
- package/dist/surfaces/adapters/claude.js.map +0 -1
- package/dist/surfaces/adapters/codex.d.ts +0 -3
- package/dist/surfaces/adapters/codex.d.ts.map +0 -1
- package/dist/surfaces/adapters/codex.js +0 -61
- package/dist/surfaces/adapters/codex.js.map +0 -1
- package/dist/surfaces/adapters/copilot.d.ts +0 -3
- package/dist/surfaces/adapters/copilot.d.ts.map +0 -1
- package/dist/surfaces/adapters/copilot.js +0 -59
- package/dist/surfaces/adapters/copilot.js.map +0 -1
- package/dist/surfaces/adapters/cursor.d.ts +0 -3
- package/dist/surfaces/adapters/cursor.d.ts.map +0 -1
- package/dist/surfaces/adapters/cursor.js +0 -78
- package/dist/surfaces/adapters/cursor.js.map +0 -1
- package/dist/surfaces/registry.d.ts +0 -76
- package/dist/surfaces/registry.d.ts.map +0 -1
- package/dist/surfaces/registry.js +0 -117
- package/dist/surfaces/registry.js.map +0 -1
- package/dist/surfaces/telemetry.d.ts +0 -24
- package/dist/surfaces/telemetry.d.ts.map +0 -1
- package/dist/surfaces/telemetry.js +0 -25
- package/dist/surfaces/telemetry.js.map +0 -1
|
@@ -1,742 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* portable-knowledge — unit tests.
|
|
3
|
-
* BET-169: transport-aware skill dispatch, target filtering, and transport section stripping.
|
|
4
|
-
*/
|
|
5
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
// vi.mock calls are hoisted — use vi.hoisted() for constants referenced inside factories.
|
|
8
|
-
const { vfs } = vi.hoisted(() => ({
|
|
9
|
-
vfs: {},
|
|
10
|
-
}));
|
|
11
|
-
vi.mock('fs', () => ({
|
|
12
|
-
mkdirSync: vi.fn(),
|
|
13
|
-
writeFileSync: vi.fn((path, content) => {
|
|
14
|
-
vfs[path] = content;
|
|
15
|
-
}),
|
|
16
|
-
existsSync: vi.fn((path) => {
|
|
17
|
-
// Check if the path itself or any child key exists (for directory checks)
|
|
18
|
-
if (path in vfs)
|
|
19
|
-
return true;
|
|
20
|
-
// For directory checks: return true if any key starts with path + '/'
|
|
21
|
-
return Object.keys(vfs).some((k) => k.startsWith(path + '/'));
|
|
22
|
-
}),
|
|
23
|
-
readFileSync: vi.fn((path, _enc) => {
|
|
24
|
-
if (path in vfs)
|
|
25
|
-
return vfs[path];
|
|
26
|
-
throw Object.assign(new Error(`ENOENT: no such file '${path}'`), { code: 'ENOENT' });
|
|
27
|
-
}),
|
|
28
|
-
readdirSync: vi.fn((dir) => {
|
|
29
|
-
const prefix = dir.endsWith('/') ? dir : dir + '/';
|
|
30
|
-
const files = new Set();
|
|
31
|
-
for (const key of Object.keys(vfs)) {
|
|
32
|
-
if (key.startsWith(prefix)) {
|
|
33
|
-
const rest = key.slice(prefix.length);
|
|
34
|
-
const parts = rest.split('/');
|
|
35
|
-
if (parts.length === 1)
|
|
36
|
-
files.add(parts[0]);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return [...files];
|
|
40
|
-
}),
|
|
41
|
-
}));
|
|
42
|
-
import { readCanonicalSkills, readCanonicalRules, shouldEmitToTarget, stripTransportSections, filterByLevel, evaluateConditions, generateCursorSkill, generateCursorRule, generateCodexSkill, generateCodexSkillIndex, } from './portable-knowledge.js';
|
|
43
|
-
import { generateCopilotInstructionFiles, MARKER } from './adapters.js';
|
|
44
|
-
const PB_DIR = '/tmp/pb-test/.productbrain';
|
|
45
|
-
describe('readCanonicalSkills', () => {
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
Object.keys(vfs).forEach((k) => delete vfs[k]);
|
|
48
|
-
});
|
|
49
|
-
it('parses targets from frontmatter', () => {
|
|
50
|
-
vfs[join(PB_DIR, 'skills', 'test-skill.md')] = `---
|
|
51
|
-
name: test-skill
|
|
52
|
-
description: A test skill
|
|
53
|
-
triggers:
|
|
54
|
-
- test
|
|
55
|
-
targets:
|
|
56
|
-
- claude
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
# Test Skill Body
|
|
60
|
-
`;
|
|
61
|
-
const skills = readCanonicalSkills(PB_DIR);
|
|
62
|
-
expect(skills).toHaveLength(1);
|
|
63
|
-
expect(skills[0].targets).toEqual(['claude']);
|
|
64
|
-
});
|
|
65
|
-
it('returns undefined targets when not specified in frontmatter', () => {
|
|
66
|
-
vfs[join(PB_DIR, 'skills', 'universal-skill.md')] = `---
|
|
67
|
-
name: universal-skill
|
|
68
|
-
description: A universal skill
|
|
69
|
-
triggers:
|
|
70
|
-
- universal
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
# Universal Skill Body
|
|
74
|
-
`;
|
|
75
|
-
const skills = readCanonicalSkills(PB_DIR);
|
|
76
|
-
expect(skills).toHaveLength(1);
|
|
77
|
-
expect(skills[0].targets).toBeUndefined();
|
|
78
|
-
});
|
|
79
|
-
it('parses multiple targets', () => {
|
|
80
|
-
vfs[join(PB_DIR, 'skills', 'multi-target.md')] = `---
|
|
81
|
-
name: multi-target
|
|
82
|
-
description: Multi-target skill
|
|
83
|
-
triggers:
|
|
84
|
-
- multi
|
|
85
|
-
targets:
|
|
86
|
-
- claude
|
|
87
|
-
- cursor
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
# Multi-Target Body
|
|
91
|
-
`;
|
|
92
|
-
const skills = readCanonicalSkills(PB_DIR);
|
|
93
|
-
expect(skills).toHaveLength(1);
|
|
94
|
-
expect(skills[0].targets).toEqual(['claude', 'cursor']);
|
|
95
|
-
});
|
|
96
|
-
it('parses level from frontmatter', () => {
|
|
97
|
-
vfs[join(PB_DIR, 'skills', 'leveled-skill.md')] = `---
|
|
98
|
-
name: leveled-skill
|
|
99
|
-
description: A leveled skill
|
|
100
|
-
level: core
|
|
101
|
-
triggers:
|
|
102
|
-
- leveled
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
# Leveled Skill Body
|
|
106
|
-
`;
|
|
107
|
-
const skills = readCanonicalSkills(PB_DIR);
|
|
108
|
-
expect(skills).toHaveLength(1);
|
|
109
|
-
expect(skills[0].level).toBe('core');
|
|
110
|
-
});
|
|
111
|
-
it('returns undefined level when not specified in frontmatter', () => {
|
|
112
|
-
vfs[join(PB_DIR, 'skills', 'no-level-skill.md')] = `---
|
|
113
|
-
name: no-level-skill
|
|
114
|
-
description: A skill without level
|
|
115
|
-
triggers:
|
|
116
|
-
- nolevel
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
# No Level Skill Body
|
|
120
|
-
`;
|
|
121
|
-
const skills = readCanonicalSkills(PB_DIR);
|
|
122
|
-
expect(skills).toHaveLength(1);
|
|
123
|
-
expect(skills[0].level).toBeUndefined();
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe('shouldEmitToTarget', () => {
|
|
127
|
-
it('returns true when targets is undefined (emit to all)', () => {
|
|
128
|
-
const skill = {
|
|
129
|
-
name: 'test',
|
|
130
|
-
description: '',
|
|
131
|
-
triggers: [],
|
|
132
|
-
body: '',
|
|
133
|
-
sourcePath: '',
|
|
134
|
-
};
|
|
135
|
-
expect(shouldEmitToTarget(skill, 'claude')).toBe(true);
|
|
136
|
-
expect(shouldEmitToTarget(skill, 'cursor')).toBe(true);
|
|
137
|
-
expect(shouldEmitToTarget(skill, 'copilot')).toBe(true);
|
|
138
|
-
expect(shouldEmitToTarget(skill, 'codex')).toBe(true);
|
|
139
|
-
});
|
|
140
|
-
it('returns true when target is in the list', () => {
|
|
141
|
-
const skill = {
|
|
142
|
-
name: 'test',
|
|
143
|
-
description: '',
|
|
144
|
-
triggers: [],
|
|
145
|
-
body: '',
|
|
146
|
-
sourcePath: '',
|
|
147
|
-
targets: ['claude'],
|
|
148
|
-
};
|
|
149
|
-
expect(shouldEmitToTarget(skill, 'claude')).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
it('returns false when target is not in the list', () => {
|
|
152
|
-
const skill = {
|
|
153
|
-
name: 'test',
|
|
154
|
-
description: '',
|
|
155
|
-
triggers: [],
|
|
156
|
-
body: '',
|
|
157
|
-
sourcePath: '',
|
|
158
|
-
targets: ['claude'],
|
|
159
|
-
};
|
|
160
|
-
expect(shouldEmitToTarget(skill, 'cursor')).toBe(false);
|
|
161
|
-
expect(shouldEmitToTarget(skill, 'copilot')).toBe(false);
|
|
162
|
-
});
|
|
163
|
-
it('works for CanonicalRule as well', () => {
|
|
164
|
-
const rule = {
|
|
165
|
-
name: 'test-rule',
|
|
166
|
-
description: '',
|
|
167
|
-
autoApply: true,
|
|
168
|
-
body: '',
|
|
169
|
-
sourcePath: '',
|
|
170
|
-
targets: ['cursor'],
|
|
171
|
-
};
|
|
172
|
-
expect(shouldEmitToTarget(rule, 'cursor')).toBe(true);
|
|
173
|
-
expect(shouldEmitToTarget(rule, 'claude')).toBe(false);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
describe('stripTransportSections', () => {
|
|
177
|
-
it('keeps content for the matching target and removes delimiters', () => {
|
|
178
|
-
const body = `Universal content above.
|
|
179
|
-
|
|
180
|
-
<!-- transport:claude -->
|
|
181
|
-
Claude-specific instructions here.
|
|
182
|
-
<!-- /transport -->
|
|
183
|
-
|
|
184
|
-
Universal content below.`;
|
|
185
|
-
const result = stripTransportSections(body, 'claude');
|
|
186
|
-
expect(result).toContain('Claude-specific instructions here.');
|
|
187
|
-
expect(result).toContain('Universal content above.');
|
|
188
|
-
expect(result).toContain('Universal content below.');
|
|
189
|
-
expect(result).not.toContain('<!-- transport:claude -->');
|
|
190
|
-
expect(result).not.toContain('<!-- /transport -->');
|
|
191
|
-
});
|
|
192
|
-
it('removes blocks for other targets entirely', () => {
|
|
193
|
-
const body = `Universal content.
|
|
194
|
-
|
|
195
|
-
<!-- transport:cursor -->
|
|
196
|
-
Cursor-only instructions.
|
|
197
|
-
<!-- /transport -->
|
|
198
|
-
|
|
199
|
-
More universal.`;
|
|
200
|
-
const result = stripTransportSections(body, 'claude');
|
|
201
|
-
expect(result).toContain('Universal content.');
|
|
202
|
-
expect(result).toContain('More universal.');
|
|
203
|
-
expect(result).not.toContain('Cursor-only instructions.');
|
|
204
|
-
expect(result).not.toContain('<!-- transport:cursor -->');
|
|
205
|
-
});
|
|
206
|
-
it('handles multiple transport blocks for different targets', () => {
|
|
207
|
-
const body = `# Heading
|
|
208
|
-
|
|
209
|
-
<!-- transport:claude -->
|
|
210
|
-
Claude dispatch: use Agent tool.
|
|
211
|
-
<!-- /transport -->
|
|
212
|
-
|
|
213
|
-
<!-- transport:cursor -->
|
|
214
|
-
Cursor dispatch: use fresh conversation.
|
|
215
|
-
<!-- /transport -->
|
|
216
|
-
|
|
217
|
-
## Footer`;
|
|
218
|
-
const claudeResult = stripTransportSections(body, 'claude');
|
|
219
|
-
expect(claudeResult).toContain('Claude dispatch: use Agent tool.');
|
|
220
|
-
expect(claudeResult).not.toContain('Cursor dispatch: use fresh conversation.');
|
|
221
|
-
expect(claudeResult).toContain('# Heading');
|
|
222
|
-
expect(claudeResult).toContain('## Footer');
|
|
223
|
-
const cursorResult = stripTransportSections(body, 'cursor');
|
|
224
|
-
expect(cursorResult).toContain('Cursor dispatch: use fresh conversation.');
|
|
225
|
-
expect(cursorResult).not.toContain('Claude dispatch: use Agent tool.');
|
|
226
|
-
expect(cursorResult).toContain('# Heading');
|
|
227
|
-
expect(cursorResult).toContain('## Footer');
|
|
228
|
-
});
|
|
229
|
-
it('keeps universal content untouched when no transport blocks exist', () => {
|
|
230
|
-
const body = `# Just a normal skill
|
|
231
|
-
|
|
232
|
-
No transport sections here.
|
|
233
|
-
|
|
234
|
-
## Section 2
|
|
235
|
-
|
|
236
|
-
More content.`;
|
|
237
|
-
const result = stripTransportSections(body, 'claude');
|
|
238
|
-
expect(result).toBe(body);
|
|
239
|
-
});
|
|
240
|
-
it('handles markdown and code blocks inside transport sections', () => {
|
|
241
|
-
const body = `Universal.
|
|
242
|
-
|
|
243
|
-
<!-- transport:claude -->
|
|
244
|
-
**Bold text** and \`inline code\`.
|
|
245
|
-
|
|
246
|
-
\`\`\`bash
|
|
247
|
-
git diff main..HEAD
|
|
248
|
-
\`\`\`
|
|
249
|
-
|
|
250
|
-
- List item 1
|
|
251
|
-
- List item 2
|
|
252
|
-
<!-- /transport -->
|
|
253
|
-
|
|
254
|
-
End.`;
|
|
255
|
-
const result = stripTransportSections(body, 'claude');
|
|
256
|
-
expect(result).toContain('**Bold text** and `inline code`.');
|
|
257
|
-
expect(result).toContain('git diff main..HEAD');
|
|
258
|
-
expect(result).toContain('- List item 1');
|
|
259
|
-
expect(result).toContain('End.');
|
|
260
|
-
});
|
|
261
|
-
it('handles transport sections with no trailing newline after closing tag', () => {
|
|
262
|
-
const body = `Before.
|
|
263
|
-
<!-- transport:claude -->
|
|
264
|
-
Content.
|
|
265
|
-
<!-- /transport -->After.`;
|
|
266
|
-
const result = stripTransportSections(body, 'claude');
|
|
267
|
-
expect(result).toContain('Content.');
|
|
268
|
-
expect(result).toContain('After.');
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
describe('generateCursorSkill (transport stripping)', () => {
|
|
272
|
-
it('strips non-cursor transport sections from generated output', () => {
|
|
273
|
-
const skill = {
|
|
274
|
-
name: 'test-skill',
|
|
275
|
-
description: 'Test skill',
|
|
276
|
-
triggers: ['test'],
|
|
277
|
-
body: `# Heading
|
|
278
|
-
|
|
279
|
-
<!-- transport:claude -->
|
|
280
|
-
Claude-only content.
|
|
281
|
-
<!-- /transport -->
|
|
282
|
-
|
|
283
|
-
<!-- transport:cursor -->
|
|
284
|
-
Cursor-only content.
|
|
285
|
-
<!-- /transport -->
|
|
286
|
-
|
|
287
|
-
Universal content.`,
|
|
288
|
-
sourcePath: '/tmp/.productbrain/skills/test-skill.md',
|
|
289
|
-
};
|
|
290
|
-
const output = generateCursorSkill(skill);
|
|
291
|
-
expect(output).toContain('Cursor-only content.');
|
|
292
|
-
expect(output).not.toContain('Claude-only content.');
|
|
293
|
-
expect(output).toContain('Universal content.');
|
|
294
|
-
expect(output).not.toContain('<!-- transport:');
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
describe('generateCodexSkill / generateCodexSkillIndex', () => {
|
|
298
|
-
it('strips non-codex transport sections from generated Codex skill output', () => {
|
|
299
|
-
const skill = {
|
|
300
|
-
name: 'test-skill',
|
|
301
|
-
description: 'Test skill',
|
|
302
|
-
triggers: ['test'],
|
|
303
|
-
body: `# Heading
|
|
304
|
-
|
|
305
|
-
<!-- transport:claude -->
|
|
306
|
-
Claude-only content.
|
|
307
|
-
<!-- /transport -->
|
|
308
|
-
|
|
309
|
-
<!-- transport:codex -->
|
|
310
|
-
Codex-only content.
|
|
311
|
-
<!-- /transport -->
|
|
312
|
-
|
|
313
|
-
Universal content.`,
|
|
314
|
-
sourcePath: '/tmp/.productbrain/skills/test-skill.md',
|
|
315
|
-
};
|
|
316
|
-
const output = generateCodexSkill(skill);
|
|
317
|
-
expect(output).toContain('Codex-only content.');
|
|
318
|
-
expect(output).not.toContain('Claude-only content.');
|
|
319
|
-
expect(output).toContain('Universal content.');
|
|
320
|
-
});
|
|
321
|
-
it('generates a Codex skill index with links to projected skills', () => {
|
|
322
|
-
const skills = [
|
|
323
|
-
{
|
|
324
|
-
name: 'preflight',
|
|
325
|
-
description: 'Ground the task before changing code.',
|
|
326
|
-
triggers: ['preflight', 'system check'],
|
|
327
|
-
body: '# Preflight',
|
|
328
|
-
sourcePath: '/tmp/.productbrain/skills/preflight.md',
|
|
329
|
-
},
|
|
330
|
-
];
|
|
331
|
-
const output = generateCodexSkillIndex(skills);
|
|
332
|
-
expect(output).toContain('Product Brain Skills for Codex');
|
|
333
|
-
expect(output).toContain('## preflight');
|
|
334
|
-
expect(output).toContain('`preflight`');
|
|
335
|
-
expect(output).toContain('Read: `.codex/skills/preflight.md`');
|
|
336
|
-
});
|
|
337
|
-
it('hides learnings and template files from the Codex skill index', () => {
|
|
338
|
-
const skills = [
|
|
339
|
-
{
|
|
340
|
-
name: 'preflight',
|
|
341
|
-
description: 'Ground the task before changing code.',
|
|
342
|
-
triggers: ['preflight'],
|
|
343
|
-
body: '# Preflight',
|
|
344
|
-
sourcePath: '/tmp/.productbrain/skills/preflight.md',
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
name: 'retro-learnings',
|
|
348
|
-
description: 'Internal learnings companion.',
|
|
349
|
-
triggers: [],
|
|
350
|
-
body: '# Retro Learnings',
|
|
351
|
-
sourcePath: '/tmp/.productbrain/skills/retro-learnings.md',
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
name: 'LEARNINGS-TEMPLATE',
|
|
355
|
-
description: 'Template',
|
|
356
|
-
triggers: [],
|
|
357
|
-
body: '# Template',
|
|
358
|
-
sourcePath: '/tmp/.productbrain/skills/LEARNINGS-TEMPLATE.md',
|
|
359
|
-
},
|
|
360
|
-
];
|
|
361
|
-
const output = generateCodexSkillIndex(skills);
|
|
362
|
-
expect(output).toContain('## preflight');
|
|
363
|
-
expect(output).not.toContain('## retro-learnings');
|
|
364
|
-
expect(output).not.toContain('## LEARNINGS-TEMPLATE');
|
|
365
|
-
expect(output).toContain('hidden from this index');
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
describe('shouldEmitToTarget skill filtering across surfaces (DEC-1736: claude has no skill router)', () => {
|
|
369
|
-
it('skill with targets: [claude] does not appear in Cursor output', () => {
|
|
370
|
-
const claudeOnly = {
|
|
371
|
-
name: 'claude-exclusive',
|
|
372
|
-
description: 'Claude exclusive skill',
|
|
373
|
-
triggers: ['claude-trigger'],
|
|
374
|
-
body: '# Claude Exclusive',
|
|
375
|
-
sourcePath: '/tmp/skills/claude-exclusive.md',
|
|
376
|
-
targets: ['claude'],
|
|
377
|
-
};
|
|
378
|
-
// Filter for Cursor (as handshake.ts would do)
|
|
379
|
-
const cursorSkills = [claudeOnly].filter((s) => shouldEmitToTarget(s, 'cursor'));
|
|
380
|
-
expect(cursorSkills).toHaveLength(0);
|
|
381
|
-
});
|
|
382
|
-
it('skill with no targets appears in both Claude and Cursor filtering', () => {
|
|
383
|
-
const universal = {
|
|
384
|
-
name: 'universal',
|
|
385
|
-
description: 'Universal skill',
|
|
386
|
-
triggers: ['uni'],
|
|
387
|
-
body: '# Universal',
|
|
388
|
-
sourcePath: '/tmp/skills/universal.md',
|
|
389
|
-
};
|
|
390
|
-
const claudeSkills = [universal].filter((s) => shouldEmitToTarget(s, 'claude'));
|
|
391
|
-
const cursorSkills = [universal].filter((s) => shouldEmitToTarget(s, 'cursor'));
|
|
392
|
-
expect(claudeSkills).toHaveLength(1);
|
|
393
|
-
expect(cursorSkills).toHaveLength(1);
|
|
394
|
-
const cursorOutput = generateCursorSkill(cursorSkills[0]);
|
|
395
|
-
expect(cursorOutput).toContain('universal');
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
describe('generateCursorRule (scope propagation)', () => {
|
|
399
|
-
const baseRule = {
|
|
400
|
-
name: 'test-rule',
|
|
401
|
-
description: 'A test rule',
|
|
402
|
-
autoApply: true,
|
|
403
|
-
body: '# Rule body content',
|
|
404
|
-
sourcePath: '/tmp/.productbrain/rules/test-rule.md',
|
|
405
|
-
};
|
|
406
|
-
it('emits empty globs and alwaysApply: true when scope is empty string', () => {
|
|
407
|
-
const rule = { ...baseRule, scope: '' };
|
|
408
|
-
const output = generateCursorRule(rule);
|
|
409
|
-
expect(output).toContain('globs: ');
|
|
410
|
-
expect(output).toContain('alwaysApply: true');
|
|
411
|
-
expect(output).toContain('# Rule body content');
|
|
412
|
-
});
|
|
413
|
-
it('emits empty globs and alwaysApply: true when scope is undefined', () => {
|
|
414
|
-
const rule = { ...baseRule };
|
|
415
|
-
const output = generateCursorRule(rule);
|
|
416
|
-
expect(output).toContain('globs: ');
|
|
417
|
-
expect(output).toContain('alwaysApply: true');
|
|
418
|
-
});
|
|
419
|
-
it('emits glob pattern and alwaysApply: false when scope is set', () => {
|
|
420
|
-
const rule = { ...baseRule, scope: 'convex/**/*.ts' };
|
|
421
|
-
const output = generateCursorRule(rule);
|
|
422
|
-
expect(output).toContain('globs: convex/**/*.ts');
|
|
423
|
-
expect(output).toContain('alwaysApply: false');
|
|
424
|
-
});
|
|
425
|
-
it('respects autoApply: false with empty scope', () => {
|
|
426
|
-
const rule = { ...baseRule, autoApply: false, scope: '' };
|
|
427
|
-
const output = generateCursorRule(rule);
|
|
428
|
-
expect(output).toContain('alwaysApply: false');
|
|
429
|
-
});
|
|
430
|
-
it('replaces .productbrain paths with .cursor paths in body', () => {
|
|
431
|
-
const rule = {
|
|
432
|
-
...baseRule,
|
|
433
|
-
body: 'Read `.productbrain/rules/foo.md` and `.productbrain/skills/bar.md`.',
|
|
434
|
-
};
|
|
435
|
-
const output = generateCursorRule(rule);
|
|
436
|
-
expect(output).toContain('.cursor/rules/foo.mdc');
|
|
437
|
-
expect(output).toContain('.cursor/skills/bar/SKILL.md');
|
|
438
|
-
expect(output).not.toContain('.productbrain/rules/foo.md');
|
|
439
|
-
});
|
|
440
|
-
it('includes source marker comment', () => {
|
|
441
|
-
const output = generateCursorRule(baseRule);
|
|
442
|
-
expect(output).toContain('source: .productbrain/rules/test-rule.md');
|
|
443
|
-
});
|
|
444
|
-
});
|
|
445
|
-
describe('generateCodexSkillIndex (empty primary skills)', () => {
|
|
446
|
-
it('shows empty message when all skills are learnings/templates', () => {
|
|
447
|
-
const skills = [
|
|
448
|
-
{
|
|
449
|
-
name: 'retro-learnings',
|
|
450
|
-
description: 'Internal learnings companion.',
|
|
451
|
-
triggers: [],
|
|
452
|
-
body: '# Retro Learnings',
|
|
453
|
-
sourcePath: '/tmp/.productbrain/skills/retro-learnings.md',
|
|
454
|
-
},
|
|
455
|
-
{
|
|
456
|
-
name: 'LEARNINGS-TEMPLATE',
|
|
457
|
-
description: 'Template',
|
|
458
|
-
triggers: [],
|
|
459
|
-
body: '# Template',
|
|
460
|
-
sourcePath: '/tmp/.productbrain/skills/LEARNINGS-TEMPLATE.md',
|
|
461
|
-
},
|
|
462
|
-
];
|
|
463
|
-
const output = generateCodexSkillIndex(skills);
|
|
464
|
-
expect(output).toContain('No Product Brain skills are currently projected');
|
|
465
|
-
});
|
|
466
|
-
});
|
|
467
|
-
describe('filterByLevel', () => {
|
|
468
|
-
const items = [
|
|
469
|
-
{ name: 'core-item', level: 'core' },
|
|
470
|
-
{ name: 'intermediate-item', level: 'intermediate' },
|
|
471
|
-
{ name: 'expert-item', level: 'expert' },
|
|
472
|
-
{ name: 'no-level-item' },
|
|
473
|
-
];
|
|
474
|
-
it('filterByLevel("beginner") returns only level:core items + items with no level', () => {
|
|
475
|
-
const result = filterByLevel(items, 'beginner');
|
|
476
|
-
const names = result.map((i) => i.name);
|
|
477
|
-
expect(names).toContain('core-item');
|
|
478
|
-
expect(names).toContain('no-level-item');
|
|
479
|
-
expect(names).not.toContain('intermediate-item');
|
|
480
|
-
expect(names).not.toContain('expert-item');
|
|
481
|
-
expect(result).toHaveLength(2);
|
|
482
|
-
});
|
|
483
|
-
it('filterByLevel("intermediate") returns core + intermediate + no level', () => {
|
|
484
|
-
const result = filterByLevel(items, 'intermediate');
|
|
485
|
-
const names = result.map((i) => i.name);
|
|
486
|
-
expect(names).toContain('core-item');
|
|
487
|
-
expect(names).toContain('intermediate-item');
|
|
488
|
-
expect(names).toContain('no-level-item');
|
|
489
|
-
expect(names).not.toContain('expert-item');
|
|
490
|
-
expect(result).toHaveLength(3);
|
|
491
|
-
});
|
|
492
|
-
it('filterByLevel("expert") returns all items', () => {
|
|
493
|
-
const result = filterByLevel(items, 'expert');
|
|
494
|
-
expect(result).toHaveLength(4);
|
|
495
|
-
});
|
|
496
|
-
it('filterByLevel(undefined) returns all items (backward compat)', () => {
|
|
497
|
-
const result = filterByLevel(items, undefined);
|
|
498
|
-
expect(result).toHaveLength(4);
|
|
499
|
-
});
|
|
500
|
-
it('filterByLevel(null-ish) returns all items (backward compat)', () => {
|
|
501
|
-
const result = filterByLevel(items);
|
|
502
|
-
expect(result).toHaveLength(4);
|
|
503
|
-
});
|
|
504
|
-
it('unknown level throws an error', () => {
|
|
505
|
-
expect(() => filterByLevel(items, 'unknown')).toThrow('Unknown level "unknown"');
|
|
506
|
-
});
|
|
507
|
-
it('DEC-1800: filterByLevel with no requested level returns every item, unconditionally (no more stage cap)', () => {
|
|
508
|
-
// Red-then-green (DEC-1800): against the pre-fix code, calling the old 3-arg signature as
|
|
509
|
-
// filterByLevel(items, undefined, 'blank') capped the result to 2 (core + no-level only).
|
|
510
|
-
// The stage parameter is deleted — there is no argument left that can ever cap this call.
|
|
511
|
-
const result = filterByLevel(items, undefined);
|
|
512
|
-
expect(result).toHaveLength(4);
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
describe('evaluateConditions', () => {
|
|
516
|
-
const noProfile = null;
|
|
517
|
-
const profile = {
|
|
518
|
-
totalRelations: 10,
|
|
519
|
-
};
|
|
520
|
-
const emptyRepo = { detectedStack: [] };
|
|
521
|
-
const sveltekitRepo = { detectedStack: ['sveltekit', 'typescript'] };
|
|
522
|
-
// 1. No conditions → included
|
|
523
|
-
it('no conditions → included', () => {
|
|
524
|
-
const result = evaluateConditions({}, profile, sveltekitRepo);
|
|
525
|
-
expect(result.included).toBe(true);
|
|
526
|
-
expect(result.reasons).toEqual(['no conditions']);
|
|
527
|
-
});
|
|
528
|
-
// 2. Matching when_stack → included
|
|
529
|
-
it('matching when_stack → included', () => {
|
|
530
|
-
const result = evaluateConditions({ when_stack: 'sveltekit' }, profile, sveltekitRepo);
|
|
531
|
-
expect(result.included).toBe(true);
|
|
532
|
-
expect(result.reasons.some((r) => r.includes('matched'))).toBe(true);
|
|
533
|
-
});
|
|
534
|
-
// 3. Non-matching when_stack → excluded with reason
|
|
535
|
-
it('non-matching when_stack → excluded with reason', () => {
|
|
536
|
-
const result = evaluateConditions({ when_stack: 'nextjs' }, profile, sveltekitRepo);
|
|
537
|
-
expect(result.included).toBe(false);
|
|
538
|
-
expect(result.reasons.some((r) => r.includes('when_stack=nextjs'))).toBe(true);
|
|
539
|
-
});
|
|
540
|
-
// 4. when_stack case-insensitive matching
|
|
541
|
-
it('when_stack is case-insensitive', () => {
|
|
542
|
-
const result = evaluateConditions({ when_stack: 'SvelteKit' }, profile, { detectedStack: ['sveltekit'] });
|
|
543
|
-
expect(result.included).toBe(true);
|
|
544
|
-
});
|
|
545
|
-
// 8. when_minGovernance with enough relations → included
|
|
546
|
-
it('when_minGovernance with enough relations → included', () => {
|
|
547
|
-
const result = evaluateConditions({ when_minGovernance: '5' }, profile, emptyRepo);
|
|
548
|
-
expect(result.included).toBe(true);
|
|
549
|
-
expect(result.reasons.some((r) => r.includes('satisfied'))).toBe(true);
|
|
550
|
-
});
|
|
551
|
-
// 9. when_minGovernance with too few → excluded
|
|
552
|
-
it('when_minGovernance with too few relations → excluded', () => {
|
|
553
|
-
const lowRelProfile = { totalRelations: 3 };
|
|
554
|
-
const result = evaluateConditions({ when_minGovernance: '5' }, lowRelProfile, emptyRepo);
|
|
555
|
-
expect(result.included).toBe(false);
|
|
556
|
-
expect(result.reasons.some((r) => r.includes('when_minGovernance=5'))).toBe(true);
|
|
557
|
-
});
|
|
558
|
-
// 10. Multiple conditions: all pass → included
|
|
559
|
-
it('multiple conditions: all pass → included', () => {
|
|
560
|
-
const result = evaluateConditions({ when_stack: 'sveltekit', when_minGovernance: '5' }, profile, sveltekitRepo);
|
|
561
|
-
expect(result.included).toBe(true);
|
|
562
|
-
});
|
|
563
|
-
// 11. Multiple conditions: one fails → excluded (AND semantics)
|
|
564
|
-
it('multiple conditions: one fails → excluded', () => {
|
|
565
|
-
const result = evaluateConditions({ when_stack: 'nextjs', when_minGovernance: '5' }, profile, // totalRelations=10, satisfies when_minGovernance
|
|
566
|
-
sveltekitRepo // detectedStack has no 'nextjs'
|
|
567
|
-
);
|
|
568
|
-
expect(result.included).toBe(false);
|
|
569
|
-
expect(result.reasons.some((r) => r.includes('when_stack=nextjs'))).toBe(true);
|
|
570
|
-
});
|
|
571
|
-
// 12. Null profile + when_minGovernance → included (fail-open)
|
|
572
|
-
it('null profile with when_minGovernance → fail-open (included)', () => {
|
|
573
|
-
const result = evaluateConditions({ when_minGovernance: '5' }, noProfile, emptyRepo);
|
|
574
|
-
expect(result.included).toBe(true);
|
|
575
|
-
expect(result.reasons.some((r) => r.includes('fail-open'))).toBe(true);
|
|
576
|
-
});
|
|
577
|
-
// 13. Null profile + when_stack only → still evaluated (stack comes from repoContext)
|
|
578
|
-
it('null profile with when_stack only → still evaluated from repoContext', () => {
|
|
579
|
-
const matchResult = evaluateConditions({ when_stack: 'sveltekit' }, noProfile, sveltekitRepo);
|
|
580
|
-
expect(matchResult.included).toBe(true);
|
|
581
|
-
const noMatchResult = evaluateConditions({ when_stack: 'nextjs' }, noProfile, sveltekitRepo);
|
|
582
|
-
expect(noMatchResult.included).toBe(false);
|
|
583
|
-
});
|
|
584
|
-
});
|
|
585
|
-
describe('BET-170 acceptance criteria — integration (DEC-1800: stage-cap acceptance criteria deleted)', () => {
|
|
586
|
-
/**
|
|
587
|
-
* Mock rules cover the surviving combinations: stack condition, governance condition, and
|
|
588
|
-
* unconditional at core/intermediate/expert levels. The stage-condition rule (`feature-flags`,
|
|
589
|
-
* formerly `when_minStage: 'grounded'`) and every stage-keyed acceptance criterion (AC1-AC5,
|
|
590
|
-
* the 0/5/50/500-entry scale test) are deleted with the cap they exercised — no more stage
|
|
591
|
-
* argument exists to feed them.
|
|
592
|
-
*/
|
|
593
|
-
const mockRules = [
|
|
594
|
-
{ name: 'deployment', level: 'core', conditions: { when_stack: 'sveltekit' } },
|
|
595
|
-
{ name: 'domain-boundaries', level: 'expert', conditions: { when_minGovernance: '5' } },
|
|
596
|
-
{ name: 'code-integrity', level: 'core' }, // no conditions — always included
|
|
597
|
-
{ name: 'review-gate', level: 'intermediate' }, // no conditions
|
|
598
|
-
{ name: 'orchestrator-mode', level: 'expert' }, // no conditions
|
|
599
|
-
];
|
|
600
|
-
function applyPipeline(rules, profile, repo) {
|
|
601
|
-
// No stage argument — filterByLevel takes requestedLevel only (DEC-1800).
|
|
602
|
-
const levelFiltered = filterByLevel(rules, undefined);
|
|
603
|
-
// condition filter
|
|
604
|
-
return levelFiltered.filter((rule) => {
|
|
605
|
-
const result = evaluateConditions(rule.conditions ?? {}, profile, repo);
|
|
606
|
-
return result.included;
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
it('all levels included, unconditional + stack-matched + governance-satisfied rules pass', () => {
|
|
610
|
-
const profile = { totalRelations: 15 };
|
|
611
|
-
const repo = { detectedStack: ['typescript', 'sveltekit'] };
|
|
612
|
-
const result = applyPipeline(mockRules, profile, repo);
|
|
613
|
-
const names = result.map((r) => r.name);
|
|
614
|
-
// No stage cap: every level (core/intermediate/expert) survives filterByLevel.
|
|
615
|
-
// sveltekit matches, 15 >= 5 → every rule's condition passes.
|
|
616
|
-
expect(names).toContain('deployment');
|
|
617
|
-
expect(names).toContain('domain-boundaries');
|
|
618
|
-
expect(names).toContain('code-integrity');
|
|
619
|
-
expect(names).toContain('review-gate');
|
|
620
|
-
expect(names).toContain('orchestrator-mode');
|
|
621
|
-
expect(result).toHaveLength(5);
|
|
622
|
-
});
|
|
623
|
-
it('unknown stack — only non-stack-conditional rules pass, still no level cap', () => {
|
|
624
|
-
const profile = { totalRelations: 15 };
|
|
625
|
-
const repo = { detectedStack: [] };
|
|
626
|
-
const result = applyPipeline(mockRules, profile, repo);
|
|
627
|
-
const names = result.map((r) => r.name);
|
|
628
|
-
// deployment requires sveltekit stack — excluded; all others pass regardless of level.
|
|
629
|
-
expect(names).not.toContain('deployment');
|
|
630
|
-
expect(names).toContain('domain-boundaries');
|
|
631
|
-
expect(names).toContain('code-integrity');
|
|
632
|
-
expect(names).toContain('review-gate');
|
|
633
|
-
expect(names).toContain('orchestrator-mode');
|
|
634
|
-
expect(result).toHaveLength(4);
|
|
635
|
-
});
|
|
636
|
-
it('null profile (readiness failure) — fail-open, profile conditions pass, no level cap', () => {
|
|
637
|
-
const profile = null;
|
|
638
|
-
const repo = { detectedStack: ['typescript'] };
|
|
639
|
-
const result = applyPipeline(mockRules, profile, repo);
|
|
640
|
-
const names = result.map((r) => r.name);
|
|
641
|
-
// Null profile: when_minGovernance fails open (included); when_stack still evaluated
|
|
642
|
-
// against repoContext — sveltekit not in [typescript] → excluded.
|
|
643
|
-
expect(names).not.toContain('deployment');
|
|
644
|
-
expect(names).toContain('domain-boundaries'); // fail-open (profile null)
|
|
645
|
-
expect(names).toContain('code-integrity');
|
|
646
|
-
expect(names).toContain('review-gate');
|
|
647
|
-
expect(names).toContain('orchestrator-mode');
|
|
648
|
-
expect(result).toHaveLength(4);
|
|
649
|
-
});
|
|
650
|
-
});
|
|
651
|
-
describe('readCanonicalRules — backward compat with when_* frontmatter', () => {
|
|
652
|
-
beforeEach(() => {
|
|
653
|
-
Object.keys(vfs).forEach((k) => delete vfs[k]);
|
|
654
|
-
});
|
|
655
|
-
it('parses when_stack from frontmatter into conditions', () => {
|
|
656
|
-
vfs[join(PB_DIR, 'rules', 'deploy.md')] = `---
|
|
657
|
-
name: deploy
|
|
658
|
-
description: Deploy rule
|
|
659
|
-
scope: ""
|
|
660
|
-
autoApply: true
|
|
661
|
-
when_stack: sveltekit
|
|
662
|
-
---
|
|
663
|
-
|
|
664
|
-
# Deploy body
|
|
665
|
-
`;
|
|
666
|
-
const rules = readCanonicalRules(PB_DIR);
|
|
667
|
-
expect(rules).toHaveLength(1);
|
|
668
|
-
expect(rules[0].conditions?.when_stack).toBe('sveltekit');
|
|
669
|
-
});
|
|
670
|
-
it('parses when_minGovernance from frontmatter into conditions', () => {
|
|
671
|
-
vfs[join(PB_DIR, 'rules', 'domains.md')] = `---
|
|
672
|
-
name: domains
|
|
673
|
-
description: Domain boundaries rule
|
|
674
|
-
scope: ""
|
|
675
|
-
autoApply: true
|
|
676
|
-
when_minGovernance: 5
|
|
677
|
-
---
|
|
678
|
-
|
|
679
|
-
# Domains body
|
|
680
|
-
`;
|
|
681
|
-
const rules = readCanonicalRules(PB_DIR);
|
|
682
|
-
expect(rules).toHaveLength(1);
|
|
683
|
-
expect(rules[0].conditions?.when_minGovernance).toBe('5');
|
|
684
|
-
});
|
|
685
|
-
it('returns undefined conditions when no when_* keys are present (backward compat)', () => {
|
|
686
|
-
vfs[join(PB_DIR, 'rules', 'plain.md')] = `---
|
|
687
|
-
name: plain
|
|
688
|
-
description: Plain rule
|
|
689
|
-
scope: ""
|
|
690
|
-
autoApply: true
|
|
691
|
-
---
|
|
692
|
-
|
|
693
|
-
# Plain body
|
|
694
|
-
`;
|
|
695
|
-
const rules = readCanonicalRules(PB_DIR);
|
|
696
|
-
expect(rules).toHaveLength(1);
|
|
697
|
-
expect(rules[0].conditions).toBeUndefined();
|
|
698
|
-
});
|
|
699
|
-
});
|
|
700
|
-
describe('readCanonicalRules → generateCopilotInstructionFiles (DEC-1343 integration)', () => {
|
|
701
|
-
beforeEach(() => {
|
|
702
|
-
Object.keys(vfs).forEach((k) => delete vfs[k]);
|
|
703
|
-
});
|
|
704
|
-
it('parses applyTo and projects a path-scoped Copilot instruction file end to end', () => {
|
|
705
|
-
vfs[join(PB_DIR, 'rules', 'security-boundaries.md')] = `---
|
|
706
|
-
name: security-boundaries
|
|
707
|
-
description: Security boundaries
|
|
708
|
-
applyTo: "convex/**/*.ts"
|
|
709
|
-
level: core
|
|
710
|
-
---
|
|
711
|
-
|
|
712
|
-
# Security Boundaries
|
|
713
|
-
|
|
714
|
-
Scope every workspace read by workspaceId at the index level. Fail closed.
|
|
715
|
-
`;
|
|
716
|
-
const rules = readCanonicalRules(PB_DIR);
|
|
717
|
-
expect(rules).toHaveLength(1);
|
|
718
|
-
expect(rules[0].applyTo).toBe('convex/**/*.ts');
|
|
719
|
-
const files = generateCopilotInstructionFiles(rules.map((r) => ({ name: r.name, body: r.body, applyTo: r.applyTo, sourcePath: r.sourcePath })), '2026-06-22T00:00:00.000Z');
|
|
720
|
-
expect(files).toHaveLength(1);
|
|
721
|
-
expect(files[0].relativePath).toBe('.github/instructions/security-boundaries.instructions.md');
|
|
722
|
-
expect(files[0].content).toContain('applyTo: "convex/**/*.ts"');
|
|
723
|
-
expect(files[0].content).toContain('Scope every workspace read by workspaceId at the index level.');
|
|
724
|
-
expect(files[0].content).toContain(MARKER);
|
|
725
|
-
});
|
|
726
|
-
it('leaves a rule without applyTo out of the instruction-file set (repo-wide only)', () => {
|
|
727
|
-
vfs[join(PB_DIR, 'rules', 'git-workflow.md')] = `---
|
|
728
|
-
name: git-workflow
|
|
729
|
-
description: Git workflow
|
|
730
|
-
level: core
|
|
731
|
-
---
|
|
732
|
-
|
|
733
|
-
# Git Workflow
|
|
734
|
-
|
|
735
|
-
One logical change per PR.
|
|
736
|
-
`;
|
|
737
|
-
const rules = readCanonicalRules(PB_DIR);
|
|
738
|
-
const files = generateCopilotInstructionFiles(rules.map((r) => ({ name: r.name, body: r.body, applyTo: r.applyTo, sourcePath: r.sourcePath })), '2026-06-22T00:00:00.000Z');
|
|
739
|
-
expect(files).toHaveLength(0);
|
|
740
|
-
});
|
|
741
|
-
});
|
|
742
|
-
//# sourceMappingURL=portable-knowledge.test.js.map
|