File size: 3,301 Bytes
c9c2d7e
 
 
 
46b394e
 
c9c2d7e
 
46b394e
c9c2d7e
46b394e
c9c2d7e
 
 
 
 
46b394e
c9c2d7e
 
46b394e
 
 
c9c2d7e
 
 
 
 
 
 
 
 
 
 
46b394e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pytest
import subprocess
import sys
import os
import json
from pathlib import Path

def test_cli_help():
    result = subprocess.run([sys.executable, "-m", "llm_agent_builder.cli", "--help"], capture_output=True, text=True)
    assert result.returncode == 0
    assert "LLM Agent Builder" in result.stdout

def test_cli_generate_agent(temp_output_dir):
    agent_name = "CLITestAgent"
    
    result = subprocess.run([
        sys.executable, "-m", "llm_agent_builder.cli", "generate",
        "--name", agent_name,
        "--output", temp_output_dir,
        "--model", "claude-3-5-sonnet-20241022",
        "--prompt", "Test prompt",
        "--task", "Test task"
    ], capture_output=True, text=True)
    
    assert result.returncode == 0
    assert f"Agent '{agent_name}' has been created" in result.stdout
    
    output_file = os.path.join(temp_output_dir, f"{agent_name.lower()}.py")
    assert os.path.exists(output_file)
    
    with open(output_file, "r") as f:
        content = f.read()
        assert f"class {agent_name}:" in content
        assert "claude-3-5-sonnet-20241022" in content

def test_cli_list_agents(temp_output_dir):
    # First create an agent
    agent_name = "ListTestAgent"
    subprocess.run([
        sys.executable, "-m", "llm_agent_builder.cli", "generate",
        "--name", agent_name,
        "--output", temp_output_dir,
        "--prompt", "Test",
        "--task", "Test"
    ], capture_output=True, text=True)
    
    # Then list agents
    result = subprocess.run([
        sys.executable, "-m", "llm_agent_builder.cli", "list",
        "--output", temp_output_dir
    ], capture_output=True, text=True)
    
    assert result.returncode == 0
    assert agent_name.lower() in result.stdout.lower()

def test_cli_batch_generate(temp_output_dir):
    # Create a batch config file
    config = [
        {
            "name": "BatchAgent1",
            "prompt": "Test prompt 1",
            "task": "Test task 1",
            "model": "claude-3-5-sonnet-20241022",
            "provider": "anthropic"
        },
        {
            "name": "BatchAgent2",
            "prompt": "Test prompt 2",
            "task": "Test task 2",
            "model": "claude-3-5-sonnet-20241022",
            "provider": "anthropic"
        }
    ]
    
    config_file = os.path.join(temp_output_dir, "batch_config.json")
    with open(config_file, "w") as f:
        json.dump(config, f)
    
    result = subprocess.run([
        sys.executable, "-m", "llm_agent_builder.cli", "batch",
        config_file,
        "--output", temp_output_dir
    ], capture_output=True, text=True)
    
    assert result.returncode == 0
    assert "BatchAgent1" in result.stdout
    assert "BatchAgent2" in result.stdout
    
    # Verify files were created
    assert os.path.exists(os.path.join(temp_output_dir, "batchagent1.py"))
    assert os.path.exists(os.path.join(temp_output_dir, "batchagent2.py"))

def test_cli_invalid_agent_name():
    result = subprocess.run([
        sys.executable, "-m", "llm_agent_builder.cli", "generate",
        "--name", "Invalid Name!",
        "--prompt", "Test",
        "--task", "Test"
    ], capture_output=True, text=True)
    
    assert result.returncode != 0
    assert "Error" in result.stdout or "Error" in result.stderr