import { describe, expect, it } from 'vitest';

import {
  DEFAULT_AGENT_COMPRESSION_TOKEN_THRESHOLD,
  resolveAgentCompressionTokenThreshold,
} from './compression-threshold';

describe('resolveAgentCompressionTokenThreshold', () => {
  it('uses the lower value between 85 percent and reserved context', () => {
    expect(
      resolveAgentCompressionTokenThreshold({
        contextWindowTokens: 128_000,
        maxOutputTokens: 64_000,
      }),
    ).toBe(108_800);
    expect(
      resolveAgentCompressionTokenThreshold({
        contextWindowTokens: 128_000,
        generationConfig: { maxCompletionTokens: 32_000 },
        systemPrompt: 'a'.repeat(10_000),
      }),
    ).toBe(85_595);
  });

  it('falls back to 30K when the context window is unavailable', () => {
    for (const contextWindowTokens of [undefined, 0, 'invalid']) {
      expect(
        resolveAgentCompressionTokenThreshold({ contextWindowTokens }),
      ).toBe(DEFAULT_AGENT_COMPRESSION_TOKEN_THRESHOLD);
    }
  });
});
