fix(add-video/add-audio): de-collide different sources sharing a basename#38
Merged
Merged
Conversation
…name addVideo/addAudio copied sources into assets/<kind>/<basename> and skipped the copy when the destination already existed. The skip is intentional (the Wikimedia fetch path pre-writes there, and re-adding the same file must not re-copy), but when a *different* source resolved to an existing basename (e.g. en/0_00.png vs jp/0_00.png) the copy was skipped silently and the draft pointed at the wrong content. Route both through a shared copyAssetDeduped(): byte-identical existing file keeps the silent no-op; a different source is written under a content-hashed name (0_00.<sha1-8>.png) and a warning is printed to stderr, so the draft references the correct content instead of a stale one. Adds test/asset-collision.test.mjs covering the collision and the idempotent re-add. Reported by @naoyashiga. Closes #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #37 (reported by @naoyashiga).
Problem
addVideo/addAudiocopy each source intoassets/<kind>/<basename>and skip the copy when the destination already exists. The skip is intentional and load-bearing — the Wikimedia fetch path pre-writes into that dir, and re-adding the same file must not re-copy. But when a different source resolves to a basename that's already present (e.g.en/0_00.pngvsjp/0_00.png), the copy is skipped silently and the draft ends up pointing at the first file's content, with no error or warning.Fix
Both functions now route through a shared
copyAssetDeduped():0_00.<sha1-8>.png) and print a warning to stderr. The draft references the correct content instead of a stale one.This goes one step past the warning-only suggestion in the issue: warning-only would surface the collision but still leave the draft pointing at wrong media. De-colliding by content makes the draft correct.
Note: the warning is written to stderr, so JSON stdout output stays clean.
Tests
test/asset-collision.test.mjs:Full suite green (218 tests).
Follow-up (not in this PR)
replace.tsmirrors this copy pattern; a separate change could route it through the same helper for consistency.