const http = require('http');

function get(url) {
  return new Promise((resolve, reject) => {
    http.get(url, res => {
      let data = '';
      res.on('data', c => data += c);
      res.on('end', () => resolve(JSON.parse(data)));
    }).on('error', reject);
  });
}

async function main() {
  // 查书籍详情
  const detail = await get('http://localhost:3000/api/book-generator/langgraph/books/194');
  const b = detail.data.book;
  
  console.log('=== 策略3 测试结果 ===');
  console.log('状态:', b.genStage, '进度:', b.progress + '%');
  
  // 规划结果
  if (b.bookAnalysis) {
    const plan = JSON.parse(b.bookAnalysis);
    console.log('\n--- AI规划 ---');
    console.log('大纲层级:', plan.genLevel);
    console.log('书籍类型:', plan.bookType || 'N/A');
    console.log('写作风格:', plan.writingStyle);
    console.log('结构逻辑:', plan.structureLogic);
    console.log('内容深度:', plan.contentDepth);
    console.log('目标读者:', (plan.targetAudienceAnalysis || '').slice(0, 80));
    console.log('规划理由:', (plan.reasoning || '').slice(0, 120));
  }
  
  // 章节
  const chapters = b.chapters || [];
  console.log('\n--- 章节 ---');
  for (const c of chapters) {
    console.log(`[${c.level}] ${c.number}. ${c.title}`);
    console.log(`  状态: ${c.genStage}, 字数: ${c.wordCount || (c.content ? c.content.length : 0)}`);
    if (c.content) {
      console.log(`  正文预览: ${c.content.replace(/\n/g, ' ').slice(0, 200)}...`);
    }
  }

  console.log('\n✅ 策略3（逐章内聚）测试完成');
}

main().catch(e => console.error('失败:', e));
