Skip to content

Commit e8672b3

Browse files
committed
test(lint): pin audio group membership guards
1 parent 6f1de66 commit e8672b3

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

packages/lint/src/rules/media.test.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,29 @@ describe("audio_group_no_members", () => {
590590
expect(finding?.message).toContain("voiceovr");
591591
});
592592

593+
it("suggests only unmatched member ids, not a healthy sibling group", async () => {
594+
const res = await lintHyperframeHtml(
595+
doc(`${BUS}<hf-audio-group id="music"></hf-audio-group>
596+
<audio id="bgm" src="music.wav" data-start="0" data-duration="5" data-audio-group="music"></audio>
597+
<audio id="vo-1" src="vo.wav" data-start="0" data-duration="5" data-audio-group="voiceovr"></audio>`),
598+
);
599+
const finding = res.findings.find((item) => item.code === "audio_group_no_members");
600+
expect(finding?.message).toContain('"voiceovr"');
601+
expect(finding?.message).not.toContain('"music"');
602+
});
603+
604+
it("does not count video as group membership", async () => {
605+
const res = await lintHyperframeHtml(
606+
doc(`${BUS}<video id="v" src="v.mp4" data-start="0" data-duration="5" data-audio-group="voiceover"></video>
607+
<audio id="s-1" src="s.wav" data-start="0" data-duration="2" data-audio-group="sfx"></audio>`),
608+
);
609+
expect(
610+
res.findings.some(
611+
(finding) => finding.code === "audio_group_no_members" && finding.elementId === "voiceover",
612+
),
613+
).toBe(true);
614+
});
615+
593616
it("stays quiet when a clip belongs to it", async () => {
594617
const res = await lintHyperframeHtml(
595618
doc(
@@ -607,11 +630,7 @@ describe("audio_group_no_members", () => {
607630
// file (timelineAudioGroupCreate) — so a file holding a bus and no members at
608631
// all is the normal cross-file shape, not a mistake.
609632
it("stays quiet in a file that declares no members at all", async () => {
610-
const res = await lintHyperframeHtml(
611-
doc(
612-
`${BUS}<div id="host" data-composition-src="compositions/voices.html" data-start="0" data-duration="10"></div>`,
613-
),
614-
);
633+
const res = await lintHyperframeHtml(doc(BUS));
615634
expect(res.findings.some((f) => f.code === "audio_group_no_members")).toBe(false);
616635
});
617636

@@ -627,7 +646,8 @@ describe("audio_group_no_members", () => {
627646

628647
it("stays quiet for a bus with no id", async () => {
629648
const res = await lintHyperframeHtml(
630-
doc(`<hf-audio-group data-label="Nameless"></hf-audio-group>`),
649+
doc(`<hf-audio-group data-label="Nameless"></hf-audio-group>
650+
<audio id="s-1" src="s.wav" data-start="0" data-duration="2" data-audio-group="sfx"></audio>`),
631651
);
632652
expect(res.findings.some((f) => f.code === "audio_group_no_members")).toBe(false);
633653
});

packages/lint/src/rules/media.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,13 @@ function findAudioGroupNoMembersFindings(ctx: LintContext): HyperframeLintFindin
814814
const mayHaveCrossFileMembers = ctx.tags.some((tag) =>
815815
Boolean(readAttr(tag.raw, "data-composition-src")),
816816
);
817+
const declaredGroupIds = new Set(
818+
ctx.tags
819+
.filter((tag) => tag.name === "hf-audio-group")
820+
.map((tag) => readAttr(tag.raw, "id"))
821+
.filter((id): id is string => Boolean(id)),
822+
);
823+
const unmatchedMemberGroupIds = [...memberGroupIds].filter((id) => !declaredGroupIds.has(id));
817824

818825
const findings: HyperframeLintFinding[] = [];
819826
for (const tag of ctx.tags) {
@@ -831,7 +838,9 @@ function findAudioGroupNoMembersFindings(ctx: LintContext): HyperframeLintFindin
831838

832839
// Naming the near-misses is the whole value: the fix is almost always a
833840
// typo on one member, and the author is looking at the bus, not the clip.
834-
const nearby = [...memberGroupIds].filter((id) => id !== elementId);
841+
// Do not offer a correctly matched sibling bus as the fix for this one.
842+
// Only member ids with no declared bus are plausible typos.
843+
const nearby = unmatchedMemberGroupIds.filter((id) => id !== elementId);
835844
const suffix =
836845
nearby.length > 0
837846
? ` Clips in this file name ${nearby.map((id) => `"${id}"`).join(", ")} instead.`

0 commit comments

Comments
 (0)