import { describe, expect, it } from 'vitest';
import { resolveToolBudget } from '../inference/budget.js';
import type { Agent } from '../../types/api.js';

const BASE_AGENT: Agent = {
  id: 'test-agent',
  name: 'Test',
  description: 'test',
  system_prompt: '',
  temperature: 0.7,
  top_p: null,
  top_k: null,
  min_p: null,
  presence_penalty: null,
  top_n_sigma: null,
  dry_multiplier: null,
  dry_base: null,
  dry_allowed_length: null,
  dry_penalty_last_n: null,
  tools: ['view_file'],
  model: null,
  source: 'global',
  max_tool_calls: null,
  steps: null,
};

describe('resolveToolBudget', () => {
  it('returns 100 when agent is null (no-agent raw chat)', () => {
    expect(resolveToolBudget(null)).toBe(100);
  });

  it('returns 100 when agent has no max_tool_calls override', () => {
    expect(resolveToolBudget(BASE_AGENT)).toBe(100);
  });

  it('returns max_tool_calls when agent overrides the default', () => {
    const agent: Agent = { ...BASE_AGENT, max_tool_calls: 25 };
    expect(resolveToolBudget(agent)).toBe(25);
  });

  it('returns 0 when max_tool_calls is explicitly 0 (text-only mode)', () => {
    const agent: Agent = { ...BASE_AGENT, max_tool_calls: 0 };
    expect(resolveToolBudget(agent)).toBe(0);
  });
});
