#!/usr/bin/env python3
"""直接测试 extract_travel_info 函数

所有数据从 .invoice_cache 缓存中自动加载，无需手动构造样本数据。

用法:
    python scripts/test_travel_info.py
"""

import json
import sys
from pathlib import Path

# 项目根目录
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))  # noqa: E402

from src.doc.llm_extractor import extract_travel_info  # noqa: E402


def main() -> None:
    source_dir = ROOT / "scripts" / "data"

    if not source_dir.exists():
        print(f"源文件目录不存在: {source_dir}")
        sys.exit(1)

    print("=" * 60)
    print("测试 extract_travel_info（数据来自缓存）")
    print("=" * 60)
    print(f"源文件目录: {source_dir}")
    print()

    try:
        result = extract_travel_info(
            source_dir=source_dir,
        )
        print()
        print("=" * 60)
        print("提取结果:")
        print("=" * 60)
        print(json.dumps(result, ensure_ascii=False, indent=2))
        print()
        print("测试通过!")
    except Exception as e:
        print(f"测试失败: {e}")
        import traceback

        traceback.print_exc()
        sys.exit(1)


if __name__ == "__main__":
    main()
