|
| 1 | +# Test agentapi module with default settings (enable_agentapi = true) |
| 2 | +run "test_agentapi_defaults" { |
| 3 | + command = plan |
| 4 | + |
| 5 | + variables { |
| 6 | + agent_id = "test-agent-id" |
| 7 | + agent_name = "claude" |
| 8 | + module_dir_name = ".agentapi-module" |
| 9 | + web_app_display_name = "AgentAPI Web" |
| 10 | + web_app_slug = "agentapi-web" |
| 11 | + web_app_icon = "/icon/coder.svg" |
| 12 | + cli_app_display_name = "AgentAPI CLI" |
| 13 | + cli_app_slug = "agentapi-cli" |
| 14 | + install_script = "echo 'install'" |
| 15 | + start_script = "echo 'start'" |
| 16 | + } |
| 17 | + |
| 18 | + assert { |
| 19 | + condition = length(coder_script.agentapi) == 1 |
| 20 | + error_message = "AgentAPI script should be created when enable_agentapi is true" |
| 21 | + } |
| 22 | + |
| 23 | + assert { |
| 24 | + condition = coder_script.agentapi[0].agent_id == "test-agent-id" |
| 25 | + error_message = "AgentAPI script agent ID should match input" |
| 26 | + } |
| 27 | + |
| 28 | + assert { |
| 29 | + condition = coder_script.agentapi[0].display_name == "Start AgentAPI" |
| 30 | + error_message = "AgentAPI script should have correct display name" |
| 31 | + } |
| 32 | + |
| 33 | + assert { |
| 34 | + condition = coder_script.agentapi[0].run_on_start == true |
| 35 | + error_message = "AgentAPI script should run on start" |
| 36 | + } |
| 37 | + |
| 38 | + assert { |
| 39 | + condition = length(coder_script.agentapi_shutdown) == 1 |
| 40 | + error_message = "AgentAPI shutdown script should be created when enable_agentapi is true" |
| 41 | + } |
| 42 | + |
| 43 | + assert { |
| 44 | + condition = coder_script.agentapi_shutdown[0].run_on_stop == true |
| 45 | + error_message = "AgentAPI shutdown script should run on stop" |
| 46 | + } |
| 47 | + |
| 48 | + assert { |
| 49 | + condition = length(coder_app.agentapi_web) == 1 |
| 50 | + error_message = "AgentAPI web app should be created when enable_agentapi is true" |
| 51 | + } |
| 52 | + |
| 53 | + assert { |
| 54 | + condition = coder_app.agentapi_web[0].slug == "agentapi-web" |
| 55 | + error_message = "AgentAPI web app slug should match input" |
| 56 | + } |
| 57 | + |
| 58 | + assert { |
| 59 | + condition = coder_app.agentapi_web[0].subdomain == true |
| 60 | + error_message = "AgentAPI web app should use subdomain by default" |
| 61 | + } |
| 62 | + |
| 63 | + assert { |
| 64 | + condition = length(coder_app.agent_cli) == 0 |
| 65 | + error_message = "CLI app should not be created by default" |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +# Test with enable_agentapi = false |
| 70 | +run "test_agentapi_disabled" { |
| 71 | + command = plan |
| 72 | + |
| 73 | + variables { |
| 74 | + agent_id = "test-agent-id" |
| 75 | + agent_name = "claude" |
| 76 | + module_dir_name = ".agentapi-module" |
| 77 | + web_app_display_name = "AgentAPI Web" |
| 78 | + web_app_slug = "agentapi-web" |
| 79 | + web_app_icon = "/icon/coder.svg" |
| 80 | + cli_app_display_name = "AgentAPI CLI" |
| 81 | + cli_app_slug = "agentapi-cli" |
| 82 | + install_script = "echo 'install'" |
| 83 | + start_script = "echo 'start'" |
| 84 | + enable_agentapi = false |
| 85 | + } |
| 86 | + |
| 87 | + assert { |
| 88 | + condition = length(coder_script.agentapi) == 0 |
| 89 | + error_message = "AgentAPI script should not be created when enable_agentapi is false" |
| 90 | + } |
| 91 | + |
| 92 | + assert { |
| 93 | + condition = length(coder_script.agentapi_shutdown) == 0 |
| 94 | + error_message = "AgentAPI shutdown script should not be created when enable_agentapi is false" |
| 95 | + } |
| 96 | + |
| 97 | + assert { |
| 98 | + condition = length(coder_app.agentapi_web) == 0 |
| 99 | + error_message = "AgentAPI web app should not be created when enable_agentapi is false" |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +# Test with CLI app enabled |
| 104 | +run "test_cli_app_enabled" { |
| 105 | + command = plan |
| 106 | + |
| 107 | + variables { |
| 108 | + agent_id = "test-agent-id" |
| 109 | + agent_name = "claude" |
| 110 | + module_dir_name = ".agentapi-module" |
| 111 | + web_app_display_name = "AgentAPI Web" |
| 112 | + web_app_slug = "agentapi-web" |
| 113 | + web_app_icon = "/icon/coder.svg" |
| 114 | + cli_app_display_name = "AgentAPI CLI" |
| 115 | + cli_app_slug = "agentapi-cli" |
| 116 | + install_script = "echo 'install'" |
| 117 | + start_script = "echo 'start'" |
| 118 | + cli_app = true |
| 119 | + } |
| 120 | + |
| 121 | + assert { |
| 122 | + condition = length(coder_app.agent_cli) == 1 |
| 123 | + error_message = "CLI app should be created when cli_app is true" |
| 124 | + } |
| 125 | + |
| 126 | + assert { |
| 127 | + condition = coder_app.agent_cli[0].slug == "agentapi-cli" |
| 128 | + error_message = "CLI app slug should match input" |
| 129 | + } |
| 130 | + |
| 131 | + assert { |
| 132 | + condition = coder_app.agent_cli[0].display_name == "AgentAPI CLI" |
| 133 | + error_message = "CLI app display name should match input" |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +# Test custom port |
| 138 | +run "test_custom_port" { |
| 139 | + command = plan |
| 140 | + |
| 141 | + variables { |
| 142 | + agent_id = "test-agent-id" |
| 143 | + agent_name = "claude" |
| 144 | + module_dir_name = ".agentapi-module" |
| 145 | + web_app_display_name = "AgentAPI Web" |
| 146 | + web_app_slug = "agentapi-web" |
| 147 | + web_app_icon = "/icon/coder.svg" |
| 148 | + cli_app_display_name = "AgentAPI CLI" |
| 149 | + cli_app_slug = "agentapi-cli" |
| 150 | + install_script = "echo 'install'" |
| 151 | + start_script = "echo 'start'" |
| 152 | + agentapi_port = 4000 |
| 153 | + } |
| 154 | + |
| 155 | + assert { |
| 156 | + condition = coder_app.agentapi_web[0].url == "http://localhost:4000/" |
| 157 | + error_message = "AgentAPI web app URL should use custom port" |
| 158 | + } |
| 159 | + |
| 160 | + assert { |
| 161 | + condition = one([for h in coder_app.agentapi_web[0].healthcheck : h.url]) == "http://localhost:4000/status" |
| 162 | + error_message = "AgentAPI healthcheck URL should use custom port" |
| 163 | + } |
| 164 | +} |
| 165 | + |
| 166 | +# Test subdomain false validation rejects old versions |
| 167 | +run "test_subdomain_false_rejects_old_version" { |
| 168 | + command = plan |
| 169 | + |
| 170 | + variables { |
| 171 | + agent_id = "test-agent-id" |
| 172 | + agent_name = "claude" |
| 173 | + module_dir_name = ".agentapi-module" |
| 174 | + web_app_display_name = "AgentAPI Web" |
| 175 | + web_app_slug = "agentapi-web" |
| 176 | + web_app_icon = "/icon/coder.svg" |
| 177 | + cli_app_display_name = "AgentAPI CLI" |
| 178 | + cli_app_slug = "agentapi-cli" |
| 179 | + install_script = "echo 'install'" |
| 180 | + start_script = "echo 'start'" |
| 181 | + agentapi_subdomain = false |
| 182 | + agentapi_version = "v0.3.2" |
| 183 | + } |
| 184 | + |
| 185 | + expect_failures = [ |
| 186 | + var.agentapi_subdomain, |
| 187 | + ] |
| 188 | +} |
| 189 | + |
| 190 | +# Test subdomain false with valid version |
| 191 | +run "test_subdomain_false_allows_valid_version" { |
| 192 | + command = plan |
| 193 | + |
| 194 | + variables { |
| 195 | + agent_id = "test-agent-id" |
| 196 | + agent_name = "claude" |
| 197 | + module_dir_name = ".agentapi-module" |
| 198 | + web_app_display_name = "AgentAPI Web" |
| 199 | + web_app_slug = "agentapi-web" |
| 200 | + web_app_icon = "/icon/coder.svg" |
| 201 | + cli_app_display_name = "AgentAPI CLI" |
| 202 | + cli_app_slug = "agentapi-cli" |
| 203 | + install_script = "echo 'install'" |
| 204 | + start_script = "echo 'start'" |
| 205 | + agentapi_subdomain = false |
| 206 | + agentapi_version = "v0.3.3" |
| 207 | + } |
| 208 | + |
| 209 | + assert { |
| 210 | + condition = coder_app.agentapi_web[0].subdomain == false |
| 211 | + error_message = "AgentAPI web app should not use subdomain" |
| 212 | + } |
| 213 | +} |
0 commit comments