fix: translate dropped paths for wsl worktrees (#3851)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { resolveLocalDroppedPathsForAgent } from './dropped-path-resolution'
|
||||
|
||||
describe('resolveLocalDroppedPathsForAgent', () => {
|
||||
it('translates dropped Windows paths for local WSL worktrees', () => {
|
||||
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')
|
||||
Object.defineProperty(process, 'platform', { configurable: true, value: 'win32' })
|
||||
try {
|
||||
expect(
|
||||
resolveLocalDroppedPathsForAgent(
|
||||
[
|
||||
'C:\\Users\\alice\\Desktop\\notes.txt',
|
||||
'\\\\wsl.localhost\\Ubuntu\\home\\alice\\repo\\README.md'
|
||||
],
|
||||
'\\\\wsl.localhost\\Ubuntu\\home\\alice\\repo'
|
||||
)
|
||||
).toEqual(['/mnt/c/Users/alice/Desktop/notes.txt', '/home/alice/repo/README.md'])
|
||||
} finally {
|
||||
if (originalPlatform) {
|
||||
Object.defineProperty(process, 'platform', originalPlatform)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('leaves dropped paths unchanged for non-WSL worktrees', () => {
|
||||
const paths = ['C:\\Users\\alice\\Desktop\\notes.txt']
|
||||
|
||||
expect(resolveLocalDroppedPathsForAgent(paths, 'C:\\Users\\alice\\repo')).toBe(paths)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
import { parseWslPath, toLinuxPath } from '../wsl'
|
||||
|
||||
export function resolveLocalDroppedPathsForAgent(paths: string[], worktreePath: string): string[] {
|
||||
// Why: a local WSL PTY runs inside Linux, so Windows drop paths must be
|
||||
// rewritten to paths the shell and agent can read.
|
||||
return parseWslPath(worktreePath) ? paths.map((droppedPath) => toLinuxPath(droppedPath)) : paths
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { pipeline } from 'stream/promises'
|
||||
import type { Store } from '../persistence'
|
||||
import { authorizeExternalPath, resolveAuthorizedPath, isENOENT } from './filesystem-auth'
|
||||
import { requireSshFilesystemProvider } from '../providers/ssh-filesystem-dispatch'
|
||||
import { resolveLocalDroppedPathsForAgent } from './dropped-path-resolution'
|
||||
import { importExternalPathsSsh } from './filesystem-import-ssh'
|
||||
import { assertNoClobberRenameDestinationAvailable } from '../../shared/filesystem-rename-collision'
|
||||
|
||||
@@ -209,7 +210,11 @@ export function registerFilesystemMutationHandlers(store: Store): void {
|
||||
// Why: `== null` (not `!args.connectionId`) so an empty string is
|
||||
// treated as a renderer error, not silently routed to the local branch.
|
||||
if (args.connectionId == null) {
|
||||
return { resolvedPaths: args.paths, skipped: [], failed: [] }
|
||||
return {
|
||||
resolvedPaths: resolveLocalDroppedPathsForAgent(args.paths, args.worktreePath),
|
||||
skipped: [],
|
||||
failed: []
|
||||
}
|
||||
}
|
||||
const worktreePath = args.worktreePath.replace(/\/+$/, '')
|
||||
const destDir = `${worktreePath}/.orca/drops`
|
||||
|
||||
Reference in New Issue
Block a user