Skip to content

tests: pin /fastboot wire format + recv-leftover stress#90

Merged
widgetii merged 1 commit into
masterfrom
more-tests-fastboot-leftover
May 11, 2026
Merged

tests: pin /fastboot wire format + recv-leftover stress#90
widgetii merged 1 commit into
masterfrom
more-tests-fastboot-leftover

Conversation

@widgetii
Copy link
Copy Markdown
Member

Summary

Test-only PR — locks in two integration points that previously rested on real-hardware verification alone.

1. /fastboot binary blob (tests/test_power_rack.py)

RackController.fastboot() packs profile + SPL + agent into a single big-endian binary blob that the pod's C handler in rack/firmware/main/http_api.c parses field by field. Any drift between the two breaks bring-up silently — pod returns 400, the host can't tell why.

Six new TestFastbootWireFormat cases:

Case Why
test_packs_expected_layout round-trip every field
test_prestep1_passthrough optional prestep1 not dropped
test_success_response_returned_verbatim done/elapsed/markers preserved
test_pod_500_returns_json_body_not_exception protocol failure (500 + JSON) surfaces as a dict, not an exception — callers need failed_phase / error
test_pod_unreachable_raises_power_controller_error network-layer errors stay raised
test_realistic_blob_size_within_pod_limit 41 834 B for a typical hi3516ev300 upload, under the pod's 1 MiB cap

Shared helper _parse_fastboot_blob() is the inverse of the host packer; if either side bumps the format, the round-trip test fails loudly.

2. Async recv_packet leftover stress (tests/test_agent_protocol.py)

PR #86 added a per-transport leftover buffer so multi-packet TCP chunks don't drop trailing packets. The existing tests covered the two simplest cases (two/three packets in one chunk). Six stress cases added:

Case Why
test_frame_split_across_two_reads_recombines half a packet, then the other half (TCP MTU split)
test_large_stream_50_packets_in_one_chunk catches off-by-one in leftover slicing
test_recv_response_skips_ready_in_leftover READY skipping still works when READYs are in leftover, not on the wire
test_per_transport_isolation two transports must not share leftover state
test_incomplete_frame_in_leftover_blocks_until_timeout half a frame must wait for the rest, never spuriously return partial
test_corrupt_frame_skipped_then_recovers bit-flipped CRC mid-stream must be discarded; parser picks up the next valid frame

Test plan

  • uv run pytest tests/ -x -v --ignore=tests/fuzz480 passed / 2 skipped (was 468)
  • uv run ruff check tests/ src/defib/
  • uv run mypy src/defib/ --ignore-missing-imports

No production code touched.

🤖 Generated with Claude Code

Test-only PR — locks in two integration points that previously rested
on real-hardware verification alone.

### /fastboot binary blob (tests/test_power_rack.py)

`RackController.fastboot()` packs profile + SPL + agent into a single
big-endian binary blob that the pod's C handler in
`rack/firmware/main/http_api.c` parses field-by-field. Any drift
between the two breaks bring-up silently — pod returns 400, but the
host can't tell why. Six new tests pin it down:

- `test_packs_expected_layout`        — round-trip every field
- `test_prestep1_passthrough`         — optional prestep1 not dropped
- `test_success_response_returned_verbatim` — done/elapsed/markers
- `test_pod_500_returns_json_body_not_exception` — protocol failure
  comes back as a dict (so callers can read `failed_phase`/`error`)
  rather than raising
- `test_pod_unreachable_raises_power_controller_error`
- `test_realistic_blob_size_within_pod_limit` — 41 834 B for a typical
  hi3516ev300 upload, well under the pod's 1 MiB cap

Shared helper `_parse_fastboot_blob()` is the inverse of the host
packer — if anyone bumps either side, the round-trip test fails
loudly.

### Async recv_packet leftover (tests/test_agent_protocol.py)

PR #86 added a per-transport leftover buffer so multi-packet TCP
chunks don't drop trailing packets. The existing tests cover the
two simplest cases (two/three packets in one chunk). Six stress
tests added to lock down the corner cases:

- `test_frame_split_across_two_reads_recombines` — half a packet
  arrives, then the other half (TCP MTU split)
- `test_large_stream_50_packets_in_one_chunk` — catches off-by-one
  in leftover slicing
- `test_recv_response_skips_ready_in_leftover` — READY skipping
  still works when the READYs are in leftover, not on the wire
- `test_per_transport_isolation` — two transports must not share
  leftover state
- `test_incomplete_frame_in_leftover_blocks_until_timeout` — half
  a frame must wait for the rest, never spuriously return partial
- `test_corrupt_frame_skipped_then_recovers` — bit-flipped CRC
  mid-stream must be discarded; parser picks up the next valid frame

Suite: **480 passed / 2 skipped** (was 468); ruff + mypy clean.
No production code touched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@widgetii widgetii merged commit 01253cf into master May 11, 2026
13 checks passed
@widgetii widgetii deleted the more-tests-fastboot-leftover branch May 11, 2026 20:03
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