|
1 | | -// Terraform tests for the cursor-cli module |
2 | | -// Validates that we render expected script content given inputs |
3 | | - |
4 | | -run "defaults" { |
| 1 | +run "test_cursor_cli_basic" { |
5 | 2 | command = plan |
6 | 3 |
|
7 | 4 | variables { |
8 | | - agent_id = "test-agent" |
9 | | - folder = "/home/coder" |
| 5 | + agent_id = "test-agent-123" |
| 6 | + folder = "/home/coder/projects" |
| 7 | + } |
| 8 | + |
| 9 | + assert { |
| 10 | + condition = coder_env.status_slug.name == "CODER_MCP_APP_STATUS_SLUG" |
| 11 | + error_message = "Status slug environment variable should be set correctly" |
| 12 | + } |
| 13 | + |
| 14 | + assert { |
| 15 | + condition = coder_env.status_slug.value == "cursorcli" |
| 16 | + error_message = "Status slug value should be 'cursorcli'" |
| 17 | + } |
| 18 | + |
| 19 | + assert { |
| 20 | + condition = var.folder == "/home/coder/projects" |
| 21 | + error_message = "Folder variable should be set correctly" |
10 | 22 | } |
11 | 23 |
|
12 | 24 | assert { |
13 | | - condition = can(regex("Cursor CLI", resource.coder_script.cursor_cli.display_name)) |
14 | | - error_message = "Expected coder_script to be created" |
| 25 | + condition = var.agent_id == "test-agent-123" |
| 26 | + error_message = "Agent ID variable should be set correctly" |
15 | 27 | } |
16 | 28 | } |
17 | 29 |
|
18 | | -run "non_interactive_mode" { |
| 30 | +run "test_cursor_cli_with_api_key" { |
19 | 31 | command = plan |
20 | 32 |
|
21 | 33 | variables { |
22 | | - agent_id = "test-agent" |
23 | | - folder = "/home/coder" |
24 | | - output_format = "json" |
25 | | - ai_prompt = "refactor the auth module to use JWT tokens" |
| 34 | + agent_id = "test-agent-456" |
| 35 | + folder = "/home/coder/workspace" |
| 36 | + api_key = "test-api-key-123" |
26 | 37 | } |
27 | 38 |
|
28 | 39 | assert { |
29 | | - // non-interactive always prints; output format propagates |
30 | | - condition = can(regex("OUTPUT_FORMAT='json'", resource.coder_script.cursor_cli.script)) |
31 | | - error_message = "Expected OUTPUT_FORMAT to be propagated" |
| 40 | + condition = coder_env.cursor_api_key[0].name == "CURSOR_API_KEY" |
| 41 | + error_message = "Cursor API key environment variable should be set correctly" |
32 | 42 | } |
33 | 43 |
|
34 | 44 | assert { |
35 | | - condition = can(regex("AI_PROMPT='refactor the auth module to use JWT tokens'", resource.coder_script.cursor_cli.script)) |
36 | | - error_message = "Expected ai_prompt to be propagated via AI_PROMPT" |
| 45 | + condition = coder_env.cursor_api_key[0].value == "test-api-key-123" |
| 46 | + error_message = "Cursor API key value should match the input" |
37 | 47 | } |
38 | 48 | } |
39 | 49 |
|
40 | | -run "model_and_force" { |
| 50 | +run "test_cursor_cli_with_custom_options" { |
41 | 51 | command = plan |
42 | 52 |
|
43 | 53 | variables { |
44 | | - agent_id = "test-agent" |
45 | | - folder = "/home/coder" |
46 | | - model = "test-model" |
47 | | - force = true |
| 54 | + agent_id = "test-agent-789" |
| 55 | + folder = "/home/coder/custom" |
| 56 | + order = 5 |
| 57 | + group = "development" |
| 58 | + icon = "/icon/custom.svg" |
| 59 | + model = "sonnet-4" |
| 60 | + ai_prompt = "Help me write better code" |
| 61 | + force = false |
| 62 | + install_cursor_cli = false |
| 63 | + install_agentapi = false |
| 64 | + } |
| 65 | + |
| 66 | + assert { |
| 67 | + condition = var.order == 5 |
| 68 | + error_message = "Order variable should be set to 5" |
| 69 | + } |
| 70 | + |
| 71 | + assert { |
| 72 | + condition = var.group == "development" |
| 73 | + error_message = "Group variable should be set to 'development'" |
| 74 | + } |
| 75 | + |
| 76 | + assert { |
| 77 | + condition = var.icon == "/icon/custom.svg" |
| 78 | + error_message = "Icon variable should be set to custom icon" |
| 79 | + } |
| 80 | + |
| 81 | + assert { |
| 82 | + condition = var.model == "sonnet-4" |
| 83 | + error_message = "Model variable should be set to 'sonnet-4'" |
48 | 84 | } |
49 | 85 |
|
50 | 86 | assert { |
51 | | - condition = can(regex("MODEL='test-model'", resource.coder_script.cursor_cli.script)) |
52 | | - error_message = "Expected MODEL to be propagated" |
| 87 | + condition = var.ai_prompt == "Help me write better code" |
| 88 | + error_message = "AI prompt variable should be set correctly" |
53 | 89 | } |
54 | 90 |
|
55 | 91 | assert { |
56 | | - condition = can(regex("FORCE='true'", resource.coder_script.cursor_cli.script)) |
57 | | - error_message = "Expected FORCE true to be propagated" |
| 92 | + condition = var.force == false |
| 93 | + error_message = "Force variable should be set to false" |
58 | 94 | } |
59 | 95 | } |
60 | 96 |
|
61 | | -run "additional_settings_propagated" { |
| 97 | +run "test_cursor_cli_with_mcp_and_rules" { |
62 | 98 | command = plan |
63 | 99 |
|
64 | 100 | variables { |
65 | | - agent_id = "test-agent" |
66 | | - folder = "/home/coder" |
67 | | - mcp_json = jsonencode({ mcpServers = { foo = { command = "foo", type = "stdio" } } }) |
| 101 | + agent_id = "test-agent-mcp" |
| 102 | + folder = "/home/coder/mcp-test" |
| 103 | + mcp = jsonencode({ |
| 104 | + mcpServers = { |
| 105 | + test = { |
| 106 | + command = "test-server" |
| 107 | + args = ["--config", "test.json"] |
| 108 | + } |
| 109 | + } |
| 110 | + }) |
68 | 111 | rules_files = { |
69 | | - "global.yml" = "version: 1\nrules:\n - name: global\n include: ['**/*']\n description: global rule" |
| 112 | + "general.md" = "# General coding rules\n- Write clean code\n- Add comments" |
| 113 | + "security.md" = "# Security rules\n- Never commit secrets\n- Validate inputs" |
70 | 114 | } |
71 | | - pre_install_script = "#!/bin/bash\necho pre-install" |
72 | | - post_install_script = "#!/bin/bash\necho post-install" |
73 | 115 | } |
74 | 116 |
|
75 | | - // Ensure project mcp_json is passed |
76 | 117 | assert { |
77 | | - condition = can(regex(base64encode(jsonencode({ mcpServers = { foo = { command = "foo", type = "stdio" } } })), resource.coder_script.cursor_cli.script)) |
78 | | - error_message = "Expected PROJECT_MCP_JSON (base64) to be in the install step" |
| 118 | + condition = var.mcp != null |
| 119 | + error_message = "MCP configuration should be provided" |
79 | 120 | } |
80 | 121 |
|
81 | | - // Ensure rules map is passed |
82 | 122 | assert { |
83 | | - condition = can(regex(base64encode(jsonencode({ "global.yml" : "version: 1\nrules:\n - name: global\n include: ['**/*']\n description: global rule" })), resource.coder_script.cursor_cli.script)) |
84 | | - error_message = "Expected PROJECT_RULES_JSON (base64) to be in the install step" |
| 123 | + condition = var.rules_files != null |
| 124 | + error_message = "Rules files should be provided" |
85 | 125 | } |
86 | 126 |
|
87 | | - // Ensure pre/post install scripts are embedded |
88 | | - assert { |
89 | | - condition = can(regex(base64encode("#!/bin/bash\necho pre-install"), resource.coder_script.cursor_cli.script)) |
90 | | - error_message = "Expected pre-install script to be embedded" |
91 | | - } |
92 | 127 | assert { |
93 | | - condition = can(regex(base64encode("#!/bin/bash\necho post-install"), resource.coder_script.cursor_cli.script)) |
94 | | - error_message = "Expected post-install script to be embedded" |
| 128 | + condition = length(var.rules_files) == 2 |
| 129 | + error_message = "Should have 2 rules files" |
95 | 130 | } |
96 | 131 | } |
97 | 132 |
|
98 | | -run "api_key_env_var" { |
| 133 | +run "test_cursor_cli_with_scripts" { |
99 | 134 | command = plan |
100 | 135 |
|
101 | 136 | variables { |
102 | | - agent_id = "test-agent" |
103 | | - folder = "/home/coder" |
104 | | - api_key = "sk-test-123" |
| 137 | + agent_id = "test-agent-scripts" |
| 138 | + folder = "/home/coder/scripts" |
| 139 | + pre_install_script = "echo 'Pre-install script'" |
| 140 | + post_install_script = "echo 'Post-install script'" |
105 | 141 | } |
106 | 142 |
|
107 | 143 | assert { |
108 | | - condition = resource.coder_env.cursor_api_key[0].name == "CURSOR_API_KEY" |
109 | | - error_message = "Expected CURSOR_API_KEY env to be created when api_key is set" |
| 144 | + condition = var.pre_install_script == "echo 'Pre-install script'" |
| 145 | + error_message = "Pre-install script should be set correctly" |
110 | 146 | } |
111 | 147 |
|
112 | 148 | assert { |
113 | | - condition = resource.coder_env.cursor_api_key[0].value == "sk-test-123" |
114 | | - error_message = "Expected CURSOR_API_KEY env value to be set from api_key" |
| 149 | + condition = var.post_install_script == "echo 'Post-install script'" |
| 150 | + error_message = "Post-install script should be set correctly" |
115 | 151 | } |
116 | 152 | } |
0 commit comments