Skip to content

Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.

TypeScript
3.2 KB
Raw Blame
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { authFailureHint } from '../agents/computer/daemon.js'
import { classifyEngineFailure, ENGINE_IDS, type EngineId } from '../agents/computer/engine.js'

test('authFailureHint provides specific guidance for every supported engine', () => {
  for (const engine of ENGINE_IDS) {
    const hint = authFailureHint(engine as EngineId, '401 invalid api key or unauthorized')
    assert.ok(hint.length > 0, `hint for ${engine} should not be empty`)
    // None of the non-codex engines should mention Codex
    if (engine !== 'codex') {
      assert.ok(!hint.includes('Open Codex'), `hint for ${engine} should not tell the user to Open Codex: "${hint}"`)
    }
  }
})

test('authFailureHint correctly mentions the relevant CLI/tool for each engine', () => {
  assert.match(authFailureHint('claude', 'quota exceeded'), /Claude Code/)
  assert.match(authFailureHint('codex', 'quota exceeded'), /Codex/)
  assert.match(authFailureHint('grok', 'quota exceeded'), /grok/)
  assert.match(authFailureHint('cursor', 'quota exceeded'), /cursor-agent/)
  assert.match(authFailureHint('opencode', 'quota exceeded'), /opencode/)
  assert.match(authFailureHint('pi', 'quota exceeded'), /pi/)
  assert.match(authFailureHint('gemini', 'quota exceeded'), /gemini/)
  assert.match(authFailureHint('qwen', 'quota exceeded'), /qwen/)
  assert.match(authFailureHint('antigravity', 'quota exceeded'), /agy/)
  assert.match(authFailureHint('zcode', 'quota exceeded'), /zcode/)
  assert.match(authFailureHint('maka', 'quota exceeded'), /maka/)
})

test('Codex authentication guidance signs in to the isolated runtime', () => {
  for (const detail of [
    'Not logged in',
    'Please sign in to continue',
    'Please sign in.',
    'Sign in to Codex',
    'Sign in with your ChatGPT account to continue',
    'You need to sign in before continuing',
    'Your sign-in has expired',
    'Log in to continue',
    'Please run /login',
  ]) {
    assert.equal(classifyEngineFailure(detail), 'authentication')
    assert.match(authFailureHint('codex', detail), /cumora agent computer --codex-login/)
  }
  for (const file of ['sign-in.md', 'docs/sign-in.md', 'docs/signin.md', 'C:\\docs\\sign-in.md']) {
    const detail = `filesystem failed while writing ${file}: EIO`
    assert.equal(classifyEngineFailure(detail), 'unknown')
    assert.match(authFailureHint('codex', detail), /daemon terminal for details/)
  }
})

test('authFailureHint handles context overflow and poisoned body sentinels', () => {
  assert.match(authFailureHint('gemini', 'context window overflowed max tokens'), /context window/)
  assert.match(authFailureHint('qwen', 'lone surrogate split emoji poisoned'), /poisoned/)
  assert.match(authFailureHint('gemini', 'unrelated socket reset error'), /daemon terminal for details/)
})

test('local startup failures get executable and sandbox guidance, not account advice', () => {
  const hint = authFailureHint('codex', 'process exited with code 1\nbwrap: execvp /home/quota/token/codex: No such file or directory')
  assert.match(hint, /executable path/)
  assert.match(hint, /sandbox/)
  assert.doesNotMatch(hint, /login|quota|unsandboxed|disable/i)
  assert.match(authFailureHint('codex', 'process terminated by SIGTERM'), /daemon terminal/)
})