Skip to content

test(dispatch): prove which decoder runs on shared shapes + sync twins#48

Merged
lesnik512 merged 1 commit into
mainfrom
test/dispatch-decoder-identity
Jun 13, 2026
Merged

test(dispatch): prove which decoder runs on shared shapes + sync twins#48
lesnik512 merged 1 commit into
mainfrom
test/dispatch-decoder-identity

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

Closes the Medium finding plus two related test nits from the 0.9.0 delta audit (planning/audit/2026-06-12-delta-audit.md). Test-only; no behavior change.

The shared-shape routing tests asserted only output equality — but PydanticDecoder and MsgspecDecoder decode dict[str, int] and a stdlib dataclass to identical values, so a regression that routed to the wrong decoder would still pass. The central ordering invariant of the multi-decoder epic ("shared shapes go to the first decoder in the list") was never actually verified.

What changed

  • New _decode_spies(*decoders) helper wraps each real decoder's decode() so a test can assert which decoder the dispatcher selected.
  • The dict (×4: async/sync, normal/reversed) and dataclass routing tests now assert first.decode ran once and the other was never called — pinning the ordering invariant with real decoders, not synthetic stubs.
  • Added the missing sync Client twins for dataclass routing and list[BaseModel] routing (previously async-only).

Proof the strengthening is real

Temporarily reversing _dispatch_decoder (last-match-wins) makes the strengthened tests fail on the spy assertion — while the old assert result == {...} still passed, because the wrong decoder produces the same value. Mutation reverted; that gap is exactly what this PR removes.

Test Plan

  • just lint clean
  • just test — 509 passed, 100% coverage (+2 sync twins)
  • Mutation test: reversed dispatch → strengthened asserts fail; reverted → green

🤖 Generated with Claude Code

…wins

Closes the Medium + two test nits from planning/audit/2026-06-12-delta-audit.md.

The shared-shape routing tests (dict, dataclass) asserted only output
equality — but PydanticDecoder and MsgspecDecoder decode dict[str,int] / a
stdlib dataclass to identical values, so a regression that routed to the
wrong decoder would still pass. They now spy on each real decoder's decode()
via a _decode_spies helper and assert WHICH one ran (first-in-list wins;
the other is never called), pinning the epic's ordering invariant.

Also adds the missing sync Client twins for dataclass routing and
list-of-BaseModel routing (previously async-only).

Verified the strengthened asserts catch the regression: temporarily
reversing _dispatch_decoder makes them fail on the spy assertion while the
old output-equality check still passed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 5377bdd into main Jun 13, 2026
5 checks passed
@lesnik512 lesnik512 deleted the test/dispatch-decoder-identity branch June 13, 2026 08:41
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