* test: reproduce extractFrontmatter LAST-block bug (#3240) * fix(sdk): anchor extractFrontmatter at file start (#3240) * changeset: pr=3247 for #3240
This commit is contained in:
@@ -66,10 +66,62 @@ describe('extractFrontmatter', () => {
|
||||
expect(result).toEqual({ items: ['one', 'two'] });
|
||||
});
|
||||
|
||||
it('uses the LAST block when multiple stacked blocks exist', () => {
|
||||
it('uses the LEADING block when multiple stacked blocks exist', () => {
|
||||
// extractFrontmatter is anchored at file start — leading block wins (#3240 fix)
|
||||
const content = '---\nold: data\n---\n---\nnew: data\n---\nbody';
|
||||
const result = extractFrontmatter(content);
|
||||
expect(result).toEqual({ new: 'data' });
|
||||
expect(result).toEqual({ old: 'data' });
|
||||
});
|
||||
|
||||
it('returns the LEADING block when body contains markdown horizontal rules', () => {
|
||||
// Regression: LAST-block semantics picked up body separators as frontmatter (#3240)
|
||||
const content = [
|
||||
'---',
|
||||
'wave: 3',
|
||||
'autonomous: false',
|
||||
'phase: 05-hardening',
|
||||
'---',
|
||||
'',
|
||||
'## Section One',
|
||||
'',
|
||||
'---',
|
||||
'',
|
||||
'## Section Two',
|
||||
'',
|
||||
'---',
|
||||
'',
|
||||
'body text',
|
||||
].join('\n');
|
||||
const result = extractFrontmatter(content);
|
||||
expect(result.wave).toBe('3');
|
||||
expect(result.autonomous).toBe('false');
|
||||
expect(result.phase).toBe('05-hardening');
|
||||
});
|
||||
|
||||
it('returns the LEADING block when body contains embedded YAML in fenced code block', () => {
|
||||
// Regression: LAST-block semantics matched YAML inside ```yaml fences (#3240)
|
||||
const content = [
|
||||
'---',
|
||||
'wave: 2',
|
||||
'autonomous: true',
|
||||
'phase: 04-polish',
|
||||
'---',
|
||||
'',
|
||||
'## Example',
|
||||
'',
|
||||
'```yaml',
|
||||
'---',
|
||||
'name: example',
|
||||
'value: 99',
|
||||
'---',
|
||||
'```',
|
||||
'',
|
||||
'More body text.',
|
||||
].join('\n');
|
||||
const result = extractFrontmatter(content);
|
||||
expect(result.wave).toBe('2');
|
||||
expect(result.autonomous).toBe('true');
|
||||
expect(result.phase).toBe('04-polish');
|
||||
});
|
||||
|
||||
it('handles empty-object-to-array conversion', () => {
|
||||
|
||||
Reference in New Issue
Block a user