Skip to content

test: make the gzip fixture compressible on every toolchain - #278

Merged
BaaRai merged 2 commits into
BaaRai:mainfrom
00xcyd:fix/decode-fixture-toolchain-independent
Nov 17, 2026
Merged

BaaRai merged 2 commits into
BaaRai:mainfrom
00xcyd:fix/decode-fixture-toolchain-independent

Conversation

@00xcyd

@00xcyd 00xcyd commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What this fixes

TestDecodeEvidenceBodyGzipQuoteFound fails on Go 1.27 with fixture is not compressed (issue #276). The test body is the 60-byte decodeHTML constant, and the guard asserted !strings.Contains(string(raw), "admin") on the compressed bytes. Go 1.27's compress/flate emits 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:

  • build the fixture as 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);
  • check the gzip magic, so a broken fixture cannot pass as a compressed one;
  • assert compression by size, 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;
  • assert the decoded bytes equal the body (reported as lengths, so a failure does not dump 12 KB into the log), and keep the quote check on the decoded text.

Verification

Clean checkout of 278de8b2e (current main), macOS arm64:

command go1.27.4 GOTOOLCHAIN=go1.26.10
go test ./server/ ok, 10.2s ok, 10.1s
go test ./... all packages ok not re-run

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

finding_verification_decode_test.go:75: fixture is not compressed: 60 bytes in, 85 bytes out

Before the change, on go1.27.4, go test ./... had exactly one failing test in the whole repository: this one. go.mod still says go 1.26.10, so CI (which reads the version from go.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

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.
@00xcyd

00xcyd commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up commit fa33d4d hardens the fixture guard rather than keeping the old substring check alongside it: compression is now asserted by size (len(raw) < len(body)/2), which a stored block cannot satisfy and which no longer assumes how flate picks its block type. Proved it still catches the original case by swapping the 60-byte fixture back on go1.27.4: fixture is not compressed: 60 bytes in, 85 bytes out.

Re-ran after the change: go test ./server/ and go test ./... pass on go1.27.4, go test ./server/ passes under GOTOOLCHAIN=go1.26.10, vet/build clean. Still waiting on the workflow approval for the PR run.

@BaaRai
BaaRai merged commit 2d21da1 into BaaRai:main Nov 17, 2026
4 checks passed
@BaaRai

BaaRai commented Nov 17, 2026

Copy link
Copy Markdown
Owner

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.

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.

go test ./server fails on Go 1.27: TestDecodeEvidenceBodyGzipQuoteFound's fixture guard assumes gzip output never contains plaintext

2 participants