#!/usr/bin/env python3
"""
Test runner for then chaining tests to verify they fail before implementation
"""

import unittest
import sys
import os

# Add the src directory to the Python path
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'src'))

# Import the test class
from tests.test_interpreter import TestAlloyFeatures

def run_chaining_tests():
    """Run all then chaining tests"""
    # Create test suite with just chaining tests
    suite = unittest.TestSuite()
    
    # Add all chaining tests
    chaining_tests = [
        'test_then_chaining_basic',
        'test_then_chaining_multiple',
        'test_then_chaining_data_flow',
        'test_then_chaining_error_propagation',
        'test_then_chaining_with_agents',
        'test_then_chaining_agent_to_tool',
        'test_then_chaining_complex_pipeline',
        'test_then_chaining_with_nested_calls',
        'test_then_chaining_error_in_middle',
        'test_then_chaining_single_assignment'
    ]
    
    for test_name in chaining_tests:
        suite.addTest(TestAlloyFeatures(test_name))
    
    # Run the tests
    runner = unittest.TextTestRunner(verbosity=2)
    result = runner.run(suite)
    
    # Print summary
    print(f"\n=== CHAINING TESTS SUMMARY ===")
    print(f"Tests run: {result.testsRun}")
    print(f"Failures: {len(result.failures)}")
    print(f"Errors: {len(result.errors)}")
    
    if result.failures:
        print("\nFAILURES:")
        for test, traceback in result.failures:
            print(f"  - {test}")
    
    if result.errors:
        print("\nERRORS:")
        for test, traceback in result.errors:
            print(f"  - {test}")
    
    print(f"\nAll tests should FAIL since chaining is not yet implemented!")
    
    return len(result.failures) + len(result.errors)

if __name__ == '__main__':
    failures = run_chaining_tests()
    sys.exit(0 if failures > 0 else 1)  # Success if tests fail (as expected)