Skip to content

test(transport): cover the protocol gaps later suites left, and floor src/transport - #296

Merged
saadahmed95 merged 2 commits into
mainfrom
test/transport-protocol-gaps
Oct 27, 2026
Merged

saadahmed95 merged 2 commits into
mainfrom
test/transport-protocol-gaps

Conversation

@saadahmed95

@saadahmed95 saadahmed95 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Why

#79 asked for the transport layer to be tested against the shipped protocol docs. Since it was written in September, later work has covered most of it: the session-resume, credential-binding, upgrade-failure, single-terminal-frame and suppression suites all test what it lists. This PR maps every criterion to the test that now covers it, adds tests for the ones nothing covered, and gives src/transport/ its own coverage floor.

What Changed

New tests, each cited from the statement it validates:

  • ws/validation.test.ts: 10,000 characters accepted and 10,001 refused with the limit named; three spaces refused as empty; {type: 'nope'} refused with its type named; a ping with a missing or text timestamp refused, and a numeric one passed through unchanged.
  • ws/helpers.test.ts: parseWsData reads JSON from text and from bytes, and reads an unterminated { as null. rejectSocket writes exactly HTTP/1.1 401 Unauthorized\r\n\r\n to a real Duplex and destroys it.
  • invalidFrame.test.ts, new: over a real socket, a frame that is not JSON gets {type: 'error', code: 'INVALID_FORMAT', message: 'Invalid JSON'}, and a ping on the same socket still gets its pong.
  • createApp.test.ts: with neither corsOrigin nor CORS_ORIGIN, a response allows http://localhost:3000 with credentials.
  • contentFreeLogs.test.ts, new, at the root because it drives createHalEngine: with LOG_LEVEL=debug set before the logger loads and the console captured, a turn with a tool call logs contentLength: 32 for a 32-character question. No line carries the question, the tool's argument or result, or the answer. Injecting a debug line with the question makes it fail.

Spec statements:

  • hal-engine-websocket-protocol: the two content constraints in § 4.1 and the two validation lines in § 12 are now cited. New statements cover the ping timestamp, frame parsing, the INVALID_FORMAT answer and the bare HTTP status line before the handshake, plus a GDPR data-minimisation line for logs.
  • hal-engine-architecture: the CORS default.
  • hal-engine-session-resume: four citations moved down one line, because helpers.test.ts gained an import.

Coverage:

  • jest.config.js gains 'src/transport/' at what it measures: 97.19% statements, 93.77% branches, 96.81% functions and 97.30% lines.
  • global is re-measured, because naming the path takes the transport files out of it. The re-measurement and the counts are recorded in hal-engine-npm-release § Coverage floor.

Decisions for the reviewer

These are deviations from the issue text.

  1. global's percentages go down. The issue asks both to re-measure global and to lower no threshold, and both cannot hold in percentages. The files still in global measured 457/496 statements, 228/266 branches, 119/132 functions and 391/418 lines on main, and 458, 228, 120 and 392 here. No count fell; the percentages fell because well-covered files left the group. AGENTS.md settles a change of measure on absolutes, and this follows that rule. The two new floors together are strictly tighter than the old one. The old global floor let the combined files fall to 1116 statements, 635 branches, 271 functions and 969 lines. The new floors require at least 1117, 635, 272 and 970, and hold transport and the rest separately, so a drop in one can no longer hide behind a rise in the other.
  2. Four pinned divergences no longer exist, so nothing pins them:
    • sessionStore.delete on every close was reversed by feat(session): stop erasing a conversation on socket close #116. sessionSurvivesClose.test.ts pins the opposite.
    • Authorization taking precedence over the subprotocol was replaced by the agree-or-refuse rule. credential.test.ts and handshake.test.ts pin it.
    • The session id unread at upgrade is now read, which helpers.test.ts and sessionResume.test.ts cover.
    • The prefix-matched path is now what § 2.1 documents, and wsPath.test.ts pins it. isValidWsPath also takes two arguments now, not three.
  3. Two of the three named new files are not created. messageHandler.test.ts already covers everything listed for messageHandler.characterization.test.ts: frame order, thinking, tool entries, suppression, error mapping, the hidden AIError message and the terminal frame. The real-port suites already cover createServer.integration.test.ts: handshake, sessionResume, upgradeFailure and historyControls each start a server on port 0, run a turn and stop it.
  4. The invalid-JSON test runs over a real socket in its own file, not in connectionHandler.test.ts. The recording socket there cannot show that the connection stayed open; a pong on the same socket does.

Already covered

Criterion Covered by
send_message refused validation.test.ts, rejects send_message
?sessionId=abc-123 on the path helpers.test.ts, wsPath.test.ts
Subprotocol credential, and header beside it credential.test.ts, handshake.test.ts
x-forwarded-host beats host forwardHeaders.test.ts
400, 401 and 500 before the handshake malformedUpgrade.test.ts, upgradeFailure.test.ts, handshake.test.ts
The connected frame connectionHandler.test.ts, which matches a UUIDv4 and the default message; connectExamplePrompts.test.ts
Frame order for a plain reply, thinking, suppression, stream_end after suppression messageHandler.test.ts
The assistant entry opening empty with isStreaming: true, and a tool entry carrying its toolName and toolInput src/testing/frames.test.ts, which compares the recorded thinkingThenTool frames field for field with a fresh run of the handler; messageHandler.test.ts also asserts the tool fields under suppression
RATE_LIMITED, SERVER_ERROR, no thrown message in a frame, the terminal frame messageHandler.test.ts, errorMapping.test.ts
A real server on port 0 that starts, answers and stops with no open handle handshake.test.ts, historyControls.test.ts and others; Jest runs without --forceExit, so a handle left open would hang the run
Synthetic fixtures Every value in the new tests is made up

Alternatives Considered

Writing the three files the issue names anyway. It would duplicate suites that exist, and no-duplicate-code refuses most of that duplication. Exporting module-private helpers for testing was ruled out by the issue itself.

ADRs & Architecture

No source change. The log test sits at the root because the layering rule lets only the root reach createHalEngine.

Testing

npm run verify passes: 1030 tests in 114 suites, coverage at the new floors, and every spec check. scripts/check-changelog.sh finds no shipped source changed. The Build chain check will fail until #295 lands, because of a body-parser advisory published on 23 October.

Related Issues

Closes #79.

🤖 Generated with Claude Code

… src/transport

Most of #79's criteria are now covered by suites written after it. This
adds what nothing covered: the 10,000-character boundary, whitespace
content, an unknown type and a ping timestamp in the validator;
parseWsData and rejectSocket; an INVALID_FORMAT answer that leaves the
socket open, over a real socket; the CORS default; and a debug-level
run proving no log line carries a turn's content. Each test is cited
from the statement it validates.

src/transport/ gets its own coverage floor at the measured figures, and
global is re-measured without those files. No covered count fell; the
counts are recorded in the npm-release spec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lore-agent

lore-agent Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Lore is reviewing this PR — 27c96faa-8038-424d-ac46-2607a1be7f87.

Submit a review that requests changes to have Lore push a fix for it. Comment @lore review to re-run the review.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🔍 Lore Spec Impact — advisory

This PR touches 42 statement(s) across 6 spec(s), and 16 of them have validating tests this PR does not change.

Session Resume · 19 statement(s)

specs/hal-engine-session-resume/spec.md

Reading the requested id
✓ this PR also changes the tests that validate it

The id is the sessionId query parameter of the upgrade request, never a path segment, and only 1–128 characters of `[…

validated by src/transport/ws/helpers.test.ts:40

Reading the requested id
✓ this PR also changes the tests that validate it

A 128-character id is the longest one read ([validated by: reads a 128-character id, the longest it accepts](../../src/…

validated by src/transport/ws/helpers.test.ts:40

Reading the requested id
✓ this PR also changes the tests that validate it

An upgrade outside {basePath}/ws carries no id ([validated by: reads nothing from an upgrade outside the base path](.…

validated by src/transport/ws/helpers.test.ts:40

Reading the requested id
✓ this PR also changes the tests that validate it

Reading the id never throws: a target that is not a URL, such as //, or an empty one carries no id ([validated by: re…

validated by src/transport/ws/helpers.test.ts:40

Continuing the latest session
✓ this PR also changes the tests that validate it

?new=1 counts only when it is exactly 1, and only on an upgrade inside {basePath}/ws ([validated by: reads exactl…

validated by src/transport/ws/helpers.test.ts:40

Opt-in
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

With resume off, a socket opened at {basePath}/ws/undefined still completes the handshake and gets a server-minted id…

validated by src/transport/sessionResume.test.ts:360

Rejoining a conversation
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

An entry still streaming when its session is resumed, because its turn is running on the socket that started it, is rep…

validated by src/transport/sessionResume.test.ts:360

Rejoining a conversation
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

An answer still open when suppression begins is first committed as streamed so far, then retracted and marked like any …

validated by src/transport/ws/messageHandler.test.ts:170, src/transport/sessionResume.test.ts:360

The store decides what is live
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

A resumed session whose socket closes before its replay is kept, never evicted: eviction erases, and it is reserved for…

validated by src/transport/sessionResume.test.ts:360

Continuing the latest session
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

With latest on, a connect that names no ?sessionId= rejoins the user's most recently active session, which the stor…

validated by src/transport/sessionResume.test.ts:360

…and 11 more statement(s).

Weaker signals (21) — linked by a spec, not proven by a test run

HAL Engine chat routes · 10 statement(s)

specs/hal-engine-chat-routes/spec.md

How the routes are mounted
✓ this PR also changes the tests that validate it

With no authMiddleware, POST /hal/chats is refused ([validated by: refuses to create a chat](../../src/transport/cr…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

Health still answers 200 alongside that refusal ([validated by: still answers health, so a denied chat route is not a…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

A path off the base path still answers 404 ([validated by: still answers 404 off the base path](../../src/transport/c…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

A supplied middleware is invoked ([validated by: invokes the middleware it was given](../../src/transport/createApp.tes…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

Once it attaches a user, the route is served ([validated by: serves the route once that middleware attaches a user](../…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

The chat routes mount only when a sessionStore is supplied; without one the path is 404 ([validated by: mounts no c…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

POST /chats calls sessionStore.create and the session is retrievable from the store by its id; after erasure, a fur…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

Two apps built on one store do not see each other's chats ([validated by: does not share chats between two apps built o…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

An Express RequestHandler is accepted as an HttpAuthMiddleware ([validated by: accepts a plain express RequestHandl…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

How the routes are mounted
✓ this PR also changes the tests that validate it

An HttpAuthMiddleware is usable as an Express RequestHandler ([validated by: is itself usable as an express Request…

validated by src/transport/createApp.test.ts:149
via changed file src/transport/createApp.test.ts

…and 11 more statement(s).

3 changed statement(s) had no validating test, so no coverage broke. 33 new statement(s) have no test link yet.

Deterministic · graph @ c3fc831 (projected 2026-10-27) · 10 file(s) skipped: changed since the graph last saw them, so their line numbers no longer line up · no tests run by this check

@lore-agent lore-agent Bot 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.

Lore review — Approved

Covers the remaining transport protocol gaps from #79 with spec-linked tests and adds the measured coverage floor for src/transport/.

Must fix (0) · Consider (0) · Nits (0)

Reviewed by gemini-4-argon

Submit a review that requests changes to have Lore push a fix for it. Comment @lore review to re-run the review.

Posted by floor, visit b9438844-146d-4482-9a71-692cf532a8e7.

@lore-agent lore-agent Bot 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.

Lore review — Approved

Clean merge of origin/main (body-parser 2.4.0 lockfile update) with all CI checks passing.

Must fix (0) · Consider (0) · Nits (0)

Reviewed by gemini-4-argon

Submit a review that requests changes to have Lore push a fix for it. Comment @lore review to re-run the review.

Posted by floor, visit a0acfedf-070f-4095-b760-9b1332d1394c.

@saadahmed95
saadahmed95 merged commit a872d61 into main Oct 27, 2026
10 checks passed
@saadahmed95
saadahmed95 deleted the test/transport-protocol-gaps branch October 27, 2026 09:43
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 the transport layer against the shipped protocol docs

1 participant