stdio-chat.spec.ts 961 B

123456789101112131415161718192021222324252627282930313233
  1. import { EventEmitter } from 'node:events'
  2. import type { Context } from 'cordis'
  3. import { describe, expect, test, vi } from 'vitest'
  4. const createInterface = vi.hoisted(() => vi.fn(() => {
  5. const reader = new EventEmitter() as EventEmitter & { close(): void }
  6. reader.close = vi.fn()
  7. return reader
  8. }))
  9. vi.mock('node:readline', () => ({ createInterface }))
  10. function fakeContext(): Context {
  11. return {
  12. agents: { get: vi.fn() },
  13. on: vi.fn(() => vi.fn()),
  14. effect: vi.fn((callback: () => () => void) => callback()),
  15. } as unknown as Context
  16. }
  17. describe('coding-agent stdio chat', () => {
  18. test('creates a terminal readline interface so TTY editing keys work', async () => {
  19. const { apply } = await import('../src/stdio-chat.ts')
  20. apply(fakeContext())
  21. expect(createInterface).toHaveBeenCalledWith({
  22. input: process.stdin,
  23. output: process.stdout,
  24. terminal: process.stdin.isTTY && process.stdout.isTTY,
  25. })
  26. })
  27. })