Stabilize OpenCode terminal rendering before release (#4850)
This commit is contained in:
@@ -5250,11 +5250,22 @@ describe('OrcaRuntimeService', () => {
|
||||
const [terminal] = (await runtime.listTerminals()).terminals
|
||||
const lines = Array.from({ length: 120 }, (_, index) => `line-${index}-${'x'.repeat(400)}`)
|
||||
runtime.onPtyData('pty-1', `${lines.join('\n')}\n`, 100)
|
||||
// Why: xterm-headless uses Array.shift internally while draining writes;
|
||||
// this test guards read-preview trimming, not emulator parsing.
|
||||
await runtime.serializeMainTerminalBuffer('pty-1')
|
||||
|
||||
const shiftSpy = vi.spyOn(Array.prototype, 'shift')
|
||||
const preview = await runtime.readTerminal(terminal.handle)
|
||||
const shiftCallCount = shiftSpy.mock.calls.length
|
||||
shiftSpy.mockRestore()
|
||||
const originalShift = Array.prototype.shift
|
||||
let shiftCallCount = 0
|
||||
Array.prototype.shift = function (...args) {
|
||||
shiftCallCount += 1
|
||||
return originalShift.apply(this, args)
|
||||
}
|
||||
let preview: Awaited<ReturnType<typeof runtime.readTerminal>>
|
||||
try {
|
||||
preview = await runtime.readTerminal(terminal.handle)
|
||||
} finally {
|
||||
Array.prototype.shift = originalShift
|
||||
}
|
||||
|
||||
expect(preview.limited).toBe(true)
|
||||
expect(preview.tail.at(-1)).toBe(lines.at(-1))
|
||||
|
||||
@@ -12345,11 +12345,8 @@ export class OrcaRuntimeService {
|
||||
const retained = [...this.ptysById.values()]
|
||||
.filter((pty) => !pty.connected && !this.leafExistsForPty(pty.ptyId))
|
||||
.sort((a, b) => (a.disconnectedAt ?? 0) - (b.disconnectedAt ?? 0))
|
||||
while (retained.length > DISCONNECTED_PTY_RECORD_MAX) {
|
||||
const stale = retained.shift()
|
||||
if (!stale) {
|
||||
return
|
||||
}
|
||||
const staleCount = Math.max(0, retained.length - DISCONNECTED_PTY_RECORD_MAX)
|
||||
for (const stale of retained.slice(0, staleCount)) {
|
||||
// Why: exited runtime-owned PTYs stay readable after exit, but long-lived
|
||||
// runtimes can churn through many background sessions. Bound the archive.
|
||||
this.dropDisconnectedPtyRecord(stale.ptyId)
|
||||
|
||||
Reference in New Issue
Block a user