From ec1839e4a17925d9c04dce5bfd5153b4f3ca8a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sat, 21 Nov 2026 23:34:05 +0000 Subject: [PATCH] fix(media-use): a project manifest's provider claim never writes a sound credit (#8410) --- packages/cli/src/media-use/resolve.mjs | 5 ++-- packages/cli/src/media-use/resolve.test.mjs | 26 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/media-use/resolve.mjs b/packages/cli/src/media-use/resolve.mjs index 1e2f777c0e..34181e0135 100644 --- a/packages/cli/src/media-use/resolve.mjs +++ b/packages/cli/src/media-use/resolve.mjs @@ -1353,8 +1353,9 @@ function recordedMatch(record) { async function result(record, source, match = recordedMatch(record)) { warnLowConfidence(record, match); const { provider, license, credit, source_url: sourceUrl } = record.provenance ?? {}; - // Under the media lock: two resolves at once each read, then rewrite, the whole credits file. - if (provider === OPENVERSE_SFX_PROVIDER) + // Under the media lock: two resolves at once each read, then rewrite, the whole credits file. A project + // manifest's record ("cached") is the project's own text, so its provider claim never writes a credit. + if (provider === OPENVERSE_SFX_PROVIDER && source !== "cached") withMediaLock(projectDir, () => writeSfxCredit(join(ownTypeDir(projectDir, "sfx"), "CREDITS.md"), record.path, { license, diff --git a/packages/cli/src/media-use/resolve.test.mjs b/packages/cli/src/media-use/resolve.test.mjs index 5bf3f6f2ac..b9898f2bb0 100644 --- a/packages/cli/src/media-use/resolve.test.mjs +++ b/packages/cli/src/media-use/resolve.test.mjs @@ -592,7 +592,8 @@ for (const [name, place] of [ }); } -test("a manifest record whose path is inside the project is reused and credited", () => { +// fails without the fix: the manifest's own provider claim wrote "Sam Sound" into the credits file. +test("a manifest record inside the project is reused, but its provider claim writes no credit", () => { setup(); recordedSound("assets/sfx/boom.mp3", join(tmp, "assets", "sfx", "boom.mp3")); const result = spawnResolve(["--type", "sfx", "--intent", "whoosh", "--project", tmp, "--json"], { @@ -601,9 +602,28 @@ test("a manifest record whose path is inside the project is reused and credited" }); assert.equal(result.status, 0, result.stderr); assert.equal(JSON.parse(result.stdout)._source, "cached"); + assert.equal(existsSync(join(tmp, ".media/audio/sfx/CREDITS.md")), false); + cleanup(); +}); + +test("an Openverse sound reused from the cache in another project is credited there", () => { + setup(); + const first = join(tmp, "first"); + const second = join(tmp, "second"); + for (const project of [first, second]) mkdirSync(project); + const resolveIn = (project, sounds) => + spawnResolve(["--type", "sfx", "--intent", "whoosh", "--project", project, "--json"], { + env: { HOME: tmp, PATH: tmp }, + nodeArgs: openverseImport(sounds), + }); + assert.equal(resolveIn(first, [OPENVERSE_BY_WHOOSH]).status, 0); + const reused = resolveIn(second, []); + assert.equal(reused.status, 0, reused.stderr); + const parsed = JSON.parse(reused.stdout); + assert.equal(parsed._source, "reused"); assert.ok( - readFileSync(join(tmp, ".media/audio/sfx/CREDITS.md"), "utf8").includes( - "`assets/sfx/boom.mp3`: Sam Sound", + readFileSync(join(second, ".media/audio/sfx/CREDITS.md"), "utf8").includes( + `\`${parsed.path}\`: ${OPENVERSE_BY_WHOOSH.attribution}`, ), ); cleanup();