Skip to content

refactor(shared): dedupe the local-default connection-to-host conversion and the trim helpers - #27797

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/p399-2-8
Oct 12, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/p399-2-8

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14 $\color{#cf222e}{\Huge{\mathbf{−}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21

ELI5

Orca had the same tiny rule written out several times: "turn a stored SSH connection id into a host id, and treat a blank one as this computer", plus three copies of "trim a stored id, blank means none". This PR keeps one copy of each and points the callers at it.

What Changed

  • src/shared/execution-host.ts now exports its trim-to-null helper normalizeHostPart. The private copy in execution-host-registry.ts and normalizeConnectionId in folder-workspace-execution-host.ts (same body, one caller file) are gone.
  • Three places that rebuilt "repo/folder host stamp, else SSH connection id, else local" by hand now call the existing shared functions:
    • local-path-open-guard.ts → getConnectionExecutionHostId
    • resolved-worktree-execution-host.ts (repo branch) → getRepoExecutionHostId
    • detected-worktree-meta.ts folderWorkspaceMatchesHost → getRepoExecutionHostId
  • Deliberately not touched: the readers that return null/undefined when ownership is unknown (workspace cleanup host identity, worktree host ownership, PTY stable owner, pane evidence). There, "absent" means "no ownership evidence", and turning it into "local" would let cleanup act on the wrong machine. ssh-pty-id's normalizeConnectionId is an id decoder and also stays. The hostScope.kind === 'ssh' ? … : local sites take a parsed scope, a different shape, and stay.

User-visible before/after: none. The one theoretical difference: a connection id stored with surrounding whitespace (no write path produces one) used to become ssh:%20id%20 in the two renderer readers and now becomes ssh:id, which is what every other reader, including the host registry, already produced.

Net lines: prod −20 (10 added / 30 removed in 6 files); tests +35 (characterization only).

Why

Each hand-written copy is a place a future change can drift: the two renderer readers already differed from the shared one on trimming. Folding them into the functions the rest of the app already uses removes that. The design narrowed this from a broader sweep after review found that most "connection ? ssh : …" spots are evidence readers whose missing branch must stay "unknown", not "local".

Linked Issue

N/A (maintainer cleanup, Phase 3.99 PR 2.8).

Visual Proof

N/A: no UI or behaviour change.

Testing

  • New characterization tests pin the precedence (host stamp > connection id > local), a blank/whitespace connection id reading as local, an explicit SSH owner without a connection id, and a runtime stamp winning over a nested connection id: local-path-open-guard.test.ts, resolved-worktree-execution-host.test.ts, detected-worktree-meta.test.ts.

  • Dead-code proof: rg normalizeConnectionId|normalizeHostPart across src config scripts mobile (including @ts-nocheck files) leaves only the new export and the unrelated private decoder in ssh-pty-id.ts; pnpm run build:electron-vite succeeds.

  • pnpm tc, pnpm lint (all ratchets), pnpm run check:code-quality:changed, and pnpm test src/renderer/src/store/slices/worktrees src/renderer/src/lib src/shared (1799 files, 20193 tests) pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

P0/P1 review: own review plus an independent reviewer; no P0/P1 findings.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

SSH: SSH ownership spellings (stamp-only, connection-id-only) resolve exactly as before. Folder workspaces: folderWorkspaceMatchesHost covered. No wire, mobile, or platform-specific change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@OrcaWin
OrcaWin marked this pull request as ready for review October 12, 2026 06:40
@OrcaWin
OrcaWin merged commit 8a1c63b into main Oct 12, 2026
34 checks passed
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.

1 participant