Hide orphan json fences in chat bubbles (0.15.14).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Leonid Pershin
2026-08-23 20:34:04 +03:00
co-authored by Cursor
parent 5a7a72d972
commit 61b4b51118
5 changed files with 117 additions and 19 deletions
+24
View File
@@ -3,8 +3,10 @@ import assert from 'node:assert/strict';
import {
extractPatch,
isPatchObject,
liveStreamProse,
normalizePatch,
setPatchKeys,
stripFenceArtifacts,
visibleProse,
} from '../src/patch.js';
import {
@@ -63,6 +65,28 @@ describe('patch.js', () => {
assert.equal(visibleProse('просто чат без патча'), 'просто чат без патча');
});
it('extractPatch strips orphan ```json when JSON is unfenced', () => {
const text = 'О, круто\n\n```json\n{"prompt":"girl on leather sofa, flirt","generate":true}';
const { prose, patch } = extractPatch(text);
assert.ok(patch);
assert.equal(patch.generate, true);
assert.equal(prose, 'О, круто');
assert.ok(!prose.includes('```'));
});
it('liveStreamProse hides unclosed fence while streaming', () => {
const partial = 'О, круто\n\n```json\n{"prompt":"girl';
assert.equal(liveStreamProse(partial), 'О, круто');
assert.equal(
liveStreamProse('Ок\n```json\n{"prompt":"fox","generate":true}\n```'),
'Ок',
);
});
it('stripFenceArtifacts removes lone JSON Patch headers', () => {
assert.equal(stripFenceArtifacts('### JSON Patch\n'), '');
});
it('scheduler-only patch is detected with full key list', () => {
setPatchKeys(['prompt', 'scheduler', 'generate', 'ask']);
assert.equal(isPatchObject({ scheduler: 'euler' }), true);