Skip to content

feat: preserve Socket.IO event maps - #210

Merged
electrohyun merged 3 commits into
mainfrom
feat/type-event-maps
Aug 10, 2026
Merged

electrohyun merged 3 commits into
mainfrom
feat/type-event-maps

Conversation

@electrohyun

@electrohyun electrohyun commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Preserve Socket.IO's four server generic slots across the server, namespace, socket, broadcast, timeout, volatile, middleware, adapter, and test-harness contracts.
  • Keep server/client event directions, the SocketData default, acknowledgement selection, and reserved disconnect listener types aligned with Socket.IO.
  • Add compile-only consumer coverage for inference and rejection, and record the substitution boundary in decision 0021 and the test-runner guide.

Type compatibility

  • Omitting event maps keeps the accept-any-event default.
  • A concrete map narrows event names, payloads, acknowledgements, and socket.data.
  • Server emitWithAck accepts acknowledgement callbacks that carry a response value; the client retains socket.io-client's wider event-name rule.
  • ServerSideEvents preserves Socket.IO's generic position without adding multi-server behavior.
  • The free connect and io functions remain non-generic, matching socket.io-client.

Related issue

Closes #171

Verification

  • pnpm vitest run (48 files, 402 tests)
  • pnpm test:dist (21 files, 172 tests)
  • pnpm typecheck
  • pnpm lint
  • pnpm format:check
  • pnpm check:conformance
  • pnpm check:package

@github-actions github-actions Bot added the enhancement New feature or request label Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@electrohyun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 09969757-7ded-4a26-b86d-579f8b1cbdec

📥 Commits

Reviewing files that changed from the base of the PR and between 0b95e2d and fd5240b.

📒 Files selected for processing (1)
  • src/event-maps.typecheck.ts
📝 Walkthrough

Walkthrough

The PR adds Socket.IO-compatible event-map generics across contracts and mock-server APIs. It preserves permissive defaults, adds compile-time validation, exports DefaultEventsMap, and updates integration documentation and ADR records.

Changes

Event-map typing

Layer / File(s) Summary
Event-map contracts and helpers
src/contract.ts
Defines event-map constraints, event-name and argument helpers, acknowledgement types, reserved-event listeners, and generic server, namespace, socket, and adapter contracts.
Typed event APIs
src/contract.ts
Propagates event maps and socket data through broadcasts, timeouts, volatile sockets, namespaces, clients, connections, and server contexts.
Mock-server wiring
src/mock-server.ts, src/setup-real-server.ts
Propagates generic parameters through Server, namespace access, middleware, connections, adapters, broadcasts, and the real-server contract boundary.
Compatibility validation and documentation
src/event-maps.typecheck.ts, src/index.ts, docs/decisions/*, docs/test-runner-integration.md, vitest.config.ts
Adds compile-time assertions, exports DefaultEventsMap, records ADR 0021, documents inferred socket types and typed event maps, and excludes typecheck fixtures from coverage.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related issues

Possibly related PRs

Suggested labels: documentation

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy the coding objectives in [#171], including four generic slots, type propagation, defaults, acknowledgements, reserved events, and compile-time coverage.
Out of Scope Changes check ✅ Passed The implementation, compile-only fixtures, documentation, and coverage configuration support the linked issue without unrelated code changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title clearly and concisely describes preserving Socket.IO event maps, which is the main change.
Description check ✅ Passed The description directly covers the event-map, socket-data, contract, documentation, and verification changes.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/contract.ts (1)

180-183: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Align the client-side emitWithAck constraints to Socket.IO’s ack-only semantics.

TimeoutEmitterContract and VolatileClientSocket currently allow events without an acknowledgement callback, so a non-ack event can call emitWithAck, drop the real last argument via AllButLast, and resolve unknown via FirstAckValue. Real Socket.IO clients constrain emitWithAck to ack-enabled events. Apply the same EventNameWithAck<EmitEvents> constraint at both client positions.

♻️ Proposed alignment
   emitWithAck<Event extends EventNameWithAck<EmitEvents>>(
     event: Event,
     ...args: allButLast<EventParams<EmitEvents, Event>>
   ): Promise<FirstAckValue<Last<EventParams<EmitEvents, Event>>>>> ;
</diff
</details>
  
</verification_result>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @src/contract.ts around lines 180 - 183, Update the emitWithAck generic
constraint in both TimeoutEmitterContract and VolatileClientSocket to use
EventNameWithAck instead of EventName, while preserving
the existing argument and return-type definitions.


</details>

<!-- cr-comment:v1:4017edca12d2b39542f0cac8 -->

</blockquote></details>

</blockquote></details>

<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @docs/decisions/0021-event-maps-cross-the-substitution-seam.md:

  • Around line 1-5: Update
    docs/decisions/0021-event-maps-cross-the-substitution-seam.md:1-5 by adding the
    matching Korean decision file
    docs/decisions/0021-event-maps-cross-the-substitution-seam.ko.md and its row in
    the Korean decisions README. Update docs/test-runner-integration.md:187-215 by
    adding the “Preserving application event maps” section to
    docs/test-runner-integration.ko.md and mirror annotation removals at lines
    36-44, 71-72, and 135-146.

In @src/contract.ts:

  • Around line 830-884: Widen ServerSocketParityContract and
    ClientSocketParityContract in src/contract.ts (lines 830-884) to include every
    non-listener member of the corresponding Socket.IO contracts, especially emit,
    emitWithAck, timeout, and volatile; retain use in ServerParityContract and
    NamespaceParityContract. In src/setup-real-server.ts (lines 32-35), update the
    justification to identify only listener members as unproven, or preserve a
    narrower assignment that structurally checks the non-listener members.

Nitpick comments:
In @src/contract.ts:

  • Around line 180-183: Update the emitWithAck generic constraint in both
    TimeoutEmitterContract and VolatileClientSocket to use
    EventNameWithAck instead of EventName, while preserving
    the existing argument and return-type definitions.

</details>

<details>
<summary>🪄 Autofix</summary>

Fix all unresolved CodeRabbit comments on this PR:

- [ ] <!-- {"checkboxId": "4b0d0e0a-96d7-4f10-b296-3a18ea78f0b9"} --> Push a commit to this branch (recommended)
- [ ] <!-- {"checkboxId": "ff5b1114-7d8c-49e6-8ac1-43f82af23a33"} --> Create a new PR with the fixes

</details>

---

<details>
<summary>ℹ️ Review info</summary>

<details>
<summary>⚙️ Run configuration</summary>

**Configuration used**: Path: .coderabbit.yaml

**Review profile**: CHILL

**Plan**: Pro Plus

**Run ID**: `1292ac15-54ca-4dc1-b89a-7b5ba21ffbde`

</details>

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between b63346fc455b6af3531d413092b5176153f01276 and 76ba4b7618b200be303cf83bfdddaf2dddeb0da0.

</details>

<details>
<summary>📒 Files selected for processing (8)</summary>

* `docs/decisions/0021-event-maps-cross-the-substitution-seam.md`
* `docs/decisions/README.md`
* `docs/test-runner-integration.md`
* `src/contract.ts`
* `src/event-maps.typecheck.ts`
* `src/index.ts`
* `src/mock-server.ts`
* `src/setup-real-server.ts`

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment thread src/contract.ts Resolved
@electrohyun
electrohyun force-pushed the feat/type-event-maps branch from 76ba4b7 to 3f37e0b Compare August 10, 2026 08:44
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@electrohyun
electrohyun force-pushed the feat/type-event-maps branch from 3f37e0b to 197de44 Compare August 10, 2026 08:57
@electrohyun

electrohyun commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner Author

@coderabbitai Regarding the emitWithAck nit: I verified this against both socket.io-client 4.7.5 and 4.8.x and did not apply the suggested ack-only constraint. The client declaration intentionally uses EventNames, while the server socket uses EventNamesWithAck. Restricting TimeoutEmitterContract or VolatileClientSocket would therefore make smocket narrower than the client API it substitutes. The compile-only fixture now includes the non-ack client case on both the real and smocket shapes so this distinction stays explicit.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@electrohyun The ack-only constraint does not apply to TimeoutEmitterContract or VolatileClientSocket. The client contract must preserve EventNames<EmitEvents> compatibility. I withdraw the nit.


✏️ Learnings added
Learnt from: electrohyun
URL: https://github.com/electrohyun/smocket/pull/210

Timestamp: 2026-08-10T08:59:44.620Z
Learning: For Smocket’s Socket.IO client substitution contracts, including `TimeoutEmitterContract` and `VolatileClientSocket`, `emitWithAck` must accept `EventNames<EmitEvents>`, not only acknowledgement-bearing event names. Socket.IO client 4.7.5 and 4.8.x intentionally permit this broader event-name set, while server sockets use `EventNamesWithAck<EmitEvents>`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

@electrohyun
electrohyun force-pushed the feat/type-event-maps branch from 197de44 to 0b95e2d Compare August 10, 2026 12:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/event-maps.typecheck.ts`:
- Around line 67-75: Extend both server assertion sections in
assertRealSocketIoListenerInferenceCompiles to cover IoServer emit,
room/namespace filtering, and timeout().emit acknowledgement result typing using
the existing real Socket.IO generics. Preserve the current callback type
assertions, and do not add ServerSideEvents delivery cases.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 93b8546a-2b17-48f7-83dd-edb6145ba41b

📥 Commits

Reviewing files that changed from the base of the PR and between 76ba4b7 and 0b95e2d.

📒 Files selected for processing (6)
  • docs/decisions/0021-event-maps-cross-the-substitution-seam.md
  • src/contract.ts
  • src/event-maps.typecheck.ts
  • src/mock-server.ts
  • src/setup-real-server.ts
  • vitest.config.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/setup-real-server.ts
  • docs/decisions/0021-event-maps-cross-the-substitution-seam.md
  • src/mock-server.ts
  • src/contract.ts

Comment thread src/event-maps.typecheck.ts Resolved
@electrohyun
electrohyun force-pushed the feat/type-event-maps branch from 0b95e2d to 79f24fa Compare August 10, 2026 12:35
@electrohyun
electrohyun force-pushed the feat/type-event-maps branch from 79f24fa to fd5240b Compare August 10, 2026 12:41
@electrohyun
electrohyun merged commit fd0990c into main Aug 10, 2026
13 checks passed
@electrohyun
electrohyun deleted the feat/type-event-maps branch August 10, 2026 12:42
@electrohyun electrohyun added the 📏 xl Pull request changes at least 1,000 lines label Aug 11, 2026
@electrohyun electrohyun self-assigned this Aug 11, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in smocket Aug 27, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in smocket Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request 📏 xl Pull request changes at least 1,000 lines

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat: type events with generic event maps

1 participant