Skip to content

test: run the shared boolean_tolerant block (CORELIB_PLAN §4.4) - #147

Merged
Andste82 merged 1 commit into
mainfrom
test/run-boolean-tolerant
Sep 20, 2026
Merged

Andste82 merged 1 commit into
mainfrom
test/run-boolean-tolerant

Conversation

@Andste82

Copy link
Copy Markdown
Member

Runs the shared corpus's boolean_tolerant block (CORELIB_PLAN §4.4), the guard
for 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
true as 1; 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: not INVALID, and not truncated to
false.

The positive vectors block cannot reach that half of the rule. Its bytes are
produced by replaying fields ops through a conforming encoder, and a
conforming encoder never emits a non-canonical boolean; bytes carrying 2,
256 or 2^64-1 at a boolean position only ever arrive from someone else's
encoder. Hence a separate, hand-authored, decode-then-re-encode block.

Both halves are checked, because neither catches the other

defect caught by
answers INVALID for 256 the outcome assertion
masks 256 down to the destination width before the zero-test the stored-value assertion — the outcome is a perfect complete and the value is silently false
stores the raw 2 without normalising the re-encode assertion — the outcome and any truthiness check both pass, and only the emitted 2 vs 1 shows it

A 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:

  • The stored value is compared as bytes, memcpy'd out of the bool
    destination, never read as a bool lvalue. A bool object holding 2 has no
    value in C++, so == true on it is already 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 before every feed, so a decoder
    that never writes it cannot pass boolean_tolerant_zero against zeroed
    storage. 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 counted
    and 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_max and boolean_tolerant_array_u64_max across feed
boundaries. 6 scalar cases and 2 array cases; 3 of the 8 carry requires tags
(int64, array, or both).

In this block an unsatisfied requires tag means reject, not skip — the
opposite of header_limits, and the same rule a positive vector gets: §4.4
lifts 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-1 overflows before any
boolean rule can apply and INVALID (§5.2.2) is the conformant answer. Skipping
would 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 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.

test_vectors now reports the §12 split:

8 boolean_tolerant cases found, 8 decoded, 0 rejected (unsatisfied requires), 36 checks

found == decoded + rejected and a run that finds zero cases fails, alongside a
floor 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_tolerant column, so a renamed or emptied key is rejected
rather than silently walked as "nothing to test".

assets/test_vectors.json is untouched — it already carries the block and is
byte-identical to corelib-c-cpp@main (sha256 68366b52…), so its provenance
row 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:

injected defect assertion that fired
scalar read masks the accumulator to 8 bits before the zero-test boolean_tolerant_256/boolean-normalised (+ -chunked): destination holds 00, expected 01
array element stored raw instead of normalised boolean_tolerant_array/boolean-normalised: holds 00010200ff, expected 0001010101
encoder writes true as 2 boolean-reencode-canonical: re-encoded 0002, expected 0001 — caught despite both being the same length
decoder never writes the destination boolean-normalised: holds aa (the poison)

Gates run locally

Read from .github/workflows/ and run locally, every leg of ci.yml that this
machine can host — all green:

gate (from ci.yml) command result
gate cmake -S . -B … -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++ + build PASS
gcc-x86_64 Debug / Release configure + build + ctest --output-on-failure PASS / PASS (6/6 tests each)
gcc-x86_64 strict-UTF-8 OFF, Debug / Release -DCMAKE_CXX_FLAGS=-DSOFAB_STRICT_UTF8=0 + build + ctest PASS / PASS
clang-x86_64 Debug / Release configure + build + ctest PASS / PASS
lto-x86_64 gcc / clang -O3 -flto -fstrict-aliasing, Release + build + ctest PASS / PASS
coverage -DSOFAB_ENABLE_COVERAGE=ON + build + ctest + gcovr --print-summary PASS (lines 93.9%, functions 96.2%)
shared-vectors sha256sum assets/test_vectors.json vs corelib-c-cpp@main PASS (identical; the file is not touched by this PR)

Not run locally, with the reason:

  • ppc64-be — no g++-powerpc64-linux-gnu / qemu-user-static is
    installable 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 — push to main only; never runs on a PR.
  • version-consistency — tag pushes only; never runs on a PR.

🤖 Generated with Claude Code

§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>
@Andste82
Andste82 merged commit 20ef536 into main Sep 20, 2026
9 checks passed
@Andste82
Andste82 deleted the test/run-boolean-tolerant branch September 20, 2026 21:36
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