Files
orca/src/main/runtime/workspaces/creation/created-worktree-approved-setup.test.ts
T
Brennan Benson b08064cfd5 feat(workspaces): run setup and archive scripts for folder projects
Folder projects get the setup and archive scripts git projects have:
creating a workspace runs setup in a Setup tab, and removing one runs
archive first. The script sees the workspace's name and id, so
`orca worktree create` inside it attaches each new worktree to that
workspace, however the workspace was created.

- Folder creates (desktop IPC and runtime) prepare setup through the
  shared setup prep; runtime creates start it with the worktree terminal
  startup, so Setup-before-agent ordering matches.
- Runner files live in <folder>/.orca, one fresh file per launch, removed
  with the workspace.
- Only the host whose catalog holds the folder reads its orca.yaml or runs
  its scripts; a setup problem becomes a warning, never a failed create.
- Shared orca.yaml setup with no approval from an older client is skipped;
  ask/inherit never refuses a folder create.
- No orca.yaml default tabs for folders, since every workspace shares the
  directory.
- New capability worktree.folder-setup.v1 gates the Settings section on
  runtime hosts; the composer, Settings and trust prompt reuse the
  existing setup surfaces.
2026-11-08 15:26:26 -08:00

75 lines
2.6 KiB
TypeScript

import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { Repo } from '../../../../shared/repo-types'
import { getDefaultSettings } from '../../../../shared/constants'
import { hashOrcaHookTrustContent } from '../../../workspace-hooks/created-worktree-setup-trust'
import { runApprovedCreatedWorktreeSetup } from './created-worktree-approved-setup'
const runner = vi.hoisted(() => ({ createSetupRunnerScript: vi.fn() }))
vi.mock('../../../workspace-hooks/worktree-runner-script', () => ({
createSetupRunnerScript: runner.createSetupRunnerScript,
resolveSetupRunnerShell: () => undefined
}))
const BRANCH_YAML =
'scripts:\n setup: make bootstrap\ndefaultTabs:\n - title: dev\n command: pnpm dev\n - title: notes\n'
const BRANCH_TRUST_CONTENT = 'make bootstrap\n\n# defaultTabs[1] dev\npnpm dev'
let worktreePath: string
let repo: Repo
const provisionManagedWorktreeTerminals = vi.fn()
function runtimeFor() {
const worktree = {
id: `repo::${worktreePath}`,
repoId: 'repo',
path: worktreePath,
displayName: 'w'
}
return {
showManagedWorktree: vi.fn(async () => worktree),
requireStore: () => ({
getRepo: (id: string) => (id === repo.id ? repo : undefined),
getSettings: () => getDefaultSettings(tmpdir())
}),
provisionManagedWorktreeTerminals
}
}
beforeEach(() => {
worktreePath = mkdtempSync(join(tmpdir(), 'orca-approved-setup-'))
repo = { id: 'repo', path: '/primary', displayName: 'r', badgeColor: '', addedAt: 0 }
writeFileSync(join(worktreePath, 'orca.yaml'), BRANCH_YAML)
provisionManagedWorktreeTerminals.mockReset().mockResolvedValue({ setupSpawned: true })
runner.createSetupRunnerScript.mockReset().mockResolvedValue({
runnerScriptPath: join(worktreePath, 'runner.sh'),
envVars: {}
})
})
afterEach(() => {
rmSync(worktreePath, { recursive: true, force: true })
})
describe('runApprovedCreatedWorktreeSetup', () => {
it('runs nothing when the content changed after the user approved it', async () => {
const result = await runApprovedCreatedWorktreeSetup(
runtimeFor(),
'id:wt',
hashOrcaHookTrustContent('make bootstrap')
)
expect(result).toEqual({
status: 'mismatch',
setupTrustMismatch: {
contentHash: hashOrcaHookTrustContent(BRANCH_TRUST_CONTENT),
scriptContent: BRANCH_TRUST_CONTENT
}
})
expect(runner.createSetupRunnerScript).not.toHaveBeenCalled()
expect(provisionManagedWorktreeTerminals).not.toHaveBeenCalled()
})
})