codeburn/tests/ink-win.test.ts
ozymandiashh bff930e645 fix(ink-win): strip synchronized-update escapes instead of exact-matching them
The ConPTY guard swallowed a chunk only when it exactly equaled BSU or
ESU, so any write concatenating them with other output reached Windows
raw and hung ConPTY, which buffers the unimplemented 2026 sequence
indefinitely (#195; the class recurred in #863's resize path). Strip
every occurrence from string chunks instead: standalone escapes are
swallowed, concatenated ones lose only the escapes, and a swallowed
write now also honors its callback so callback-style writers cannot
wedge. Non-string chunks pass through untouched.
2026-08-04 03:06:47 +03:00

42 lines
1.6 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { BSU, ESU, stripSyncUpdateEscapes, patchStdoutForWindows } from '../src/ink-win.js'
describe('stripSyncUpdateEscapes', () => {
it('strips an exact BSU chunk to empty', () => {
expect(stripSyncUpdateEscapes(BSU)).toBe('')
})
it('strips an exact ESU chunk to empty', () => {
expect(stripSyncUpdateEscapes(ESU)).toBe('')
})
it('strips a leading BSU from a concatenated clear write', () => {
// #863 regression shape: the clear sequence glued to a BSU used to slip
// through raw and hang Windows ConPTY.
expect(stripSyncUpdateEscapes(BSU + '\x1b[2J\x1b[H')).toBe('\x1b[2J\x1b[H')
})
it('strips a trailing ESU, and both ends at once', () => {
expect(stripSyncUpdateEscapes('x' + ESU)).toBe('x')
expect(stripSyncUpdateEscapes(BSU + 'x' + ESU)).toBe('x')
})
it('removes every occurrence when escapes appear multiple times', () => {
expect(stripSyncUpdateEscapes(BSU + 'a' + BSU + 'b' + ESU + 'c' + ESU)).toBe('abc')
})
it('leaves a string without escapes untouched (same reference-equal content)', () => {
const plain = 'status line \x1b[2J'
expect(stripSyncUpdateEscapes(plain)).toBe(plain)
})
})
describe('patchStdoutForWindows', () => {
it('is a no-op off win32: process.stdout.write stays reference-identical', () => {
// Skip on actual Windows runners, where the patch legitimately applies.
if (process.platform === 'win32') return
const before = process.stdout.write
patchStdoutForWindows()
expect(process.stdout.write).toBe(before)
})
})