Repository navigation
fix(runtime): keep a slept remote shell terminal stopped #24416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import type { PtyRuntimeControllerDeps } from './controller-deps' | ||
| import { executeRuntimePtySpawn } from './spawn-execute' | ||
| import { createRuntimePtySpawnState, type RuntimePtySpawnArgs } from './spawn-state' | ||
|
|
||
| function spawnCtx(leaveWorktreeSleeping: boolean) { | ||
| const acquireWorktreeTerminalSpawn = vi.fn(async () => { | ||
| throw new Error('stop-after-acquire') | ||
| }) | ||
| const deps = { | ||
| runtime: { acquireWorktreeTerminalSpawn }, | ||
| store: undefined, | ||
| options: {} | ||
| } as unknown as PtyRuntimeControllerDeps | ||
| const args = { | ||
| cols: 80, | ||
| rows: 24, | ||
| worktreeId: 'wt-1', | ||
| ...(leaveWorktreeSleeping ? { leaveWorktreeSleeping: true } : {}) | ||
| } satisfies RuntimePtySpawnArgs | ||
| return { ctx: createRuntimePtySpawnState(deps, args), acquireWorktreeTerminalSpawn } | ||
| } | ||
|
|
||
| describe('runtime spawn sleep disposition', () => { | ||
| it('asks an automatic recovery to leave a committed host sleep', async () => { | ||
| const { ctx, acquireWorktreeTerminalSpawn } = spawnCtx(true) | ||
| await expect(executeRuntimePtySpawn(ctx)).rejects.toThrow('stop-after-acquire') | ||
| expect(acquireWorktreeTerminalSpawn).toHaveBeenCalledWith('wt-1', 'leave') | ||
| }) | ||
|
|
||
| it('wakes a committed host sleep for an explicit spawn', async () => { | ||
| const { ctx, acquireWorktreeTerminalSpawn } = spawnCtx(false) | ||
| await expect(executeRuntimePtySpawn(ctx)).rejects.toThrow('stop-after-acquire') | ||
| expect(acquireWorktreeTerminalSpawn).toHaveBeenCalledWith('wt-1', 'wake') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,11 @@ import { | |
| makeWorkspaceSessionWithHeadlessTerminal, | ||
| store | ||
| } from '../orca-runtime-test-fixtures.spec' | ||
| import { runtimeWorktreeIdentityKey } from '../runtime-worktree-path-identity' | ||
| import { | ||
| WorktreeTerminalLeftAsleepError, | ||
| type WorktreeTerminalSleepSnapshot | ||
| } from '../worktree-terminal-spawn-sleep-disposition' | ||
|
|
||
| describe('OrcaRuntimeService', () => { | ||
| describe('deliberately parked pane activation (STA-3465)', () => { | ||
|
|
@@ -307,6 +312,91 @@ describe('OrcaRuntimeService', () => { | |
| expect(spawn).not.toHaveBeenCalled() | ||
| expect(activated.tabs[0]).toMatchObject({ status: 'pending-handle', terminal: null }) | ||
| }) | ||
|
|
||
| function hostSleepStates( | ||
| runtime: OrcaRuntimeService | ||
| ): Map<string, WorktreeTerminalSleepSnapshot> { | ||
| return ( | ||
| runtime as unknown as { | ||
| terminalSleepStateByWorktreeId: Map<string, WorktreeTerminalSleepSnapshot> | ||
| } | ||
| ).terminalSleepStateByWorktreeId | ||
| } | ||
|
|
||
| function rememberHostSleep( | ||
| runtime: OrcaRuntimeService, | ||
| phase: WorktreeTerminalSleepSnapshot['phase'] | ||
| ): void { | ||
| hostSleepStates(runtime).set(runtimeWorktreeIdentityKey(TEST_WORKTREE_ID), { | ||
| worktreeId: TEST_WORKTREE_ID, | ||
| generation: 2, | ||
| phase, | ||
| ptyIds: ['persisted-pty'], | ||
| terminalHandles: ['term-1'], | ||
| terminalHandlesByPtyId: { 'persisted-pty': ['term-1'] } | ||
| }) | ||
| } | ||
|
|
||
| function shellSessionRuntime(): { | ||
| runtime: OrcaRuntimeService | ||
| spawn: ReturnType<typeof vi.fn> | ||
| } { | ||
| const { runtimeStore } = makeRuntimeStoreWithWorkspaceSession( | ||
| makeWorkspaceSessionWithHeadlessTerminal() | ||
| ) | ||
| return makeParkedRuntime(runtimeStore) | ||
| } | ||
|
|
||
| it('still materializes a shell tab that has no host sleep record', async () => { | ||
| const { runtime, spawn } = shellSessionRuntime() | ||
|
|
||
| const activated = await automaticActivate(runtime) | ||
|
|
||
| expect(spawn).toHaveBeenCalledOnce() | ||
| expect(activated.tabs[0]).toMatchObject({ status: 'ready' }) | ||
| }) | ||
|
|
||
| it.each(['sleeping', 'partial', 'stopping'] as const)( | ||
| 'refuses automatic recovery while the host sleep phase is %s', | ||
| async (phase) => { | ||
| const { runtime, spawn } = shellSessionRuntime() | ||
| rememberHostSleep(runtime, phase) | ||
|
|
||
| const activated = await automaticActivate(runtime) | ||
|
|
||
| expect(spawn).not.toHaveBeenCalled() | ||
| expect(activated.tabs[0]).toMatchObject({ status: 'pending-handle', terminal: null }) | ||
| expect( | ||
| hostSleepStates(runtime).get(runtimeWorktreeIdentityKey(TEST_WORKTREE_ID))?.phase | ||
| ).toBe(phase) | ||
| } | ||
| ) | ||
|
|
||
| it('still materializes a host-slept shell tab when the user opens it', async () => { | ||
| const { runtime, spawn } = shellSessionRuntime() | ||
| rememberHostSleep(runtime, 'sleeping') | ||
|
|
||
| const activated = await userActivate(runtime) | ||
|
|
||
| expect(spawn).toHaveBeenCalledOnce() | ||
| expect(activated.tabs[0]).toMatchObject({ status: 'ready' }) | ||
| }) | ||
|
|
||
| it('keeps a committed host sleep when an automatic spawn reaches the lock', async () => { | ||
| const { runtime } = shellSessionRuntime() | ||
| rememberHostSleep(runtime, 'sleeping') | ||
|
|
||
| await expect( | ||
| runtime.acquireWorktreeTerminalSpawn(TEST_WORKTREE_ID, 'leave') | ||
|
Comment on lines
+385
to
+390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Knowledge Base Used: PTY streaming and recovery Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| ).rejects.toBeInstanceOf(WorktreeTerminalLeftAsleepError) | ||
| expect( | ||
| hostSleepStates(runtime).get(runtimeWorktreeIdentityKey(TEST_WORKTREE_ID))?.phase | ||
| ).toBe('sleeping') | ||
|
|
||
| const release = await runtime.acquireWorktreeTerminalSpawn(TEST_WORKTREE_ID) | ||
| release() | ||
| expect(hostSleepStates(runtime).has(runtimeWorktreeIdentityKey(TEST_WORKTREE_ID))).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| it('reattaches hydrated SSH headless terminals with the persisted relay identity', async () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.