diff --git a/packages/studio/src/components/nle/audioSealedPreview.test.ts b/packages/studio/src/components/nle/audioSealedPreview.test.ts index 2631ca2202..18fdb3e38a 100644 --- a/packages/studio/src/components/nle/audioSealedPreview.test.ts +++ b/packages/studio/src/components/nle/audioSealedPreview.test.ts @@ -181,6 +181,53 @@ it("groups clips in a sealed preview, and unwinds the preview when the save fail expect(document.querySelector("hf-audio-group#vo")).not.toBeNull(); }); +it("ends a sealed group's undo cleanly when the frame's reply is not the shape it asked for", async () => { + document.body.innerHTML = `
+ +
`; + // Studio's end of the port, with the group reply's `previous` replaced as a broken frame might send it. + const brokenReplies = (port: MessagePort) => + ({ + postMessage: (data: unknown) => port.postMessage(data), + start: () => port.start(), + close: () => port.close(), + get onmessage() { + return port.onmessage; + }, + set onmessage(listener: ((event: MessageEvent) => void) | null) { + port.onmessage = + listener && + ((event) => { + const result = (event.data as { result?: Record }).result; + if (result && "previous" in result) result.previous = null; + listener(event); + }); + }, + }) as unknown as MessagePort; + const iframe = sealedPreviewFrame({ wrapHandedOverPort: brokenReplies }).iframe; + stubProjectFiles(new Map([["index.html", document.body.innerHTML]])); + const elements = ["voice-1", "voice-2"].map((domId) => ({ + ...member(domId), + key: `index.html#${domId}`, + audioGroup: undefined, + })); + await expect( + createAudioGroupAndAssignMembers({ + projectId: "project-1", + activeCompPath: "index.html", + elements, + groupId: "vo", + groupLabel: "Voice", + previewIframe: iframe, + recordEdit: async () => {}, + pendingTimelineEditPathRef: { current: new Set() }, + writeProjectFile: async () => { + throw new Error("disk full"); + }, + }), + ).rejects.toThrow("disk full"); +}); + it("reads a sealed preview's groups and ids off an inert copy", async () => { document.body.innerHTML = ``; const copy = await previewDocumentCopy(sealedPreviewFrame().iframe); diff --git a/packages/studio/src/hooks/timelineAudioGroupCreate.ts b/packages/studio/src/hooks/timelineAudioGroupCreate.ts index 5d602fc7d7..92e13514ae 100644 --- a/packages/studio/src/hooks/timelineAudioGroupCreate.ts +++ b/packages/studio/src/hooks/timelineAudioGroupCreate.ts @@ -181,10 +181,17 @@ async function patchSealedGroup( elements.map((element) => findOpaqueTimelineElement(iframe, element, lookup)), ); const handles = found.flatMap((element) => (element ? [element.handle] : [])); - const assigned = await previewRequest(iframe, "assign-audio-group", { + const reply = await previewRequest(iframe, "assign-audio-group", { members: handles.map((handle) => ({ handle, group: groupId })), element: { id: groupId, label: groupLabel ?? null, present: true }, }); + const previous: unknown = reply?.previous; + const assigned = + Array.isArray(previous) && + previous.length === handles.length && + typeof reply?.changed === "boolean" + ? { previous, changed: reply.changed } + : null; return async () => { if (!assigned) return; await previewRequest(iframe, "assign-audio-group", {