Skip to content

Conversation

@sirtimid
Copy link
Contributor

@sirtimid sirtimid commented Jan 22, 2026

Summary

  • Extract constants to dedicated constants.ts file
  • Extract PeerStateManager class for peer state management
  • Extract writeWithTimeout and makeErrorLogger to channel-utils.ts
  • Extract makeMessageSizeValidator and makeConnectionLimitChecker to validators.ts
  • Extract reconnection lifecycle logic to reconnection-lifecycle.ts
  • Add comprehensive unit tests for all extracted modules (73 new tests)

This reduces transport.ts from 784 to 521 lines (~33% reduction) while improving testability and maintainability.

Test plan

  • All 1634 unit tests pass
  • Lint passes
  • New test files added for all extracted modules

🤖 Generated with Claude Code


Note

Splits transport responsibilities into focused modules to improve testability and maintainability while preserving behavior.

  • Introduces constants.ts, channel-utils.ts (makeErrorLogger, writeWithTimeout), peer-state-manager.ts, validators.ts (message size/connection limit), and reconnection-lifecycle.ts
  • Refactors transport.ts to use these modules: centralized timeouts/limits, peer state tracking, reconnection orchestration, and error logging; removes duplicated inline logic
  • Adds comprehensive unit tests for new modules and reconnection flow

Written by Cursor Bugbot for commit 24cc1f6. This will update automatically on new commits. Configure here.

@sirtimid sirtimid requested a review from a team as a code owner January 22, 2026 20:23
@sirtimid sirtimid force-pushed the sirtimid/split-transport-concerns branch from 102ebf4 to ece964a Compare January 22, 2026 20:25
@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 88.44%
⬆️ +0.34%
5765 / 6518
🔵 Statements 88.32%
⬆️ +0.33%
5857 / 6631
🔵 Functions 87.23%
⬆️ +0.13%
1504 / 1724
🔵 Branches 84.95%
⬆️ +0.48%
2078 / 2446
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/ocap-kernel/src/remotes/platform/channel-utils.ts 100% 80% 100% 100%
packages/ocap-kernel/src/remotes/platform/constants.ts 100% 100% 100% 100%
packages/ocap-kernel/src/remotes/platform/peer-state-manager.ts 100% 100% 100% 100%
packages/ocap-kernel/src/remotes/platform/reconnection-lifecycle.ts 86.2% 86.2% 80% 86.2% 100-104, 124-125, 193-194
packages/ocap-kernel/src/remotes/platform/transport.ts 88.19%
⬆️ +5.50%
80%
⬆️ +5.22%
80%
⬇️ -2.14%
88.19%
⬆️ +5.50%
89, 108-111, 144, 178-196, 219, 352, 364, 416, 427
packages/ocap-kernel/src/remotes/platform/validators.ts 100% 100% 100% 100%
Generated in workflow #3338 for commit 24cc1f6 by the Vitest Coverage Report Action

@sirtimid sirtimid added this pull request to the merge queue Jan 26, 2026
sirtimid and others added 7 commits January 26, 2026 20:24
Move transport-related constants to constants.ts:
- DEFAULT_MAX_CONCURRENT_CONNECTIONS
- DEFAULT_MAX_MESSAGE_SIZE_BYTES
- DEFAULT_CLEANUP_INTERVAL_MS
- DEFAULT_STALE_PEER_TIMEOUT_MS
- DEFAULT_WRITE_TIMEOUT_MS
- SCTP_USER_INITIATED_ABORT

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move peer state management to dedicated PeerStateManager class:
- Encapsulates peerStates, lastConnectionTime, intentionallyClosed
- Provides methods: getState, countActiveConnections, updateConnectionTime
- Handles intentional close tracking (mark, check, clear)
- Location hints management (addLocationHints)
- Stale peer detection and removal

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move the writeWithTimeout utility function to a dedicated
channel-utils.ts module for better separation of concerns.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create factory functions for validators:
- makeMessageSizeValidator: validates message size limits
- makeConnectionLimitChecker: validates connection limits

Both use ResourceLimitError with structured data for error handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add factory function for creating error logging functions with
peer context, reducing boilerplate in transport.ts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move handleConnectionLoss and attemptReconnection to reconnection-lifecycle.ts:
- Creates makeReconnectionLifecycle factory function
- Uses holder pattern to break circular dependency
- Encapsulates reconnection orchestration logic

This significantly reduces transport.ts complexity while keeping
the reconnection logic cohesive and testable.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test coverage for the newly extracted modules:
- validators.test.ts: Tests for message size and connection limit validators
- channel-utils.test.ts: Tests for error logging and writeWithTimeout
- peer-state-manager.test.ts: Tests for PeerStateManager class
- reconnection-lifecycle.test.ts: Tests for reconnection lifecycle functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 26, 2026
@sirtimid sirtimid added this pull request to the merge queue Jan 26, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 26, 2026
@sirtimid sirtimid added this pull request to the merge queue Jan 26, 2026
@sirtimid sirtimid removed this pull request from the merge queue due to a manual request Jan 26, 2026
@sirtimid sirtimid force-pushed the sirtimid/split-transport-concerns branch from ece964a to 24cc1f6 Compare January 26, 2026 19:10
@sirtimid sirtimid enabled auto-merge January 26, 2026 19:11
@sirtimid sirtimid added this pull request to the merge queue Jan 26, 2026
Merged via the queue into main with commit 9b20297 Jan 26, 2026
75 of 95 checks passed
@sirtimid sirtimid deleted the sirtimid/split-transport-concerns branch January 26, 2026 19:45
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.

3 participants