@makerkit/prd 0.0.0 → 0.0.1
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/package.json +2 -21
- package/.turbo/turbo-build.log +0 -46
- package/.turbo/turbo-test.log +0 -21
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/README.md +0 -65
- package/dist/package.json +0 -49
- package/src/__tests__/agent-workflow.test.ts +0 -377
- package/src/__tests__/attachments.test.ts +0 -475
- package/src/__tests__/node.test.ts +0 -141
- package/src/__tests__/plan-check.test.ts +0 -229
- package/src/__tests__/planning.test.ts +0 -1059
- package/src/__tests__/prd-operations.test.ts +0 -423
- package/src/__tests__/prd.service.test.ts +0 -477
- package/src/__tests__/prd.tool.test.ts +0 -282
- package/src/__tests__/templates.test.ts +0 -141
- package/src/applicability.ts +0 -73
- package/src/attachment-paths.ts +0 -78
- package/src/attachments.ts +0 -160
- package/src/edge-cases.ts +0 -52
- package/src/index.ts +0 -35
- package/src/markdown.ts +0 -268
- package/src/mcp/index.ts +0 -839
- package/src/mcp/tool-response.ts +0 -85
- package/src/node.ts +0 -146
- package/src/open-questions.ts +0 -93
- package/src/plan-check.ts +0 -282
- package/src/planning-operations.ts +0 -429
- package/src/prd-operations.ts +0 -690
- package/src/prd.service.ts +0 -1051
- package/src/prompts.ts +0 -110
- package/src/safe-file-name.ts +0 -42
- package/src/schema.ts +0 -976
- package/src/templates.ts +0 -173
- package/src/testing/fake-mcp-server.ts +0 -81
- package/src/types.ts +0 -333
- package/tsconfig.json +0 -23
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -7
- package/tsdown.config.mts +0 -11
- package/vitest.config.mts +0 -8
- /package/{dist/LICENSE → LICENSE} +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/index.mjs → index.mjs} +0 -0
- /package/{dist/mcp.d.ts → mcp.d.ts} +0 -0
- /package/{dist/mcp.js → mcp.js} +0 -0
- /package/{dist/mcp.mjs → mcp.mjs} +0 -0
- /package/{dist/node.d.ts → node.d.ts} +0 -0
- /package/{dist/node.js → node.js} +0 -0
- /package/{dist/node.mjs → node.mjs} +0 -0
- /package/{dist/prd.service-DSBp8sMl.d.ts → prd.service-DSBp8sMl.d.ts} +0 -0
- /package/{dist/prompts-Bber0S1Z.mjs → prompts-Bber0S1Z.mjs} +0 -0
- /package/{dist/prompts-CIX8IeAx.js → prompts-CIX8IeAx.js} +0 -0
|
@@ -1,1059 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { registerPRDTools } from '../mcp';
|
|
4
|
-
import {
|
|
5
|
-
type PrdDeps,
|
|
6
|
-
PrdRevisionConflictError,
|
|
7
|
-
createPrdService,
|
|
8
|
-
} from '../prd.service';
|
|
9
|
-
import { createFakeMcpServer } from '../testing/fake-mcp-server';
|
|
10
|
-
import type { StructuredPRD } from '../types';
|
|
11
|
-
|
|
12
|
-
const basename = (path: string) => path.replace(/\\/g, '/').split('/').pop()!;
|
|
13
|
-
|
|
14
|
-
function createDeps(files: Record<string, string>): PrdDeps {
|
|
15
|
-
return {
|
|
16
|
-
rootPath: '/repo',
|
|
17
|
-
async readdir() {
|
|
18
|
-
return Object.keys(files);
|
|
19
|
-
},
|
|
20
|
-
async readFile(path) {
|
|
21
|
-
const content = files[basename(path)];
|
|
22
|
-
|
|
23
|
-
if (content === undefined) {
|
|
24
|
-
throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return content;
|
|
28
|
-
},
|
|
29
|
-
async writeFile(path, content) {
|
|
30
|
-
files[basename(path)] = content;
|
|
31
|
-
},
|
|
32
|
-
async mkdir() {},
|
|
33
|
-
async unlink(path) {
|
|
34
|
-
delete files[basename(path)];
|
|
35
|
-
},
|
|
36
|
-
async fileExists(path) {
|
|
37
|
-
return basename(path) in files;
|
|
38
|
-
},
|
|
39
|
-
now: () => new Date('2026-10-14T10:00:00Z'),
|
|
40
|
-
verifyCompletion: async () => ({
|
|
41
|
-
passed: true,
|
|
42
|
-
checks: [],
|
|
43
|
-
errors: 0,
|
|
44
|
-
warnings: 0,
|
|
45
|
-
diagnostics: [],
|
|
46
|
-
messages: [],
|
|
47
|
-
}),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function seed() {
|
|
52
|
-
const files: Record<string, string> = {};
|
|
53
|
-
const service = createPrdService(createDeps(files));
|
|
54
|
-
|
|
55
|
-
const { filename } = await service.create({
|
|
56
|
-
title: 'Simple CRM',
|
|
57
|
-
overview: 'Track contacts and deals',
|
|
58
|
-
problemStatement: 'Spreadsheets lose context',
|
|
59
|
-
marketOpportunity: 'Internal tool',
|
|
60
|
-
targetUsers: ['Founder'],
|
|
61
|
-
solutionDescription: 'Contacts, deals and a pipeline board',
|
|
62
|
-
keyFeatures: ['Contacts', 'Deals'],
|
|
63
|
-
successMetrics: ['Every deal has a next step'],
|
|
64
|
-
openQuestions: [
|
|
65
|
-
'Can a deal have several contacts?',
|
|
66
|
-
'Do we need custom fields?',
|
|
67
|
-
],
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const read = () => JSON.parse(files[filename]!) as StructuredPRD;
|
|
71
|
-
|
|
72
|
-
return { files, filename, service, read };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
describe('update_prd_section', () => {
|
|
76
|
-
it('merges object sections and keeps keys that were not given', async () => {
|
|
77
|
-
const { filename, service, read } = await seed();
|
|
78
|
-
|
|
79
|
-
const result = await service.updatePrdSection({
|
|
80
|
-
filename,
|
|
81
|
-
section: 'solutionOverview',
|
|
82
|
-
value: { keyFeatures: ['Contacts', 'Deals', 'Pipeline board'] },
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
expect(result.updated).toEqual(['keyFeatures']);
|
|
86
|
-
expect(read().solutionOverview).toMatchObject({
|
|
87
|
-
description: 'Contacts, deals and a pipeline board',
|
|
88
|
-
keyFeatures: ['Contacts', 'Deals', 'Pipeline board'],
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('replaces list sections', async () => {
|
|
93
|
-
const { filename, service, read } = await seed();
|
|
94
|
-
|
|
95
|
-
await service.updatePrdSection({
|
|
96
|
-
filename,
|
|
97
|
-
section: 'nonGoals',
|
|
98
|
-
value: ['Custom fields', 'Email sync'],
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(read().nonGoals).toEqual(['Custom fields', 'Email sync']);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('assigns ids to risks that have none', async () => {
|
|
105
|
-
const { filename, service, read } = await seed();
|
|
106
|
-
|
|
107
|
-
await service.updatePrdSection({
|
|
108
|
-
filename,
|
|
109
|
-
section: 'risks',
|
|
110
|
-
value: [
|
|
111
|
-
{
|
|
112
|
-
description: 'Data loss',
|
|
113
|
-
mitigation: 'Backups',
|
|
114
|
-
owner: 'me',
|
|
115
|
-
severity: 'high',
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
id: 'RISK009',
|
|
119
|
-
description: 'Scope creep',
|
|
120
|
-
mitigation: 'Non-goals',
|
|
121
|
-
owner: 'me',
|
|
122
|
-
severity: 'low',
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
expect(read().risks.map((risk) => risk.id)).toEqual(['RISK001', 'RISK009']);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('rejects a value with the wrong shape and says why', async () => {
|
|
131
|
-
const { filename, service } = await seed();
|
|
132
|
-
|
|
133
|
-
await expect(
|
|
134
|
-
service.updatePrdSection({
|
|
135
|
-
filename,
|
|
136
|
-
section: 'nonGoals',
|
|
137
|
-
value: 'Custom fields',
|
|
138
|
-
}),
|
|
139
|
-
).rejects.toThrow(/Invalid value for section "nonGoals"/);
|
|
140
|
-
|
|
141
|
-
await expect(
|
|
142
|
-
service.updatePrdSection({
|
|
143
|
-
filename,
|
|
144
|
-
section: 'constraints',
|
|
145
|
-
value: { deadline: 'Friday' },
|
|
146
|
-
}),
|
|
147
|
-
).rejects.toThrow(/Unrecognized key/);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('applies the change when expectedRevision matches the PRD', async () => {
|
|
151
|
-
const { filename, service, read } = await seed();
|
|
152
|
-
const revision = read().metadata.revision ?? 0;
|
|
153
|
-
|
|
154
|
-
await service.updatePrdSection({
|
|
155
|
-
filename,
|
|
156
|
-
section: 'nonGoals',
|
|
157
|
-
value: ['Mobile app'],
|
|
158
|
-
expectedRevision: revision,
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
expect(read().nonGoals).toEqual(['Mobile app']);
|
|
162
|
-
expect(read().metadata.revision).toBe(revision + 1);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('rejects a change based on an older revision and leaves the PRD as is', async () => {
|
|
166
|
-
const { filename, service, read } = await seed();
|
|
167
|
-
const seen = read().metadata.revision ?? 0;
|
|
168
|
-
|
|
169
|
-
// Someone else edits the same section after it was read
|
|
170
|
-
await service.updatePrdSection({
|
|
171
|
-
filename,
|
|
172
|
-
section: 'nonGoals',
|
|
173
|
-
value: ['Changed by the agent'],
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const error = await service
|
|
177
|
-
.updatePrdSection({
|
|
178
|
-
filename,
|
|
179
|
-
section: 'nonGoals',
|
|
180
|
-
value: ['Stale edit'],
|
|
181
|
-
expectedRevision: seen,
|
|
182
|
-
})
|
|
183
|
-
.catch((caught: unknown) => caught);
|
|
184
|
-
|
|
185
|
-
expect(error).toBeInstanceOf(PrdRevisionConflictError);
|
|
186
|
-
expect(error).toMatchObject({
|
|
187
|
-
code: 'PRD_REVISION_CONFLICT',
|
|
188
|
-
expectedRevision: seen,
|
|
189
|
-
currentRevision: seen + 1,
|
|
190
|
-
});
|
|
191
|
-
expect(read().nonGoals).toEqual(['Changed by the agent']);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
describe('decisions and open questions', () => {
|
|
196
|
-
it('supersedes an earlier decision', async () => {
|
|
197
|
-
const { filename, service, read } = await seed();
|
|
198
|
-
|
|
199
|
-
await service.addDecision({
|
|
200
|
-
filename,
|
|
201
|
-
decision: 'Pipeline stages are hard-coded',
|
|
202
|
-
rationale: 'Internal tool, one user',
|
|
203
|
-
status: 'accepted',
|
|
204
|
-
});
|
|
205
|
-
const second = await service.addDecision({
|
|
206
|
-
filename,
|
|
207
|
-
decision: 'Pipeline stages are configurable',
|
|
208
|
-
rationale: 'A second team will use it',
|
|
209
|
-
status: 'accepted',
|
|
210
|
-
supersedes: 'DEC001',
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
expect(second).toEqual({
|
|
214
|
-
decision_id: 'DEC002',
|
|
215
|
-
superseded: 'DEC001',
|
|
216
|
-
total_decisions: 2,
|
|
217
|
-
});
|
|
218
|
-
expect(read().decisionLog.map((entry) => entry.status)).toEqual([
|
|
219
|
-
'superseded',
|
|
220
|
-
'accepted',
|
|
221
|
-
]);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('resolves an open question into the decision log', async () => {
|
|
225
|
-
const { filename, service, read } = await seed();
|
|
226
|
-
|
|
227
|
-
const result = await service.resolveOpenQuestion({
|
|
228
|
-
filename,
|
|
229
|
-
question: ' can a deal have several CONTACTS? ',
|
|
230
|
-
answer: 'Yes, a deal has one or more contacts',
|
|
231
|
-
recordDecision: true,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
expect(result).toEqual({ remaining_questions: 1, decision_id: 'DEC001' });
|
|
235
|
-
expect(read().openQuestions).toEqual([{ id: 'Q002', question: 'Do we need custom fields?' }]);
|
|
236
|
-
expect(read().decisionLog[0]).toMatchObject({
|
|
237
|
-
decision: 'Yes, a deal has one or more contacts',
|
|
238
|
-
topic: 'open-question:Q001',
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('lists the open questions when the question does not match', async () => {
|
|
243
|
-
const { filename, service } = await seed();
|
|
244
|
-
|
|
245
|
-
await expect(
|
|
246
|
-
service.resolveOpenQuestion({
|
|
247
|
-
filename,
|
|
248
|
-
question: 'Nope',
|
|
249
|
-
answer: 'x',
|
|
250
|
-
recordDecision: true,
|
|
251
|
-
}),
|
|
252
|
-
).rejects.toThrow(/Do we need custom fields\?/);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
describe('glossary', () => {
|
|
257
|
-
it('adds terms and redefines existing ones regardless of casing', async () => {
|
|
258
|
-
const { filename, service, read } = await seed();
|
|
259
|
-
|
|
260
|
-
await service.addGlossaryTerm({
|
|
261
|
-
filename,
|
|
262
|
-
term: 'Deal',
|
|
263
|
-
definition: 'A potential sale',
|
|
264
|
-
avoid: ['Opportunity'],
|
|
265
|
-
});
|
|
266
|
-
const redefined = await service.addGlossaryTerm({
|
|
267
|
-
filename,
|
|
268
|
-
term: 'deal',
|
|
269
|
-
definition: 'A potential sale with a value and a stage',
|
|
270
|
-
avoid: ['Opportunity', 'Lead'],
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
expect(redefined).toEqual({ term: 'deal', replaced: true, total_terms: 1 });
|
|
274
|
-
expect(read().glossary).toEqual([
|
|
275
|
-
{
|
|
276
|
-
term: 'deal',
|
|
277
|
-
definition: 'A potential sale with a value and a stage',
|
|
278
|
-
avoid: ['Opportunity', 'Lead'],
|
|
279
|
-
},
|
|
280
|
-
]);
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
describe('phases', () => {
|
|
285
|
-
async function seedPhases() {
|
|
286
|
-
const context = await seed();
|
|
287
|
-
const { filename, service } = context;
|
|
288
|
-
|
|
289
|
-
for (const name of ['Contacts', 'Deals', 'Pipeline']) {
|
|
290
|
-
await service.createCustomPhase({
|
|
291
|
-
filename,
|
|
292
|
-
name,
|
|
293
|
-
description: '',
|
|
294
|
-
color: '#4f46e5',
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return context;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
it('renames a phase and rejects duplicate names', async () => {
|
|
302
|
-
const { filename, service } = await seedPhases();
|
|
303
|
-
|
|
304
|
-
const result = await service.updatePhase({
|
|
305
|
-
filename,
|
|
306
|
-
phaseId: 'PHASE001',
|
|
307
|
-
name: 'People',
|
|
308
|
-
});
|
|
309
|
-
expect(result.phases[0]).toMatchObject({ id: 'PHASE001', name: 'People' });
|
|
310
|
-
|
|
311
|
-
await expect(
|
|
312
|
-
service.updatePhase({ filename, phaseId: 'PHASE002', name: 'people' }),
|
|
313
|
-
).rejects.toThrow(/already exists/);
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it('deletes a phase, keeps its stories and renumbers the rest', async () => {
|
|
317
|
-
const { filename, service, read } = await seedPhases();
|
|
318
|
-
|
|
319
|
-
await service.addUserStory({
|
|
320
|
-
filename,
|
|
321
|
-
userType: 'founder',
|
|
322
|
-
action: 'add a contact',
|
|
323
|
-
benefit: 'I remember people',
|
|
324
|
-
acceptanceCriteria: ['Contact saved'],
|
|
325
|
-
priority: 'P1',
|
|
326
|
-
});
|
|
327
|
-
await service.assignStoryToPhase({
|
|
328
|
-
filename,
|
|
329
|
-
storyId: 'US001',
|
|
330
|
-
phaseId: 'PHASE001',
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
const result = await service.deletePhase({ filename, phaseId: 'PHASE001' });
|
|
334
|
-
|
|
335
|
-
expect(result.phases.map((phase) => [phase.id, phase.order])).toEqual([
|
|
336
|
-
['PHASE002', 0],
|
|
337
|
-
['PHASE003', 1],
|
|
338
|
-
]);
|
|
339
|
-
expect(read().userStories.map((story) => story.id)).toEqual(['US001']);
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
it('reorders phases, which changes what get_next_story picks', async () => {
|
|
343
|
-
const { filename, service } = await seedPhases();
|
|
344
|
-
|
|
345
|
-
for (const action of ['add a contact', 'add a deal']) {
|
|
346
|
-
await service.addUserStory({
|
|
347
|
-
filename,
|
|
348
|
-
userType: 'founder',
|
|
349
|
-
action,
|
|
350
|
-
benefit: 'it helps',
|
|
351
|
-
acceptanceCriteria: ['works'],
|
|
352
|
-
priority: 'P2',
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
await service.assignStoryToPhase({
|
|
356
|
-
filename,
|
|
357
|
-
storyId: 'US001',
|
|
358
|
-
phaseId: 'PHASE001',
|
|
359
|
-
});
|
|
360
|
-
await service.assignStoryToPhase({
|
|
361
|
-
filename,
|
|
362
|
-
storyId: 'US002',
|
|
363
|
-
phaseId: 'PHASE002',
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
expect((await service.getNextStory(filename)).story?.id).toBe('US001');
|
|
367
|
-
|
|
368
|
-
await service.reorderPhases({
|
|
369
|
-
filename,
|
|
370
|
-
phaseIds: ['PHASE002', 'PHASE001', 'PHASE003'],
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
expect((await service.getNextStory(filename)).story?.id).toBe('US002');
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it('requires every phase exactly once when reordering', async () => {
|
|
377
|
-
const { filename, service } = await seedPhases();
|
|
378
|
-
|
|
379
|
-
await expect(
|
|
380
|
-
service.reorderPhases({ filename, phaseIds: ['PHASE002', 'PHASE001'] }),
|
|
381
|
-
).rejects.toThrow(/every phase exactly once/);
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
describe('test seams', () => {
|
|
386
|
-
it('stores seams when adding and updating a story', async () => {
|
|
387
|
-
const { filename, service, read } = await seed();
|
|
388
|
-
|
|
389
|
-
await service.addUserStory({
|
|
390
|
-
filename,
|
|
391
|
-
userType: 'founder',
|
|
392
|
-
action: 'move a deal between stages',
|
|
393
|
-
benefit: 'the board stays current',
|
|
394
|
-
acceptanceCriteria: ['Stage saved'],
|
|
395
|
-
priority: 'P1',
|
|
396
|
-
testSeams: ['moveDealAction'],
|
|
397
|
-
});
|
|
398
|
-
expect(read().userStories[0]?.testSeams).toEqual(['moveDealAction']);
|
|
399
|
-
|
|
400
|
-
await service.updateUserStory({
|
|
401
|
-
filename,
|
|
402
|
-
storyId: 'US001',
|
|
403
|
-
testSeams: ['DealsService.move'],
|
|
404
|
-
});
|
|
405
|
-
expect(read().userStories[0]?.testSeams).toEqual(['DealsService.move']);
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
describe('story design and security notes', () => {
|
|
410
|
-
async function seedStory() {
|
|
411
|
-
const seeded = await seed();
|
|
412
|
-
|
|
413
|
-
await seeded.service.addUserStory({
|
|
414
|
-
filename: seeded.filename,
|
|
415
|
-
userType: 'founder',
|
|
416
|
-
action: 'export deals as CSV',
|
|
417
|
-
benefit: 'I can share them',
|
|
418
|
-
acceptanceCriteria: ['CSV downloads'],
|
|
419
|
-
priority: 'P1',
|
|
420
|
-
designNotes: ['Export button sits in the table toolbar'],
|
|
421
|
-
securityNotes: [
|
|
422
|
-
'Formula injection: cells starting with = are prefixed with a quote',
|
|
423
|
-
],
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
return seeded;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
it('stores notes when adding a story and shows them in get_story', async () => {
|
|
430
|
-
const { filename, service, read } = await seedStory();
|
|
431
|
-
|
|
432
|
-
expect(read().userStories[0]).toMatchObject({
|
|
433
|
-
designNotes: ['Export button sits in the table toolbar'],
|
|
434
|
-
securityNotes: [
|
|
435
|
-
'Formula injection: cells starting with = are prefixed with a quote',
|
|
436
|
-
],
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
const context = await service.getStory({ filename, storyId: 'US001' });
|
|
440
|
-
|
|
441
|
-
expect(context.design.story_notes).toEqual([
|
|
442
|
-
'Export button sits in the table toolbar',
|
|
443
|
-
]);
|
|
444
|
-
expect(context.security.story_notes).toHaveLength(1);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
it('replaces the notes on update, dropping blank entries', async () => {
|
|
448
|
-
const { filename, service, read } = await seedStory();
|
|
449
|
-
|
|
450
|
-
const result = await service.updateUserStory({
|
|
451
|
-
filename,
|
|
452
|
-
storyId: 'US001',
|
|
453
|
-
designNotes: [' Empty state says "No deals to export" ', ' '],
|
|
454
|
-
securityNotes: [],
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
expect(result.updated_fields).toEqual(['designNotes', 'securityNotes']);
|
|
458
|
-
expect(read().userStories[0]?.designNotes).toEqual([
|
|
459
|
-
'Empty state says "No deals to export"',
|
|
460
|
-
]);
|
|
461
|
-
expect(read().userStories[0]?.securityNotes).toEqual([]);
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it('defaults to empty notes in get_story for stories without them', async () => {
|
|
465
|
-
const { filename, service } = await seed();
|
|
466
|
-
|
|
467
|
-
await service.addUserStory({
|
|
468
|
-
filename,
|
|
469
|
-
userType: 'founder',
|
|
470
|
-
action: 'rename a deal',
|
|
471
|
-
benefit: 'names stay accurate',
|
|
472
|
-
acceptanceCriteria: ['Name saved'],
|
|
473
|
-
priority: 'P2',
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
const context = await service.getStory({ filename, storyId: 'US001' });
|
|
477
|
-
|
|
478
|
-
expect(context.design.story_notes).toEqual([]);
|
|
479
|
-
expect(context.security.story_notes).toEqual([]);
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
describe('MCP registration', () => {
|
|
484
|
-
it('exposes the planning tools and the shape_prd prompt', async () => {
|
|
485
|
-
const fake = createFakeMcpServer();
|
|
486
|
-
const { files, filename } = await seed();
|
|
487
|
-
|
|
488
|
-
registerPRDTools(fake.server, createPrdService(createDeps(files)));
|
|
489
|
-
|
|
490
|
-
const result = await fake.call('update_prd_section', {
|
|
491
|
-
filename,
|
|
492
|
-
section: 'outOfScope',
|
|
493
|
-
value: ['Mobile app'],
|
|
494
|
-
});
|
|
495
|
-
expect(result.structuredContent).toEqual({
|
|
496
|
-
section: 'outOfScope',
|
|
497
|
-
updated: ['outOfScope'],
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
const invalid = await fake.call('update_prd_section', {
|
|
501
|
-
filename,
|
|
502
|
-
section: 'outOfScope',
|
|
503
|
-
value: 42,
|
|
504
|
-
});
|
|
505
|
-
expect(invalid.isError).toBe(true);
|
|
506
|
-
|
|
507
|
-
const prompt = fake.prompts.find((entry) => entry.name === 'shape_prd');
|
|
508
|
-
const text = prompt!.handler({ idea: 'A simple CRM' }).messages[0]!.content
|
|
509
|
-
.text;
|
|
510
|
-
|
|
511
|
-
expect(text).toContain('The idea: A simple CRM');
|
|
512
|
-
for (const tool of [
|
|
513
|
-
'create_prd',
|
|
514
|
-
'update_prd_section',
|
|
515
|
-
'add_glossary_term',
|
|
516
|
-
'add_decision',
|
|
517
|
-
'add_user_story',
|
|
518
|
-
]) {
|
|
519
|
-
expect(text).toContain(tool);
|
|
520
|
-
}
|
|
521
|
-
expect(text).toContain('dataModels');
|
|
522
|
-
expect(text).toContain('integrationNeeds');
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
describe('add_user_story with dependencies and a phase', () => {
|
|
527
|
-
const STORY = {
|
|
528
|
-
userType: 'founder',
|
|
529
|
-
benefit: 'it helps',
|
|
530
|
-
acceptanceCriteria: ['works', 'is tested'],
|
|
531
|
-
priority: 'P2' as const,
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
it('sets dependencies and the phase in the same call', async () => {
|
|
535
|
-
const { filename, service, read } = await seed();
|
|
536
|
-
const { phase } = await service.createCustomPhase({
|
|
537
|
-
filename,
|
|
538
|
-
name: 'Deals',
|
|
539
|
-
description: '',
|
|
540
|
-
color: '#4f46e5',
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
await service.addUserStory({ ...STORY, filename, action: 'add a contact' });
|
|
544
|
-
await service.addUserStory({
|
|
545
|
-
...STORY,
|
|
546
|
-
filename,
|
|
547
|
-
action: 'add a deal',
|
|
548
|
-
dependencies: ['US001'],
|
|
549
|
-
phaseId: phase.id,
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
const prd = read();
|
|
553
|
-
|
|
554
|
-
expect(prd.userStories[1]?.dependencies).toEqual(['US001']);
|
|
555
|
-
expect(prd.customPhases[0]?.userStoryIds).toEqual(['US002']);
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
it('rejects an unknown dependency or phase without saving the story', async () => {
|
|
559
|
-
const { filename, service, read } = await seed();
|
|
560
|
-
|
|
561
|
-
await expect(
|
|
562
|
-
service.addUserStory({
|
|
563
|
-
...STORY,
|
|
564
|
-
filename,
|
|
565
|
-
action: 'add a deal',
|
|
566
|
-
dependencies: ['US404'],
|
|
567
|
-
}),
|
|
568
|
-
).rejects.toThrow(/US404/);
|
|
569
|
-
|
|
570
|
-
await expect(
|
|
571
|
-
service.addUserStory({
|
|
572
|
-
...STORY,
|
|
573
|
-
filename,
|
|
574
|
-
action: 'add a deal',
|
|
575
|
-
phaseId: 'PHASE404',
|
|
576
|
-
}),
|
|
577
|
-
).rejects.toThrow(/PHASE404/);
|
|
578
|
-
|
|
579
|
-
expect(read().userStories).toEqual([]);
|
|
580
|
-
expect(read().metadata.lastStoryNumber).toBeUndefined();
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
it('accepts both fields through the MCP tool', async () => {
|
|
584
|
-
const fake = createFakeMcpServer();
|
|
585
|
-
const { files, filename, service, read } = await seed();
|
|
586
|
-
|
|
587
|
-
await service.addUserStory({ ...STORY, filename, action: 'add a contact' });
|
|
588
|
-
const { phase } = await service.createCustomPhase({
|
|
589
|
-
filename,
|
|
590
|
-
name: 'Deals',
|
|
591
|
-
description: '',
|
|
592
|
-
color: '#4f46e5',
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
registerPRDTools(fake.server, createPrdService(createDeps(files)));
|
|
596
|
-
|
|
597
|
-
const result = await fake.call('add_user_story', {
|
|
598
|
-
...STORY,
|
|
599
|
-
filename,
|
|
600
|
-
action: 'add a deal',
|
|
601
|
-
dependencies: ['US001'],
|
|
602
|
-
phaseId: phase.id,
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
expect(result.isError).toBeFalsy();
|
|
606
|
-
expect(read().userStories[1]?.dependencies).toEqual(['US001']);
|
|
607
|
-
expect(read().customPhases[0]?.userStoryIds).toEqual(['US002']);
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
describe('edge cases and design guidance', () => {
|
|
612
|
-
async function seedWithStories() {
|
|
613
|
-
const seeded = await seed();
|
|
614
|
-
|
|
615
|
-
for (const action of ['send an invoice', 'get paid']) {
|
|
616
|
-
await seeded.service.addUserStory({
|
|
617
|
-
filename: seeded.filename,
|
|
618
|
-
userType: 'founder',
|
|
619
|
-
action,
|
|
620
|
-
benefit: 'I get paid',
|
|
621
|
-
acceptanceCriteria: ['It works', 'It is fast'],
|
|
622
|
-
priority: 'P1',
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
return seeded;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
it('replaces the edge cases, giving new ones an id', async () => {
|
|
630
|
-
const { filename, service, read } = await seedWithStories();
|
|
631
|
-
|
|
632
|
-
await service.updatePrdSection({
|
|
633
|
-
filename,
|
|
634
|
-
section: 'edgeCases',
|
|
635
|
-
value: [
|
|
636
|
-
{ case: 'Client pays part of the invoice', status: 'open', storyIds: ['US002'] },
|
|
637
|
-
{ case: 'Email bounces', expectedBehavior: 'Pause and notify', status: 'decided' },
|
|
638
|
-
],
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
expect(read().edgeCases).toEqual([
|
|
642
|
-
{
|
|
643
|
-
id: 'EC001',
|
|
644
|
-
case: 'Client pays part of the invoice',
|
|
645
|
-
expectedBehavior: '',
|
|
646
|
-
status: 'open',
|
|
647
|
-
storyIds: ['US002'],
|
|
648
|
-
},
|
|
649
|
-
{ id: 'EC002', case: 'Email bounces', expectedBehavior: 'Pause and notify', status: 'decided' },
|
|
650
|
-
]);
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
it('rejects a decided case without behaviour and links to unknown stories', async () => {
|
|
654
|
-
const { filename, service, read } = await seedWithStories();
|
|
655
|
-
|
|
656
|
-
await expect(
|
|
657
|
-
service.updatePrdSection({
|
|
658
|
-
filename,
|
|
659
|
-
section: 'edgeCases',
|
|
660
|
-
value: [{ case: 'Bounce', status: 'decided' }],
|
|
661
|
-
}),
|
|
662
|
-
).rejects.toThrow(/decided edge case needs its expectedBehavior/);
|
|
663
|
-
|
|
664
|
-
await expect(
|
|
665
|
-
service.updatePrdSection({
|
|
666
|
-
filename,
|
|
667
|
-
section: 'edgeCases',
|
|
668
|
-
value: [{ case: 'Bounce', storyIds: ['US999'] }],
|
|
669
|
-
}),
|
|
670
|
-
).rejects.toThrow(/unknown stories US999/);
|
|
671
|
-
|
|
672
|
-
expect(read().edgeCases).toEqual([]);
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
it('gives a story its edge cases and the design rules', async () => {
|
|
676
|
-
const { filename, service } = await seedWithStories();
|
|
677
|
-
|
|
678
|
-
await service.updatePrdSection({
|
|
679
|
-
filename,
|
|
680
|
-
section: 'edgeCases',
|
|
681
|
-
value: [
|
|
682
|
-
{ case: 'Partial payment', storyIds: ['US002'] },
|
|
683
|
-
{ case: 'Server down', expectedBehavior: 'Retry later', status: 'decided' },
|
|
684
|
-
],
|
|
685
|
-
});
|
|
686
|
-
await service.updatePrdSection({
|
|
687
|
-
filename,
|
|
688
|
-
section: 'designGuidance',
|
|
689
|
-
value: ['Use the kit components'],
|
|
690
|
-
});
|
|
691
|
-
await service.addDecision({
|
|
692
|
-
filename,
|
|
693
|
-
decision: 'Invoices open in a side panel',
|
|
694
|
-
rationale: 'Keeps the list in view',
|
|
695
|
-
status: 'accepted',
|
|
696
|
-
topic: 'design:invoice-detail',
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
const first = await service.getStory({ filename, storyId: 'US001' });
|
|
700
|
-
const second = await service.getStory({ filename, storyId: 'US002' });
|
|
701
|
-
|
|
702
|
-
expect(first.edge_cases.map((edgeCase) => edgeCase.case)).toEqual(['Server down']);
|
|
703
|
-
expect(second.edge_cases.map((edgeCase) => edgeCase.case)).toEqual([
|
|
704
|
-
'Partial payment',
|
|
705
|
-
'Server down',
|
|
706
|
-
]);
|
|
707
|
-
expect(first.design).toEqual({
|
|
708
|
-
guidance: ['Use the kit components'],
|
|
709
|
-
decisions: [
|
|
710
|
-
expect.objectContaining({ decision: 'Invoices open in a side panel' }),
|
|
711
|
-
],
|
|
712
|
-
story_notes: [],
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
it('drops an edge case only about a deleted story and unlinks shared ones', async () => {
|
|
717
|
-
const { filename, service, read } = await seedWithStories();
|
|
718
|
-
|
|
719
|
-
await service.updatePrdSection({
|
|
720
|
-
filename,
|
|
721
|
-
section: 'edgeCases',
|
|
722
|
-
value: [
|
|
723
|
-
{ case: 'Only about US002', storyIds: ['US002'] },
|
|
724
|
-
{ case: 'Shared', storyIds: ['US001', 'US002'] },
|
|
725
|
-
],
|
|
726
|
-
});
|
|
727
|
-
await service.deleteUserStory({ filename, storyId: 'US002' });
|
|
728
|
-
|
|
729
|
-
expect(read().edgeCases.map(({ case: text, storyIds }) => [text, storyIds])).toEqual([
|
|
730
|
-
['Shared', ['US001']],
|
|
731
|
-
]);
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
it('keeps hand-edited files readable', async () => {
|
|
735
|
-
const { normalizePrd } = await import('../prd.service');
|
|
736
|
-
|
|
737
|
-
const prd = normalizePrd(
|
|
738
|
-
{
|
|
739
|
-
edgeCases: [{ id: 'EC1', case: 'Fine' }, { case: 'No id' }, 'nonsense', null],
|
|
740
|
-
designGuidance: ['Ok', 3],
|
|
741
|
-
},
|
|
742
|
-
'2026-10-15',
|
|
743
|
-
);
|
|
744
|
-
|
|
745
|
-
expect(prd.edgeCases).toEqual([
|
|
746
|
-
{ id: 'EC1', case: 'Fine', expectedBehavior: '', status: 'open' },
|
|
747
|
-
]);
|
|
748
|
-
expect(prd.designGuidance).toEqual(['Ok']);
|
|
749
|
-
});
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
describe('mark_not_applicable', () => {
|
|
753
|
-
it('marks and unmarks a part, keeping the reason', async () => {
|
|
754
|
-
const { filename, service, read } = await seed();
|
|
755
|
-
|
|
756
|
-
expect(
|
|
757
|
-
await service.markNotApplicable({
|
|
758
|
-
filename,
|
|
759
|
-
topic: 'rollout',
|
|
760
|
-
notApplicable: true,
|
|
761
|
-
reason: ' Internal tool ',
|
|
762
|
-
}),
|
|
763
|
-
).toEqual({ topic: 'rollout', not_applicable: true, reason: 'Internal tool' });
|
|
764
|
-
expect(read().notApplicable).toEqual({ rollout: 'Internal tool' });
|
|
765
|
-
|
|
766
|
-
await service.markNotApplicable({ filename, topic: 'rollout', notApplicable: false });
|
|
767
|
-
|
|
768
|
-
expect(read().notApplicable).toEqual({});
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
it('rejects a change based on an older revision', async () => {
|
|
772
|
-
const { filename, service, read } = await seed();
|
|
773
|
-
const seen = read().metadata.revision ?? 0;
|
|
774
|
-
|
|
775
|
-
await service.updatePrdSection({ filename, section: 'nonGoals', value: ['x'] });
|
|
776
|
-
|
|
777
|
-
await expect(
|
|
778
|
-
service.markNotApplicable({
|
|
779
|
-
filename,
|
|
780
|
-
topic: 'risks',
|
|
781
|
-
notApplicable: true,
|
|
782
|
-
expectedRevision: seen,
|
|
783
|
-
}),
|
|
784
|
-
).rejects.toThrow(/changed by someone else/);
|
|
785
|
-
});
|
|
786
|
-
|
|
787
|
-
it('drops unknown topics from hand-edited files', async () => {
|
|
788
|
-
const { normalizePrd } = await import('../prd.service');
|
|
789
|
-
|
|
790
|
-
expect(
|
|
791
|
-
normalizePrd({ notApplicable: { rollout: 'x', nonsense: 'y', risks: 3 } }, '2026-10-15')
|
|
792
|
-
.notApplicable,
|
|
793
|
-
).toEqual({ rollout: 'x' });
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
it('tells the agent about security rules and parts that do not apply', async () => {
|
|
797
|
-
const { filename, service } = await seed();
|
|
798
|
-
|
|
799
|
-
await service.addUserStory({
|
|
800
|
-
filename,
|
|
801
|
-
userType: 'founder',
|
|
802
|
-
action: 'send an invoice',
|
|
803
|
-
benefit: 'I get paid',
|
|
804
|
-
acceptanceCriteria: ['a', 'b'],
|
|
805
|
-
priority: 'P1',
|
|
806
|
-
});
|
|
807
|
-
await service.updatePrdSection({
|
|
808
|
-
filename,
|
|
809
|
-
section: 'securityConsiderations',
|
|
810
|
-
value: ['Validate all input on the server'],
|
|
811
|
-
});
|
|
812
|
-
await service.updatePrdSection({
|
|
813
|
-
filename,
|
|
814
|
-
section: 'technicalContracts',
|
|
815
|
-
value: { permissions: ['Only the owner sees an invoice'] },
|
|
816
|
-
});
|
|
817
|
-
await service.markNotApplicable({ filename, topic: 'rollout', notApplicable: true, reason: 'Internal' });
|
|
818
|
-
|
|
819
|
-
const context = await service.getStory({ filename, storyId: 'US001' });
|
|
820
|
-
|
|
821
|
-
expect(context.security).toEqual({
|
|
822
|
-
permissions: ['Only the owner sees an invoice'],
|
|
823
|
-
compliance: [],
|
|
824
|
-
considerations: ['Validate all input on the server'],
|
|
825
|
-
story_notes: [],
|
|
826
|
-
});
|
|
827
|
-
expect(context.not_applicable).toEqual({ rollout: 'Internal' });
|
|
828
|
-
});
|
|
829
|
-
});
|
|
830
|
-
|
|
831
|
-
describe('open questions', () => {
|
|
832
|
-
async function seedWithStory() {
|
|
833
|
-
const seeded = await seed();
|
|
834
|
-
|
|
835
|
-
await seeded.service.addUserStory({
|
|
836
|
-
filename: seeded.filename,
|
|
837
|
-
userType: 'founder',
|
|
838
|
-
action: 'track deals',
|
|
839
|
-
benefit: 'I close more',
|
|
840
|
-
acceptanceCriteria: ['a', 'b'],
|
|
841
|
-
priority: 'P1',
|
|
842
|
-
});
|
|
843
|
-
|
|
844
|
-
return seeded;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
it('stores questions with why, options, recommendation and blocked stories', async () => {
|
|
848
|
-
const { filename, service, read } = await seedWithStory();
|
|
849
|
-
const [existing] = read().openQuestions;
|
|
850
|
-
|
|
851
|
-
await service.updatePrdSection({
|
|
852
|
-
filename,
|
|
853
|
-
section: 'openQuestions',
|
|
854
|
-
value: [
|
|
855
|
-
existing,
|
|
856
|
-
{
|
|
857
|
-
question: 'Can a deal be reopened?',
|
|
858
|
-
why: 'Otherwise the agent decides whether lost deals are final',
|
|
859
|
-
options: ['Yes, by its owner', 'No, create a new deal'],
|
|
860
|
-
recommended: 'No, create a new deal',
|
|
861
|
-
storyIds: ['US001'],
|
|
862
|
-
},
|
|
863
|
-
'A plain question still works',
|
|
864
|
-
],
|
|
865
|
-
});
|
|
866
|
-
|
|
867
|
-
expect(read().openQuestions.map(({ id, question }) => `${id} ${question}`)).toEqual([
|
|
868
|
-
'Q001 Can a deal have several contacts?',
|
|
869
|
-
'Q003 Can a deal be reopened?',
|
|
870
|
-
'Q004 A plain question still works',
|
|
871
|
-
]);
|
|
872
|
-
expect(read().openQuestions[1]).toMatchObject({
|
|
873
|
-
options: ['Yes, by its owner', 'No, create a new deal'],
|
|
874
|
-
recommended: 'No, create a new deal',
|
|
875
|
-
storyIds: ['US001'],
|
|
876
|
-
});
|
|
877
|
-
});
|
|
878
|
-
|
|
879
|
-
it('never reuses the id of an answered question', async () => {
|
|
880
|
-
const { filename, service, read } = await seed();
|
|
881
|
-
|
|
882
|
-
await service.resolveOpenQuestion({
|
|
883
|
-
filename,
|
|
884
|
-
questionId: 'Q002',
|
|
885
|
-
answer: 'No',
|
|
886
|
-
recordDecision: true,
|
|
887
|
-
});
|
|
888
|
-
await service.updatePrdSection({
|
|
889
|
-
filename,
|
|
890
|
-
section: 'openQuestions',
|
|
891
|
-
value: [...read().openQuestions, 'New question'],
|
|
892
|
-
});
|
|
893
|
-
|
|
894
|
-
expect(read().openQuestions.map((q) => q.id)).toEqual(['Q001', 'Q003']);
|
|
895
|
-
});
|
|
896
|
-
|
|
897
|
-
it('rejects links to unknown stories', async () => {
|
|
898
|
-
const { filename, service } = await seed();
|
|
899
|
-
|
|
900
|
-
await expect(
|
|
901
|
-
service.updatePrdSection({
|
|
902
|
-
filename,
|
|
903
|
-
section: 'openQuestions',
|
|
904
|
-
value: [{ question: 'x', storyIds: ['US404'] }],
|
|
905
|
-
}),
|
|
906
|
-
).rejects.toThrow(/unknown stories US404/);
|
|
907
|
-
});
|
|
908
|
-
|
|
909
|
-
it('answers by id with the revision it was based on', async () => {
|
|
910
|
-
const { filename, service, read } = await seed();
|
|
911
|
-
const seen = read().metadata.revision ?? 0;
|
|
912
|
-
|
|
913
|
-
await service.updatePrdSection({ filename, section: 'nonGoals', value: ['x'] });
|
|
914
|
-
|
|
915
|
-
await expect(
|
|
916
|
-
service.resolveOpenQuestion({
|
|
917
|
-
filename,
|
|
918
|
-
questionId: 'Q001',
|
|
919
|
-
answer: 'Yes',
|
|
920
|
-
recordDecision: true,
|
|
921
|
-
expectedRevision: seen,
|
|
922
|
-
}),
|
|
923
|
-
).rejects.toThrow(/changed by someone else/);
|
|
924
|
-
expect(read().openQuestions).toHaveLength(2);
|
|
925
|
-
});
|
|
926
|
-
|
|
927
|
-
it('gives a story the questions that block it', async () => {
|
|
928
|
-
const { filename, service } = await seedWithStory();
|
|
929
|
-
|
|
930
|
-
await service.updatePrdSection({
|
|
931
|
-
filename,
|
|
932
|
-
section: 'openQuestions',
|
|
933
|
-
value: [{ question: 'Blocks it', storyIds: ['US001'] }, 'Does not'],
|
|
934
|
-
});
|
|
935
|
-
|
|
936
|
-
const context = await service.getStory({ filename, storyId: 'US001' });
|
|
937
|
-
|
|
938
|
-
expect(context.open_questions.map((q) => q.question)).toEqual(['Blocks it']);
|
|
939
|
-
});
|
|
940
|
-
|
|
941
|
-
it('reads plain-string questions from older files', async () => {
|
|
942
|
-
const { normalizePrd } = await import('../prd.service');
|
|
943
|
-
|
|
944
|
-
expect(
|
|
945
|
-
normalizePrd({ openQuestions: ['First', { id: 'Q007', question: 'Kept' }, '', 3] }, '2026-10-15')
|
|
946
|
-
.openQuestions,
|
|
947
|
-
).toEqual([
|
|
948
|
-
{ id: 'Q008', question: 'First' },
|
|
949
|
-
{ id: 'Q007', question: 'Kept' },
|
|
950
|
-
]);
|
|
951
|
-
});
|
|
952
|
-
});
|
|
953
|
-
|
|
954
|
-
describe('decide_edge_case', () => {
|
|
955
|
-
it('decides an open edge case', async () => {
|
|
956
|
-
const { filename, service, read } = await seed();
|
|
957
|
-
|
|
958
|
-
await service.updatePrdSection({
|
|
959
|
-
filename,
|
|
960
|
-
section: 'edgeCases',
|
|
961
|
-
value: [{ case: 'Duplicate contact' }, { case: 'Deal without owner' }],
|
|
962
|
-
});
|
|
963
|
-
|
|
964
|
-
expect(
|
|
965
|
-
await service.decideEdgeCase({
|
|
966
|
-
filename,
|
|
967
|
-
edgeCaseId: 'EC001',
|
|
968
|
-
expectedBehavior: ' Merge into the existing contact ',
|
|
969
|
-
}),
|
|
970
|
-
).toEqual({ edge_case_id: 'EC001', open_edge_cases: 1 });
|
|
971
|
-
expect(read().edgeCases[0]).toMatchObject({
|
|
972
|
-
status: 'decided',
|
|
973
|
-
expectedBehavior: 'Merge into the existing contact',
|
|
974
|
-
});
|
|
975
|
-
});
|
|
976
|
-
|
|
977
|
-
it('fails for an unknown edge case', async () => {
|
|
978
|
-
const { filename, service } = await seed();
|
|
979
|
-
|
|
980
|
-
await expect(
|
|
981
|
-
service.decideEdgeCase({ filename, edgeCaseId: 'EC404', expectedBehavior: 'x' }),
|
|
982
|
-
).rejects.toThrow(/EC404/);
|
|
983
|
-
});
|
|
984
|
-
});
|
|
985
|
-
|
|
986
|
-
describe('update_story_status with expectedRevision', () => {
|
|
987
|
-
it('rejects a status change based on an older revision, before running checks', async () => {
|
|
988
|
-
const { filename, service, read } = await seed();
|
|
989
|
-
|
|
990
|
-
await service.addUserStory({
|
|
991
|
-
filename,
|
|
992
|
-
userType: 'founder',
|
|
993
|
-
action: 'track deals',
|
|
994
|
-
benefit: 'I close more',
|
|
995
|
-
acceptanceCriteria: ['a', 'b'],
|
|
996
|
-
priority: 'P1',
|
|
997
|
-
});
|
|
998
|
-
const seen = read().metadata.revision ?? 0;
|
|
999
|
-
|
|
1000
|
-
await service.updatePrdSection({ filename, section: 'nonGoals', value: ['x'] });
|
|
1001
|
-
|
|
1002
|
-
await expect(
|
|
1003
|
-
service.updateStoryStatus({
|
|
1004
|
-
filename,
|
|
1005
|
-
storyId: 'US001',
|
|
1006
|
-
status: 'blocked',
|
|
1007
|
-
expectedRevision: seen,
|
|
1008
|
-
}),
|
|
1009
|
-
).rejects.toThrow(/changed by someone else/);
|
|
1010
|
-
expect(read().userStories[0]?.status).toBe('not_started');
|
|
1011
|
-
|
|
1012
|
-
await service.updateStoryStatus({
|
|
1013
|
-
filename,
|
|
1014
|
-
storyId: 'US001',
|
|
1015
|
-
status: 'blocked',
|
|
1016
|
-
expectedRevision: seen + 1,
|
|
1017
|
-
});
|
|
1018
|
-
expect(read().userStories[0]?.status).toBe('blocked');
|
|
1019
|
-
});
|
|
1020
|
-
});
|
|
1021
|
-
|
|
1022
|
-
describe('update_user_story with phase and revision', () => {
|
|
1023
|
-
it('moves the story to a phase in the same write, and refuses stale edits', async () => {
|
|
1024
|
-
const { filename, service, read } = await seed();
|
|
1025
|
-
|
|
1026
|
-
await service.addUserStory({
|
|
1027
|
-
filename,
|
|
1028
|
-
userType: 'founder',
|
|
1029
|
-
action: 'track deals',
|
|
1030
|
-
benefit: 'I close more',
|
|
1031
|
-
acceptanceCriteria: ['a', 'b'],
|
|
1032
|
-
priority: 'P1',
|
|
1033
|
-
});
|
|
1034
|
-
const { phase } = await service.createCustomPhase({
|
|
1035
|
-
filename,
|
|
1036
|
-
name: 'MVP',
|
|
1037
|
-
description: '',
|
|
1038
|
-
color: '#4f46e5',
|
|
1039
|
-
});
|
|
1040
|
-
const seen = read().metadata.revision ?? 0;
|
|
1041
|
-
|
|
1042
|
-
const result = await service.updateUserStory({
|
|
1043
|
-
filename,
|
|
1044
|
-
storyId: 'US001',
|
|
1045
|
-
title: 'Track deals',
|
|
1046
|
-
phaseId: phase.id,
|
|
1047
|
-
expectedRevision: seen,
|
|
1048
|
-
});
|
|
1049
|
-
|
|
1050
|
-
expect(result.updated_fields).toEqual(['title', 'phase']);
|
|
1051
|
-
expect(read().customPhases[0]?.userStoryIds).toEqual(['US001']);
|
|
1052
|
-
expect(read().metadata.revision).toBe(seen + 1);
|
|
1053
|
-
|
|
1054
|
-
await expect(
|
|
1055
|
-
service.updateUserStory({ filename, storyId: 'US001', title: 'Stale', expectedRevision: seen }),
|
|
1056
|
-
).rejects.toThrow(/changed by someone else/);
|
|
1057
|
-
expect(read().userStories[0]?.title).toBe('Track deals');
|
|
1058
|
-
});
|
|
1059
|
-
});
|