Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415import { test } from 'node:test';import assert from 'node:assert/strict';import { extractJSON, SYSTEM_PROMPT } from '../web/lib/ops.js';
test('extractJSON tolerates fences, prose and think blocks', () => { assert.deepEqual(extractJSON('{"a":1}'), { a: 1 }); assert.deepEqual(extractJSON('Sure!\n```json\n{"summary":"x","ops":[]}\n```'), { summary: 'x', ops: [] }); assert.deepEqual(extractJSON('<think>hmm {not json}</think>{"ops":[{"op":"set","kid":1,"attrs":{"d":"M0 0 {"}}]}').ops[0].attrs.d, 'M0 0 {'); assert.equal(extractJSON('no json here'), null);});
test('system prompt documents every op', () => { for (const op of ['set', 'text', 'insert', 'replace', 'remove', 'move', 'wrap', 'document']) assert.match(SYSTEM_PROMPT, new RegExp(`"op":"${op}"`));});