mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-11 15:39:04 +02:00
fix(gen-skill-docs): throw when a template contains {{PREAMBLE}} twice
Hardens the #2508/#2362 class: a second {{PREAMBLE}} occurrence — even a
prose mention, which is exactly how spec/SKILL.md.tmpl re-expanded the full
~12K-token preamble mid-document — now fails generation with the template
path instead of silently shipping a doubled preamble. Pure exported guard
(assertSinglePreamble) called from resolvePlaceholders, unit-tested with the
original prose-mention shape.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
ba979dbd6f
commit
480ebe4f26
@@ -1,4 +1,5 @@
|
||||
import { describe, test, expect, beforeAll } from 'bun:test';
|
||||
import { assertSinglePreamble } from '../scripts/gen-skill-docs';
|
||||
import { COMMAND_DESCRIPTIONS } from '../browse/src/commands';
|
||||
import { SNAPSHOT_FLAGS } from '../browse/src/snapshot';
|
||||
import * as fs from 'fs';
|
||||
@@ -1507,6 +1508,25 @@ describe('CHANGELOG_WORKFLOW resolver', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// --- Duplicate {{PREAMBLE}} guard (#2508/#2362) ---
|
||||
|
||||
describe('assertSinglePreamble', () => {
|
||||
test('one {{PREAMBLE}} passes', () => {
|
||||
expect(() => assertSinglePreamble('a\n{{PREAMBLE}}\nb', 'x/SKILL.md.tmpl')).not.toThrow();
|
||||
});
|
||||
|
||||
test('zero {{PREAMBLE}} passes (sections have none)', () => {
|
||||
expect(() => assertSinglePreamble('no macro here', 'x/sections/y.md.tmpl')).not.toThrow();
|
||||
});
|
||||
|
||||
test('a second occurrence throws with the template path — even in prose', () => {
|
||||
// The original #2508 bug WAS a prose mention: "emitted by {{PREAMBLE}}'s
|
||||
// preamble bash". Resolution is context-blind, so the guard must be too.
|
||||
const tmpl = '{{PREAMBLE}}\n\n...later: emitted by {{PREAMBLE}}\'s preamble bash';
|
||||
expect(() => assertSinglePreamble(tmpl, 'spec/SKILL.md.tmpl')).toThrow(/spec\/SKILL\.md\.tmpl.*2 times/);
|
||||
});
|
||||
});
|
||||
|
||||
// --- Parameterized resolver infrastructure tests ---
|
||||
|
||||
describe('parameterized resolver support', () => {
|
||||
|
||||
Reference in New Issue
Block a user