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.9 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { pinNeutralMachineNoun } from './testMachineNoun'
import { presentAccount } from './accountPresentation'


// The copy under test names the machine, and `machineNoun()` sniffs the host — pin it so the
// literals below hold on a Mac too (see testMachineNoun.ts).
pinNeutralMachineNoun()

describe('presentAccount', () => {
  it('uses a chosen name before the email and identifies a local login', () => {
    expect(presentAccount({ label: 'Work', email: '[email protected]' })).toEqual({
      identity: 'Work',
      provenance: 'Local',
      tooltip: 'Work ([email protected]) · This computer'
    })
  })

  it('falls back to email and never exposes system or managed storage terminology', () => {
    expect(
      presentAccount({
        label: 'System Codex account',
        email: '[email protected]'
      })
    ).toEqual({
      identity: '[email protected]',
      provenance: 'Local',
      tooltip: '[email protected] · This computer'
    })
    // A row still carrying the generated placeholder collapses to "Default account".
    expect(presentAccount({ label: 'New Codex account' }).identity).toBe('Default account')
    // The provenance/tooltip must never leak the credential-storage kind.
    const t = presentAccount({ label: 'New Codex account' }).tooltip
    expect(t).not.toMatch(/managed|system/i)
  })

  it('uses one SSH provenance format with the friendly machine name', () => {
    expect(
      presentAccount({
        email: '[email protected]',
        host: 'corvin@devbox',
        machineLabel: 'Ubuntu WSL'
      })
    ).toEqual({
      identity: '[email protected]',
      provenance: 'SSH · Ubuntu WSL',
      tooltip: '[email protected] · SSH corvin@devbox'
    })
  })

  it('falls back to the raw host when no friendly machine label is saved', () => {
    // The `host ?` branch is provenance's load-bearing local/SSH split — with the machineLabel
    // absent the raw `user@host` must still read as SSH, never as Local.
    expect(presentAccount({ email: 'r@x', host: 'me@box' }).provenance).toBe('SSH · me@box')
  })

  it('gives a linked config dir its own provenance, with the path in the tooltip', () => {
    // A linked account is local, but "Local" alone loses the one fact that identifies it: WHICH
    // dir. Removing it keeps that folder, so the path is what the user is deciding about.
    expect(
      presentAccount({ label: 'second', email: '[email protected]', linked: true, configDir: '/home/me/.claude-2' })
    ).toEqual({
      identity: 'second',
      provenance: 'Linked',
      tooltip: 'second ([email protected]) · Linked /home/me/.claude-2'
    })
  })

  it('never calls a remote account linked (a linked dir is local by definition)', () => {
    const p = presentAccount({ email: 'r@x', host: 'me@box', linked: true, configDir: '/nope' })
    expect(p.provenance).toBe('SSH · me@box')
    expect(p.tooltip).toBe('r@x · SSH me@box')
  })
})