Skip to content

test: cover the pure protocol units (Window, Codec, Protocol, ErrorCode)#1

Merged
bradgessler merged 1 commit into
mainfrom
tests-coverage
Jun 22, 2026
Merged

test: cover the pure protocol units (Window, Codec, Protocol, ErrorCode)#1
bradgessler merged 1 commit into
mainfrom
tests-coverage

Conversation

@bradgessler

Copy link
Copy Markdown
Contributor

Why

The standalone unit suite left the pure, sans-IO protocol modules thin — they were only exercised incidentally by the cross-language corpus run, which is excluded without TERMINALWIRE_CORPUS. So this repo's own mix test (what CI gates on) under-covered the contract:

Module Before After
Terminalwire.Window (flow-control ledger) 0% 100%
Terminalwire.Protocol.ErrorCode 0% 100%
Terminalwire.Protocol 57% 100%
Terminalwire.Codec 66% 100%
Total 87.3% 91.8%

What

  • window_testnew/take/grant: credit math, the never-negative take, draining to empty and refilling, and the MAX_WINDOW ceiling clamp on both new/1 and grant/2 (the anti-DoS bound).
  • protocol_test — pins the wire constants (version, control sid, default/max window, capability set) and every frame-type / signal / error-code token. These are the cross-language contract; a silent change here breaks interop.
  • codec_test — encode/decode round-trips (including control sid 0 and the max signed-64-bit sid) and every decode rejection path: non-map, corrupt msgpack, missing/empty/non-string t, and missing/non-integer/negative/out-of-range sid.
  • Also documents (and corrects a misleading comment about) the fact that bin payloads decode as Msgpax.Bin — kept wrapped so a decode→re-encode preserves the MessagePack bin type; the Session unwraps before use.

All new files are mix format-clean and credo --strict-clean. mix test: 101 passed, 9 excluded (corpus).

The standalone suite left the pure, sans-IO protocol modules thin — Window (the
flow-control ledger) and Protocol.ErrorCode were at 0%, Codec 66%, Protocol 57%.
These are the cross-language contract; they deserve dedicated unit tests, not just
incidental coverage from the corpus run (which is excluded standalone).

- window_test: new/take/grant — credit math, the never-negative take, draining,
  and the MAX_WINDOW ceiling clamp on both new/1 and grant/2.
- protocol_test: pins the wire constants (version, control sid, default/max window,
  capabilities) and every frame type / signal / error-code token.
- codec_test: encode/decode round-trips (incl. control sid 0 and the max signed-64
  sid) and every decode rejection (non-map, corrupt msgpack, missing/empty/non-string
  't', missing/non-integer/negative/out-of-range 'sid'). Also documents that bin
  payloads decode as Msgpax.Bin (binary: true) so a re-encode keeps the bin type.

Also fixes a misleading codec doc comment (it claimed bin decodes to a plain
binary; it's a Msgpax.Bin the Session unwraps).

Total coverage 87% -> 92%; Window/Codec/Protocol/ErrorCode now 100%.
@bradgessler bradgessler merged commit 031a71f into main Jun 22, 2026
1 check passed
@bradgessler bradgessler deleted the tests-coverage branch June 22, 2026 07:24
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