Repository navigation
test: run the shared boolean_tolerant block (CORELIB_PLAN §4.4) - #147
Merged
Merged
Conversation
§4.4 is "canonical on encode, tolerant on decode": an encoder MUST write `true` as `1`, and a decoder MUST read EVERY value other than `0` as `true`. A boolean carries no width bound at all — unlike an `enum` or a `bitfield` (MESSAGE_SPEC §1), which are bounded by their declared width — so `2`, `256` and `2^64-1` at a boolean position are `true`: never INVALID, never truncated to `false`. This block is the guard for the §4.4 support that landed in #143. The positive `vectors` block cannot reach that half of the rule. Its bytes come from replaying `fields` ops through a conforming encoder, and a conforming encoder never emits a non-canonical boolean; bytes carrying `2` or `256` at a boolean position only ever arrive from somebody else's encoder. Hence a hand-authored, decode-then-RE-ENCODE block. Three defects, three assertions, and no two of them overlap: * answering INVALID for `256` -> the outcome check; * masking `256` down to the destination width before the zero-test -> the stored-value check: the value is silently `false` while the outcome is a perfect `complete`; * storing the raw `2` unnormalised -> the re-encode check: the outcome and every truthiness test pass, and only the emitted `2` vs `1` shows it. A runner asserting only the outcome certifies a decoder that violates §4.4 in two of the three ways; adding a truthy value check still certifies the third. The stored value is compared as BYTES copied out of the `bool` destination, never read as a `bool` lvalue: a C++ `bool` object holding `2` has no value, so `== true` on it would be meaningless rather than revealing. What is asserted is that the object ends up holding a representation it is allowed to have. The destination is poisoned with `0xaa` first, so a decoder that never writes it cannot pass `boolean_tolerant_zero` against zeroed storage; where the bytes come out wrong the re-encode is deliberately not attempted (reading those objects would be UB and deriving the values from the raw bytes would launder the defect into a canonical `1`) and is still counted and reported as failed. All eight cases run positively here, each twice — whole and one byte at a time, which is what puts the ten-byte varints of the two `u64_max` cases across feed boundaries. In this block an unsatisfied `requires` tag REJECTS rather than skips, the opposite of `header_limits`: §4.4 lifts the bound the TYPE carries, never the one a BUILD has, so under a narrowed accumulator (§6.2.2) `2^64-1` overflows before any boolean rule applies and INVALID (§5.2.2) is the conformant answer. This build satisfies every tag, so that branch is unreachable; it is implemented anyway so a reduced profile would need no new code, and so it can never be mistaken for an unconditional skip of the tagged cases. Reported per §12 — found / decoded / rejected / checks — with a floor of eight cases, a both-shapes guard and a `boolean_tolerant` column in the envelope-drift walker, so a stale corpus, a scalar-only filter or a renamed key fails loudly instead of reading as a green run of nothing. corelib-cpp passes all eight, scalar and array. Verified non-vacuous by mutating the library four ways — a scalar read that masks to 8 bits, an array element stored raw, an encoder writing `true` as `2`, and a decoder that never writes the destination — each of which turns the block red on exactly the assertion it should. Family tracking issue: sofa-buffers/crucible#189. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Runs the shared corpus's
boolean_tolerantblock (CORELIB_PLAN §4.4), the guardfor the §4.4 boolean support that landed in #143.
Family-wide tracking issue: sofa-buffers/crucible#189.
What the block asserts
§4.4 is canonical on encode, tolerant on decode: an encoder MUST write
trueas1; a decoder MUST read every value other than0astrue.A boolean carries no width bound at all — unlike an
enumor abitfield(MESSAGE_SPEC §1), which are bounded by their declared width — so
2,256and2^64-1at a boolean position aretrue: notINVALID, and not truncated tofalse.The positive
vectorsblock cannot reach that half of the rule. Its bytes areproduced by replaying
fieldsops through a conforming encoder, and aconforming encoder never emits a non-canonical boolean; bytes carrying
2,256or2^64-1at a boolean position only ever arrive from someone else'sencoder. Hence a separate, hand-authored, decode-then-re-encode block.
Both halves are checked, because neither catches the other
INVALIDfor256256down to the destination width before the zero-testcompleteand the value is silentlyfalse2without normalising2vs1shows itA runner that asserts only the outcome certifies a decoder that violates §4.4 in
two of the three ways; one that adds a truthy value check still certifies the
third.
Two C++-specific points:
memcpy'd out of thebooldestination, never read as a
boollvalue. Aboolobject holding2has novalue in C++, so
== trueon it is already meaningless rather than revealing.What is asserted is that the object ends up holding a representation it is
allowed to have.
0xaabefore every feed, so a decoderthat never writes it cannot pass
boolean_tolerant_zeroagainst zeroedstorage. Where the stored bytes are wrong the re-encode is deliberately not
attempted (reading those objects would be UB, and deriving the values from the
raw bytes would launder the defect into a canonical
1) — it is still countedand still reported as failed.
Cases run vs gated
All 8 cases run positively; 0 are gated. Each runs twice — whole and one
byte at a time — which is what puts the ten-byte varints of
boolean_tolerant_u64_maxandboolean_tolerant_array_u64_maxacross feedboundaries. 6 scalar cases and 2 array cases; 3 of the 8 carry
requirestags(
int64,array, or both).In this block an unsatisfied
requirestag means reject, not skip — theopposite of
header_limits, and the same rule a positive vector gets: §4.4lifts the width bound the type carries, never the one a build has, so under
a narrowed accumulator (§6.2.2) a boolean carrying
2^64-1overflows before anyboolean rule can apply and
INVALID(§5.2.2) is the conformant answer. Skippingwould assert nothing at all, leaving the truncation the block exists to catch
untested in exactly the build most likely to have it. This pure-C++20 build has
no feature switches, so
buildCaps()satisfies every tag and the reject branchis unreachable; it is implemented anyway so a reduced profile would need no new
code, and so it can never be mistaken for an unconditional skip of the tagged
cases.
test_vectorsnow reports the §12 split:found == decoded + rejectedand a run that finds zero cases fails, alongside afloor of ≥ 8 cases and a "both shapes" guard (≥ 5 scalar, ≥ 2 array) so a
scalar-only filter or a stale corpus cannot go green. The envelope-drift guard
gained a
boolean_tolerantcolumn, so a renamed or emptied key is rejectedrather than silently walked as "nothing to test".
assets/test_vectors.jsonis untouched — it already carries the block and isbyte-identical to
corelib-c-cpp@main(sha25668366b52…), so its provenancerow stands.
Defects found
None. corelib-cpp passes all eight cases, scalar and array, whole and
chunked. The block was verified non-vacuous by mutating the library four ways
and confirming each turns it red on exactly the assertion it should:
boolean_tolerant_256/boolean-normalised(+-chunked): destination holds00, expected01boolean_tolerant_array/boolean-normalised: holds00010200ff, expected0001010101trueas2boolean-reencode-canonical: re-encoded0002, expected0001— caught despite both being the same lengthboolean-normalised: holdsaa(the poison)Gates run locally
Read from
.github/workflows/and run locally, every leg ofci.ymlthat thismachine can host — all green:
ci.yml)gatecmake -S . -B … -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g+++ buildgcc-x86_64Debug / Releasectest --output-on-failuregcc-x86_64strict-UTF-8 OFF, Debug / Release-DCMAKE_CXX_FLAGS=-DSOFAB_STRICT_UTF8=0+ build + ctestclang-x86_64Debug / Releaselto-x86_64gcc / clang-O3 -flto -fstrict-aliasing, Release + build + ctestcoverage-DSOFAB_ENABLE_COVERAGE=ON+ build + ctest +gcovr --print-summaryshared-vectorssha256sum assets/test_vectors.jsonvscorelib-c-cpp@mainNot run locally, with the reason:
ppc64-be— nog++-powerpc64-linux-gnu/qemu-user-staticisinstallable in this environment. It will run on CI. The block reads the
destination through single bytes, so it carries no endianness assumption of
its own.
build-doxygen—pushtomainonly; never runs on a PR.version-consistency— tag pushes only; never runs on a PR.🤖 Generated with Claude Code