mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
* fix(ssh): prune superseded staged server builds when an update defers GC ran only after an activation, so a host whose updates kept deferring over live terminals kept one staged orcad slot per release. Prune on deferral too, keeping the active, previous, live-daemon and newly staged builds. Refs #34149 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(ssh): keep recently staged builds; route and harden the deferred-slot e2e Desktops on different releases can share a host, so the deferral prune keeps complete builds staged within three days instead of deleting a peer's candidate and forcing it to re-upload. Windows hosts, which cannot date their builds, keep them all. Refs #34149 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(ssh): read a build's staging age as unknown when find cannot date it A find without -mtime used to read as an old build and let the deferral prune remove a peer's candidate. Report an error instead, which keeps every candidate; a build without .install-complete reads as not recent. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * test(ssh): pin that an undatable staged build keeps every build Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * test(ssh): fold the deferred-slot e2e into the update-anyway spec Keeps the routing table under its size limit and runs the check on the same deferred-update sources. Also drop the unused readiness argument from pruneSupersededOrcadCandidates. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(ssh): report GC as unfinished when it kept a recently staged build Callers that memoize a clean pass would otherwise never prune the build once it ages. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
199 lines
8.5 KiB
TypeScript
199 lines
8.5 KiB
TypeScript
/** Prove Update defers on a running process, Update anyway preserves it across restart, and repeated deferrals keep one staged build (#34149). */
|
|
import { cpSync, mkdtempSync, rmSync } from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import type { Page } from '@stablyai/playwright-test'
|
|
import { expect, test } from './helpers/orca-app'
|
|
import { readPairedPaneContent } from './helpers/paired-host-terminal'
|
|
import { focusActiveTerminalInput } from './helpers/terminal'
|
|
import {
|
|
activateManagedWorkspace,
|
|
expectPaneText,
|
|
expectTerminalAnswers,
|
|
launchManagedWorkspace,
|
|
ORCAD_TEMPLATE,
|
|
relaunchManagedApp,
|
|
selectTerminalTab,
|
|
skipUnlessManagedDockerHost,
|
|
openTerminalTab,
|
|
terminalTabIds,
|
|
typeInTerminal,
|
|
waitForPane,
|
|
withManagedHost
|
|
} from './helpers/orcad-managed-workspace'
|
|
import { makeOrcadTemplateVariant, readHostOrcadActivation } from './helpers/orcad-template-variant'
|
|
|
|
skipUnlessManagedDockerHost()
|
|
test.skip(process.platform === 'win32', 'The Docker SSH host uses POSIX tooling')
|
|
|
|
const TICK = /AGENT_TICK_(\d+)/g
|
|
|
|
async function latestTick(page: Page, tabId: string): Promise<number> {
|
|
const ticks = [...(await readPairedPaneContent(page, tabId)).matchAll(TICK)]
|
|
return ticks.length === 0 ? -1 : Math.max(...ticks.map((match) => Number(match[1])))
|
|
}
|
|
|
|
test('Update anyway moves a managed host to the new build and keeps its running terminal', async (// oxlint-disable-next-line no-empty-pattern -- Owns its app launch through a restart session.
|
|
{}, testInfo) => {
|
|
test.setTimeout(20 * 60_000)
|
|
const scratch = mkdtempSync(path.join(os.tmpdir(), 'orca-update-anyway-'))
|
|
const templateDir = path.join(scratch, 'template')
|
|
cpSync(ORCAD_TEMPLATE!, templateDir, { recursive: true })
|
|
try {
|
|
await withManagedHost(
|
|
testInfo,
|
|
async (fixture) => {
|
|
const workspace = await launchManagedWorkspace(fixture)
|
|
const { seeded, environmentId } = workspace
|
|
const tab = await openTerminalTab(workspace.page, seeded.worktreeId)
|
|
// Single quotes keep $$ for the inner bash: its pid is the long-running process itself.
|
|
await typeInTerminal(
|
|
workspace.page,
|
|
tab,
|
|
`bash -c 'echo AGENT_PID=$$; i=0; while :; do echo AGENT_TICK_$i; i=$((i+1)); sleep 1; done'`
|
|
)
|
|
await expectPaneText(workspace.page, tab, 'AGENT_TICK_2')
|
|
const pid = /AGENT_PID=(\d+)/.exec(await readPairedPaneContent(workspace.page, tab))?.[1]
|
|
expect(pid, 'the agent printed its pid').toBeTruthy()
|
|
const deployed = readHostOrcadActivation(fixture.host.exec!)
|
|
|
|
// An app update bundling a newer orcad; its connect defers over the running terminal.
|
|
makeOrcadTemplateVariant(templateDir, 'B')
|
|
const page = await relaunchManagedApp(fixture)
|
|
await expect
|
|
.poll(
|
|
() =>
|
|
page.evaluate(
|
|
async (selector) =>
|
|
(await window.api.runtimeEnvironments.managedOrcad?.getStatus({ selector }))
|
|
?.availableUpdate ?? null,
|
|
environmentId
|
|
),
|
|
{ timeout: 4 * 60_000, intervals: [3_000] }
|
|
)
|
|
.toBeTruthy()
|
|
expect(readHostOrcadActivation(fixture.host.exec!).active).toBe(deployed.active)
|
|
|
|
await page.evaluate(() => {
|
|
const state = window.__store!.getState()
|
|
state.openSettingsTarget({ pane: 'servers', repoId: null })
|
|
state.openSettingsPage()
|
|
})
|
|
const row = page.locator(`[data-settings-section="${environmentId}"]`)
|
|
const update = row.getByRole('button', { name: 'Update', exact: true })
|
|
await expect(update).toBeVisible({ timeout: 60_000 })
|
|
await update.click()
|
|
await expect(row.getByText(/keeps? running through the update/)).toBeVisible({
|
|
timeout: 4 * 60_000
|
|
})
|
|
expect(readHostOrcadActivation(fixture.host.exec!).active).toBe(deployed.active)
|
|
await page.screenshot({ path: testInfo.outputPath('update-anyway-confirm.png') })
|
|
await row.getByRole('button', { name: 'Update anyway' }).click()
|
|
|
|
await expect
|
|
.poll(() => readHostOrcadActivation(fixture.host.exec!).active, {
|
|
timeout: 6 * 60_000,
|
|
intervals: [3_000]
|
|
})
|
|
.not.toBe(deployed.active)
|
|
await expect(update).toHaveCount(0, { timeout: 2 * 60_000 })
|
|
await page.screenshot({ path: testInfo.outputPath('update-anyway-done.png') })
|
|
expect(fixture.host.exec!(`kill -0 ${pid} && echo alive`)).toContain('alive')
|
|
|
|
// The same pane reattaches: its earlier output, the process still printing, then input.
|
|
await activateManagedWorkspace(page, seeded.worktreeId, environmentId)
|
|
expect(await terminalTabIds(page, seeded.worktreeId)).toContain(tab)
|
|
await selectTerminalTab(page, tab)
|
|
await waitForPane(page, tab)
|
|
await expectPaneText(page, tab, `AGENT_PID=${pid}`, 2 * 60_000)
|
|
const resumedAt = await latestTick(page, tab)
|
|
await expect
|
|
.poll(() => latestTick(page, tab), { timeout: 60_000 })
|
|
.toBeGreaterThan(resumedAt + 2)
|
|
await focusActiveTerminalInput(page)
|
|
await page.keyboard.press('Control+C')
|
|
await expectTerminalAnswers(page, tab)
|
|
expect(fixture.host.exec!(`kill -0 ${pid} 2>/dev/null || echo gone`)).toContain('gone')
|
|
},
|
|
templateDir
|
|
)
|
|
} finally {
|
|
rmSync(scratch, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
function slotVersions(exec: (command: string) => string): string[] {
|
|
return exec('cd /root/.orca-remote && ls -d orcad-0* 2>/dev/null || true')
|
|
.split('\n')
|
|
.map((line) => line.trim().replace(/^orcad-/, ''))
|
|
.filter(Boolean)
|
|
.sort()
|
|
}
|
|
|
|
function deferredCandidate(page: Page, environmentId: string): Promise<string | null> {
|
|
return page.evaluate(
|
|
async (selector) =>
|
|
(await window.api.runtimeEnvironments.managedOrcad?.getStatus({ selector }))?.deferredUpdate
|
|
?.candidateVersion ?? null,
|
|
environmentId
|
|
)
|
|
}
|
|
|
|
test('a release deferred over running terminals replaces the build the last one staged', async (// oxlint-disable-next-line no-empty-pattern -- Owns its app launch through a restart session.
|
|
{}, testInfo) => {
|
|
// Deploys a server, then relaunches through two app updates that each stage a build.
|
|
test.setTimeout(20 * 60_000)
|
|
const scratch = mkdtempSync(path.join(os.tmpdir(), 'orca-deferred-slots-'))
|
|
const templateDir = path.join(scratch, 'template')
|
|
cpSync(ORCAD_TEMPLATE!, templateDir, { recursive: true })
|
|
try {
|
|
await withManagedHost(
|
|
testInfo,
|
|
async (fixture) => {
|
|
const exec = fixture.host.exec!
|
|
const workspace = await launchManagedWorkspace(fixture)
|
|
const { environmentId } = workspace
|
|
const tab = await openTerminalTab(workspace.page, workspace.seeded.worktreeId)
|
|
await typeInTerminal(workspace.page, tab, `bash -c 'while :; do echo TICK; sleep 1; done'`)
|
|
await expectPaneText(workspace.page, tab, 'TICK')
|
|
const deployed = readHostOrcadActivation(exec).active!
|
|
|
|
makeOrcadTemplateVariant(templateDir, 'B')
|
|
let page = await relaunchManagedApp(fixture)
|
|
await expect
|
|
.poll(() => deferredCandidate(page, environmentId), { timeout: 4 * 60_000 })
|
|
.not.toBeNull()
|
|
const staged = (await deferredCandidate(page, environmentId))!
|
|
expect(slotVersions(exec)).toEqual([deployed, staged].sort())
|
|
|
|
// Releases come days apart; a build staged this recently could still be another desktop's.
|
|
exec(`touch -d '5 days ago' /root/.orca-remote/orcad-${staged}/.install-complete`)
|
|
makeOrcadTemplateVariant(templateDir, 'C')
|
|
page = await relaunchManagedApp(fixture)
|
|
let next: string | null = null
|
|
await expect
|
|
.poll(
|
|
async () => {
|
|
const candidate = await deferredCandidate(page, environmentId)
|
|
next = candidate !== staged ? candidate : null
|
|
return next
|
|
},
|
|
{ timeout: 4 * 60_000 }
|
|
)
|
|
.not.toBeNull()
|
|
expect(readHostOrcadActivation(exec).active).toBe(deployed)
|
|
await expect
|
|
.poll(() => slotVersions(exec), { timeout: 60_000 })
|
|
.toEqual([deployed, next!].sort())
|
|
// The prune must not touch the running terminal the deferral protected.
|
|
expect(
|
|
exec("pgrep -f '[w]hile :; do echo TICK' >/dev/null && echo alive || true")
|
|
).toContain('alive')
|
|
},
|
|
templateDir
|
|
)
|
|
} finally {
|
|
rmSync(scratch, { recursive: true, force: true })
|
|
}
|
|
})
|