Skip to content

test: Add TCP transport test suite#150

Open
benaadams with Copilot wants to merge 3 commits into
masterfrom
copilot/add-tcp-transport-tests
Open

test: Add TCP transport test suite#150
benaadams with Copilot wants to merge 3 commits into
masterfrom
copilot/add-tcp-transport-tests

Conversation

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

TCP transport (state machine, segment parsing, retransmission, window management) had zero test coverage.

Test Coverage (72 tests)

Header Parsing (19 tests)

  • Field extraction/writing: ports, sequence/ack numbers, flags, window size
  • All flag combinations (SYN/ACK/FIN/RST/PSH/URG/ECE/CWR/NS)
  • DataOffset and TryConsume methods
  • Endianness conversion validation

Checksums (7 tests)

  • IPv4 pseudo-header calculation
  • Partial checksum for split buffers
  • Validation against known packet captures

State Machine (15 tests)

  • All transition paths: CLOSED→LISTEN→SYN_RCVD→ESTABLISHED
  • Teardown: FIN_WAIT_1/2, CLOSING, TIME_WAIT, CLOSE_WAIT, LAST_ACK

Options (12 tests)

  • MSS, Window Scale, SACK Permitted, Timestamps
  • NoOp padding and End-of-Options handling

Edge Cases (19 tests)

  • Zero-window probing, RST handling, out-of-order segments
  • Sequence number wrap-around, duplicate ACKs
  • Min/max header sizes (20/60 bytes)

Pattern

Tests use type-punning for zero-copy header access:

var span = tcpPacket.AsSpan();
ref var header = ref Unsafe.As<byte, TcpHeader>(ref MemoryMarshal.GetReference(span));

// Validate checksum with pseudo-header
var pseudoSum = Checksum.PartialCalculate(ref Unsafe.As<TcpV4PseudoHeader, byte>(ref pseudo), ...);
header.SetChecksum(span, pseudoSum);

Follows existing test patterns from Magma.Internet.Ip.Facts with HexToByteArray for known-good packets.

Original prompt

This section details on the original issue you should resolve

<issue_title>test: TCP transport</issue_title>
<issue_description>## Problem

Magma.Transport.Tcp has a connection state machine, segment parsing, retransmission logic, and window management - all untested. This is the highest-risk untested area.

Sub-tasks

  • Create test/Magma.Transport.Tcp.Facts project, add to solution
  • TCP header parsing: construct known-good segments in byte[], verify field extraction
  • State machine transitions: CLOSED -> SYN_SENT -> ESTABLISHED -> FIN_WAIT etc.
  • Checksum computation: validate against known packet captures
  • Edge cases: zero-window probing, RST handling, out-of-order segments

Dependencies

Depends on: nothing (tests existing code)
Unlocks: #105 (UDP datagram), #122 (TCP benchmarks), #131 (Kestrel), establishes test patterns for other projects

Phase

Phase 0 (Foundation) - can start immediately</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 11, 2026 05:02
Co-authored-by: benaadams <1142958+benaadams@users.noreply.github.com>
Co-authored-by: benaadams <1142958+benaadams@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for TCP transport connection state and parsing test: Add TCP transport test suite Feb 11, 2026
Copilot AI requested a review from benaadams February 11, 2026 05:09
@benaadams benaadams marked this pull request as ready for review February 11, 2026 05:11
Copilot AI review requested due to automatic review settings February 11, 2026 05:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

test: TCP transport

3 participants