from pathlib import Path from pam_deploy_graph.agent import PamDeployAgent from pam_deploy_graph.fake_runner import FakeActionRunner PARAMS = { "HOME_BASE_URL": "https://pam.home.example.com", "CLIENT_ID": "client", "CLIENT_SECRET": "secret", "AIRPORT_CODE": "HET", "APP_NAME": "PAM", "MODULE_NAME": "Node", "VERSION_NUMBER": "2.0.5", "ZIP_FILE_PATH": "C:/pkg.zip", } def test_run_deploy_flow_success(tmp_path: Path): agent = PamDeployAgent(fake_runner=FakeActionRunner()) state = agent.create_state( params=PARAMS, execution_strategy="fake", config_path=str(tmp_path / "config.txt"), ) agent.run_deploy_flow(state) assert state.pending_confirmation == "" assert set(state.ip_states) == {"192.168.1.10", "192.168.1.11"} assert all(item["status"] == "SUCCESS" for item in state.ip_states.values()) def test_run_deploy_flow_stops_on_verify_failure(tmp_path: Path): fake = FakeActionRunner( { "verify-ip:192.168.1.10": { "ACTION": "verify-ip", "IP": "192.168.1.10", "SUCCESS": "false", "MESSAGE": "health check failed", } } ) agent = PamDeployAgent(fake_runner=fake) state = agent.create_state( params=PARAMS, execution_strategy="fake", config_path=str(tmp_path / "config.txt"), ) agent.run_deploy_flow(state) assert state.pending_confirmation == "rollback-ip:192.168.1.10" assert state.ip_states["192.168.1.10"]["status"] == "FAILED" assert state.ip_states["192.168.1.10"]["rollback_status"] == "PENDING_AGENT_CONFIRMATION" assert "192.168.1.11" not in state.ip_states assert any(event["type"] == "CONFIRMATION_REQUIRED" for event in state.events)