Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

5.0 KB
Raw Blame
import { describe, expect, it } from 'vitest';

import {
  buildHeterogeneousAgentAuthRequiredError,
  buildHeterogeneousAgentCliNotFoundError,
  getHeterogeneousAgentConfig,
  isHeterogeneousAgentAuthRequired,
  isRemoteHeterogeneousType,
  resolveHeterogeneousAgentCommand,
} from './config';
import { getHeterogeneousTypeLabel } from './labels';

describe('heterogeneous agent config', () => {
  it('resolves Copilot descriptor metadata by type', () => {
    expect(getHeterogeneousAgentConfig('copilot')).toMatchObject({
      auth: { signInCommand: 'copilot login' },
      defaultCommand: 'copilot',
      install: {
        commands: [
          'curl -fsSL https://gh.io/copilot-install | bash',
          'npm install -g @github/copilot',
        ],
        docsUrl: 'https://docs.github.com/en/copilot/how-tos/copilot-cli',
      },
      title: 'GitHub Copilot',
      type: 'copilot',
    });
  });

  it('resolves commands from descriptors and fails loudly for unknown types', () => {
    expect(resolveHeterogeneousAgentCommand('claude-code')).toBe('claude');
    expect(resolveHeterogeneousAgentCommand('copilot')).toBe('copilot');
    expect(resolveHeterogeneousAgentCommand('claude-code', ' claude-beta ')).toBe('claude-beta');
    expect(() => resolveHeterogeneousAgentCommand('unknown-agent')).toThrow(
      'Unknown local heterogeneous agent type: "unknown-agent"',
    );
  });

  it('builds auth guidance from descriptor metadata', () => {
    expect(isHeterogeneousAgentAuthRequired('amp', 'Please log in before continuing')).toBe(true);
    expect(isHeterogeneousAgentAuthRequired('trae', 'Please sign in before continuing')).toBe(true);
    expect(buildHeterogeneousAgentAuthRequiredError({ agentType: 'amp' })).toMatchObject({
      agentType: 'amp',
      code: 'auth_required',
      command: 'amp',
      docsUrl: 'https://ampcode.com/manual',
      message: 'Amp could not authenticate. Run `amp login` or configure AMP_API_KEY, then retry.',
    });
    expect(isHeterogeneousAgentAuthRequired('kimi-code', 'No model configured')).toBe(true);
    expect(buildHeterogeneousAgentAuthRequiredError({ agentType: 'kimi-code' })).toMatchObject({
      agentType: 'kimi-code',
      code: 'auth_required',
      command: 'kimi',
      message: 'Kimi Code could not authenticate. Run `kimi`, use `/login`, then retry.',
    });
    expect(isHeterogeneousAgentAuthRequired('devin', 'Run devin auth login to continue')).toBe(
      true,
    );
    expect(buildHeterogeneousAgentAuthRequiredError({ agentType: 'devin' })).toMatchObject({
      command: 'devin',
      message: 'Devin could not authenticate. Run `devin auth login`, then retry.',
    });
    expect(isHeterogeneousAgentAuthRequired('cursor', 'Authentication required')).toBe(true);
    expect(buildHeterogeneousAgentAuthRequiredError({ agentType: 'cursor' })).toMatchObject({
      command: 'agent',
      docsUrl: 'https://cursor.com/docs/cli/installation',
      message: 'Cursor could not authenticate. Run `agent login`, then retry.',
    });
    expect(isHeterogeneousAgentAuthRequired('droid', 'Authentication required')).toBe(true);
    expect(buildHeterogeneousAgentAuthRequiredError({ agentType: 'droid' })).toMatchObject({
      command: 'droid',
      docsUrl: 'https://docs.factory.ai/cli/getting-started/quickstart',
      message:
        'Factory Droid could not authenticate. Run `droid` to sign in or configure FACTORY_API_KEY, then retry.',
    });
  });

  it('builds TRAE CLI installation guidance without duplicating the CLI suffix', () => {
    expect(buildHeterogeneousAgentCliNotFoundError({ agentType: 'trae' })).toMatchObject({
      agentType: 'trae',
      command: 'traecli',
      installCommands: [],
      message: 'TRAE CLI was not found. Install it and make sure `traecli` can be executed.',
    });
  });

  it('resolves display labels with safe fallbacks', () => {
    expect(getHeterogeneousTypeLabel('antigravity')).toBe('Antigravity');
    expect(getHeterogeneousTypeLabel('codebuddy')).toBe('CodeBuddy');
    expect(getHeterogeneousTypeLabel('copilot')).toBe('GitHub Copilot');
    expect(getHeterogeneousTypeLabel('hermes')).toBe('Hermes');
    expect(getHeterogeneousTypeLabel('future-runtime')).toBe('future-runtime');
    expect(getHeterogeneousTypeLabel('toString')).toBe('toString');
    expect(getHeterogeneousTypeLabel(null)).toBeUndefined();
    expect(getHeterogeneousTypeLabel()).toBeUndefined();
  });

  it('classifies local CLIs separately from remote platforms', () => {
    expect(isRemoteHeterogeneousType('amp')).toBe(false);
    expect(isRemoteHeterogeneousType('codebuddy')).toBe(false);
    expect(isRemoteHeterogeneousType('droid')).toBe(false);
    expect(isRemoteHeterogeneousType('devin')).toBe(false);
    expect(isRemoteHeterogeneousType('opencode')).toBe(false);
    expect(isRemoteHeterogeneousType('pi')).toBe(false);
    expect(isRemoteHeterogeneousType('qoder')).toBe(false);
    expect(isRemoteHeterogeneousType('trae')).toBe(false);
    expect(isRemoteHeterogeneousType('openclaw')).toBe(true);
    expect(isRemoteHeterogeneousType('hermes')).toBe(true);
  });
});