Skip to content

Commit d3caa47

Browse files
committed
test(ids): align extractPurpose tests with refactored priority chain
The previous suite had a test "extracts from description field" that fed a bare `description: ...` string and expected it to be matched. That was exactly the body-level fallback regex that produced the "Analyzes provided dataset" false purpose on component-creation-guide.md (reported by CodeRabbit on PR #747). The refactor in this PR intentionally removed that match, so the test must be updated to reflect the new contract. Changes to the test file: * Replaced "extracts from description field" with two replacement tests: - "extracts from YAML frontmatter `description:` field" — feeds a `---\ndescription: X\n---` block and expects extraction from it. - "handles quoted YAML frontmatter description" — feeds `description: "X"` inside frontmatter and expects the quotes to be stripped. * Added "falls back to ## Overview when no Purpose section" — covers the new strategy 3 in the priority chain (many guides like component-creation-guide.md use Overview instead of Purpose). * Added TWO regression tests for the bug that motivated the refactor: - "does NOT match body-level `description:` outside frontmatter" — reproduces the exact component-creation-guide pattern (Overview section + a fenced code block with `Task description:` inside) and asserts the Overview wins. - "does NOT extract from `description:` lines without YAML frontmatter delimiters" — bare `description: X` without `---` delimiters falls through to the `# Title` header, NOT to the body line. Test result: 79/79 pass. Existing 5 tests in the suite still pass. Two new tests cover the YAML frontmatter branch (priority 1) and the new `## Overview` branch (priority 3). Two regression tests lock in the removal of the body-level matcher so it can't silently come back.
1 parent 88068b8 commit d3caa47

1 file changed

Lines changed: 48 additions & 2 deletions

File tree

tests/core/ids/populate-entity-registry.test.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,24 @@ describe('populate-entity-registry (AC: 3, 4, 12)', () => {
155155
expect(purpose).toBe('This is the purpose line.');
156156
});
157157

158-
it('extracts from description field', () => {
159-
const content = 'description: My awesome description here';
158+
it('extracts from YAML frontmatter `description:` field', () => {
159+
const content = '---\ndescription: My awesome description here\nversion: 1.0\n---\n\n# Title';
160160
const purpose = extractPurpose(content, '/test.md');
161161
expect(purpose).toBe('My awesome description here');
162162
});
163163

164+
it('handles quoted YAML frontmatter description', () => {
165+
const content = '---\ndescription: "A quoted description"\n---\n\n# Title';
166+
const purpose = extractPurpose(content, '/test.md');
167+
expect(purpose).toBe('A quoted description');
168+
});
169+
170+
it('falls back to ## Overview when no Purpose section', () => {
171+
const content = '# Title\n\n## Overview\n\nThis guide walks you through X.\n\n## Other';
172+
const purpose = extractPurpose(content, '/test.md');
173+
expect(purpose).toBe('This guide walks you through X.');
174+
});
175+
164176
it('falls back to header', () => {
165177
const content = '# My Module Title\n\nSome content.';
166178
const purpose = extractPurpose(content, '/test.md');
@@ -177,6 +189,40 @@ describe('populate-entity-registry (AC: 3, 4, 12)', () => {
177189
const purpose = extractPurpose(longPurpose, '/test.md');
178190
expect(purpose.length).toBeLessThanOrEqual(200);
179191
});
192+
193+
// Regression test for the bug that motivated the priority-chain refactor:
194+
// a body-level `description:` line inside example output or a code block
195+
// used to be matched and treated as the doc's purpose. That was the source
196+
// of `component-creation-guide.md` getting "Analyzes provided dataset" as
197+
// its purpose (which was example installer transcript output, not a real
198+
// description of the guide).
199+
it('does NOT match body-level `description:` outside frontmatter', () => {
200+
const content = [
201+
'# Component Creation Guide',
202+
'',
203+
'## Overview',
204+
'',
205+
'This guide walks you through creating components.',
206+
'',
207+
'## Example Output',
208+
'',
209+
'```',
210+
'? Task description: Analyzes provided dataset to identify patterns',
211+
'```',
212+
].join('\n');
213+
const purpose = extractPurpose(content, '/test.md');
214+
// Should pick up Overview section, NOT the body-level "description:"
215+
expect(purpose).toBe('This guide walks you through creating components.');
216+
expect(purpose).not.toContain('Analyzes');
217+
});
218+
219+
it('does NOT extract from `description:` lines without YAML frontmatter delimiters', () => {
220+
const content = 'description: This should not be matched\n\n# Title';
221+
const purpose = extractPurpose(content, '/test.md');
222+
// No `---` delimiters → not frontmatter → falls through to `# Title`
223+
expect(purpose).toBe('Title');
224+
expect(purpose).not.toContain('This should not');
225+
});
180226
});
181227

182228
describe('detectDependencies()', () => {

0 commit comments

Comments
 (0)