Files
orca/tests/e2e/ssh-orcad-move-anyway-inline.spec.ts
Neil ccedfe312e fix(ssh): move enabled SSH automations to the host's Orca server (#34044)
* fix(ssh): move enabled SSH automations to the host's Orca server

Connecting an SSH host moves its saved state to the host's managed Orca
server. An enabled SSH automation refused that move on every Connect
("automations (1), automation runs (4)"), leaving the host unconnectable;
Move anyway connected it but stranded the automation on the desktop, where
it no longer ran.

An enabled automation whose runs have all finished now moves with its run
history. The manifest still carries it disabled, which every server version
accepts; once the move commits the desktop disables its retained copy and
turns the server's copy back on through automation.update, re-sending its
start time so the next run is the next future occurrence. A server that
can't is noted in Settings; an unreachable one is retried on the next
Connect. While a move fences the host, the desktop scheduler, Run now and
the launch re-check write nothing for its automations, so a tick can no
longer break the fenced export; releasing the fence resumes them. A run
still in flight keeps blocking and the refusal now says to wait for it.

Fixes #29083

* test(ssh): mock the server automation enabler in the delta-move handler test

* test(e2e): keep the Move anyway specs refusing now that enabled automations move

The inline Move anyway spec seeded an enabled automation to force a
refusal, which this branch now moves instead. It seeds one pinned to an
earlier registration of the host, which still stays behind. The relay
bridge spec's Move anyway lookup also matched the refusal toast's
button since #34041; it now takes the pane's own.
2026-10-26 16:11:06 -07:00

141 lines
5.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// #29083: a host whose move a saved automation refuses offers Move anyway on its card, and that connects it.
// ORCA_E2E_ORCAD_CONVERT_HOST=docker; ORCA_E2E_ORCAD_CONVERT_TEMPLATE must be built for the Docker host.
import type { ElectronApplication } from '@stablyai/playwright-test'
import { expect, test } from './helpers/orca-app'
import { waitForSessionReady } from './helpers/store'
import { createRestartSession } from './helpers/orca-restart'
import { seedRelayEraProfile } from './helpers/orcad-upgrade-profile'
import { mutateStoppedProfileState } from './helpers/persisted-profile-state'
import { openSshHostSettings } from './helpers/ssh-config-host-picker'
import { managedServer } from './helpers/orcad-convert-flow'
import {
ORCAD_CONVERT_HOST_ENV,
startOrcadConvertHost,
type OrcadConvertHost
} from './helpers/orcad-convert-host'
const HOST = process.env[ORCAD_CONVERT_HOST_ENV]
const TEMPLATE_SOURCE = process.env.ORCA_E2E_ORCAD_CONVERT_TEMPLATE
test.skip(
HOST !== 'docker' || !TEMPLATE_SOURCE,
`Set ${ORCAD_CONVERT_HOST_ENV}=docker and ORCA_E2E_ORCAD_CONVERT_TEMPLATE`
)
let host: OrcadConvertHost | null = null
test.afterEach(() => {
host?.cleanup()
host = null
})
// Pinned to an earlier registration of this host, so the server can't take it over and it stays behind.
function seedStrandedAutomation(userDataDir: string, repoId: string, targetId: string): void {
const now = Date.now()
const automationId = `automation-${now}`
mutateStoppedProfileState(userDataDir, (state: Record<string, unknown>) => {
state.automations = [
{
id: automationId,
name: 'nightly check',
prompt: 'check',
precheck: null,
agentId: 'claude',
projectId: repoId,
executionTargetType: 'ssh',
executionTargetId: targetId,
executionTargetGeneration: 9_999,
schedulerOwner: 'ssh_bridge',
workspaceMode: 'new_per_run',
workspaceId: null,
baseBranch: null,
reuseSession: false,
timezone: 'UTC',
rrule: 'FREQ=DAILY',
dtstart: now - 86_400_000,
enabled: true,
nextRunAt: now + 86_400_000,
missedRunPolicy: 'run_once_within_grace',
missedRunGraceMinutes: 60,
createdAt: now - 86_400_000,
updatedAt: now - 86_400_000
}
]
state.automationRuns = [1, 2].map((n) => ({
id: `${automationId}-run-${n}`,
automationId,
title: `run ${n}`,
scheduledFor: now - n * 3_600_000,
status: 'completed',
trigger: 'scheduled',
workspaceId: null,
sessionKind: 'terminal',
chatSessionId: null,
terminalSessionId: null,
terminalPaneKey: null,
terminalPtyId: null,
outputSnapshot: null,
precheckResult: null,
usage: null,
error: null,
startedAt: now - n * 3_600_000,
dispatchedAt: now - n * 3_600_000,
createdAt: now - n * 3_600_000,
runNumber: n
}))
})
}
test('a move a saved automation refuses offers Move anyway on the host card', async ({
testRepoPath
}, testInfo) => {
// Starts a Docker host and two app launches, then converts the host.
test.setTimeout(10 * 60_000)
host = startOrcadConvertHost('docker', testInfo)
const session = createRestartSession(testInfo, { ORCA_ORCAD_TEMPLATE_PATH: TEMPLATE_SOURCE! })
let app: ElectronApplication | null = null
try {
const first = await session.launch()
app = first.app
await waitForSessionReady(first.page)
await first.page.evaluate((repoPath) => window.api.repos.add({ path: repoPath }), testRepoPath)
await session.close(app)
app = null
const seeded = seedRelayEraProfile(session.userDataDir, host.input, {
repoPath: host.remoteRepoPath,
folderPath: host.remoteFolderPath
})
seedStrandedAutomation(session.userDataDir, seeded.repoId, seeded.targetId)
const upgraded = await session.launch()
app = upgraded.app
const page = upgraded.page
await waitForSessionReady(page)
const section = await openSshHostSettings(page)
const card = section.locator(
`[data-ssh-target-card][data-ssh-target-label="${host.input.label}"]`
)
await card.hover()
await card.getByRole('button', { name: 'Connect', exact: true }).click()
await expect(card).toContainText(
'Some saved items for this host can’t move to its Orca server: automations (1), automation runs (2). Move anyway connects the host and keeps them on this computer.',
{ timeout: 4 * 60_000 }
)
const toast = page.locator('[data-sonner-toast]').filter({ hasText: 'automations (1)' })
await expect(toast.getByRole('button', { name: 'Move anyway…' })).toBeVisible()
const moveAnyway = card.getByRole('button', { name: 'Move anyway…', exact: true })
await expect(moveAnyway).toBeVisible()
await page.screenshot({ path: testInfo.outputPath('refused.png') })
await moveAnyway.click()
await page.getByRole('dialog').getByRole('button', { name: 'Move anyway', exact: true }).click()
await expect
.poll(() => managedServer(page, seeded.targetId), { timeout: 4 * 60_000 })
.toMatchObject({ kind: 'managed' })
await expect(card).toContainText('Connected', { timeout: 30_000 })
await page.screenshot({ path: testInfo.outputPath('moved.png') })
} finally {
if (app) {
await session.close(app)
}
await session.dispose()
}
})