#!/usr/bin/env python3
"""
Test file to verify the clean agent syntax changes work correctly.
This tests only the parser without running the full interpreter.
"""

import sys
import os

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

def test_syntax_validation():
    """Test that our syntax changes are valid Python code"""
    
    # Test 1: Check if the module can be imported
    try:
        from alloy import AlloyLexer
        alloy_lexer = AlloyLexer()
        print("✅ Module import successful")
    except Exception as e:
        print(f"❌ Module import failed: {e}")
        return False
    
    # Test 2: Check if new tokens are defined
    expected_tokens = ['WITH', 'TOOLS']
    for token in expected_tokens:
        if token in alloy_lexer.tokens:
            print(f"✅ Token {token} found")
        else:
            print(f"❌ Token {token} missing")
            return False
    
    # Test 3: Check if new reserved words are defined
    expected_reserved = ['with', 'tools']
    for word in expected_reserved:
        if word in alloy_lexer.reserved:
            print(f"✅ Reserved word '{word}' found")
        else:
            print(f"❌ Reserved word '{word}' missing")
            return False
    
    # Test 4: Check if parser functions exist
    expected_functions = [
        'p_tuple_assignment',
        'p_identifier_list', 
        'p_agent_definition',
        'p_tool_list'
    ]
    
    for func_name in expected_functions:
        if hasattr(alloy_lexer, func_name):
            print(f"✅ Parser function {func_name} found")
        else:
            print(f"❌ Parser function {func_name} missing")
            return False
    
    print("✅ All syntax validation tests passed!")
    return True

def test_simple_examples():
    """Test some simple example code snippets"""
    
    try:
        from alloy import AlloyParser
        parser = AlloyParser()
        
        # Simple examples to test
        examples = [
            ('claude = agent "claude-3.5-sonnet"', "Agent definition"),
            ('result, error = some_call()', "Tuple assignment"),
            ('researcher = agent "claude-3.5-sonnet" with tools web_search, read_files', "Agent with tools")
        ]
        
        for code, description in examples:
            try:
                # Just test parsing, not execution
                ast = parser.parse(code)
                print(f"✅ {description}: {code}")
            except Exception as e:
                print(f"❌ {description}: {code} - Error: {e}")
                return False
        
        print("✅ All parsing tests passed!")
        return True
        
    except Exception as e:
        print(f"❌ Testing failed: {e}")
        return False

if __name__ == "__main__":
    print("🧪 Testing Alloy Clean Agent Syntax Updates")
    print("=" * 50)
    
    if test_syntax_validation():
        print("\n" + "=" * 50)
        test_simple_examples()
    
    print("\n🎯 Syntax testing complete!")