Spaces:
Sleeping
Sleeping
File size: 1,910 Bytes
27cdb3e | 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 | """
Regression tests for agent command extraction and curriculum sampling behavior.
"""
from agent.baseline_agent import BaselineAgent
from agent.devops_agent import DevOpsAgent
from training.curriculum import CurriculumScheduler
def test_extract_command_strips_common_prefixes_and_comments():
agent = DevOpsAgent(model_name="rule-based")
assert agent._extract_command("1. pip install flask") == "pip install flask"
assert agent._extract_command("Command: pip install flask") == "pip install flask"
assert agent._extract_command("Step 1: pip install flask") == "pip install flask"
assert agent._extract_command("pip install flask # install dependency") == "pip install flask"
def test_devops_agent_service_handler_uses_extracted_port():
agent = DevOpsAgent(model_name="rule-based")
error = "Connection refused on port 9090"
cmd = agent._handle_service_not_running(error, history=[])
assert cmd == "python /app/server.py --port 9090 &"
def test_baseline_agent_service_handler_uses_extracted_port():
agent = BaselineAgent()
error = "Connection refused on port 9090"
cmd = agent._fix_service_not_running(error, history=[])
assert cmd == "python /app/server.py --port 9090 &"
def test_curriculum_sample_level_non_frontier_half_never_returns_newest(monkeypatch):
scheduler = CurriculumScheduler()
scheduler._unlocked[2] = True
monkeypatch.setattr("training.curriculum.random.random", lambda: 0.9)
monkeypatch.setattr("training.curriculum.random.choice", lambda levels: levels[0])
sampled = scheduler.sample_level()
assert sampled == 1
def test_curriculum_sample_level_frontier_half_returns_newest(monkeypatch):
scheduler = CurriculumScheduler()
scheduler._unlocked[2] = True
monkeypatch.setattr("training.curriculum.random.random", lambda: 0.1)
sampled = scheduler.sample_level()
assert sampled == 2
|