""" 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