fix(worktrees): drop an unreachable runtime arm from the retirement gate

`findExactRepoOwner` already refuses a repo carrying both a runtime
`executionHostId` and a `connectionId` -- `resolveRepoOwnershipEvidence` calls
that pair contradictory, and one non-owned candidate voids the whole lookup.
There is also no way for a `connectionId` to yield a `runtime:` host id, since
`toSshExecutionHostId` always emits `ssh:`. The runtime arm of
`connectionMatchesHost` could therefore never decide anything, and the test
meant to pin it was passing through the contradiction gate instead.

Keep the SSH arm, which does gate, and record where the runtime refusal
actually comes from. Unreachable code on a destructive path reads as a
guarantee it is not making.

Refs #17776
This commit is contained in:
Neil
2026-09-01 17:20:17 -07:00
parent 398aeccdfe
commit f2fa4a7754
2 changed files with 9 additions and 6 deletions
@@ -486,7 +486,9 @@ describe('registerWorktreeHandlers', () => {
)
})
// A repo that reaches its checkouts over SSH is not the runtime host's to condemn.
// A repo that reaches its checkouts over SSH is not the runtime host's to condemn. The refusal
// comes from `findExactRepoOwner`: a runtime `executionHostId` beside a `connectionId` is
// contradictory ownership evidence, so no owner resolves at all.
it('refuses to retire a connection-backed repo under a runtime host id', async () => {
const runtimeHostId = toRuntimeExecutionHostId('env-1')
store.getRepos.mockReturnValue([
@@ -111,12 +111,13 @@ export function registerHostCatalogHandlers(context: WorktreeIpcContext): void {
) {
return nothingForgotten
}
// No runtime arm in the check below: `findExactRepoOwner` already refuses a repo carrying both
// a runtime `executionHostId` and a `connectionId`, because `resolveRepoOwnershipEvidence`
// calls that pair contradictory and one non-owned candidate voids the whole lookup. A second
// check would be unreachable, and unreachable code on a destructive path reads as a guarantee
// it is not making.
const repo = findExactRepoOwner(store, args?.repoId ?? '', requestedExecutionHostId)
// The connection must be the one the host id names, so a caller cannot retire a row belonging
// to a repo that reaches its checkouts some other way.
const connectionMatchesHost =
parsedHost.kind === 'ssh' ? repo?.connectionId === parsedHost.targetId : !repo?.connectionId
if (!repo || !connectionMatchesHost) {
if (!repo || (parsedHost.kind === 'ssh' && repo.connectionId !== parsedHost.targetId)) {
return nothingForgotten
}
// Why: a folder workspace's meta IS the workspace record, not a checkout row — gcStaleWorktreeMeta skips