infra(test): add probe-based friend injection for server-private methods (Phase 2D of #1074)#1104
Merged
Conversation
Add friend-test injection so unit tests can drive two private
server-side methods previously unreachable from public APIs:
- messaging_quic_server::handle_packet
(src/internal/experimental/quic_server.h:432)
- messaging_ws_server::handle_new_connection
(src/internal/http/websocket_server.h:415)
Mechanism: new compile definition NETWORK_ENABLE_TEST_INJECTION
gated behind BUILD_TESTS in cmake/network_system_targets.cmake.
The two production headers gain a forward declaration block and
a single 'friend class' line, all wrapped in
'#if defined(NETWORK_ENABLE_TEST_INJECTION)'. When BUILD_TESTS=OFF
the production binary is byte-identical to the previous develop tip.
Probe types live entirely in tests/support/:
- network_test_friends.h forward-declares the probes
- quic_server_probe.{h,cpp} forwards to handle_packet
- ws_server_probe.{h,cpp} forwards to handle_new_connection
Demo tests verify end-to-end wiring:
- QuicServerProbeTest.HandlePacket{Empty,Garbage}BufferDoesNotCrash
- WsServerProbeTest.HandleNewConnectionEarlyReturnNoSessionManager
- WsServerProbeTest.HandleNewConnectionEmptySocketEarlyReturn
Per #1074 scope: no behavioral changes to src/. Phases 2A (#1075),
2A.2 (#1082), 2B (#1102), 2C (#1103) merged; 2E remains.
Part of #1074
Contributor
Coverage Report
Coverage DetailsFull HTML report is available as a build artifact. |
This was referenced May 6, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add friend-test injection so unit tests can drive two server-side private methods previously unreachable from public APIs. Plus probe classes and demo tests. No behavioral changes to
src/.Targets opened to friend access
messaging_quic_server(kcenon::network::core)handle_packet(span, endpoint)src/internal/experimental/quic_server.hmessaging_ws_server(kcenon::network::core)handle_new_connection(shared_ptr<tcp::socket>)src/internal/http/websocket_server.hChange Type
frienddeclaration + namespace forward-decl per header, both gated)Why
Part of #1074 (Phase 2D). Continues #1075 (2A), #1082 (2A.2), #1102 (2B), #1103 (2C).
Issue #1074 §"Out of scope" explicitly limits this work to friend declarations. Two private methods were called out as the remaining barriers to unit-test coverage of server-side QUIC and WebSocket reception logic. Without friend access, post-private-state branches in
quic_server.cppandwebsocket_server.cppremain dead code from the test runner's perspective.Related Issues
messaging_quic_server(test(quic): expand experimental/quic_server.cpp coverage to 80% line / 70% branch #1066) andmessaging_ws_serverpathsWhere
cmake/network_system_targets.cmakeif(BUILD_TESTS))src/internal/experimental/quic_server.hfriend, both gated)src/internal/http/websocket_server.htests/support/network_test_friends.htests/support/quic_server_probe.{h,cpp}tests/support/ws_server_probe.{h,cpp}tests/support/CMakeLists.txttests/CMakeLists.txttests/unit/quic_server_probe_test.cpptests/unit/ws_server_probe_test.cppTotal: 12 files, 319 insertions, 0 deletions. PR size: M.
How
Implementation Highlights
Gate symbol —
NETWORK_ENABLE_TEST_INJECTION. Defined astarget_compile_definitions(network_system PUBLIC NETWORK_ENABLE_TEST_INJECTION)inside anif(BUILD_TESTS)block. PUBLIC propagation so probe TUs and test executables inherit the same define. WhenBUILD_TESTS=OFF, the production binary is byte-identical to the previous develop tip —friendblocks compile out entirely.Production header pattern (mirrored in both):
The forward-decl block lives outside the production namespace, so the production header pulls in zero test types. Probe definitions live entirely in
tests/support/.Probe shape (pure forwarder):
Static-method forwarders, no instance state, no fixture dependency. The probe exists solely to grant the friend bridge.
Testing Done
QuicServerProbeTest.HandlePacketEmptyBufferDoesNotCrash— passesQuicServerProbeTest.HandlePacketGarbageBufferDoesNotCrash— passesWsServerProbeTest.HandleNewConnectionEarlyReturnNoSessionManager— passesWsServerProbeTest.HandleNewConnectionEmptySocketEarlyReturn— passesThe WebSocket tests exercise the
session_mgr_ == nullptrearly-return branch (server is never started). Reaching the started-server path requires aws_session_managerand a connected loopback peer driving the WebSocket upgrade — that is the domain ofnetwork_websocket_server_loopback_test, not the probe wiring test. Phase 2D's job is proving the friend bridge works end-to-end and that the previously-private entry points are now reachable from tests.Test Plan for Reviewers
Note: GTest test-case names are PascalCase (
QuicServerProbeTest), CTest target names are snake_case (network_quic_server_probe_test) — the-Rfilter matches GTest names.Off-by-default Verification
To confirm
BUILD_TESTS=OFFproduces a byte-identical production library:Breaking Changes
None.
Rollback
Revert this PR. No data, no public-API impact. Production binary semantics unchanged.
Part of #1074