Repository navigation
test: make the gzip fixture compressible on every toolchain - #278
Conversation
TestDecodeEvidenceBodyGzipQuoteFound built its body from the 60-byte decodeHTML constant and guarded with "the stream must not contain admin". That assumes the encoder always deflates, and Go 1.27's flate does not: for this input it emits a stored block, the stream is 85 bytes, and the raw bytes are the plaintext the guard rejects. The test then fails on the encoder's choice rather than on the decode it is meant to cover. Repeat the body so it has something to compress, and assert the decoded output equals it, so the guard measures the round trip instead of one encoder's block selection. The quote and the body's content are unchanged, and the sibling truncated/deflate tests already use repeated input.
The plaintext-substring guard encoded one encoder's output shape: it only held while a small input compressed to fewer bytes than it started with, and Go 1.27 stores instead. Comparing sizes states the same invariant without assuming how flate picks between stored and compressed blocks: a stored block is larger than its input by construction, so "output is under half the input" is true for any working encoder on a repetitive body and false for a body that was never compressed. Checked against the old 60-byte fixture on go1.27.4: it fails with "fixture is not compressed: 60 bytes in, 85 bytes out", so the guard still catches the case it was written for.
|
Follow-up commit Re-ran after the change: |
|
Merged. The stored-block path makes the old plaintext guard meaningless, and asserting the ratio is the invariant that actually holds. The gzip-magic precondition also keeps a broken fixture from passing as compressed. Thanks. |
What this fixes
TestDecodeEvidenceBodyGzipQuoteFoundfails on Go 1.27 withfixture is not compressed(issue #276). The test body is the 60-bytedecodeHTMLconstant, and the guard asserted!strings.Contains(string(raw), "admin")on the compressed bytes. Go 1.27'scompress/flateemits a stored block for input that small (60 bytes in, 85 bytes out), so the stream carries the plaintext verbatim and the guard rejects a fixture that is in fact correctly gzipped. The test fails on the encoder's block-selection heuristic, not on the decode it exists to cover.The change
One test file, no production code:
strings.Repeat(decodeHTML, 200), so it has redundancy worth compressing under any encoder (the quote stays the same and still has to survive the round trip);len(raw) < len(body)/2, instead of by searching for a word in the output. A stored block is larger than its input by construction, so this holds for any working encoder on a repetitive body and fails for a body that was never compressed. That decouples the guard from the encoder, which is what go test ./server fails on Go 1.27: TestDecodeEvidenceBodyGzipQuoteFound's fixture guard assumes gzip output never contains plaintext #276 asked for;Verification
Clean checkout of
278de8b2e(currentmain), macOS arm64:GOTOOLCHAIN=go1.26.10go test ./server/go test ./...go vet ./server/clean,go build ./...clean,gofmt -l server/empty.The guard still catches what it was written for: swapping the fixture back to the 60-byte constant on go1.27.4 fails with
Before the change, on go1.27.4,
go test ./...had exactly one failing test in the whole repository: this one.go.modstill saysgo 1.26.10, so CI (which reads the version fromgo.mod) is unaffected either way; this just makes the suite meaningful on a newer toolchain. #279 adds the CI job that would have caught it.Closes #276