Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

2.6 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import type { CanvasNode } from '../state/workspace'
import { canCopyFilesToClipboard, selectedLocalFilePaths } from './canvas-file-copy'

const node = (
  id: string,
  type: CanvasNode['type'],
  filePath: string,
  data: Record<string, unknown> = {}
): CanvasNode =>
  ({
    id,
    type,
    selected: true,
    position: { x: 0, y: 0 },
    data: { title: id, color: '#fff', group: null, filePath, ...data }
  }) as CanvasNode

describe('selectedLocalFilePaths', () => {
  it('returns selected local file-backed nodes once and in canvas order', () => {
    expect(
      selectedLocalFilePaths([
        node('image', 'editor', '/tmp/image.png'),
        node('video', 'video', '/tmp/video.mp4'),
        node('html', 'web', '/tmp/page.html'),
        node('duplicate', 'editor', '/tmp/image.png')
      ])
    ).toEqual(['/tmp/image.png', '/tmp/video.mp4', '/tmp/page.html'])
  })

  it('copies nothing at all from a relay tab, whose paths describe the PEER disk', () => {
    // Not "filters the remote ones out": in a relay tab EVERY path is the peer's, and the local
    // statSync can silently match a same-named local file. The whole gesture is off.
    expect(
      selectedLocalFilePaths([node('image', 'editor', '/home/me/proj/src/x.ts')], {
        projectIsRelay: true
      })
    ).toEqual([])
    expect(
      selectedLocalFilePaths([node('image', 'editor', '/home/me/proj/src/x.ts')], {
        projectIsRelay: false
      })
    ).toEqual(['/home/me/proj/src/x.ts'])
  })

  it('excludes unselected, remote, missing and non-file node kinds', () => {
    const unselected = node('unselected', 'editor', '/tmp/a')
    unselected.selected = false
    expect(
      selectedLocalFilePaths([
        unselected,
        node('remote', 'editor', '/tmp/b', { sshFs: true }),
        node('missing', 'video', '/tmp/c', { fileMissing: true }),
        node('diff', 'diff', '/tmp/d'),
        node('url', 'web', '')
      ])
    ).toEqual([])
  })
})

describe('canCopyFilesToClipboard', () => {
  it('is the macOS and Windows desktop app only', () => {
    expect(canCopyFilesToClipboard({ mac: true, windows: false }, false)).toBe(true)
    expect(canCopyFilesToClipboard({ mac: false, windows: true }, false)).toBe(true)
    expect(canCopyFilesToClipboard({ mac: false, windows: false }, false)).toBe(false)
  })

  it('never claims the keystroke in the Server Edition, whose bridge cannot write files', () => {
    expect(canCopyFilesToClipboard({ mac: true, windows: false }, true)).toBe(false)
    expect(canCopyFilesToClipboard({ mac: false, windows: true }, true)).toBe(false)
  })
})