Skip to content

Commit e7b2e43

Browse files
jonit-devTest User
andauthored
fix: embed prd-creator structure in roadmap slicer
Co-authored-by: Test User <test@test.com>
1 parent bc61d33 commit e7b2e43

3 files changed

Lines changed: 238 additions & 116 deletions

File tree

packages/core/src/__tests__/templates/slicer-prompt.test.ts

Lines changed: 108 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,149 +2,174 @@
22
* Tests for the Slicer Prompt Template rendering system
33
*/
44

5-
import { describe, it, expect, beforeEach } from "vitest";
5+
import { describe, it, expect, beforeEach } from 'vitest';
66
import {
77
renderSlicerPrompt,
88
loadSlicerTemplate,
99
clearTemplateCache,
1010
createSlicerPromptVars,
1111
ISlicerPromptVars,
12-
} from "../../templates/slicer-prompt.js";
12+
} from '../../templates/slicer-prompt.js';
1313

1414
function createTestVars(overrides: Partial<ISlicerPromptVars> = {}): ISlicerPromptVars {
1515
return {
16-
title: "Test Feature",
17-
section: "Features",
18-
description: "A test feature description",
19-
outputFilePath: "/path/to/prds/01-test-feature.md",
20-
prdDir: "/path/to/prds",
16+
title: 'Test Feature',
17+
section: 'Features',
18+
description: 'A test feature description',
19+
outputFilePath: '/path/to/prds/01-test-feature.md',
20+
prdDir: '/path/to/prds',
2121
...overrides,
2222
};
2323
}
2424

25-
describe("slicer-prompt", () => {
25+
describe('slicer-prompt', () => {
2626
beforeEach(() => {
2727
// Clear the template cache before each test
2828
clearTemplateCache();
2929
});
3030

31-
describe("renderSlicerPrompt", () => {
32-
it("should interpolate all placeholders", () => {
31+
describe('renderSlicerPrompt', () => {
32+
it('should interpolate all placeholders', () => {
3333
const vars = createTestVars({
34-
title: "My Awesome Feature",
35-
section: "Roadmap",
36-
description: "This feature does amazing things",
37-
outputFilePath: "/project/docs/PRDs/42-awesome.md",
38-
prdDir: "/project/docs/PRDs",
34+
title: 'My Awesome Feature',
35+
section: 'Roadmap',
36+
description: 'This feature does amazing things',
37+
outputFilePath: '/project/docs/PRDs/42-awesome.md',
38+
prdDir: '/project/docs/PRDs',
3939
});
4040

4141
const result = renderSlicerPrompt(vars);
4242

43-
expect(result).toContain("My Awesome Feature");
44-
expect(result).toContain("Roadmap");
45-
expect(result).toContain("This feature does amazing things");
46-
expect(result).toContain("/project/docs/PRDs/42-awesome.md");
47-
expect(result).toContain("/project/docs/PRDs");
43+
expect(result).toContain('My Awesome Feature');
44+
expect(result).toContain('Roadmap');
45+
expect(result).toContain('This feature does amazing things');
46+
expect(result).toContain('/project/docs/PRDs/42-awesome.md');
47+
expect(result).toContain('/project/docs/PRDs');
4848
});
4949

50-
it("should not contain any uninterpolated placeholders", () => {
50+
it('should not contain any uninterpolated placeholders', () => {
5151
const vars = createTestVars();
5252

5353
const result = renderSlicerPrompt(vars);
5454

55-
expect(result).not.toContain("{{");
56-
expect(result).not.toContain("}}");
55+
expect(result).not.toContain('{{');
56+
expect(result).not.toContain('}}');
5757
});
5858

59-
it("should include prd-creator template structure", () => {
59+
it('should include prd-creator template structure', () => {
6060
const vars = createTestVars();
6161

6262
const result = renderSlicerPrompt(vars);
6363

6464
// Check for key PRD structure elements
65-
expect(result).toContain("Complexity");
66-
expect(result).toContain("Execution Phases");
67-
expect(result).toContain("Context");
68-
expect(result).toContain("Solution");
69-
expect(result).toContain("Acceptance Criteria");
65+
expect(result).toContain('Complexity');
66+
expect(result).toContain('Execution Phases');
67+
expect(result).toContain('Context');
68+
expect(result).toContain('Solution');
69+
expect(result).toContain('Acceptance Criteria');
7070
});
7171

72-
it("should include complexity scoring guide", () => {
72+
it('should embed prd-creator instructions instead of referencing an external file', () => {
7373
const vars = createTestVars();
7474

7575
const result = renderSlicerPrompt(vars);
7676

77-
expect(result).toContain("Complexity Scoring");
78-
expect(result).toContain("Touches 1-5 files");
79-
expect(result).toContain("LOW");
80-
expect(result).toContain("MEDIUM");
81-
expect(result).toContain("HIGH");
77+
expect(result).not.toContain('Read and apply `instructions/prd-creator.md`');
78+
expect(result).not.toContain('Load Planner Skill');
79+
expect(result).toContain('The PRD will be used directly as a GitHub issue body');
8280
});
8381

84-
it("should include instructions to write the file", () => {
82+
it('should include exact required PRD sections inline', () => {
83+
const vars = createTestVars();
84+
85+
const result = renderSlicerPrompt(vars);
86+
87+
expect(result).toContain('## 1. Context');
88+
expect(result).toContain('**Problem:**');
89+
expect(result).toContain('**Files Analyzed:**');
90+
expect(result).toContain('**Current Behavior:**');
91+
expect(result).toContain('## 2. Solution');
92+
expect(result).toContain('## 4. Execution Phases');
93+
expect(result).toContain('## 5. Acceptance Criteria');
94+
expect(result).toContain('The PRD MUST include these sections');
95+
});
96+
97+
it('should include complexity scoring guide', () => {
98+
const vars = createTestVars();
99+
100+
const result = renderSlicerPrompt(vars);
101+
102+
expect(result).toContain('Complexity Scoring');
103+
expect(result).toContain('Touches 1-5 files');
104+
expect(result).toContain('LOW');
105+
expect(result).toContain('MEDIUM');
106+
expect(result).toContain('HIGH');
107+
});
108+
109+
it('should include instructions to write the file', () => {
85110
const vars = createTestVars({
86-
outputFilePath: "/custom/path/feature.md",
111+
outputFilePath: '/custom/path/feature.md',
87112
});
88113

89114
const result = renderSlicerPrompt(vars);
90115

91-
expect(result).toContain("/custom/path/feature.md");
92-
expect(result).toContain("Write tool");
116+
expect(result).toContain('/custom/path/feature.md');
117+
expect(result).toContain('Write tool');
93118
});
94119

95-
it("should use custom template when provided", () => {
96-
const vars = createTestVars({ title: "Custom Title" });
97-
const customTemplate = "Custom Prompt: {{TITLE}} in {{SECTION}}";
120+
it('should use custom template when provided', () => {
121+
const vars = createTestVars({ title: 'Custom Title' });
122+
const customTemplate = 'Custom Prompt: {{TITLE}} in {{SECTION}}';
98123

99124
const result = renderSlicerPrompt(vars, customTemplate);
100125

101-
expect(result).toBe("Custom Prompt: Custom Title in Features");
126+
expect(result).toBe('Custom Prompt: Custom Title in Features');
102127
});
103128

104-
it("should handle empty description", () => {
105-
const vars = createTestVars({ description: "" });
129+
it('should handle empty description', () => {
130+
const vars = createTestVars({ description: '' });
106131

107132
const result = renderSlicerPrompt(vars);
108133

109134
// Should still render without errors
110-
expect(result).toContain("Test Feature");
111-
expect(result).not.toContain("{{DESCRIPTION}}");
135+
expect(result).toContain('Test Feature');
136+
expect(result).not.toContain('{{DESCRIPTION}}');
112137
});
113138

114-
it("should handle special characters in values", () => {
139+
it('should handle special characters in values', () => {
115140
const vars = createTestVars({
116-
title: "Feature with `backticks` and $pecial chars",
117-
description: "Description with\nnewlines\nand **markdown**",
141+
title: 'Feature with `backticks` and $pecial chars',
142+
description: 'Description with\nnewlines\nand **markdown**',
118143
});
119144

120145
const result = renderSlicerPrompt(vars);
121146

122-
expect(result).toContain("Feature with `backticks` and $pecial chars");
123-
expect(result).toContain("Description with\nnewlines\nand **markdown**");
147+
expect(result).toContain('Feature with `backticks` and $pecial chars');
148+
expect(result).toContain('Description with\nnewlines\nand **markdown**');
124149
});
125150
});
126151

127-
describe("loadSlicerTemplate", () => {
128-
it("should load template from file", () => {
152+
describe('loadSlicerTemplate', () => {
153+
it('should load template from file', () => {
129154
const template = loadSlicerTemplate();
130155

131-
expect(template).toContain("Principal Software Architect");
132-
expect(template).toContain("{{TITLE}}");
133-
expect(template).toContain("{{SECTION}}");
134-
expect(template).toContain("{{DESCRIPTION}}");
135-
expect(template).toContain("{{OUTPUT_FILE_PATH}}");
136-
expect(template).toContain("{{PRD_DIR}}");
156+
expect(template).toContain('Principal Software Architect');
157+
expect(template).toContain('{{TITLE}}');
158+
expect(template).toContain('{{SECTION}}');
159+
expect(template).toContain('{{DESCRIPTION}}');
160+
expect(template).toContain('{{OUTPUT_FILE_PATH}}');
161+
expect(template).toContain('{{PRD_DIR}}');
137162
});
138163

139-
it("should cache the template", () => {
164+
it('should cache the template', () => {
140165
const template1 = loadSlicerTemplate();
141166
const template2 = loadSlicerTemplate();
142167

143168
// Should return the same reference (cached)
144169
expect(template1).toBe(template2);
145170
});
146171

147-
it("should clear cache when requested", () => {
172+
it('should clear cache when requested', () => {
148173
loadSlicerTemplate();
149174
clearTemplateCache();
150175

@@ -155,53 +180,47 @@ describe("slicer-prompt", () => {
155180
});
156181
});
157182

158-
describe("createSlicerPromptVars", () => {
159-
it("should create variables with correct paths", () => {
183+
describe('createSlicerPromptVars', () => {
184+
it('should create variables with correct paths', () => {
160185
const vars = createSlicerPromptVars(
161-
"Feature Title",
162-
"Section Name",
163-
"Feature description",
164-
"/path/to/prds",
165-
"99-feature-title.md",
186+
'Feature Title',
187+
'Section Name',
188+
'Feature description',
189+
'/path/to/prds',
190+
'99-feature-title.md',
166191
);
167192

168-
expect(vars.title).toBe("Feature Title");
169-
expect(vars.section).toBe("Section Name");
170-
expect(vars.description).toBe("Feature description");
171-
expect(vars.prdDir).toBe("/path/to/prds");
172-
expect(vars.outputFilePath).toBe("/path/to/prds/99-feature-title.md");
193+
expect(vars.title).toBe('Feature Title');
194+
expect(vars.section).toBe('Section Name');
195+
expect(vars.description).toBe('Feature description');
196+
expect(vars.prdDir).toBe('/path/to/prds');
197+
expect(vars.outputFilePath).toBe('/path/to/prds/99-feature-title.md');
173198
});
174199

175-
it("should handle empty description with default", () => {
176-
const vars = createSlicerPromptVars(
177-
"Feature",
178-
"Section",
179-
"",
180-
"/prds",
181-
"file.md",
182-
);
200+
it('should handle empty description with default', () => {
201+
const vars = createSlicerPromptVars('Feature', 'Section', '', '/prds', 'file.md');
183202

184-
expect(vars.description).toBe("(No description provided)");
203+
expect(vars.description).toBe('(No description provided)');
185204
});
186205
});
187206

188-
describe("integration with prd-creator format", () => {
189-
it("should produce a prompt that instructs AI to explore the codebase", () => {
207+
describe('integration with prd-creator format', () => {
208+
it('should produce a prompt that instructs AI to explore the codebase', () => {
190209
const vars = createTestVars();
191210
const result = renderSlicerPrompt(vars);
192211

193212
expect(result).toMatch(/explore/i);
194213
expect(result).toMatch(/codebase/i);
195214
});
196215

197-
it("should produce a prompt that instructs AI to assess complexity", () => {
216+
it('should produce a prompt that instructs AI to assess complexity', () => {
198217
const vars = createTestVars();
199218
const result = renderSlicerPrompt(vars);
200219

201220
expect(result).toMatch(/assess.*complexity/i);
202221
});
203222

204-
it("should produce a prompt that instructs AI to write a complete PRD with all required sections", () => {
223+
it('should produce a prompt that instructs AI to write a complete PRD with all required sections', () => {
205224
const vars = createTestVars();
206225
const result = renderSlicerPrompt(vars);
207226

@@ -212,9 +231,9 @@ describe("slicer-prompt", () => {
212231
expect(result).toMatch(/acceptance.?criteria/i);
213232
});
214233

215-
it("should emphasize the exact output file path", () => {
234+
it('should emphasize the exact output file path', () => {
216235
const vars = createTestVars({
217-
outputFilePath: "/exact/path/to/prd.md",
236+
outputFilePath: '/exact/path/to/prd.md',
218237
});
219238
const result = renderSlicerPrompt(vars);
220239

0 commit comments

Comments
 (0)