Skip to content

test(http2): expand hpack.cpp coverage (encoder/decoder/dynamic_table edge cases) #1009

Description

@kcenon

What

Expand unit test coverage for src/protocols/http2/hpack.cpp (currently 673 lines, existing test hpack_test.cpp is 515 lines — test:source ratio 0.77, the lowest among remaining EPIC #953 candidate files). The existing test exercises happy-path encode/decode round-trips but does not exhaustively cover error paths, integer/string boundary conditions, and dynamic-table eviction pressure.

This is a Step 2 narrow-scoped test expansion under EPIC #953.

Why

  • HPACK is the binary header compression layer for HTTP/2; bugs here corrupt every request/response on a connection.
  • EPIC Expand unit test coverage from 40% to 80% #953 baseline (2026-04-13, pre-BUILD_WITH_*) reported 13.5% line coverage on this file. The file has nearly tripled in size since then (244 → 673 lines), so the real branch-coverage gap is larger.
  • Decoder error paths (Result<T> returns) need verification — a miscoded length prefix or invalid table index must produce a clean error, not undefined behavior.

Where

  • Source: src/protocols/http2/hpack.cpp
  • Header: src/internal/protocols/http2/hpack.h
  • New test: tests/unit/hpack_coverage_test.cpp
  • CMake registration: tests/CMakeLists.txt via add_network_test(...)

How

Test surface (per public API in hpack.h)

  • dynamic_tableinsert, set_max_size (force eviction), evict_to_size, find (name-only and name+value), clear, entry_count after eviction
  • hpack_encoderencode_integer with prefix_bits 1..8 and edge values (0, 2^N - 2, 2^N - 1 triggers continuation, large uint64_t); encode_string huffman vs literal toggle; encode_indexed; encode_literal_with/without_indexing (both string-name and indexed-name overloads); set_max_table_size mid-encode
  • hpack_decoderdecode_integer truncated input, decode_string truncated input + huffman/literal both, get_indexed_header zero index and out-of-range index, full decode on truncated frames and invalid index references; dynamic table size update inside header block
  • huffmanencode/decode round-trip across full byte range (0..255 sweep), encoded_size consistency vs encode().size(), decode of intentionally malformed bitstream

Acceptance Criteria

  • tests/unit/hpack_coverage_test.cpp added and registered in tests/CMakeLists.txt
  • network_hpack_coverage_test builds and all tests pass on local build
  • Tests do not require any network I/O or external HTTP/2 peer
  • Tests use only the public API of the hpack translation unit (no private/friend access)
  • All tests pass on Ubuntu/macOS/Windows CI when run via release pipeline
  • No regression in existing network_hpack_test cases

Out of scope

Dependencies

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions