Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/renderer/src/components/terminal-pane/pty-connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
resetAgentStartupDelayedDeliveryForTests
} from '@/lib/agent-startup-delayed-delivery'
import type { PaneForegroundAgentEntry } from '@/store/slices/pane-foreground-agent'
import type { createPaneForegroundAgentTracker } from './pane-foreground-agent-tracker'

// Repro command:
// pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts -t "OpenTUI-style small ANSI redraw"
Expand Down Expand Up @@ -257,6 +258,12 @@ let mockStoreState: StoreState
let transportFactoryQueue: MockTransport[] = []
let createdTransportOptions: Record<string, unknown>[] = []
let storeSubscribers: ((state: StoreState) => void)[] = []
type PaneForegroundAgentTrackerFactory = typeof createPaneForegroundAgentTracker
type PaneForegroundAgentTracker = ReturnType<PaneForegroundAgentTrackerFactory>
type PaneForegroundAgentTrackerModule = {
createPaneForegroundAgentTracker: PaneForegroundAgentTrackerFactory
}
const paneForegroundAgentTrackers = new Set<PaneForegroundAgentTracker>()

vi.mock('@/runtime/sync-runtime-graph', () => ({
scheduleRuntimeGraphSync
Expand All @@ -278,6 +285,20 @@ vi.mock('./terminal-webgl-atlas-recovery', () => ({
scheduleTerminalWebglAtlasRecovery
}))

vi.mock('./pane-foreground-agent-tracker', async (importOriginal) => {
const actual = await importOriginal<PaneForegroundAgentTrackerModule>()
return {
...actual,
createPaneForegroundAgentTracker: (
...args: Parameters<typeof actual.createPaneForegroundAgentTracker>
) => {
const tracker = actual.createPaneForegroundAgentTracker(...args)
paneForegroundAgentTrackers.add(tracker)
return tracker
}
}
})

function notifyStoreSubscribers(): void {
for (const listener of storeSubscribers.slice()) {
listener(mockStoreState)
Expand Down Expand Up @@ -894,7 +915,14 @@ describe('connectPanePty', () => {
})

afterEach(() => {
// Why: most cases do not retain their pane binding; cancel its delayed reads
// before they can publish into the next case's freshly reset store mock.
for (const tracker of paneForegroundAgentTrackers) {
tracker.dispose()
}
paneForegroundAgentTrackers.clear()
vi.useRealTimers()
vi.restoreAllMocks()
if (originalRequestAnimationFrame) {
globalThis.requestAnimationFrame = originalRequestAnimationFrame
} else {
Expand Down Expand Up @@ -16480,6 +16508,9 @@ describe('connectPanePty', () => {
const transport = createMockTransport('pty-replaced-codex')
transportFactoryQueue.push(transport)
vi.useFakeTimers()
// Why: this assertion places the hook update between two active-cadence
// inspections, so pin the coordinator's poll jitter like its unit tests do.
vi.spyOn(Math, 'random').mockReturnValue(0.5)
const getForegroundProcess = vi.mocked(window.api.pty.getForegroundProcess)
getForegroundProcess.mockResolvedValue('codex')
const paneKey = makePaneKey('tab-1', LEAF_1)
Expand Down
Loading