refactor(websocket): extract setupNewPtyEntry phases into helpers#145
Merged
Conversation
- app-ralph.ts: add RalphLoop/RalphDeps/StartRalphBody interfaces, type all
function params, replace 5x `as any` with proper DOM types, extract
getCheckedRadioValue helper to replace `{} as any` radio pattern
- routes.ts: replace 5x `catch (e: any)` with `catch (e: unknown)` + errMsg,
remove worktree `as any` include check
- websocket.ts: remove `as any` on activePtySessions.set
- backend.ts: add DuplicateSessionError class, replace monkey-patched
`(err as any).code` pattern
- mock-backend.ts: use DuplicateSessionError for test consistency
- waitForResizeSettle, waitForOutputQuiescence, sendSnapshotPrefill, subscribeWithCoalescing as module-level functions - PtyEntryContext carries shared state (requestedSize as mutable holder so outer ws-handler reassignment is visible to helpers) - orchestrator slimmed to sequencing; setupNewPtyEntry 478->213 LOC - drop dead pendingPrefillMode var - 1483 tests pass, tsc clean, no `as any` introduced
# Conflicts: # src/public-assets.ts
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.
Extracts the 478-LOC
setupNewPtyEntrygod function into four module-level helpers driven by a sharedPtyEntryContext. Pure refactor, zero behavior changes.Helpers
waitForResizeSettle(ctx, initialSize)— pre-snapshot client-resize debounce loop. Returns settled size ornullon bail.waitForOutputQuiescence(ctx, pendingSize)— applies settled dims, then observes broker output until quiet (so SIGWINCH redraw lands in the snapshot, not the live replay). Returns final applied size ornull.sendSnapshotPrefill(ctx, appliedSize, prefillMode)— fetches broker snapshot, chunked send to viewer, returnsprefillSeqfor live-subscribesinceSeq.subscribeWithCoalescing(ctx, prefillSeq)— live data sub with adaptive coalescing + lifecycle sub + teardown wiring.Context
requestedSizeis a holder cell (not a plain field) because the outer ws message handler reassigns it AFTER helpers capture the context — they need to see the latest value on every poll.Numbers
setupNewPtyEntry: 478 → 213 LOCattachStreamingBackendorchestrator: 80 LOC (sequencing only)Drive-by
let pendingPrefillMode(declared, never read)PrefillMode+VALID_PREFILL_MODESto module scope (helpers need them)attachStreamingBackend+spawnPtyPtyEntryinterface from inline object-literal typeVerify
bunx tsc --noEmit -p .cleanbun test— 1483 / 1483 passas anyintroducedscripts/deploy-local.sh