Skip to content

Commit f1bca89

Browse files
committed
feat: update test
1 parent a844fbb commit f1bca89

File tree

1 file changed

+91
-55
lines changed

1 file changed

+91
-55
lines changed
Lines changed: 91 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,152 @@
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" {
52
command = plan
63

74
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"
1022
}
1123

1224
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"
1527
}
1628
}
1729

18-
run "non_interactive_mode" {
30+
run "test_cursor_cli_with_api_key" {
1931
command = plan
2032

2133
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"
2637
}
2738

2839
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"
3242
}
3343

3444
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"
3747
}
3848
}
3949

40-
run "model_and_force" {
50+
run "test_cursor_cli_with_custom_options" {
4151
command = plan
4252

4353
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'"
4884
}
4985

5086
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"
5389
}
5490

5591
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"
5894
}
5995
}
6096

61-
run "additional_settings_propagated" {
97+
run "test_cursor_cli_with_mcp_and_rules" {
6298
command = plan
6399

64100
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+
})
68111
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"
70114
}
71-
pre_install_script = "#!/bin/bash\necho pre-install"
72-
post_install_script = "#!/bin/bash\necho post-install"
73115
}
74116

75-
// Ensure project mcp_json is passed
76117
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"
79120
}
80121

81-
// Ensure rules map is passed
82122
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"
85125
}
86126

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-
}
92127
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"
95130
}
96131
}
97132

98-
run "api_key_env_var" {
133+
run "test_cursor_cli_with_scripts" {
99134
command = plan
100135

101136
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'"
105141
}
106142

107143
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"
110146
}
111147

112148
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"
115151
}
116152
}

0 commit comments

Comments
 (0)