/**
 * 工具函数快速验证
 */
async function main() {
  const { AsyncPool } = await import('../utils/async-pool.js');
  const { cleanThinkingText, truncateAtBoundary } = await import('../utils/content-cleaner.js');
  const { evaluateOutlineQuality } = await import('../utils/outline-quality.js');

  // 1. AsyncPool
  console.log('--- AsyncPool ---');
  const pool = new AsyncPool(4);
  const results = await pool.runAll([
    { fn: async () => { await sleep(50); return 1; } },
    { fn: async () => { await sleep(30); return 2; } },
    { fn: async () => { await sleep(10); return 3; } },
  ]);
  console.log('AsyncPool:' + JSON.stringify(results) + ' (expect [1,2,3])');

  // 2. Content Cleaner
  console.log('\n--- Content Cleaner ---');
  const withThink = '<think>hmm</think>\n\n# Title\nContent here.';
  const cleaned = cleanThinkingText(withThink);
  console.log('Clean think:' + JSON.stringify(cleaned?.substring(0, 30)));

  const longText = 'First paragraph. Second paragraph. Third paragraph.';
  const truncated = truncateAtBoundary(longText, 16, 'paragraph');
  console.log('Truncate(' + truncated.length + '):' + JSON.stringify(truncated));

  // 3. Outline Quality
  console.log('\n--- Outline Quality ---');
  const goodOutline = [
    { number: 1, title: 'Chapter 1', summary: 'Intro', keyPoints: ['a', 'b'], estimatedWords: 500 },
    { number: 2, title: 'Chapter 2', summary: 'Deep dive', keyPoints: ['c'], estimatedWords: 300 },
  ];
  const result = evaluateOutlineQuality(goodOutline, {}, 2);
  console.log('Good outline: passed=' + result.passed + ', score=' + result.score);

  const badOutline = [
    { number: 1, title: 'Same', summary: '', keyPoints: [], estimatedWords: 100 },
    { number: 1, title: 'Same', summary: '', keyPoints: [], estimatedWords: 100 },
  ];
  const badResult = evaluateOutlineQuality(badOutline, {}, 2);
  console.log('Bad outline: passed=' + badResult.passed + ', score=' + badResult.score + ', warnings=' + badResult.warnings.length);
  badResult.warnings.forEach((w: any) => console.log('  WARN: ' + w.severity + ' - ' + w.message));

  console.log('\n=== UTILS PASSED ===');
}

function sleep(ms: number) { return new Promise((r: any) => setTimeout(r, ms)); }

main().catch(err => { console.error('FAIL:', err.message); process.exit(1); });
