Skip to content

Test that the 3MF we write is actually compressed - #90

Merged
revarbat merged 1 commit into
mainfrom
threemf-deflate-comment-and-test
Aug 12, 2026
Merged

Test that the 3MF we write is actually compressed#90
revarbat merged 1 commit into
mainfrom
threemf-deflate-comment-and-test

Conversation

@revarbat

Copy link
Copy Markdown
Member

writeThreeMf() has called writeDeflateZip() all along — but nothing checked it, and export.hpp claimed the opposite.

The gap

The existing round-trip tests cannot catch a regression here. readStoredZipEntry accepts both STORED and DEFLATE, so swapping the writer back to writeStoredZip leaves every test green and shows up only as files several times larger than they need to be.

Confirmed by doing exactly that:

[       OK ] ImportModuleContext.ThreeMfRoundTripPreservesVolume    <- still passes
[  FAILED  ] ImportModuleContext.ThreeMfIsDeflateCompressed         <- catches it

What's added

ThreeMfIsDeflateCompressed exports a real cube through the evaluator pipeline, then reads the compression method straight out of the archive's central directory (authoritative, unlike the local header) and requires method 8 with a compressed size below the raw one.

Four smaller tests pin the zip layer itself:

test asserts
DeflateZipReallyWritesMethod8 method 8 in the central directory, and byte-identical read-back
DeflateZipActuallyShrinksCompressibleData 256 KB of repetitive XML-shaped input lands under a quarter its size
DeflateZipStoresDataThatWouldNotShrink a 1-byte entry falls back to method 0, as any ZIP writer would
StoredZipWritesMethod0 the control — same call shape, opposite method

The comment

export.hpp described the 3MF as "written as a stored (uncompressed) ZIP". That has been wrong since the deflate path landed. Corrected.

Worth saying plainly why this PR exists: I read that comment, reported it downstream as fact, and only found the code said otherwise when asked a follow-up question. A stale comment that contradicts the code one file over is worth a test, not just a fix.

830 tests pass. Version 0.29.1 → 0.29.2.

🤖 Generated with Claude Code

writeThreeMf() has called writeDeflateZip() all along, but nothing
checked it. The round-trip tests cannot: readStoredZipEntry accepts both
STORED and DEFLATE, so swapping the writer back to writeStoredZip leaves
every existing test green and shows up only as files several times
larger than they need to be. Confirmed by doing exactly that --
ThreeMfRoundTripPreservesVolume still passed.

ThreeMfIsDeflateCompressed reads the compression method straight out of
the central directory of a real exported .3mf and requires method 8, plus
a compressed size below the raw one. It fails on that same swap.

Four smaller tests do the same for the zip layer itself: writeDeflateZip
emits method 8 for compressible input, actually shrinks it, falls back to
STORED for input too small to benefit, and writeStoredZip still emits
method 0 as the control.

export.hpp said the 3MF was "written as a stored (uncompressed) ZIP",
which has been wrong since the deflate path landed and is corrected here.
That comment was read as fact and repeated as one, which is what prompted
this.

830 tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@revarbat
revarbat merged commit 6dccbeb into main Aug 12, 2026
3 checks passed
@revarbat
revarbat deleted the threemf-deflate-comment-and-test branch August 12, 2026 02:47
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.

1 participant