mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
* Revert "Keep same-machine folders with matching Git remotes in separate projects (#32272)"
This reverts commit 29a5f89b8a.
On a machine with several clones of one repo, #32272 moved the oldest clone
into the shared cross-host project. Shared Windows QA machines have several
orca clones, so everyone's sidebar "orca" project suddenly gained that
machine's main checkout and its worktrees. Revert until the intended
grouping is decided.
Conflicts resolved against later main: Settings files moved into
settings/repository (imports adjusted), and two test files later deleted on
main stay deleted.
* Use checked types in restored test fixtures
* Combine restored fixture type imports
141 lines
5.6 KiB
TypeScript
141 lines
5.6 KiB
TypeScript
import { execFileSync } from 'node:child_process'
|
|
import { mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import type { Page } from '@stablyai/playwright-test'
|
|
import { expect } from './orca-app'
|
|
import { RuntimeClient } from '../../../src/cli/runtime/client'
|
|
import type { RuntimeTerminalListResult } from '../../../src/shared/runtime-types'
|
|
import type { RuntimeWorktreeCreateResult } from '../../../src/shared/runtime-worktree-contracts'
|
|
import { activateWorkspaceByClick, sleepWorkspaceViaSidebar } from './slept-workspace-probe'
|
|
import { ensureTerminalVisible, waitForSessionReady } from './store'
|
|
import { splitActiveTerminalPane, waitForActiveTerminalManager } from './terminal'
|
|
import { waitForBoundPanes, type FolderWorkspaceSetup } from './terminal-layout-journeys'
|
|
import { bootstrapFirstLaunch, seededRepoPathOrSkip } from './terminal-restart-persistence'
|
|
|
|
export async function addHostCreatedSplitWorktree(
|
|
page: Page,
|
|
userDataDir: string
|
|
): Promise<FolderWorkspaceSetup> {
|
|
const { worktreeId } = await bootstrapFirstLaunch(page, seededRepoPathOrSkip())
|
|
const repoPath = realpathSync(mkdtempSync(path.join(os.tmpdir(), 'orca-e2e-parity-setup-')))
|
|
const git = (...args: string[]): void => {
|
|
execFileSync('git', args, { cwd: repoPath, stdio: 'pipe' })
|
|
}
|
|
git('init', '-b', 'main')
|
|
git('config', 'user.email', 'e2e@test.local')
|
|
git('config', 'user.name', 'E2E Test')
|
|
writeFileSync(path.join(repoPath, 'README.md'), 'Host split fixture\n')
|
|
git('add', '-A')
|
|
git('commit', '-m', 'setup hook')
|
|
const client = new RuntimeClient(userDataDir, 30_000)
|
|
const added = await client.call<{ repo: { id: string } }>('repo.add', {
|
|
path: repoPath,
|
|
kind: 'git'
|
|
})
|
|
const created = await client.call<RuntimeWorktreeCreateResult>('worktree.create', {
|
|
repo: `id:${added.result.repo.id}`,
|
|
name: 'parity-setup',
|
|
branchNameOverride: 'parity-setup',
|
|
noParent: true,
|
|
activate: false,
|
|
setupDecision: 'skip'
|
|
})
|
|
const terminals = await client.call<RuntimeTerminalListResult>('terminal.list', {
|
|
worktree: `id:${created.result.worktree.id}`
|
|
})
|
|
const primary = terminals.result.terminals[0]
|
|
if (!primary) {
|
|
throw new Error('Host did not create the primary terminal')
|
|
}
|
|
await client.call('terminal.split', { terminal: primary.handle, direction: 'vertical' })
|
|
await activateWorkspaceByClick(page, worktreeId)
|
|
const worktreePath = created.result.worktree.path
|
|
return {
|
|
worktreeId,
|
|
pathLabels: { [repoPath]: '<setup-repo>', [worktreePath]: '<setup-worktree>' },
|
|
cleanup: () => {
|
|
rmSync(worktreePath, { recursive: true, force: true })
|
|
rmSync(repoPath, { recursive: true, force: true })
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function openHostSplitWorktree(page: Page, userDataDir: string): Promise<string> {
|
|
let setupWorktreeId: string | undefined
|
|
await expect
|
|
.poll(async () => {
|
|
setupWorktreeId = await page.evaluate(async () => {
|
|
const store = window.__store!
|
|
await store.getState().fetchRepos({ runtimeEnvironmentId: null, throwOnError: true })
|
|
for (const repo of store.getState().repos) {
|
|
await store.getState().fetchWorktrees(repo.id)
|
|
}
|
|
return Object.values(store.getState().worktreesByRepo)
|
|
.flat()
|
|
.find((worktree) => worktree.branch === 'refs/heads/parity-setup')?.id
|
|
})
|
|
return setupWorktreeId
|
|
})
|
|
.toBeDefined()
|
|
const client = new RuntimeClient(userDataDir, 30_000)
|
|
// Main has spawned the first terminal and its manual split before the user opens the worktree.
|
|
let hostPtyIds: string[] = []
|
|
await expect
|
|
.poll(async () => {
|
|
const listed = await client
|
|
.call<RuntimeTerminalListResult>('terminal.list', { worktree: `id:${setupWorktreeId!}` })
|
|
.catch(() => null)
|
|
hostPtyIds = (listed?.result.terminals ?? []).flatMap((terminal) =>
|
|
terminal.ptyId ? [terminal.ptyId] : []
|
|
)
|
|
return hostPtyIds.length
|
|
})
|
|
.toBe(2)
|
|
await activateWorkspaceByClick(page, setupWorktreeId!)
|
|
await waitForActiveTerminalManager(page)
|
|
return setupWorktreeId!
|
|
}
|
|
|
|
export async function sleepAgentPane(page: Page, worktreeId: string): Promise<void> {
|
|
await splitActiveTerminalPane(page, 'vertical')
|
|
await waitForBoundPanes(page, 2)
|
|
await page.evaluate((id) => {
|
|
const state = window.__store!.getState()
|
|
const tabId = state.activeTabId!
|
|
const manager = window.__paneManagers!.get(tabId)!
|
|
const leafId = manager.getLeafId(manager.getActivePane()!.id)!
|
|
state.setAgentStatus(
|
|
`${tabId}:${leafId}`,
|
|
{ state: 'working', prompt: 'finish the task', agentType: 'codex' },
|
|
'Codex',
|
|
undefined,
|
|
{ worktreeId: id },
|
|
{ providerSession: { key: 'session_id', id: 'parity-sleep-session' } }
|
|
)
|
|
}, worktreeId)
|
|
await sleepWorkspaceViaSidebar(page, worktreeId)
|
|
await expect
|
|
.poll(() =>
|
|
page.evaluate((id) => {
|
|
const state = window.__store!.getState()
|
|
const slept = Object.values(state.sleepingAgentSessionsByPaneKey).some(
|
|
(record) => record.worktreeId === id
|
|
)
|
|
const live = (state.tabsByWorktree[id] ?? []).some(
|
|
(tab) => (state.ptyIdsByTabId[tab.id]?.length ?? 0) > 0
|
|
)
|
|
return slept && !live
|
|
}, worktreeId)
|
|
)
|
|
.toBe(true)
|
|
}
|
|
|
|
/** A slept worktree is not active after relaunch; the user's click wakes it and resumes the agent. */
|
|
export async function wakeByClick(page: Page, worktreeId: string): Promise<void> {
|
|
await waitForSessionReady(page)
|
|
await activateWorkspaceByClick(page, worktreeId)
|
|
await ensureTerminalVisible(page)
|
|
await waitForActiveTerminalManager(page, 30_000)
|
|
}
|