Skip to content

Commit 62b6d35

Browse files
committed
fix(core): address audio group review feedback
1 parent 9afb4a4 commit 62b6d35

3 files changed

Lines changed: 66 additions & 4 deletions

File tree

‎packages/core/src/audioGroups.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
resolveCarveSourceIds,
99
resolveGroupElement,
1010
} from "./audioGroups.js";
11+
import { AUDIO_GROUP_RENDER_ID_ATTR, MEDIA_RENDER_ID_ATTR } from "./compiler/mediaRenderIds.js";
1112

1213
beforeEach(() => {
1314
document.body.innerHTML = "";
@@ -124,6 +125,13 @@ describe("audioGroupOf", () => {
124125
it("normalizes an empty membership attribute to null", () => {
125126
document.body.innerHTML = `<audio id="vo-1" data-audio-group=""></audio>`;
126127
expect(audioGroupOf(document.getElementById("vo-1") as Element)).toBeNull();
128+
expect(resolveAudioGroups(document)).toEqual([]);
129+
});
130+
131+
// Groups do not nest, and the group element is not a member of itself.
132+
it("returns null for the group element even when it carries the attribute", () => {
133+
document.body.innerHTML = `<hf-audio-group id="bus" data-audio-group="other"></hf-audio-group>`;
134+
expect(audioGroupOf(document.getElementById("bus") as Element)).toBeNull();
127135
});
128136
});
129137

@@ -197,6 +205,15 @@ describe("resolveGroupElement", () => {
197205
const d = doc(`<div id="bg" data-hidden></div>`);
198206
expect(resolveGroupElement(d, "bg")).toBeNull();
199207
});
208+
209+
it("matches a stamped id containing selector syntax without throwing", () => {
210+
const d = doc("");
211+
const bus = d.createElement("hf-audio-group");
212+
bus.setAttribute(MEDIA_RENDER_ID_ATTR, 'vo"\\instance');
213+
d.body.append(bus);
214+
215+
expect(resolveGroupElement(d, 'vo"\\instance')).toBe(bus);
216+
});
200217
});
201218

202219
describe("isMemberGroupHidden", () => {
@@ -227,6 +244,18 @@ describe("isMemberGroupHidden", () => {
227244
expect(isMemberGroupHidden(d, d.getElementById("vo-1"))).toBe(false);
228245
expect(isMemberGroupHidden(d, d.getElementById("lone"))).toBe(false);
229246
});
247+
248+
it("uses the stamped bus instance when repeated compositions disagree on mute", () => {
249+
const d = doc(`
250+
<hf-audio-group id="bed" ${MEDIA_RENDER_ID_ATTR}="bed"></hf-audio-group>
251+
<audio id="m1" data-audio-group="bed" ${AUDIO_GROUP_RENDER_ID_ATTR}="bed"></audio>
252+
<hf-audio-group id="bed" ${MEDIA_RENDER_ID_ATTR}="bed__hf2" data-hidden></hf-audio-group>
253+
<audio id="m2" data-audio-group="bed" ${AUDIO_GROUP_RENDER_ID_ATTR}="bed__hf2"></audio>
254+
`);
255+
256+
expect(isMemberGroupHidden(d, d.getElementById("m1"))).toBe(false);
257+
expect(isMemberGroupHidden(d, d.getElementById("m2"))).toBe(true);
258+
});
230259
});
231260

232261
describe("resolveCarveSourceIds — empty group", () => {

‎packages/core/src/audioGroups.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,20 @@ function buildGroup(id: string, memberIds: string[], el: Element | undefined): H
8686
*/
8787
export function resolveGroupElement(
8888
doc:
89-
| (Pick<Document, "getElementById"> & Partial<Pick<Document, "querySelector">>)
89+
| (Pick<Document, "getElementById"> & Partial<Pick<Document, "querySelectorAll">>)
9090
| null
9191
| undefined,
9292
groupId: string,
9393
): Element | null {
9494
// A render-stamped key names an INSTANCE, and `getElementById` cannot find it
9595
// — the author id is what is on the element's `id`. Tried first so a compiled
9696
// document resolves the right one of two identically-named buses.
97-
const stamped =
98-
doc?.querySelector?.(`${HF_AUDIO_GROUP_TAG}[${MEDIA_RENDER_ID_ATTR}="${groupId}"]`) ?? null;
97+
// Compare the raw attribute value instead of interpolating an author-provided
98+
// id into a selector. Quotes and backslashes are valid attribute values, and
99+
// turning one into selector syntax made this otherwise tolerant reader throw.
100+
const stamped = Array.from(
101+
doc?.querySelectorAll?.(`${HF_AUDIO_GROUP_TAG}[${MEDIA_RENDER_ID_ATTR}]`) ?? [],
102+
).find((candidate) => candidate.getAttribute(MEDIA_RENDER_ID_ATTR) === groupId);
99103
if (stamped) return stamped;
100104
const el = doc?.getElementById(groupId) ?? null;
101105
if (!el) return null;
@@ -114,7 +118,11 @@ export function isMemberGroupHidden(
114118
doc: Pick<Document, "getElementById"> | null | undefined,
115119
el: Element | null | undefined,
116120
): boolean {
117-
const groupId = el?.getAttribute?.(HF_AUDIO_GROUP_ATTR);
121+
// A compiler stamp identifies the bus INSTANCE. The author id is only unique
122+
// within one composition file, so resolving by it in an inlined document made
123+
// every repeated sub-composition consult the first instance's mute state.
124+
const groupId =
125+
el?.getAttribute?.(AUDIO_GROUP_RENDER_ID_ATTR) ?? el?.getAttribute?.(HF_AUDIO_GROUP_ATTR);
118126
if (!groupId) return false;
119127
return resolveGroupElement(doc, groupId)?.hasAttribute("data-hidden") ?? false;
120128
}

‎packages/core/src/canary.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,28 @@ describe("canary reason property", () => {
426426
expect(canaryReasonKey("de-parallel-router")).toBe("canary_reason_de_parallel_router");
427427
});
428428
});
429+
430+
/**
431+
* The audio features ship to everyone.
432+
*
433+
* They landed on main across twelve PRs while all three of their canaries sat
434+
* at 0%, which meant the FX rack, the group rows, mute and solo were present in
435+
* the build and reachable by nobody. Pinned as a test because the failure mode
436+
* is silent: re-registering one of these re-hides a shipped feature, and
437+
* nothing else would say so.
438+
*/
439+
describe("the audio rollout", () => {
440+
// The three names by hand, because that is the assertion the intent needs: a
441+
// prefix check catches `audio-fx-rack` coming back but not `fx-rack` or
442+
// `audiofx-rack`, and it is the specific feature being re-hidden that matters.
443+
it("registers none of the three retired audio canaries", () => {
444+
const retired = ["audio-fx-rack", "audio-track-mute", "audio-groups"];
445+
expect(retired.filter((name) => findCanary(name))).toEqual([]);
446+
});
447+
448+
// The family guard, kept alongside it: a fourth audio canary would gate a
449+
// feature that now ships to everyone.
450+
it("registers no audio canary at all", () => {
451+
expect(CANARIES.filter((c) => c.name.startsWith("audio-")).map((c) => c.name)).toEqual([]);
452+
});
453+
});

0 commit comments

Comments
 (0)