Skip to content

fix(add-video/add-audio): de-collide different sources sharing a basename#38

Merged
renezander030 merged 1 commit into
masterfrom
fix/asset-basename-collision
Jul 2, 2026
Merged

fix(add-video/add-audio): de-collide different sources sharing a basename#38
renezander030 merged 1 commit into
masterfrom
fix/asset-basename-collision

Conversation

@renezander030

Copy link
Copy Markdown
Owner

Fixes #37 (reported by @naoyashiga).

Problem

addVideo/addAudio copy each source into assets/<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.png vs jp/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():

  • Destination absent → copy (unchanged).
  • Destination present, byte-identical → silent no-op (preserves Wikimedia idempotency and cheap re-adds).
  • Destination present, different source → write under a content-hashed name (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:

  • Two different sources sharing a basename → two distinct assets on disk, two distinct material paths whose content matches their originals, and a collision warning on stderr.
  • Re-adding the same file → idempotent no-op (single copy, no warning).

Full suite green (218 tests).

Follow-up (not in this PR)

replace.ts mirrors this copy pattern; a separate change could route it through the same helper for consistency.

…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
@renezander030 renezander030 merged commit 6147a83 into master Jul 2, 2026
7 checks passed
@renezander030 renezander030 deleted the fix/asset-basename-collision branch July 2, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add-video/add-audio: silent skip on filename collision in assets dir (no warning)

1 participant