fix(media-use): a project manifest's provider claim never writes a sound credit (#8410)

This commit is contained in:
Miguel Ángel
2026-11-21 23:34:05 +00:00
committed by GitHub
parent 267ffc46c9
commit ec1839e4a1
2 changed files with 26 additions and 5 deletions
+3 -2
View File
@@ -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,
+23 -3
View File
@@ -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();