Files
orca/src/main/runtime/rpc/methods/worktree-create-args.test.ts
T
Jinwoo Hong 8f15f217a2 Preserve user-set workspace names across branch changes (#17448)
* fix(worktrees): preserve user workspace names across branch changes

* test(worktrees): cover pinned rename metadata

* fix(workspaces): address display-name review edge cases

* fix(workspaces): keep automatic names fresh across refreshes

* fix(workspaces): preserve legacy CLI labels

* fix(workspaces): preserve display-name provenance across hosts

* fix(workspaces): honor legacy display-name provenance

* fix(workspaces): fence display-name refresh races

* fix(workspaces): accept peer renames from provenance-less hosts

The old-host preserve fence kept a pinned local label on every refresh,
which also suppressed a legitimate rename another client persisted
through the same host until app restart. Narrow it to labels the host
re-derived itself (branch short name, or path basename when detached);
any other changed label in a mode-less response is explicit meta a peer
wrote there. Stale prior-label responses stay covered by the downstream
staleness fence, in-flight writes by the pending fence.

* refactor(workspaces): unify display-name pin derivation

Three call sites (renderer optimistic update, local IPC updateMeta
handler, remote worktree.set handler) each restated the same formula;
a future edit to one would silently skew provenance between paths.
2026-08-31 19:08:05 -04:00

58 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { buildManagedWorktreeCreateArgs } from './worktree-create-args'
import { WorktreeCreate } from './worktree-create-schemas'
const PROVENANCE = {
automationProvenance: undefined,
cliProvenance: undefined,
creatorProvenance: { kind: 'host' as const }
}
const build = (params: Record<string, unknown>) =>
buildManagedWorktreeCreateArgs(WorktreeCreate.parse(params), PROVENANCE)
describe('buildManagedWorktreeCreateArgs', () => {
it('omits name provenance when the client did not claim a generated name', () => {
// Why: absent must mean user-typed. A truthy default would let the host permanently retire
// names people chose on purpose — the pool contains ordinary words like "orca" and "molly".
expect(build({ repo: 'id:repo-1', name: 'nautilus' })).not.toHaveProperty('nameWasGenerated')
expect(
build({ repo: 'id:repo-1', name: 'nautilus', nameWasGenerated: false })
).not.toHaveProperty('nameWasGenerated')
})
it('forwards the flag when the client fell back to a generated name', () => {
expect(build({ repo: 'id:repo-1', name: 'nautilus', nameWasGenerated: true })).toMatchObject({
nameWasGenerated: true
})
})
it('keeps the legacy CLI marker on a name-only create request', () => {
const args = buildManagedWorktreeCreateArgs(
WorktreeCreate.parse({ repo: 'id:repo-1', name: 'feature' }),
{ ...PROVENANCE, cliProvenance: { kind: 'created-by-cli', createdAt: 1 } }
)
expect(args).toMatchObject({
name: 'feature',
cliProvenance: { kind: 'created-by-cli', createdAt: 1 }
})
expect(args.displayName).toBeUndefined()
})
it('carries the parent-pick provenance only when the client marked it manual', () => {
// Why: older clients never send it, and those creates really are CLI-flag equivalents.
expect(
build({ repo: 'id:repo-1', name: 'child', parentWorkspace: 'folder:f1' }).lineage
).not.toHaveProperty('parentWorkspaceOrigin')
expect(
build({
repo: 'id:repo-1',
name: 'child',
parentWorkspace: 'folder:f1',
parentWorkspaceOrigin: 'manual'
}).lineage
).toMatchObject({ parentWorkspaceOrigin: 'manual' })
})
})