Skip to content

test: run the shared header_limits_nested block - #148

Merged
Andste82 merged 1 commit into
mainfrom
test/run-header-limits-nested
Sep 21, 2026
Merged

Andste82 merged 1 commit into
mainfrom
test/run-header-limits-nested

Conversation

@Andste82

Copy link
Copy Markdown
Member

Runs the shared test-vector block header_limits_nested in this port. Refs sofa-buffers/crucible#189.

What the block asserts

header_limits feeds a truncated over-ceiling header — bytes that declare a length or an element count and then end, with not one payload byte behind them — and demands the answer at that word: limit_exceeded for a receiver cap (CORELIB_PLAN §6.2.1), invalid for a schema bound (MESSAGE_SPEC §7.1), terminal either way (§6.3), and incomplete only when the declared size fits. Every case in it puts the field at the top level.

header_limits_nested is the same assertion one or two sequence frames deeper, and nothing else. It adds one key, frames — the chain of sequence field ids the target field is nested in, outermost first — and inherits the key set, the outcome vocabulary, the terminality rule and the rejection/control pairing unchanged.

Depth is its own axis because the two ceilings are separate machinery and a port can bind one of them shallower than the other: carry the schema bound into a sequence and leave the receiver cap at the top level, where these bytes never reach it. The port then answers incomplete — which here looks entirely plausible, because a frame really is open. The two depth-2 cases exist for the same reason one level down: a chain builder off by one descends once and then treats the inner sequence header as the target field.

Per case the runner asserts:

  • the final feed's outcome equals expect.outcome, with limit_exceeded and invalid mapped to distinct errors. nested_string_over_cap and nested_string_schema_bounded carry identical bytes at identical depth (3e02a206) and differ only in which ceiling the case configured; that pair is the block's highest-value assertion.
  • where expect.terminal is true: eight bytes of would-be payload are fed and the decoder must re-raise the same error, deliver nothing, and leave the destination still empty — checked after the second feed, so a late materialisation is caught too (§6.2.1 is "rejected, never clamped").
  • frames is non-empty, and the frame chain the bytes actually carry is decoded and checked against it at load time, so a receiver wired one level too shallow fails to load instead of reporting a green incomplete.
  • chunks is honoured if it appears (no case carries it today), with every non-final feed required to answer incomplete.

What the negative control demonstrated

This is the load-bearing half. Every case here ends at end-of-input with one or two frames still open, which is a fully independent reason to answer incomplete — so a rejection produced by something other than the ceiling (a depth guard, a refusal of unclosed frames, a strict-mode path) would sail through the forward pass while never consulting the ceiling under test.

A second, independent pass therefore rebuilds each rejection with the same kind of ceiling lifted to 65536 — a schema case gets a lifted schema bound, a limits case a lifted receiver cap, routed through the same read the forward pass used — and asserts the answer changed. What it showed, all four:

case forward ceiling lifted to 65536
nested_string_over_cap LimitExceeded (6) Incomplete (5)
nested_string_schema_bounded InvalidMessage (4) Incomplete (5)
nested_array_count_over_cap LimitExceeded (6) Incomplete (5)
nested_depth2_string_over_cap LimitExceeded (6) Incomplete (5)

Every rejection flips to Incomplete — i.e. it falls back to the open frames, the only reason left. The ceiling caused all four, at depth 1 and at depth 2. The pass also asserts how many cases it checked (against the count the forward pass arrived at independently, and against the absolute four when nothing is gated), because a control loop that continues through every iteration is green and proves nothing.

Five deliberate mutations were run against the finished runner to confirm it is not green by accident. All five were caught:

mutation caught by
ceiling bound at the top level (never descend) forward pass — all 4 rejections answer incomplete
descend exactly once whatever frames says forward pass — only nested_depth2_string_over_cap fails
control pass does not actually lift 4 × nested-control-ceiling-caused-it
control lifts the wrong kind (schema case gets a lifted cap) 1 × nested-control-ceiling-caused-it
control loop skips everything nested-control-count

Ran vs gated

8 of 8 run, 0 gated (4 rejections, 4 in-cap controls, 2 at depth 2). This build compiles nothing out, so sequence/fixlen/array are satisfied unconditionally, and its read API is exactly the §6.2.1 pair — readString takes the declared maxlen, readStringCapped the receiver's cap, neither has a default — so it declares receiver_caps. The suite prints ran and gated, names the tag that gated each gated case, and asserts the two sum to the block's size, so a broken capability probe cannot silently turn the block into a green no-op.

The port holds no ceiling of its own (§6.2.1): every number is passed into the one call that compares it, so nothing leaks between cases and there is no configuration to restore.

Implementation notes

The flat runner was extended, not duplicated. loadHeaderCases now takes the block key and whether frames is required — and refuses frames in the flat block, where it would bind the ceiling at the top level while the field arrived a frame down. NestedFrame links are built to the case's exact depth and the innermost one delegates to HeaderMsg, the flat block's own leaf, unchanged: a separate nested leaf could pass by a mechanism the flat path never uses. The envelope-drift guard (corelib-cpp#100) gained the new walker plus two probes for the crossed cases (frames in the flat block; a nested case without frames).

test_vectors goes from 1328 to 1329 checks; assets/test_vectors.json is untouched.

Gates run locally

Every job in .github/workflows/ci.yml, each configured, built and ctest-ed from this branch:

  • gate — Debug/g++ compile
  • gcc-x86_64 Debug and Release, each with its -DSOFAB_STRICT_UTF8=0 leg
  • clang-x86_64 Debug and Release
  • lto-x86_64 gcc and clang (-O3 -flto -fstrict-aliasing, C and C++)
  • coverage — Debug + SOFAB_ENABLE_COVERAGE=ON + the gcovr summary
  • shared-vectors — sha256 of assets/test_vectors.json against corelib-c-cpp@main

ppc64-be was not run here: no g++-powerpc64-linux-gnu/qemu-user-static in this environment. Nothing in this change is endianness-sensitive (it feeds fixed byte strings and compares error codes), but CI is the first place that leg actually runs.

🤖 Generated with Claude Code

Linearized onto main for the repo's rebase-only merge policy; tree is byte-identical to the CI-green merge result of PR #148, which carried both this block and the boolean_tolerant block merged earlier.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Andste82
Andste82 force-pushed the test/run-header-limits-nested branch from c4fb553 to 2fb4017 Compare September 21, 2026 02:50
@Andste82
Andste82 merged commit 5ec3fc2 into main Sep 21, 2026
9 checks passed
@Andste82
Andste82 deleted the test/run-header-limits-nested branch September 21, 2026 02:55
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