Files
orca/tests/e2e/helpers/nested-runtime-same-id-pairing.ts
T
Neil c2d5430489 [CI] Fix test fixtures and reduce unnecessary test setup (#27330)
* [CI] Fix E2E folder and catalog fixtures

* [CI] Strengthen folder readiness and reuse composer fixtures

* [CI] Repair E2E catalog owners and retain stronger unit checks

* [CI] Defer optional unit deletions to avoid extra CI jobs

* [CI] Forward Monaco test mocks to the real editor API

* [CI] Make agent launch fixtures handle probes and terminal resize

* [CI] Avoid unused test initialization and flush version probe output
2026-10-10 21:06:11 -07:00

59 lines
2.7 KiB
TypeScript

import type { Page } from '@stablyai/playwright-test'
import { updateEnvironmentFromPairingCode } from '../../../src/shared/runtime-environment-store'
export type SameIdPairingReplacement = {
environmentId: string
previousPairingRevision: number
nextPairingRevision: number
}
export async function replaceRuntimePairingInPlace(args: {
environmentId: string
page: Page
pairingUrl: string
userDataDir: string
}): Promise<SameIdPairingReplacement> {
const previous = await args.page.evaluate((selector) => {
return window.api.runtimeEnvironments.resolve({ selector })
}, args.environmentId)
await args.page.evaluate(async (selector) => {
await window.api.runtimeEnvironments.disconnect({ selector })
}, args.environmentId)
const updated = updateEnvironmentFromPairingCode(args.userDataDir, args.environmentId, {
pairingCode: args.pairingUrl
})
const hydrated = await args.page.evaluate(async (selector) => {
const store = window.__store
if (!store) {
throw new Error('Paired desktop store is unavailable during same-ID re-pair')
}
const connection = await window.api.runtimeEnvironments.connect({ selector })
if (!connection.ok) {
throw new Error(`Same-ID re-pair reconnect failed: ${JSON.stringify(connection.error)}`)
}
const environments = await window.api.runtimeEnvironments.list()
store.getState().setRuntimeEnvironments(environments)
if (!(await store.getState().refreshRuntimeEnvironmentStatus(selector))) {
throw new Error('Same-ID re-paired desktop could not reach the HUB runtime')
}
if (!(await store.getState().setActiveRuntimeEnvironmentPreference(selector))) {
throw new Error('Same-ID re-paired desktop could not select the HUB runtime')
}
// Why: same-ID selection is a no-op, so explicitly rehydrate the graph from the replacement transport.
await store.getState().fetchRepos({ runtimeEnvironmentId: selector, throwOnError: true })
await store.getState().fetchAllWorktrees()
await store.getState().fetchWorktreeLineage()
return window.api.runtimeEnvironments.resolve({ selector })
}, args.environmentId)
const previousPairingRevision = previous.pairingRevision ?? previous.createdAt
const nextPairingRevision = hydrated.pairingRevision ?? hydrated.createdAt
if (updated.id !== args.environmentId || hydrated.id !== args.environmentId) {
throw new Error('Same-ID re-pair unexpectedly changed the environment identity')
}
if (nextPairingRevision <= previousPairingRevision) {
throw new Error('Same-ID re-pair did not advance the pairing revision')
}
return { environmentId: args.environmentId, previousPairingRevision, nextPairingRevision }
}