|
5 | 5 | using DeterministicModel instead of real LLM models. |
6 | 6 | """ |
7 | 7 |
|
8 | | -import tempfile |
9 | | -from pathlib import Path |
10 | | -from unittest.mock import patch |
| 8 | +from codeclash import CONFIG_DIR |
| 9 | +from main import main_cli |
11 | 10 |
|
12 | | -import yaml |
13 | | -from minisweagent.models.test_models import DeterministicModel |
14 | 11 |
|
15 | | -from main import main |
16 | | - |
17 | | - |
18 | | -def test_main_battlesnake_integration(): |
19 | | - """ |
20 | | - Integration test for main.py with configs/battlesnake.yaml. |
21 | | - Success criterion: execution completes without exceptions. |
22 | | - """ |
23 | | - # Create a temporary config file with DeterministicModel settings |
24 | | - config_path = "configs/battlesnake.yaml" |
25 | | - |
26 | | - # Read the original config |
27 | | - with open(config_path) as f: |
28 | | - config = yaml.safe_load(f) |
29 | | - |
30 | | - # Create a temporary directory for test artifacts |
31 | | - with tempfile.TemporaryDirectory() as temp_dir: |
32 | | - temp_config_path = Path(temp_dir) / "test_battlesnake.yaml" |
33 | | - |
34 | | - # Reduce rounds to 1 for faster testing |
35 | | - config["tournament"]["rounds"] = 1 |
36 | | - |
37 | | - # Write the modified config |
38 | | - with open(temp_config_path, "w") as f: |
39 | | - yaml.dump(config, f) |
40 | | - |
41 | | - def mock_get_agent(original_get_agent): |
42 | | - """Wrapper to replace agent models with DeterministicModel""" |
43 | | - |
44 | | - def wrapper(config, game_context, environment): |
45 | | - agent = original_get_agent(config, game_context, environment) |
46 | | - print("In wrapper, got agent of type ", type(agent)) |
47 | | - |
48 | | - # Replace model if the agent has one (specifically for MiniSWEAgent) |
49 | | - if hasattr(agent, "agent") and hasattr(agent.agent, "model"): |
50 | | - print(f"Replacing model for agent {agent.name}") |
51 | | - # Create DeterministicModel with the specified command |
52 | | - deterministic_model = DeterministicModel( |
53 | | - outputs=["```bash\necho 'COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT'\n```"] |
54 | | - ) |
55 | | - agent.agent.model = deterministic_model |
56 | | - |
57 | | - return agent |
58 | | - |
59 | | - return wrapper |
60 | | - |
61 | | - # Import the get_agent function and patch it where it's used in the tournaments |
62 | | - from codeclash.agents import get_agent |
63 | | - |
64 | | - # Run the main function with cleanup enabled |
65 | | - with patch( |
66 | | - "codeclash.tournaments.pvp.get_agent", |
67 | | - side_effect=mock_get_agent(get_agent), |
68 | | - ): |
69 | | - # This should complete without raising any exceptions |
70 | | - main(temp_config_path, cleanup=True, push_agent=False) |
| 12 | +def test_pvp_battlesnake(): |
| 13 | + config_path = CONFIG_DIR / "test_configs" / "battlesnake_pvp_test.yaml" |
| 14 | + main_cli(["-c", str(config_path)]) |
0 commit comments