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 { usageDiagnosticLines, usageDiagnosticText } from './usageDiagnostic'

describe('usageDiagnosticLines (issue #912)', () => {
  it('prints one line per view when the reasons differ', () => {
    expect(usageDiagnosticLines('Grok', [
      { view: 'credits', reason: 'http', httpStatus: 401 },
      { view: 'default', reason: 'timeout' }
    ])).toEqual([
      usageDiagnosticText('Grok', { view: 'credits', reason: 'http', httpStatus: 401 }),
      usageDiagnosticText('Grok', { view: 'default', reason: 'timeout' })
    ])
  })

  it('prints an identical reason ONCE, naming every view it applies to', () => {
    const lines = usageDiagnosticLines('Grok', [
      { view: 'credits', reason: 'http', httpStatus: 401 },
      { view: 'default', reason: 'http', httpStatus: 401 }
    ])
    expect(lines).toHaveLength(1)
    expect(lines[0]).toMatch(/^Credits view and Default view: Grok authentication failed \(HTTP 401\)/)
  })

  it('keeps a single diagnostic byte-identical to the per-view text', () => {
    const d = { view: 'credits', reason: 'network' } as const
    expect(usageDiagnosticLines('Grok', [d])).toEqual([usageDiagnosticText('Grok', d)])
  })

  it('does not name a view twice when it reports the same reason twice', () => {
    expect(usageDiagnosticLines('Grok', [
      { view: 'credits', reason: 'timeout' },
      { view: 'credits', reason: 'timeout' }
    ])).toEqual([usageDiagnosticText('Grok', { view: 'credits', reason: 'timeout' })])
  })

  it('returns nothing for no diagnostics', () => {
    expect(usageDiagnosticLines('Grok', undefined)).toEqual([])
    expect(usageDiagnosticLines('Grok', [])).toEqual([])
  })
})

describe('Grok 401 hint (issue #983)', () => {
  const d401 = { view: 'credits', reason: 'http', httpStatus: 401 } as const

  it('says that starting a Grok session refreshes the saved credentials', () => {
    const [line] = usageDiagnosticLines('Grok', [d401], 'grok')
    expect(line).toMatch(/Grok authentication failed \(HTTP 401\)/)
    expect(line).toMatch(/Starting a Grok session refreshes the saved credentials/)
    expect(line).not.toMatch(/expired/)
    expect(usageDiagnosticText('Grok', d401, 'grok')).toMatch(/Starting a Grok session/)
  })

  it('keeps the generic text for a 403, for other providers, and without a provider id', () => {
    const generic = /Check the CLI authentication on the machine running this project\.$/
    expect(usageDiagnosticLines('Grok', [{ ...d401, httpStatus: 403 }], 'grok')[0]).toMatch(generic)
    expect(usageDiagnosticLines('Codex', [d401], 'codex')[0]).toMatch(generic)
    expect(usageDiagnosticLines('Grok', [d401])[0]).toMatch(generic)
  })
})