From 99e45f0bd2ea51336e44837dfd7521f6888cbf7a Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Sat, 19 Sep 2026 18:00:43 -0400 Subject: [PATCH] fix(studio): gate the audio-group attribute for sub-composition-only members --- .../src/hooks/useTimelineEditing.test.tsx | 52 +++++++++++++++++++ .../studio/src/hooks/useTimelineEditing.ts | 25 +++++++-- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/packages/studio/src/hooks/useTimelineEditing.test.tsx b/packages/studio/src/hooks/useTimelineEditing.test.tsx index 485fe1e8f0..7b553a7dfc 100644 --- a/packages/studio/src/hooks/useTimelineEditing.test.tsx +++ b/packages/studio/src/hooks/useTimelineEditing.test.tsx @@ -1648,6 +1648,58 @@ describe("useTimelineEditing: canEdit gate", () => { expect(fetchMock).not.toHaveBeenCalled(); unmount(); }); + + it("refuses a group write when its members live only inside a sub-composition", async () => { + // syncStoredGroupAttribute mirrors into domClipChildren for a group with + // no flat twin (timelineAudioGroupVolume.ts) — the resolver must check + // that array too, or a sub-comp-only group's write goes ungated. + const iframe = createPreviewIframe([]); + usePlayerStore.getState().setElements([]); + usePlayerStore.getState().setDomClipChildren([ + { + id: "sub-member", + parentId: "host", + hostId: "host", + label: "Sub member", + stackingContextId: "root", + audioGroup: "hf-group", + }, + ]); + const showToast = vi.fn(); + const fetchMock = vi.fn(async () => { + throw new Error("must not be called: canEdit should have refused the write"); + }); + vi.stubGlobal("fetch", fetchMock); + let hook: ReturnType | null = null; + function Harness() { + hook = useTimelineEditing({ + projectId: "p1", + activeCompPath: "index.html", + timelineElements: [], + showToast, + writeProjectFile: vi.fn(), + recordEdit: vi.fn(), + reloadPreview: vi.fn(), + previewIframeRef: { current: iframe }, + pendingTimelineEditPathRef: { current: new Set() }, + uploadProjectFiles: vi.fn(), + canEdit: (element) => + element.id === "sub-member" ? { blocked: true, reason: "Reserved by an agent" } : true, + }); + return null; + } + const { unmount } = mountHarness(); + if (!hook) throw new Error("Expected hook to mount"); + + await act(async () => { + await hook!.setAudioGroupAttribute.setQuiet("hf-group", "data-volume", "0.5", "Set volume"); + await flushAsyncWork(); + }); + + expect(showToast).toHaveBeenCalledWith("Reserved by an agent", "error"); + expect(fetchMock).not.toHaveBeenCalled(); + unmount(); + }); }); // Regression: track()/guard() must return the same wrapped handler across diff --git a/packages/studio/src/hooks/useTimelineEditing.ts b/packages/studio/src/hooks/useTimelineEditing.ts index 5a01c2700e..07c1f19cec 100644 --- a/packages/studio/src/hooks/useTimelineEditing.ts +++ b/packages/studio/src/hooks/useTimelineEditing.ts @@ -500,12 +500,27 @@ export function useTimelineEditing({ handleAutoGroupCarveSources: track(handleAutoGroupCarveSources), setAudioGroupAttribute: { ...setAudioGroupAttribute, - // Same member-resolution syncStoredGroupAttribute uses (timelineAudioGroupVolume.ts). + // Same two-array member lookup syncStoredGroupAttribute mirrors into + // (timelineAudioGroupVolume.ts): a sub-composition's group members have + // no flat twin, only a domClipChildren entry, so both are checked. setQuiet: track( - guard( - (groupId) => usePlayerStore.getState().elements.filter((el) => el.audioGroup === groupId), - setAudioGroupAttribute.setQuiet, - ), + guard((groupId) => { + const state = usePlayerStore.getState(); + const flatMembers = state.elements.filter((el) => el.audioGroup === groupId); + const domMembers = state.domClipChildren + .filter((child) => child.audioGroup === groupId) + .map( + (child): TimelineElement => ({ + id: child.id, + domId: child.id, + tag: "div", + start: 0, + duration: 0, + track: -1, + }), + ); + return [...flatMembers, ...domMembers]; + }, setAudioGroupAttribute.setQuiet), ), }, setElementFxAttribute: {