Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

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

import {
  BOT_FAILURE_REASONS,
  classifyBotFailureReason,
  isBotFailureAttentionWorthy,
} from '../botFailureReason';

describe('Hermes Bot failure reasons', () => {
  it('keeps the closed reason vocabulary stable', () => {
    expect([...BOT_FAILURE_REASONS]).toEqual([
      'runtime_offline',
      'queued_expired',
      'delivery_timeout',
      'agent_blocked',
      'cancelled',
      'provider_auth_or_access',
      'provider_quota_limit',
      'provider_rate_limit',
      'provider_server_error',
      'context_overflow',
      'missing_config',
      'model_unavailable',
      'unknown',
    ]);
  });

  it.each([
    ['Error code: 403 - forbidden', 'provider_auth_or_access'],
    ['authentication_error: account is out of funds', 'provider_auth_or_access'],
    ['Error code: 402 - payment required', 'provider_quota_limit'],
    ['quota exceeded for this billing period', 'provider_quota_limit'],
    ['Error code: 429 - Too Many Requests', 'provider_rate_limit'],
    ['Error code: 529 - overloaded_error', 'provider_server_error'],
    ['maximum context length is 128000 tokens', 'context_overflow'],
    ['No LLM provider configured', 'missing_config'],
    ['No access token found for profile', 'missing_config'],
    // Real errors when the Bot's custom provider was deleted (Pi start / send route guard).
    [
      "Error: pi: BYOM provider 'magpie-8a1e5ed8' cannot serve model 'auto/glm-5p3-flash' (provider absent, or it no longer offers this model); refusing to fall back to the Cindy gateway (would send prompts to the wrong endpoint).",
      'missing_config',
    ],
    [
      '[INVALID_PARAMS] provider "magpie-8e1b0a66" is unavailable; select an available provider before sending',
      'missing_config',
    ],
    // A transient native lookup failure is not a configuration problem.
    ["pi: BYOM provider 'p1' cannot serve model 'm1' (native provider resolution failed); refusing", 'unknown'],
    ["model 'gpt-9' not found", 'model_unavailable'],
    ['agent is blocked awaiting approval', 'agent_blocked'],
  ] as const)('classifies %s', (text, expected) => {
    expect(classifyBotFailureReason(text)).toBe(expected);
  });

  it('passes typed codes through and does not classify bare incidental numbers', () => {
    expect(classifyBotFailureReason({ reason: 'delivery_timeout' })).toBe('delivery_timeout');
    expect(classifyBotFailureReason('gate failed at line 502')).toBe('unknown');
    expect(classifyBotFailureReason('took 429 ms')).toBe('unknown');
  });

  it('only keeps durable user-action failures in needs-attention', () => {
    for (const reason of [
      'agent_blocked',
      'missing_config',
      'provider_auth_or_access',
      'provider_quota_limit',
    ] as const) {
      expect(isBotFailureAttentionWorthy(reason)).toBe(true);
    }
    for (const reason of BOT_FAILURE_REASONS.filter(
      (reason) => !['agent_blocked', 'missing_config', 'provider_auth_or_access', 'provider_quota_limit'].includes(reason),
    )) {
      expect(isBotFailureAttentionWorthy(reason)).toBe(false);
    }
  });
});