import assert from 'node:assert/strict';
import { test } from 'node:test';
import { loadCaptionSourceOperations } from '../../shared/transcript-captions.ts';
const ops = await loadCaptionSourceOperations(process.cwd());
const cue = { segments: [{ id: 'cue1', text: 'Parent caption', start: 0, end: 2 }] };
const id = '11111111-1111-4111-8111-111111111111';
test('caption edits remain inside a semantic root and leave nested and sibling tracks intact', () => {
const nested = 'Nested';
const other = '';
for (const tag of ['div','main','section','article']) {
const html = '<' + tag + ' data-composition-id="parent" data-duration="1">
' + nested + '
' + tag + '>' + other;
const added = ops.manualCaptionSource(html, id, cue);
assert.match(added.content, /data-composition-id="parent" data-duration="2">\s*`;
const damaged = added.replace(end, ''+end);
assert.throws(() => ops.updateCaptionTrackSource(damaged, id, {}, true), /markers changed/);
assert.throws(() => ops.manualCaptionSource(damaged, id, cue), /markers changed/);
});