import { strict as assert } from 'node:assert'; import { test } from 'node:test'; import { parseSourceDocument } from '@hyperframes/studio-server/source-mutation'; import { applyTimelineCommand as apply } from '../../packages/edit-core/timeline-commands.ts'; const source = '
'; const root = (s: string) => parseSourceDocument(s).document; test('trim derives the media in point, animation scale and sibling timing from stored source', () => { const after = apply(source, { kind: 'trimClips', changes: [{ hfId: 'v', start: 2, duration: 2 }] }); assert.equal(root(after).querySelector('#v')?.getAttribute('data-media-start'), '4'); assert.match(after, /duration:0.5,x:10\},2.5/); assert.match(after, /duration:1,x:20\},7.5/); }); test('moves, cuts, links, ripple deletion, track flags and gap closing are atomic source edits', () => { const moved = apply(source, { kind: 'moveClips', changes: [ { hfId: 'v', start: 2, track: 3 }, { hfId: 'b', start: 8 }, ], }); assert.equal(root(moved).querySelector('#v')?.getAttribute('data-track-index'), '3'); assert.match(moved, /duration:1,x:20\},8.5/); const cut = root(apply(source, { kind: 'splitClips', hfIds: ['v'], at: 3 })); assert.equal(cut.querySelector('#v-split')?.getAttribute('data-media-start'), '6'); const linked = apply(source, { kind: 'linkClips', hfIds: ['v', 'b'] }); assert.equal(root(linked).querySelectorAll('[data-link]').length, 2); assert.equal( root(apply(linked, { kind: 'unlinkClips', hfIds: ['b'] })).querySelectorAll('[data-link]').length, 0, ); const removed = apply(linked, { kind: 'deleteClips', hfIds: ['v'], rippleTrack: 1 }); assert.equal(root(removed).querySelector('#b')?.getAttribute('data-start'), '3'); assert.equal(root(removed).querySelectorAll('[data-link]').length, 0); const compacted = apply(source, { kind: 'closeTrackGaps', track: 1 }); assert.equal(root(compacted).querySelector('#b')?.getAttribute('data-start'), '4'); const locked = apply(source, { kind: 'setClipState', state: 'locked', enabled: true, hfIds: ['b'] }); assert.throws( () => apply(locked, { kind: 'moveClips', changes: [ { hfId: 'v', start: 2 }, { hfId: 'b', start: 5 }, ], }), /Unlock/, ); }); test('headless detach, linked move, resync and merge use the authored media', () => { const detached = apply(source, { kind: 'detachAudio', hfId: 'v' }); assert.equal(apply(source, { kind: 'detachAudio', hfId: 'v' }), detached); const audioId = root(detached).querySelector('audio[data-link]')!.getAttribute('data-hf-id')!; const moved = apply(detached, { kind: 'moveClips', changes: [{ hfId: 'v', start: 3 }], includeLinked: true, }); assert.equal(root(moved).querySelector('audio[data-link]')!.getAttribute('data-start'), '3'); const drift = apply(moved, { kind: 'moveClips', changes: [{ hfId: audioId, start: 4 }] }); const synced = apply(drift, { kind: 'moveIntoSync', hfId: audioId }); assert.equal(root(synced).querySelector('audio[data-link]')!.getAttribute('data-start'), '3'); const merged = apply(synced, { kind: 'mergeAudio', videoId: 'v', audioId }); assert.equal(root(merged).querySelector('[data-sync-origin]'), null); assert.equal(root(merged).querySelector('#v')!.hasAttribute('muted'), false); }); test('speed preserves the media in point and respects the occupied lane and ripple setting', () => { const speed = { kind: 'setClipSpeed' as const, hfId: 'v', rate: 1 }; const lane = source.replace('