Fix: test harness rewritten around a connection-owning HAP client, removing the axios dependency.#1122
Merged
Merged
Conversation
…moving the axios dependency.
Coverage Report for CI Build 29264740127Coverage increased (+0.04%) to 66.203%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
NorthernMan54
previously approved these changes
Jul 13, 2026
There was a problem hiding this comment.
Pull request overview
This PR rewrites the test harness HTTP client to own a single TCP connection for its full lifetime, aligning the tests with how HAP connections and encryption/session keys are actually bound server-side, and removing reliance on Node’s http.Agent free-socket behavior (and its security guard). It also removes the axios dependency and updates affected specs to use the new connection-owning client.
Changes:
- Introduce/expand
HAPHTTPClientas a raw-socket, connection-owning client with incremental HTTP response parsing and event-friendly buffering. - Migrate pair-setup / pair-verify test drivers and server/eventedhttp specs from axios+Agent to the owned-connection client, with explicit status assertions.
- Remove
axiosfrom devDependencies and lockfile; addHAPConnection.EVENT_COALESCING_DELAYconstant and use it in event coalescing logic/tests.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test-utils/PairVerifyClient.ts | Switch pair-verify handshake driver from axios/Agent to HAPHTTPClient and add explicit status assertions. |
| src/test-utils/PairSetupClient.ts | Switch SRP pair-setup driver from axios/Agent to HAPHTTPClient and add explicit status assertions. |
| src/test-utils/HAPHTTPClient.ts | Rework test HTTP client to own a raw socket, add arrival-based reads, incremental parsing, and event-friendly buffering. |
| src/lib/util/eventedhttp.ts | Introduce EVENT_COALESCING_DELAY constant and use it for the event flush timer. |
| src/lib/util/eventedhttp.spec.ts | Migrate tests to HAPHTTPClient, replace fixed sleeps with arrival-based reads, and anchor timing to coalescing delay. |
| src/lib/HAPServer.spec.ts | Replace axios-based requests with HAPHTTPClient across pairing, identify, auth, and error-path tests. |
| package.json | Remove axios devDependency. |
| package-lock.json | Remove axios and transitive dependencies from lockfile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… rejection, and portable loopback dialing in the test harness.
NorthernMan54
approved these changes
Jul 15, 2026
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.
Motivation
The free-socket data guard introduced by the CVE-2026-48931 fix (Node 22.23 / 24.17 / 26.3) destroys idle keep-alive agent sockets on any unsolicited read, which broke the 26 encrypted-session and event-notification tests. 17f19f1 restored green by neutralizing the guard - harvesting Node's internal
onStreamReadfrom a probe socket and overwritingsocket._handle.onreadon the stolen agent socket.That workaround carries some structural risk I'd prefer to remove:
agent.freeSocketsandsocket._handle.onread), and the guard itself arriving via a security backport to stable lines shows this class of dependency can now break on minor releases without warning.What this PR does
HAPHTTPClientnow owns a rawnet.Socketfor the connection's entire lifetime - the client-side mirror of the server'sHAPConnection, and the same shape as a real HomeKit controller. Pair-setup, pair-verify, the encrypted session, and server-pushedEVENT/1.0notifications all ride one owned connection, so the key-binding constraint disappears rather than needing a workaround. One client instance = one TCP connection = one server-sideHAPConnection, which also makes the connection-scoped pairing-state tests (M1reset prevention, crafted mid-handshake requests) explicit instead of relying on agent pool reuse.Along the way:
PairSetupClient/PairVerifyClientride the owned client; plain request/response call sites use it too.writeHTTPRequestawaits actual response bytes with a generous deadline instead ofPromiseTimeout(20), and responses are parsed incrementally across TCP segments (no single-segment assumption). Bytes trailing a parsed response (e.g. a coalesced EVENT message) are retained for the next read.HAPConnection.EVENT_COALESCING_DELAY(the only production-file change, behavior-preserving), and immediate-delivery assertions bound their waits below it - so a regression from immediate to timer-based delivery fails loudly instead of passing with identical bytes.(agent as any).totalSocketCount, and every test's clients are torn down through oneafterEachpath.200 OKin the pairing orchestrators.Test-only change apart from the named constant:
tsconfig.jsonexcludessrc/test-utilsand*.spec.tsfrom the build, so the published package is unaffected.Verification
npm run build,npm run lint, andtypedoc --emit noneall clean.restoreFreeSocketDataGuardand all agent-internals access removed; repo-wide grep foraxiosreturns only the historical CHANGELOG entry.