mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
The linear replay carried old-lineage content over parent-owned files; this checkpoint restores them and adapts the branch to the parent's post-rebase seam: - restore all pty/lsp/subprocess/code-runtime surfaces to the parent's exact content (this branch claims none of them) and drop the net-zero code-runtime-e2b/pty-e2b/lsp-e2b residue and its registrations - widen serializeRemoteEnvironment to the seam's NodeJS.ProcessEnv tombstone contract: an explicit undefined removes an ambient entry - migrate the two E2B fixture Agent stubs to the Inbox-model interface and Session.create - re-apply the branch's gen-doc-graphs roles, THIRD_PARTY_NOTICES e2b row, and packages/README group row (trimmed to the doc budget); regenerate catalogs and re-record bilingual pairings
77 lines
3.8 KiB
TypeScript
77 lines
3.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { normalizeTerminalText, TerminalSanitizer } from '@deepseek-ai/dsh-pty-local/src/sanitize.ts'
|
|
|
|
describe('TerminalSanitizer', () => {
|
|
it('removes split CSI and owned OSC prompt markers', () => {
|
|
const sanitizer = new TerminalSanitizer(64)
|
|
expect(sanitizer.push('red\x1b[3')).toEqual({ text: 'red', prompt: false })
|
|
expect(sanitizer.push('1m text\x1b[0m\r\n')).toEqual({ text: ' text\n', prompt: false })
|
|
expect(sanitizer.push('\x1b]133;')).toEqual({ text: '', prompt: false })
|
|
expect(sanitizer.push('D;0\x07dsh> ')).toEqual({ text: 'dsh> ', prompt: true, promptTail: 'dsh> ' })
|
|
})
|
|
|
|
it('drops unrelated OSC, short escapes, BEL, and incomplete trailing escape', () => {
|
|
const sanitizer = new TerminalSanitizer(64)
|
|
expect(sanitizer.push('a\x1b]0;title\x1b\\b\x1b7c\x07')).toEqual({ text: 'abc', prompt: false })
|
|
expect(sanitizer.push('tail\x1b')).toEqual({ text: 'tail', prompt: false })
|
|
expect(sanitizer.flush()).toBe('')
|
|
expect(sanitizer.flush()).toBe('')
|
|
expect(sanitizer.push('\x1b]0;one\x07middle\x1b\\')).toEqual({ text: 'middle', prompt: false })
|
|
expect(sanitizer.push('\x1b]0;one\x1b\\middle\x07')).toEqual({ text: 'middle', prompt: false })
|
|
expect(sanitizer.push('\x1b]0;title\x1b\\')).toEqual({ text: '', prompt: false })
|
|
})
|
|
|
|
it('normalizes CRLF and standalone carriage returns', () => {
|
|
expect(normalizeTerminalText('a\r\nb\rc\x07')).toBe('a\nb\nc')
|
|
})
|
|
|
|
it('carries a trailing carriage return across data chunks and flushes standalone CR', () => {
|
|
const sanitizer = new TerminalSanitizer(64)
|
|
expect(sanitizer.push('a\r')).toEqual({ text: 'a', prompt: false })
|
|
expect(sanitizer.push('\nb')).toEqual({ text: '\nb', prompt: false })
|
|
expect(sanitizer.push('\r')).toEqual({ text: '', prompt: false })
|
|
expect(sanitizer.flush()).toBe('\n')
|
|
})
|
|
|
|
it('reports printable prompt text that follows a marker in a later chunk', () => {
|
|
const sanitizer = new TerminalSanitizer(64)
|
|
expect(sanitizer.push('\x1b]133;D;0\x07')).toEqual({ text: '', prompt: true, promptTail: '' })
|
|
expect(sanitizer.push('dsh> ')).toEqual({ text: 'dsh> ', prompt: false, promptTail: 'dsh> ' })
|
|
})
|
|
|
|
it('bounds and discards unterminated control sequences through their terminators', () => {
|
|
const oscBel = new TerminalSanitizer(8)
|
|
expect(oscBel.push(`\x1b]0;${'x'.repeat(16)}`)).toEqual({ text: '', prompt: false })
|
|
expect(oscBel.push('more\x07tail')).toEqual({ text: 'tail', prompt: false })
|
|
|
|
const oscSt = new TerminalSanitizer(8)
|
|
oscSt.push(`\x1b]0;${'x'.repeat(16)}`)
|
|
expect(oscSt.push('more\x1b')).toEqual({ text: '', prompt: false })
|
|
expect(oscSt.push('\\tail')).toEqual({ text: 'tail', prompt: false })
|
|
|
|
const oscDirectSt = new TerminalSanitizer(8)
|
|
oscDirectSt.push(`\x1b]0;${'x'.repeat(16)}`)
|
|
expect(oscDirectSt.push('more\x1b\\tail')).toEqual({ text: 'tail', prompt: false })
|
|
|
|
const oscFalseSt = new TerminalSanitizer(8)
|
|
oscFalseSt.push(`\x1b]0;${'x'.repeat(16)}`)
|
|
oscFalseSt.push('\x1b')
|
|
expect(oscFalseSt.push('more')).toEqual({ text: '', prompt: false })
|
|
expect(oscFalseSt.push('\x07tail')).toEqual({ text: 'tail', prompt: false })
|
|
|
|
const oscNonTerminatingEscape = new TerminalSanitizer(8)
|
|
oscNonTerminatingEscape.push(`\x1b]0;${'x'.repeat(16)}`)
|
|
expect(oscNonTerminatingEscape.push('more\x1bxmore\x07tail')).toEqual({ text: 'tail', prompt: false })
|
|
|
|
const csi = new TerminalSanitizer(8)
|
|
expect(csi.push(`\x1b[${'1'.repeat(16)}`)).toEqual({ text: '', prompt: false })
|
|
expect(csi.push('123')).toEqual({ text: '', prompt: false })
|
|
expect(csi.push('mtext')).toEqual({ text: 'text', prompt: false })
|
|
|
|
const flushed = new TerminalSanitizer(8)
|
|
flushed.push(`\x1b]0;${'x'.repeat(16)}`)
|
|
expect(flushed.flush()).toBe('')
|
|
expect(flushed.push('text')).toEqual({ text: 'text', prompt: false })
|
|
})
|
|
})
|