#!/usr/bin/env python3
"""
测试 Channel 选择逻辑

这个脚本测试 processor 是否能正确根据配置选择 File Channel 或 Celery Channel。
"""

import sys
from pathlib import Path

# 添加 sandai 包到路径
sys.path.insert(0, str(Path(__file__).parent.parent))

from sandai.operator.processor import BatchProcessor
from sandai.operator.channel import FileChannel, CeleryChannel


def test_file_channel_selection():
    """测试 File Channel 选择"""
    print("Testing File Channel selection...")
    
    processor = BatchProcessor(name="test", version="1.0.0")
    
    # 配置使用 File Channel (默认)
    processor.config = {
        "channel.type": "file",
        "channel.file": {
            "input_path": "test_input.jsonl",
            "output_path": "test_output.jsonl"
        }
    }
    
    print("✓ File Channel configuration set")


def test_celery_channel_selection():
    """测试 Celery Channel 选择"""
    print("Testing Celery Channel selection...")
    
    processor = BatchProcessor(name="test", version="1.0.0")
    
    # 配置使用 Celery Channel
    processor.config = {
        "channel.type": "celery",
        "channel.celery": {
            "broker_url": "redis://localhost:6379/0",
            "queue_name": "test_queue"
        }
    }
    
    print("✓ Celery Channel configuration set")


def test_default_channel_selection():
    """测试默认 Channel 选择"""
    print("Testing default Channel selection...")
    
    processor = BatchProcessor(name="test", version="1.0.0")
    
    # 不设置 channel.type，应该默认使用 File Channel
    processor.config = {}
    
    print("✓ Default Channel configuration set")


def main():
    """主函数"""
    print("Channel Selection Test")
    print("=" * 50)
    
    try:
        test_file_channel_selection()
        test_celery_channel_selection()
        test_default_channel_selection()
        
        print("\n✓ All channel selection tests passed!")
        print("\nNote: This only tests configuration parsing.")
        print("To fully test Celery Channel, you need:")
        print("1. Redis server running")
        print("2. Celery installed (pip install celery)")
        print("3. Run the full examples with actual task processing")
        
    except Exception as e:
        print(f"\n✗ Test failed: {e}")
        import traceback
        traceback.print_exc()


if __name__ == "__main__":
    main()