Repository navigation
fix(core): let the sequence writer run with no eager engine loaded (dicomdir wave) - #580
Merged
awatson1978 merged 1 commit intoOct 2, 2026
Conversation
Writing a DICOMDIR from @dcmjs-org/dicomdir alone threw: core's SequenceOfItems.writeBytes serialized each item through the late-bound DicomMessage, which only @dcmjs-org/legacy (or the dcmjs wrapper) registers — so the package's hard no-legacy rule held in its imports but not at runtime. The committed suite never saw it because its readback oracle imports legacy, wiring the seam as a side effect. core/writeCore.js now registers writeDataSet into ValueRepresentation at load (a direct import between the two files is a module-level CJS cycle that breaks Tag's registration, hence the seam), and the sequence writer calls that instead of DicomMessage.write — the exact function DicomMessage.write delegates to, so bytes are unchanged either way. The new packages/dicomdir/test/standalone.test.js imports nothing from legacy (jest's per-file module registry guarantees the seam stays unwired) and proves a full DICOMDIR write: DICM magic, four undefined-length item headers for PATIENT/STUDY/SERIES/IMAGE, deterministic bytes. Full suite: 861 passed, 12 skipped, 873 total. Co-Authored-By: Claude Fable 5 <[email protected]>
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.
This is a follow-up to #573, fixing a gap I found while verifying the assembly PR's worked example. The claim over there is that
@dcmjs-org/dicomdirruns on@dcmjs-org/coreand nothing else — and the imports say so — but when I actually ranwriteDicomDirin a process that had never loaded@dcmjs-org/legacy, it threw. Core'sSequenceOfItems.writeBytesserializes each sequence item through the late-boundDicomMessageclass, and only legacy (or the dcmjs wrapper) ever registers one. The ported suite never noticed because its readback oracle importsDicomMessagefrom legacy, which wires the seam as a side effect of the import.The fix follows the intent already written down in
core/writeCore.js's header — "ValueRepresentation's sequence writer calls back into writeDataSet for its items" — which described a callback that didn't actually exist yet. I first tried the direct route, a top-level import ofwriteDataSetinValueRepresentation.js, and it promptly broke everything: under babel's CJS output the new module-level cycle (ValueRepresentation → writeCore → Tag → ValueRepresentation) runsTag.js's registration side effect against a half-evaluated class. So the fix uses the codebase's existing seam pattern instead:writeCore.jsregisterswriteDataSetintoValueRepresentationat load (setWriteDataSet, documented next to theDicomMessageseam it mirrors), and the sequence writer calls the registered function. Since legacy'sDicomMessage.writeis a one-line delegate to that samewriteDataSet, the bytes are identical no matter which package loaded first — nothing about existing behavior changes.The regression test is
packages/dicomdir/test/standalone.test.js, and its design is the point: it imports nothing from legacy, and jest gives each test file its own module registry, so the seam is guaranteed unwired when it runs. It writes a one-entry DICOMDIR and checks the bytes directly —DICMat offset 128, exactly four undefined-lengthFFFE,E000item headers (PATIENT/STUDY/SERIES/IMAGE), and determinism under a fixedfileSetUID. Before the fix this file throwsTypeError: Cannot read properties of undefined (reading 'write'); after it, green.Hand-written lines: about 100 (the seam + registration + comments ~30 in core, the standalone test ~70). Full suite: 861 passed / 12 skipped / 873 total, build, lint, and format green.
🤖 Generated with Claude Code