mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Save a pasted workspace directory as the path it names (#40347)
* Save a pasted workspace directory as the path it names
A workspace directory with a leading space (" /Users/me/dev") was saved as
typed. Readers treat it as relative, so Orca resolved it inside every
registered repository and created an empty " /Users/me/dev" tree in each.
Normalize the saved value once where settings are written and loaded, as
the leading ~ fix did: leading whitespace before an absolute or home path is
dropped, while relative paths and trailing characters stay exact. A value
repaired on load keeps its old spelling in history so checkouts under the
old root stay visible. The settings field shows the saved value.
Co-authored-by: Eng. Mahmoud Bek ElNemer <ElNeMeR70@users.noreply.github.com>
* Expand ~\ only where it is a home path; drop type casts
* Classify the padded path with the host's own path rules
On macOS and Linux a leading backslash is part of a relative name, so only
Windows treats \work as absolute.
---------
Co-authored-by: Eng. Mahmoud Bek ElNemer <ElNeMeR70@users.noreply.github.com>
This commit is contained in:
co-authored by
Eng. Mahmoud Bek ElNemer
parent
c4b54195f1
commit
0f89de5276
@@ -82,6 +82,30 @@ describe('Store', () => {
|
||||
expect(isLocalWorktreeScanGenerationCurrent('r1', generation)).toBe(false)
|
||||
})
|
||||
|
||||
it('saves a pasted workspace directory with leading spaces as the absolute path it names', async () => {
|
||||
const store = await createStore()
|
||||
store.updateSettings({ workspaceDir: '/Users/me/dev' })
|
||||
const historyBefore = store.getSettings().workspaceDirHistory
|
||||
|
||||
// Padding before an absolute path would otherwise resolve inside every repo.
|
||||
expect(store.updateSettings({ workspaceDir: ' /Users/me/dev' }).workspaceDir).toBe(
|
||||
'/Users/me/dev'
|
||||
)
|
||||
expect(store.getSettings().workspaceDirHistory).toEqual(historyBefore)
|
||||
// Trailing characters and relative paths can be real folder names.
|
||||
expect(store.updateSettings({ workspaceDir: '/tmp/workspaces ' }).workspaceDir).toBe(
|
||||
'/tmp/workspaces '
|
||||
)
|
||||
expect(store.updateSettings({ workspaceDir: ' ~notes' }).workspaceDir).toBe(' ~notes')
|
||||
if (process.platform === 'win32') {
|
||||
expect(store.updateSettings({ workspaceDir: ' C:\\work' }).workspaceDir).toBe('C:\\work')
|
||||
} else {
|
||||
// ~\ and a leading \ are relative off Windows, so the value stays exact.
|
||||
expect(store.updateSettings({ workspaceDir: ' ~\\work' }).workspaceDir).toBe(' ~\\work')
|
||||
expect(store.updateSettings({ workspaceDir: ' \\work' }).workspaceDir).toBe(' \\work')
|
||||
}
|
||||
})
|
||||
|
||||
it('updateSettings deep-merges and clamps notification custom sound volume', async () => {
|
||||
const store = await createStore()
|
||||
store.updateSettings({
|
||||
|
||||
@@ -42,7 +42,7 @@ import { normalizeNotificationSettings } from './onboarding-normalization'
|
||||
import { retireLegacyInstructionsForClearedTextActionRecipes } from './source-control-settings'
|
||||
import {
|
||||
buildWorkspaceDirHistoryForUpdate,
|
||||
expandWorkspaceDirHome,
|
||||
normalizeWorkspaceDirSetting,
|
||||
stripRetiredGlobalSettings
|
||||
} from './terminal-settings-migrations'
|
||||
|
||||
@@ -59,7 +59,7 @@ export function updateSettings(
|
||||
updates: Partial<GlobalSettings>,
|
||||
options: { notifyListeners?: boolean; originWebContentsId?: number } = {}
|
||||
): GlobalSettings {
|
||||
const sanitizedUpdates = expandWorkspaceDirHome(stripRetiredGlobalSettings(updates))
|
||||
const sanitizedUpdates = normalizeWorkspaceDirSetting(stripRetiredGlobalSettings(updates))
|
||||
const linkBehavior = updates.terminalLinkClickBehavior
|
||||
if (linkBehavior === 'actions' || linkBehavior === 'open' || linkBehavior === 'none') {
|
||||
// Loaded defaults are ambiguous; synchronize the legacy switch only on an explicit write.
|
||||
|
||||
@@ -12,14 +12,39 @@ import {
|
||||
normalizeTuiAgentEnvRecord
|
||||
} from '../../../shared/agent-launch/choices/tui-agent-launch-defaults'
|
||||
import { expandLeadingHomePath } from '../../filesystem/home-path-expansion'
|
||||
import { normalizeWorkspaceDirInput } from '../../../shared/worktree/workspace-dir-input'
|
||||
|
||||
/** Unexpanded, a leading ~ resolves inside each repo and worktrees land in <repo>/~ (#34944). */
|
||||
export function expandWorkspaceDirHome(settings: Partial<GlobalSettings>): Partial<GlobalSettings> {
|
||||
/** A raw ~ or padded absolute path resolves inside each repo (#34944, STA-14308); normalize at the store boundary. */
|
||||
export function normalizeWorkspaceDirSetting(
|
||||
settings: Partial<GlobalSettings>
|
||||
): Partial<GlobalSettings> {
|
||||
return typeof settings.workspaceDir === 'string'
|
||||
? { ...settings, workspaceDir: expandLeadingHomePath(settings.workspaceDir, homedir()) }
|
||||
? {
|
||||
...settings,
|
||||
workspaceDir: expandLeadingHomePath(
|
||||
normalizeWorkspaceDirInput(settings.workspaceDir, process.platform === 'win32'),
|
||||
homedir()
|
||||
)
|
||||
}
|
||||
: settings
|
||||
}
|
||||
|
||||
/** Keep a repaired saved spelling in history so checkouts under its old root keep their visibility. */
|
||||
export function normalizeLoadedWorkspaceDirSetting(
|
||||
settings: Partial<GlobalSettings>,
|
||||
defaults: GlobalSettings
|
||||
): Partial<GlobalSettings> {
|
||||
const normalized = normalizeWorkspaceDirSetting(settings)
|
||||
if (normalized.workspaceDir === settings.workspaceDir) {
|
||||
return normalized
|
||||
}
|
||||
const history = buildWorkspaceDirHistoryForUpdate(
|
||||
{ ...defaults, ...settings },
|
||||
{ workspaceDir: normalized.workspaceDir }
|
||||
)
|
||||
return history ? { ...normalized, workspaceDirHistory: history } : normalized
|
||||
}
|
||||
|
||||
export function buildWorkspaceDirHistoryForUpdate(
|
||||
current: GlobalSettings,
|
||||
updates: Partial<GlobalSettings>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { expect, it } from 'vitest'
|
||||
import { resolveAntigravityChatAuthConfig } from '../../../shared/antigravity-chat-auth-config'
|
||||
import { getDefaultPersistedState, getDefaultVoiceSettings } from '../../../shared/constants'
|
||||
import type { PersistedState } from '../../../shared/persisted-state-types'
|
||||
import { buildKnownOrcaWorkspaceLayouts } from '../../../shared/worktree/ownership'
|
||||
import { normalizeLoadedGlobalSettings } from './normalize-loaded-global-settings'
|
||||
import { prepareLoadedTerminalSettings } from './prepare-loaded-terminal-settings'
|
||||
import { prepareLoadedProfileSettings } from './prepare-loaded-profile-settings'
|
||||
@@ -57,3 +58,19 @@ it('stores Auto as Toggle plus hold-to-record so older builds keep a working sho
|
||||
false
|
||||
])
|
||||
})
|
||||
|
||||
it('loads a padded workspace directory as the absolute path while keeping its old root known', () => {
|
||||
const settings = normalizeLegacyProfile({
|
||||
workspaceDir: ' /Users/me/dev',
|
||||
nestWorkspaces: false,
|
||||
workspaceDirHistory: []
|
||||
})
|
||||
|
||||
expect(settings.workspaceDir).toBe('/Users/me/dev')
|
||||
// Checkouts an older build placed under <repo>/ /Users/me/dev keep their known layout.
|
||||
expect(
|
||||
buildKnownOrcaWorkspaceLayouts(settings, { path: '/repo', worktreeBasePath: undefined }).map(
|
||||
(layout) => layout.path
|
||||
)
|
||||
).toContain('/repo/ /Users/me/dev')
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ import { projectSourceControlAiToLegacyCommitMessageAi } from '../../../shared/s
|
||||
import { normalizeNativeChatShellEnvironmentVariables } from '../../../shared/native-chat/native-chat-shell-environment'
|
||||
import { publishedLegacyChatPermissionMode } from '../../../shared/agent-launch/permissions/agent-chat-permission-mode'
|
||||
import {
|
||||
expandWorkspaceDirHome,
|
||||
normalizeLoadedWorkspaceDirSetting,
|
||||
stripRetiredGlobalSettings
|
||||
} from '../applying-settings/terminal-settings-migrations'
|
||||
import { readLegacySidekickFlag } from '../applying-settings/onboarding-normalization'
|
||||
@@ -88,7 +88,10 @@ export function normalizeLoadedGlobalSettings(
|
||||
return {
|
||||
...defaults.settings,
|
||||
// Legacy stored booleans cannot distinguish opt-in from the old default; retain explicit true.
|
||||
...expandWorkspaceDirHome(stripRetiredGlobalSettings(parsed.settings)),
|
||||
...normalizeLoadedWorkspaceDirSetting(
|
||||
stripRetiredGlobalSettings(parsed.settings),
|
||||
defaults.settings
|
||||
),
|
||||
agentDefaultSurface: normalizeAgentDefaultSurface(parsed.settings?.agentDefaultSurface),
|
||||
nativeChatAppearance: normalizeNativeChatAppearanceSettings(
|
||||
parsed.settings?.nativeChatAppearance
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createGlobalSettingsFixture } from '../../../../../shared/global-settings-test-fixture'
|
||||
import { WorkspaceDirectorySetting } from './WorkspaceDirectorySetting'
|
||||
|
||||
vi.mock('../section-layout/SearchableSetting', () => ({
|
||||
SearchableSetting: ({ children }) => children
|
||||
}))
|
||||
vi.mock('../../sidebar/worktree-list/controls/use-sidebar-host-scope-options', () => ({
|
||||
useSidebarHostScopeOptions: () => ({ hostOptions: [] })
|
||||
}))
|
||||
afterEach(cleanup)
|
||||
|
||||
describe('WorkspaceDirectorySetting', () => {
|
||||
it('shows the saved path and writes nothing when a padded copy of it is committed', () => {
|
||||
const updateSettings = vi.fn()
|
||||
render(
|
||||
<WorkspaceDirectorySetting
|
||||
settings={createGlobalSettingsFixture({ workspaceDir: '/Users/me/dev' })}
|
||||
updateSettings={updateSettings}
|
||||
/>
|
||||
)
|
||||
const input = screen.getByRole<HTMLInputElement>('textbox')
|
||||
|
||||
fireEvent.change(input, { target: { value: ' /Users/me/dev' } })
|
||||
fireEvent.blur(input)
|
||||
|
||||
expect(input.value).toBe('/Users/me/dev')
|
||||
expect(updateSettings).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -8,6 +8,8 @@ import {
|
||||
clearHostSettingOverride
|
||||
} from '../../../../../shared/host-setting-overrides'
|
||||
import { LOCAL_EXECUTION_HOST_ID } from '../../../../../shared/execution-host'
|
||||
import { normalizeWorkspaceDirInput } from '../../../../../shared/worktree/workspace-dir-input'
|
||||
import { isWindowsUserAgent } from '@/lib/user-agent-platform'
|
||||
import { Button } from '../../ui/button'
|
||||
import { Input } from '../../ui/input'
|
||||
import { Label } from '../../ui/label'
|
||||
@@ -90,7 +92,9 @@ export function WorkspaceDirectorySetting({
|
||||
}
|
||||
|
||||
const commitDraftValue = (): void => {
|
||||
const next = draftValueRef.current
|
||||
// Show the value main will save, so a padded re-save of the saved path writes nothing.
|
||||
const next = normalizeWorkspaceDirInput(draftValueRef.current, isWindowsUserAgent())
|
||||
setDraft(next)
|
||||
if (next === value) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { isRuntimePathAbsolute } from '../cross-platform-path'
|
||||
|
||||
/** Leading whitespace before an absolute or home path makes readers resolve it inside every repo (STA-14308). */
|
||||
export function normalizeWorkspaceDirInput(value: string, isWindowsHost: boolean): string {
|
||||
const start = value.trimStart()
|
||||
// Trailing characters and relative values stay byte-exact: they can be part of a real folder name.
|
||||
return isRuntimePathAbsolute(start, isWindowsHost ? 'windows' : 'posix') ||
|
||||
isHomePrefixedPath(start, isWindowsHost)
|
||||
? start
|
||||
: value
|
||||
}
|
||||
|
||||
// Only the shapes main expands; ~\ is a home path on Windows alone.
|
||||
function isHomePrefixedPath(value: string, isWindowsHost: boolean): boolean {
|
||||
return value === '~' || value.startsWith('~/') || (isWindowsHost && value.startsWith('~\\'))
|
||||
}
|
||||
Reference in New Issue
Block a user