fix(worktree-palette): stop blanked display names from crashing Cmd+J (#11323)
* fix(worktree-palette): stop blanked display names from crashing Cmd+J
Blanking the "Display Name" field made buildWorktreeMetaUpdates emit
`displayName: undefined` as a present key. The store's `{ ...worktree,
...updates }` spread then erased the live name, so the next palette
keystroke threw "Cannot read properties of undefined (reading
'toLowerCase')" in searchWorktrees (crash a1f81ea1, build 1.4.159).
Fixed at three layers so no single guard is load-bearing:
- Producer: persist the blanking intent as '' instead of undefined, and
let WorktreeSet accept '' so remote/SSH hosts stop dropping the clear.
- Store: applyWorktreeUpdates and applyDetectedWorktreeUpdates drop
present-but-undefined keys for fields Worktree declares required.
- Readers: resolveWorktreeDisplayName/resolveWorktreeBranchLabel mirror
the main-side mergeWorktree fallback (custom -> branch -> folder) for
all four Cmd+J searches, the checks/review index, and the render site.
Co-authored-by: Orca <help@stably.ai>
* test(worktree): assert omitted display name shape
---------
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { WorktreeActivate, WorktreeCreate } from './worktree-schemas'
|
||||
import { WorktreeActivate, WorktreeCreate, WorktreeSet } from './worktree-schemas'
|
||||
|
||||
describe('worktree RPC schemas', () => {
|
||||
it('validates additive navigation intent', () => {
|
||||
@@ -31,4 +31,27 @@ describe('worktree RPC schemas', () => {
|
||||
|
||||
expect(parsed.success).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps a blanked display name on remote hosts instead of dropping the clear', () => {
|
||||
// Blanking sends displayName:'' meaning "fall back to the branch/folder name".
|
||||
// Coercing it to undefined made updateManagedWorktreeMeta's omitUndefinedProperties
|
||||
// drop the key, so an SSH/paired-web rename-to-blank silently kept the old name.
|
||||
const parsed = WorktreeSet.parse({ worktree: 'id:r1::/repos/wt', displayName: '' })
|
||||
|
||||
expect(parsed.displayName).toBe('')
|
||||
expect(Object.prototype.hasOwnProperty.call(parsed, 'displayName')).toBe(true)
|
||||
})
|
||||
|
||||
it('still omits a display name that was never sent', () => {
|
||||
const parsed = WorktreeSet.parse({ worktree: 'id:r1::/repos/wt', comment: 'note' })
|
||||
|
||||
expect(parsed.displayName).toBeUndefined()
|
||||
expect(Object.prototype.hasOwnProperty.call(parsed, 'displayName')).toBe(false)
|
||||
})
|
||||
|
||||
it('ignores a non-string display name rather than persisting it', () => {
|
||||
const parsed = WorktreeSet.parse({ worktree: 'id:r1::/repos/wt', displayName: 42 })
|
||||
|
||||
expect(parsed.displayName).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -189,7 +189,10 @@ export const WorktreePrefetchCreateBase = z.object({
|
||||
})
|
||||
|
||||
export const WorktreeSet = WorktreeSelector.extend({
|
||||
displayName: OptionalString,
|
||||
// Why: '' is the blanking contract — "fall back to the branch/folder name".
|
||||
// OptionalString coerced it to undefined, so on remote/SSH hosts clearing the
|
||||
// name was dropped here and the old name came back on the next refresh.
|
||||
displayName: OptionalPlainString,
|
||||
// Why: empty comments are meaningful metadata updates, so use the plain
|
||||
// string parser instead of OptionalString's empty-as-undefined behavior.
|
||||
comment: OptionalPlainString,
|
||||
|
||||
Reference in New Issue
Block a user