Skip to content

Commit 68e1192

Browse files
committed
test(wand): record the trailing-fence ambiguity as a decision
A bare fence on the last line closes the wrapper in every well-formed response and is content only when generation stopped exactly on an embedded delimiter. Nothing separates the two, so assert the chosen behavior instead of leaving it implicit.
1 parent 5985357 commit 68e1192

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

apps/sim/lib/wand/strip-code-fences.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ describe('stripCodeFences', () => {
4545
expect(stripCodeFences(truncated)).toBe('const md = `\n```\nhello\n`;\nreturn md;')
4646
})
4747

48+
it('treats a trailing bare fence as the closer even when the body was truncated at one', () => {
49+
// Irreducibly ambiguous: a trailing bare fence closes the wrapper in every
50+
// well-formed response, and is content only when generation stopped exactly
51+
// at an embedded delimiter. Declining to strip it would leave a stray fence
52+
// in the common case, which is the bug this util exists to fix.
53+
expect(stripCodeFences('```javascript\nconst md = `\n```')).toBe('const md = `')
54+
})
55+
4856
it('preserves a fenced docstring inside a Python body', () => {
4957
const fenced = '```python\ntemplate = """\n```sql\nSELECT 1\n```\n"""\nreturn template\n```'
5058
expect(stripCodeFences(fenced)).toBe(

apps/sim/lib/wand/strip-code-fences.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ export function stripCodeFences(text: string): string {
8888
while (inner.length > 0 && inner[inner.length - 1].trim() === '') inner.pop()
8989

9090
// Only the very last line may close the wrapper. A truncated response simply
91-
// has no closer, and every line after the opener survives.
91+
// has no closer, and every line after the opener survives. The one case this
92+
// cannot get right is generation stopping exactly on an embedded delimiter,
93+
// where that final line is content — indistinguishable from a real closer, and
94+
// rarer than the wrap it would otherwise fail to strip.
9295
if (inner.length > 0 && FENCE_LINE.test(inner[inner.length - 1])) inner.pop()
9396

9497
while (inner.length > 0 && inner[0].trim() === '') inner.shift()

0 commit comments

Comments
 (0)