#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""测试增强的JSON解析器"""

import sys
from pathlib import Path

# 添加项目根目录到路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

from lib.batch_match_analyzer import clean_json_text, parse_batch_match_response

# 模拟Pro模型的错误输出（包含trib{）
error_json = '''```json
[
  {
    "特征": "健忘",
    "分数": 0.00,
    "说明": "测试1"
  },
trib{
    "特征": "抗压能力",
    "分数": 0.00,
    "说明": "测试2"
  },
  {
    "特征": "公司最底层",
    "分数": 0.00,
    "说明": "测试3"
  }
]
```'''

print('=' * 70)
print('测试增强的JSON解析器')
print('=' * 70)

print('\n原始JSON（包含错误trib{）:')
print(error_json[:150] + '...')

print('\n清理后的JSON:')
cleaned = clean_json_text(error_json)
print(cleaned[:150] + '...')

print('\n尝试解析...')
result = parse_batch_match_response(error_json)
print(f'解析结果数量: {len(result)}')

if len(result) > 1:
    print('✅ 成功解析！')
    for i, r in enumerate(result):
        print(f"  {i+1}. {r.get('特征')}: {r.get('分数')}")
else:
    print('❌ 解析失败')
    print(f"返回: {result}")
