mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 16:47:34 +00:00
refactor: round-3 pass-1 follow-ups (#30699)
- one repoRowOwnerStamp for the SSH and runtime session placeholder builders - lineage refresh resolves the transport host once; pin that a server reply never appends a copy - markdown-document-paths tests live next to the shared module
This commit is contained in:
@@ -89,4 +89,20 @@ describe('row writers touch only the copy on their own host', () => {
|
||||
hostId: 'runtime:hub'
|
||||
})
|
||||
})
|
||||
|
||||
it("never appends a server's copy when only the local twin is listed", () => {
|
||||
const store = createTestStore()
|
||||
const { local } = seedTwins(store)
|
||||
store.setState({ worktreesByRepo: { [REPO_ID]: [local] } })
|
||||
applyWorktreeLineageUpdate(store.setState, WORKTREE_ID, {
|
||||
target: { kind: 'environment', environmentId: 'hub' },
|
||||
lineage: null,
|
||||
updatedRemoteWorktree: makeWorktree({
|
||||
id: WORKTREE_ID,
|
||||
repoId: REPO_ID,
|
||||
displayName: 'server after lineage'
|
||||
})
|
||||
})
|
||||
expect(store.getState().worktreesByRepo[REPO_ID]).toEqual([local])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -189,18 +189,16 @@ export function applyWorktreeLineageUpdate(
|
||||
} else {
|
||||
delete next[worktreeId]
|
||||
}
|
||||
// Why the transport's host: focus can name the local twin of a row a server just answered for.
|
||||
const transportHostId = getRuntimeTargetHostId(result.target)
|
||||
const worktreesByRepo =
|
||||
result.target.kind === 'local'
|
||||
? projectLocalWorktreeLineageUpdate(s.worktreesByRepo, worktreeId, result.lineage)
|
||||
: result.updatedRemoteWorktree
|
||||
? // Why the transport's host: focus can name the local twin of a row a server just answered for.
|
||||
replaceWorktreeInRepoLists(
|
||||
? replaceWorktreeInRepoLists(
|
||||
s,
|
||||
withRepoHostOwnership(
|
||||
result.updatedRemoteWorktree,
|
||||
getRuntimeTargetHostId(result.target)
|
||||
),
|
||||
getRuntimeTargetHostId(result.target)
|
||||
withRepoHostOwnership(result.updatedRemoteWorktree, transportHostId),
|
||||
transportHostId
|
||||
)
|
||||
: s.worktreesByRepo
|
||||
return {
|
||||
|
||||
@@ -4,9 +4,9 @@ import { DEFAULT_REPO_BADGE_COLOR } from '../../../../shared/constants'
|
||||
import {
|
||||
getRepoExecutionHostId,
|
||||
parseExecutionHostId,
|
||||
toSshExecutionHostId,
|
||||
type ExecutionHostId
|
||||
} from '../../../../shared/execution-host'
|
||||
import { repoRowOwnerStamp } from './workspace-terminal-ssh-placeholders'
|
||||
import { parseWorkspaceKey } from '../../../../shared/workspace-scope'
|
||||
import { splitWorktreeIdForFilesystem } from '../../../../shared/worktree/id'
|
||||
|
||||
@@ -16,22 +16,13 @@ export function getPathDisplayName(path: string, fallback: string): string {
|
||||
return basename || fallback
|
||||
}
|
||||
|
||||
/**
|
||||
* A server's repo that nests an SSH target lists its worktrees as `ssh:<target>` reached through
|
||||
* that server; a bare `runtime:` stamp would hide the target from an `ssh:` host selection.
|
||||
*/
|
||||
function runtimePlaceholderOwner(
|
||||
repos: readonly Repo[],
|
||||
repoId: string,
|
||||
hostId: ExecutionHostId
|
||||
): Pick<Worktree, 'hostId' | 'runtimeOwnerEnvironmentId'> {
|
||||
const host = parseExecutionHostId(hostId)
|
||||
const connectionId = repos
|
||||
.find((repo) => repo.id === repoId && getRepoExecutionHostId(repo) === hostId)
|
||||
?.connectionId?.trim()
|
||||
return connectionId && host?.kind === 'runtime'
|
||||
? { hostId: toSshExecutionHostId(connectionId), runtimeOwnerEnvironmentId: host.environmentId }
|
||||
: { hostId }
|
||||
const row = repos.find((repo) => repo.id === repoId && getRepoExecutionHostId(repo) === hostId)
|
||||
return row ? repoRowOwnerStamp(row) : { hostId }
|
||||
}
|
||||
|
||||
export function buildRuntimeSessionPlaceholders({
|
||||
|
||||
@@ -13,23 +13,33 @@ import {
|
||||
|
||||
type PlaceholderOwner = Pick<Worktree, 'hostId' | 'runtimeOwnerEnvironmentId'>
|
||||
|
||||
/**
|
||||
* The owner a listing stamps on this repo row's worktrees. A server's repo that nests an SSH
|
||||
* target lists them as `ssh:<target>` through that server, so a bare `runtime:` stamp would hide
|
||||
* the target from an `ssh:` host selection.
|
||||
*/
|
||||
export function repoRowOwnerStamp(row: Repo): PlaceholderOwner {
|
||||
const host = parseExecutionHostId(getRepoExecutionHostId(row))
|
||||
const connectionId = row.connectionId?.trim()
|
||||
if (host?.kind === 'runtime') {
|
||||
return connectionId
|
||||
? {
|
||||
hostId: toSshExecutionHostId(connectionId),
|
||||
runtimeOwnerEnvironmentId: host.environmentId
|
||||
}
|
||||
: { hostId: host.id }
|
||||
}
|
||||
// Why: a row whose explicit host disagrees with its connection is not evidence of either.
|
||||
return connectionId && host?.id === toSshExecutionHostId(connectionId) ? { hostId: host.id } : {}
|
||||
}
|
||||
|
||||
/**
|
||||
* The SSH host, and the server proxying it, that a listing would stamp. A repo id with rows on
|
||||
* several hosts names neither, so its placeholder stays unstamped rather than guessing a twin.
|
||||
*/
|
||||
function placeholderOwner(repos: readonly Repo[], repoId: string): PlaceholderOwner {
|
||||
const rows = repos.filter((repo) => repo.id === repoId)
|
||||
const connectionId = rows.length === 1 ? rows[0].connectionId?.trim() : undefined
|
||||
if (!connectionId) {
|
||||
return {}
|
||||
}
|
||||
const sshHostId = toSshExecutionHostId(connectionId)
|
||||
const host = parseExecutionHostId(getRepoExecutionHostId(rows[0]))
|
||||
if (host?.kind === 'runtime') {
|
||||
return { hostId: sshHostId, runtimeOwnerEnvironmentId: host.environmentId }
|
||||
}
|
||||
// Why: a row whose explicit host disagrees with its connection is not evidence of either.
|
||||
return host?.id === sshHostId ? { hostId: sshHostId } : {}
|
||||
return rows.length === 1 && rows[0].connectionId?.trim() ? repoRowOwnerStamp(rows[0]) : {}
|
||||
}
|
||||
|
||||
export function addHydratedSshWorktreePlaceholders(
|
||||
|
||||
+1
-4
@@ -6,10 +6,7 @@ vi.mock('node:path', async (importOriginal) => {
|
||||
return { ...actual, extname: actual.win32.extname }
|
||||
})
|
||||
|
||||
import {
|
||||
isMarkdownDocumentName,
|
||||
markdownDocumentFromRelativePath
|
||||
} from '../../shared/markdown-document-paths'
|
||||
import { isMarkdownDocumentName, markdownDocumentFromRelativePath } from './markdown-document-paths'
|
||||
|
||||
describe('remote Markdown filenames on a Windows client', () => {
|
||||
it('keeps the local filename helper on Windows semantics', () => {
|
||||
+1
-1
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
markdownDocumentFromFilePath,
|
||||
markdownDocumentFromRelativePath
|
||||
} from '../../shared/markdown-document-paths'
|
||||
} from './markdown-document-paths'
|
||||
|
||||
describe('markdownDocumentFromFilePath', () => {
|
||||
it.skipIf(process.platform === 'win32')('preserves local literal backslash names', () => {
|
||||
Reference in New Issue
Block a user