fix(pty): defer the first readiness poll

This commit is contained in:
Tianyi Cui
2026-07-29 03:44:57 +08:00
parent 65264f6c80
commit a0200376a1
2 changed files with 26 additions and 1 deletions

View File

@@ -266,7 +266,7 @@ export class LocalPtySession implements PtyBackendSession {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (this.active === operation && !this.closing) {
this.pollingReady = operation
this.schedulePoll(operation, 0)
this.schedulePoll(operation)
}
} catch (error: unknown) {
if (this.active === operation) {

View File

@@ -143,6 +143,31 @@ async function initialize(session: LocalPtySession, terminal: FakeTerminal): Pro
}
describe('LocalPtySession readiness and output', () => {
it('lets queued terminal output run before the first post-write readiness poll', async () => {
vi.useFakeTimers()
const terminal = new FakeTerminal()
const inspector = new FakeInspector()
const session = makeSession(terminal, inspector, config())
await initialize(session, terminal)
const inspect = terminal.inspectForeground.bind(terminal)
let inspections = 0
terminal.inspectForeground = async () => {
inspections += 1
return await inspect()
}
const operation = session.startSend({ text: 'true', submit: true })
await Promise.resolve()
await Promise.resolve()
expect(inspections).toBe(1)
await vi.advanceTimersByTimeAsync(0)
expect(inspections).toBe(1)
terminal.emitData('\x1b]133;D;0\x07dsh> ')
await vi.advanceTimersByTimeAsync(10)
expect((await operation.done).waitReason).toBe('stdin_read')
})
it('captures prompt MOTD, writes submit explicitly, and settles exact stdin waits', async () => {
vi.useFakeTimers()
const terminal = new FakeTerminal()