Managed SSH prompts previously depended on Desktop-owned provider and transcript state, so accepted work could stop or become uncertain when the Desktop, network, or power disappeared. The Agent now owns accepted OpenCode prompt execution, model and tool rounds, cancellation, and the durable semantic transcript, while Desktop remains authoritative for permanent projects, conversations, tasks, and messages. Recovered work attaches to the original conversation without replay. The project switcher also groups managed SSH projects by saved Host and shows live Agent connectivity beside each group without opening a connection merely to read status. Remote project subtitles now show only the path, and the Agent lock advances to 0.11.14 with Runtime ACP v4. Release note: 托管 SSH 任务在桌面端、网络或电源中断后可继续在主机上运行,并能回到原会话精确恢复;项目菜单现按主机分组并显示实时连接状态。
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { readFile } from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
import {
|
|
runCleanupBeforeDeadline,
|
|
settleCleanupPhases,
|
|
waitForCleanup
|
|
} from './shutdown'
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
describe('waitForCleanup', () => {
|
|
it('detaches runtime ownership before ordinary runtime disposal on Desktop exit', async () => {
|
|
const source = await readFile(
|
|
join(process.cwd(), 'src', 'main', 'index.ts'),
|
|
'utf8'
|
|
)
|
|
const cleanup = source.match(
|
|
/const cleanup = settleCleanupPhases\(\[[\s\S]*?\]\)\s+globalShortcut/u
|
|
)?.[0] ?? ''
|
|
|
|
expect(cleanup).toContain('runtime?.detachForApplicationExit()')
|
|
expect(cleanup).toContain(
|
|
'selectedRuntimeManager?.detachForApplicationExit()'
|
|
)
|
|
expect(cleanup.indexOf('runtime?.detachForApplicationExit()')).toBeLessThan(
|
|
cleanup.indexOf('runtime?.dispose()')
|
|
)
|
|
})
|
|
|
|
it('reports completed and failed cleanup as settled', async () => {
|
|
await expect(
|
|
waitForCleanup(Promise.resolve(), 100)
|
|
).resolves.toBe(true)
|
|
await expect(
|
|
waitForCleanup(Promise.reject(new Error('cleanup failed')), 100)
|
|
).resolves.toBe(true)
|
|
})
|
|
|
|
it('stops waiting after the shutdown deadline', async () => {
|
|
vi.useFakeTimers()
|
|
const result = waitForCleanup(new Promise(() => {}), 100)
|
|
|
|
await vi.advanceTimersByTimeAsync(100)
|
|
|
|
await expect(result).resolves.toBe(false)
|
|
})
|
|
|
|
it('runs dependent cleanup phases in order despite failures', async () => {
|
|
const order: string[] = []
|
|
|
|
await settleCleanupPhases([
|
|
[
|
|
async () => {
|
|
order.push('ipc')
|
|
throw new Error('cleanup failed')
|
|
}
|
|
],
|
|
[
|
|
async () => {
|
|
order.push('gateway')
|
|
}
|
|
],
|
|
[
|
|
async () => {
|
|
order.push('knowledge')
|
|
}
|
|
]
|
|
])
|
|
|
|
expect(order).toEqual(['ipc', 'gateway', 'knowledge'])
|
|
})
|
|
|
|
it('finalizes databases only after cleanup beats the deadline', async () => {
|
|
const finalize = vi.fn()
|
|
await expect(
|
|
runCleanupBeforeDeadline(Promise.resolve(), 100, finalize)
|
|
).resolves.toBe(true)
|
|
expect(finalize).toHaveBeenCalledOnce()
|
|
|
|
vi.useFakeTimers()
|
|
const timedOutFinalize = vi.fn()
|
|
const result = runCleanupBeforeDeadline(
|
|
new Promise(() => {}),
|
|
100,
|
|
timedOutFinalize
|
|
)
|
|
await vi.advanceTimersByTimeAsync(100)
|
|
|
|
await expect(result).resolves.toBe(false)
|
|
expect(timedOutFinalize).not.toHaveBeenCalled()
|
|
})
|
|
})
|