import { describe, it, expect } from 'vitest';
import { stripThinkingTokens } from './strip-thinking.js';

describe('stripThinkingTokens', () => {
  it('returns plain text unchanged (modulo trim)', () => {
    expect(stripThinkingTokens('hello world')).toBe('hello world');
    expect(stripThinkingTokens('  padded  ')).toBe('padded');
  });

  it('handles empty input', () => {
    expect(stripThinkingTokens('')).toBe('');
  });

  it('strips a DeepSeek-style <think> block', () => {
    expect(stripThinkingTokens('<think>internal reasoning</think>answer')).toBe('answer');
  });

  it('strips multiple <think> blocks non-greedily', () => {
    const input = '<think>a</think>first<think>b</think>second';
    expect(stripThinkingTokens(input)).toBe('firstsecond');
  });

  it('strips multiline <think> content', () => {
    const input = '<think>line1\nline2\n</think>\nresult';
    expect(stripThinkingTokens(input)).toBe('result');
  });

  it('leaves an unclosed <think> block intact', () => {
    const input = '<think>never closed... answer';
    expect(stripThinkingTokens(input)).toBe('<think>never closed... answer');
  });

  it('strips generic <|thinking|> blocks', () => {
    expect(stripThinkingTokens('<|thinking|>hmm<|/thinking|>ok')).toBe('ok');
  });

  it('strips Gemma-style thought + channel marker', () => {
    expect(stripThinkingTokens('thought\n<channel|>visible')).toBe('visible');
  });

  it('strips paired <channel|> blocks', () => {
    expect(stripThinkingTokens('<channel|>internal<channel|>visible')).toBe('visible');
  });

  it('preserves unicode content outside thinking blocks', () => {
    expect(stripThinkingTokens('<think>思考</think>日本語の回答')).toBe('日本語の回答');
  });

  it('returns empty string when the whole response is a thinking block', () => {
    expect(stripThinkingTokens('<think>only thoughts</think>')).toBe('');
  });
});
