from pathlib import Path from pam_deploy_graph.script_runner import ScriptActionRunner def test_build_shell_action_command(): runner = ScriptActionRunner() command = runner.build_command( "publish-version", script_entry="deploy.sh", config_path="./config.txt", hash_code="abc", trace_file_path="./logs/trace.log", ) assert command == [ "bash", "./deploy.sh", "--config", "./config.txt", "--action", "publish-version", "--hash-code", "abc", "--trace-file", "./logs/trace.log", ] def test_build_powershell_action_command(): runner = ScriptActionRunner() command = runner.build_command( "rollback-ip", script_entry="deploy.ps1", config_path=".\\config.txt", ip="192.168.1.10", stop_first=True, ) assert command == [ "powershell", "-File", ".\\deploy.ps1", "-ConfigPath", ".\\config.txt", "-Action", "rollback-ip", "-Ip", "192.168.1.10", "-RollbackStopFirst", ] def test_shell_rollback_uses_query_parameters_not_form_body(): text = Path("doc_scripts/deploy.sh").read_text(encoding="utf-8") start = text.index("rollback_ip()") end = text.index("run_manual_rollback()", start) rollback_block = text[start:end] assert "/api/mcp/version/upgrade/rollback?${rollback_query}" in rollback_block assert "application/x-www-form-urlencoded" not in rollback_block def test_powershell_rollback_uses_query_parameters_not_form_body(): text = Path("doc_scripts/deploy.ps1").read_text(encoding="utf-8") start = text.index("function Invoke-Rollback") end = text.index("function Invoke-IpDeploy", start) rollback_block = text[start:end] assert "/api/mcp/version/upgrade/rollback?$query" in rollback_block assert "-Body $body" not in rollback_block assert "application/x-www-form-urlencoded" not in rollback_block