Skip to content

fix(test): fail fast on bad fixture downloads in downloadToFile - #552

Merged
awatson1978 merged 2 commits into
release/1.0-beta-corefrom
core/fixture-download-guard
Sep 30, 2026
Merged

awatson1978 merged 2 commits into
release/1.0-beta-corefrom
core/fixture-download-guard

Conversation

@awatson1978

@awatson1978 awatson1978 commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

This is the small hygiene fix behind this week's CI flakes: downloadToFile in the test utilities now refuses to save anything that isn't a real, complete fixture.

The old implementation piped whatever came back from GitHub straight into the target file without ever looking at response.statusCode. When a release-asset download failed — rate limiting, a transient 5xx, an expired redirect — the error body itself got saved as a .dcm file. And because the fixture cache treats any existing file as a valid download, that poisoned file then failed every later run on the same machine with a confusing parse error, far away from the real cause.

This PR's own first CI run then demonstrated the second half of the bug, live. test/data.test.js and test/async-data.test.js both download multiframe-ultrasound.dcm and large-private-tags.dcm to the same cache path, from different jest worker processes. The dedup map in getTestDataset is per-process, so worker B's fs.existsSync gate can see worker A's half-written file and read a truncated stream — which is exactly the "expected header is missing" / "Invalid tag in sequence" flake pattern, and what the first run of this PR hit twice.

So the fix has two parts, both in downloadToFile:

  • check the status code before touching the disk, reject with the URL and status in the message, and absorb one transient hiccup with a single retry;
  • stream into a worker-private <name>.<pid>.partial file and atomically rename into place on completion, so the cache path only ever holds a complete download — no matter how many workers race.
// before: a 404 body became a "cached fixture", and a second worker
// could read the file while the first was still writing it
await downloadToFile(url, "/tmp/dcmjs-test/image.dcm"); // resolves, saves "Not Found"

// after: it fails loudly and leaves nothing behind
await downloadToFile(url, "/tmp/dcmjs-test/image.dcm");
// rejects: Download of <url> failed with HTTP status 404
// fs.existsSync("/tmp/dcmjs-test/image.dcm") === false — before and during
// a download, the target name only appears once the bytes are all there

On testing without network access: the new test/downloadToFile.test.js spins up a local http.Server that scripts the interesting responses — a clean 200, a 302 redirect, a 404, a slow two-chunk body (to pin that the target path never exists mid-download), and a 503-then-200 sequence for the retry. To make that possible I let downloadToFile pick the follow-redirects transport by URL scheme (it was hard-coded to https); real fixture downloads still go over https exactly as before.

🤖 Generated with Claude Code

awatson1978 and others added 2 commits September 30, 2026 07:23
downloadToFile never checked response.statusCode, so a failed
GitHub-release download saved the HTML/JSON error body as a .dcm and
poisoned every later run from the fixture cache. Now a non-2xx status
rejects with the URL and status in the message, nothing is written to
disk until a 2xx arrives, any partial file is removed on failure, and
one retry absorbs transient upstream hiccups.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ad a partial file

The CI failures on this branch showed the second half of the poisoning
bug: data.test.js and async-data.test.js download the same fixtures
into the same cache path from different jest workers, and the
existsSync gate in getTestDataset can observe another worker's
half-written file. Stream into a worker-private .partial name and
rename into place on completion, so the cache path only ever holds a
complete download.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit 43fcaae into release/1.0-beta-core Sep 30, 2026
8 checks passed
@awatson1978
awatson1978 deleted the core/fixture-download-guard branch September 30, 2026 12:34
awatson1978 added a commit that referenced this pull request Sep 30, 2026
…ne and event-stream findings

Engine findings 1/3/4/24/25/27/28/32 landed as PRs #544-#551; the
writers wave (#552-#557) fixed 5/6/7/11/22/23 in the ports and retired
14 by trimming the video factories from the core facade. Master
verdicts are now verified against origin/master, not just triaged.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant