Skip to content

fix: correct FRAME_HEADER_SIZE (24→20) + add protocol frame codec recovery tests#31

Open
dev-khimesh wants to merge 6 commits into
Peter7896:mainfrom
dev-khimesh:feat/rust-frame-tests
Open

fix: correct FRAME_HEADER_SIZE (24→20) + add protocol frame codec recovery tests#31
dev-khimesh wants to merge 6 commits into
Peter7896:mainfrom
dev-khimesh:feat/rust-frame-tests

Conversation

@dev-khimesh

Copy link
Copy Markdown

Summary

Fix pre-existing frame header size bug and add 9 deterministic regression tests for protocol frame codec recovery.

Bug Fix

FRAME_HEADER_SIZE was incorrectly set to 24 but the actual wire format header is only 20 bytes (magic:4 + version:1 + type:1 + flags:2 + payload_len:4 + sequence:4 + reserved:4). This mismatch caused ALL existing codec tests to fail because the decoder waited for 4 extra bytes that never arrived.

Tests Added (13 total, all pass)

  • Recovery after truncated input: partial header/payload → Ok(None) without panicking
  • Invalid frame length: payload beyond MAX → Err(MessageTooLarge)
  • Invalid magic/version: wrong magic → Err(InvalidMessage), bad version → Err(UnsupportedVersion)
  • State preservation: failed decode does not corrupt decoder state
  • Recovery: valid frame after invalid input decodes successfully
  • Bulk decoding: decode_all() collects all frames
  • Reset: reset() preserves future decode capability

Validation

cargo test --lib protocol::codec  # 13/13 pass

Closes #2

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.

[$50 BOUNTY] [Rust] Add protocol frame codec recovery tests

1 participant