mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* refactor(workspace-layout): organize concrete domain owners * test(layout): retire obsolete legacy-leaf publication setup
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import type { Page } from '@stablyai/playwright-test'
|
|
import { leafIdsInOrder } from './workspace-layout-oracle-model'
|
|
import { readWorkspaceLayoutStreamFrame } from '../../../src/shared/workspace-layout/published-layout/workspace-layout-stream-frames'
|
|
|
|
/** Terminal tab id → its pane ids in tree order, in tab-bar order. */
|
|
export type TerminalLayout = [tabId: string, paneIds: string[]][]
|
|
|
|
/** What main holds for the workspace, read from a stream of the test's own. */
|
|
export async function readMainLayout(page: Page, worktreeId: string): Promise<TerminalLayout> {
|
|
const raw = await page.evaluate(
|
|
(id) =>
|
|
new Promise<unknown>((resolve, reject) => {
|
|
const timer = setTimeout(() => reject(new Error('main sent no layout snapshot')), 10_000)
|
|
let handle: { unsubscribe: () => void } | null = null
|
|
let snapshot: unknown
|
|
const finish = (): void => {
|
|
if (handle && snapshot !== undefined) {
|
|
clearTimeout(timer)
|
|
handle.unsubscribe()
|
|
resolve(snapshot)
|
|
}
|
|
}
|
|
void window.api.runtime
|
|
.subscribe({ method: 'layout.subscribe', params: { workspaces: [id] } }, (response) => {
|
|
if (snapshot === undefined && response.ok) {
|
|
snapshot = response.result
|
|
finish()
|
|
}
|
|
})
|
|
.then((opened) => {
|
|
handle = opened
|
|
finish()
|
|
}, reject)
|
|
}),
|
|
worktreeId
|
|
)
|
|
const frame = readWorkspaceLayoutStreamFrame(raw)
|
|
if (frame?.type !== 'snapshot') {
|
|
throw new Error(
|
|
`layout.subscribe opened with no snapshot: ${JSON.stringify(raw).slice(0, 300)}`
|
|
)
|
|
}
|
|
const layout = frame.workspaces.find((entry) => entry.key === worktreeId)?.layout
|
|
return (layout?.tabs ?? [])
|
|
.filter((tab) => tab.kind === 'terminal')
|
|
.map((tab) => [tab.entityId, leafIdsInOrder(tab.terminal?.root)])
|
|
}
|