This repository was archived by the owner on Jan 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_setup.bats
More file actions
executable file
·258 lines (208 loc) · 8.58 KB
/
test_setup.bats
File metadata and controls
executable file
·258 lines (208 loc) · 8.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env bats
setup() {
# Create a temporary directory for fake binaries
export FAKE_BIN_DIR=$(mktemp -d)
export ORIGINAL_PATH="$PATH"
}
teardown() {
# Restore PATH first
export PATH="$ORIGINAL_PATH"
# Clean up temporary directory
/bin/rm -rf "$FAKE_BIN_DIR"
}
# Helper function to create fake binaries
create_fake_binary() {
local binary_name="$1"
echo '#!/bin/bash' > "$FAKE_BIN_DIR/$binary_name"
echo 'exit 0' >> "$FAKE_BIN_DIR/$binary_name"
chmod +x "$FAKE_BIN_DIR/$binary_name"
}
@test "both claude and docker are installed" {
create_fake_binary "claude"
create_fake_binary "docker"
export PATH="$FAKE_BIN_DIR:$PATH"
export SI_API_TOKEN="fake_header.fake_payload.fake_signature"
# Create a temporary directory for test config
local test_dir=$(mktemp -d)
local test_mcp_file="$test_dir/.mcp.json"
run bash -c "echo 'y' | ./setup.sh '$test_mcp_file'"
[ "$status" -eq 0 ]
[[ "$output" == *"✅ claude is installed and available"* ]]
[[ "$output" == *"✅ docker is installed and available"* ]]
[[ "$output" == *"✅ Using existing SI_API_TOKEN"* ]]
# Clean up
rm -rf "$test_dir"
}
@test "claude is missing" {
create_fake_binary "docker"
export PATH="$FAKE_BIN_DIR"
export SI_API_TOKEN="fake_header.fake_payload.fake_signature"
run ./setup.sh
[ "$status" -eq 1 ]
[[ "$output" == *"❌ Error: 'claude' is not installed!"* ]]
[[ "$output" == *"https://www.anthropic.com/claude-code"* ]]
[[ "$output" == *"npm install -g @anthropic-ai/claude-code"* ]]
}
@test "docker is missing" {
create_fake_binary "claude"
export PATH="$FAKE_BIN_DIR"
export SI_API_TOKEN="fake_header.fake_payload.fake_signature"
run ./setup.sh
[ "$status" -eq 1 ]
[[ "$output" == *"✅ claude is installed and available"* ]]
[[ "$output" == *"❌ Error: 'docker' is not installed!"* ]]
}
@test "both claude and docker are missing" {
export PATH="$FAKE_BIN_DIR"
export SI_API_TOKEN="fake_header.fake_payload.fake_signature"
run ./setup.sh
[ "$status" -eq 1 ]
[[ "$output" == *"❌ Error: 'claude' is not installed!"* ]]
# Script exits after claude check, so docker error won't appear
}
@test "docker error message on macOS" {
create_fake_binary "claude"
export PATH="$FAKE_BIN_DIR"
export OSTYPE="darwin21"
export SI_API_TOKEN="fake_header.fake_payload.fake_signature"
run ./setup.sh
[ "$status" -eq 1 ]
[[ "$output" == *"🍎 On macOS: Install Docker Desktop from https://www.docker.com/products/docker-desktop/"* ]]
}
@test "docker error message on Linux" {
create_fake_binary "claude"
export PATH="$FAKE_BIN_DIR"
export OSTYPE="linux-gnu"
export SI_API_TOKEN="fake_header.fake_payload.fake_signature"
run ./setup.sh
[ "$status" -eq 1 ]
[[ "$output" == *"🐧 Please consult your platform's documentation for Docker installation instructions"* ]]
}
@test "script handles empty PATH gracefully" {
export PATH=""
export SI_API_TOKEN="fake_header.fake_payload.fake_signature"
run ./setup.sh
[ "$status" -eq 1 ]
[[ "$output" == *"❌ Error: 'claude' is not installed!"* ]]
# Script exits after claude check, so docker error won't appear
}
@test "prompts for API token when none exists" {
create_fake_binary "claude"
create_fake_binary "docker"
export PATH="$FAKE_BIN_DIR:$PATH"
unset SI_API_TOKEN
# Create a temporary directory for test config
local test_dir=$(mktemp -d)
local test_mcp_file="$test_dir/.mcp.json"
run bash -c "echo 'test_header.test_payload.test_signature' | ./setup.sh '$test_mcp_file'"
[ "$status" -eq 0 ]
[[ "$output" == *"🔑 System Initiative API Token Required"* ]]
[[ "$output" == *"Please paste your API token:"* ]]
[[ "$output" == *"✅ API token set successfully"* ]]
# Clean up
rm -rf "$test_dir"
}
@test "accepts existing token when user says yes" {
create_fake_binary "claude"
create_fake_binary "docker"
export PATH="$FAKE_BIN_DIR:$PATH"
export SI_API_TOKEN="existing_header.existing_payload.existing_signature"
# Create a temporary directory for test config
local test_dir=$(mktemp -d)
local test_mcp_file="$test_dir/.mcp.json"
run bash -c "echo 'y' | ./setup.sh '$test_mcp_file'"
[ "$status" -eq 0 ]
[[ "$output" == *"🔑 Found existing SI_API_TOKEN in environment"* ]]
[[ "$output" == *"✅ Using existing SI_API_TOKEN"* ]]
# Clean up
rm -rf "$test_dir"
}
@test "prompts for new token when user says no to existing" {
create_fake_binary "claude"
create_fake_binary "docker"
export PATH="$FAKE_BIN_DIR:$PATH"
export SI_API_TOKEN="existing_header.existing_payload.existing_signature"
# Create a temporary directory for test config
local test_dir=$(mktemp -d)
local test_mcp_file="$test_dir/.mcp.json"
run bash -c "printf 'n\nnew_header.new_payload.new_signature\n' | ./setup.sh '$test_mcp_file'"
[ "$status" -eq 0 ]
[[ "$output" == *"🔑 Found existing SI_API_TOKEN in environment"* ]]
[[ "$output" == *"Please paste your API token:"* ]]
[[ "$output" == *"✅ API token set successfully"* ]]
# Clean up
rm -rf "$test_dir"
}
@test "rejects invalid token format" {
create_fake_binary "claude"
create_fake_binary "docker"
export PATH="$FAKE_BIN_DIR:$PATH"
unset SI_API_TOKEN
# Create a temporary directory for test config
local test_dir=$(mktemp -d)
local test_mcp_file="$test_dir/.mcp.json"
run bash -c "printf 'invalid-token\nvalid_header.valid_payload.valid_signature\n' | ./setup.sh '$test_mcp_file'"
[ "$status" -eq 0 ]
[[ "$output" == *"❌ Invalid token format. System Initiative tokens are JWTs"* ]]
[[ "$output" == *"✅ API token set successfully"* ]]
# Clean up
rm -rf "$test_dir"
}
@test "creates .mcp.json file with correct content" {
create_fake_binary "claude"
create_fake_binary "docker"
export PATH="$FAKE_BIN_DIR:$PATH"
unset SI_API_TOKEN
# Create a temporary directory for test
local test_dir=$(mktemp -d)
local test_mcp_file="$test_dir/.mcp.json"
# Run setup with custom mcp config location, providing API token when prompted
run bash -c "echo 'test_header.test_payload.test_signature' | ./setup.sh '$test_mcp_file'"
[ "$status" -eq 0 ]
# Check that .mcp.json was created in the test directory
[ -f "$test_mcp_file" ]
# Verify the content structure
local mcp_content=$(cat "$test_mcp_file")
[[ "$mcp_content" == *'"mcpServers"'* ]]
[[ "$mcp_content" == *'"system-initiative"'* ]]
[[ "$mcp_content" == *'"type": "stdio"'* ]]
[[ "$mcp_content" == *'"command": "docker"'* ]]
[[ "$mcp_content" == *'"systeminit/si-mcp-server:stable"'* ]]
[[ "$mcp_content" == *'"SI_API_TOKEN": "test_header.test_payload.test_signature"'* ]]
# Check that output indicates file creation
[[ "$output" == *"📄 Creating MCP configuration file"* ]]
[[ "$output" == *"✅ Created .mcp.json at: $test_mcp_file"* ]]
# Clean up
rm -rf "$test_dir"
}
@test "creates .claude/settings.local.json file with correct content" {
create_fake_binary "claude"
create_fake_binary "docker"
export PATH="$FAKE_BIN_DIR:$PATH"
export SI_API_TOKEN="test_header.test_payload.test_signature"
# Create a temporary directory for test
local test_dir=$(mktemp -d)
local test_script="$test_dir/setup.sh"
# Copy setup.sh to test directory so .claude directory is created there
cp ./setup.sh "$test_script"
# Run setup from test directory
run bash -c "cd '$test_dir' && echo 'y' | bash setup.sh"
[ "$status" -eq 0 ]
# Check that .claude directory and settings file were created
[ -d "$test_dir/.claude" ]
[ -f "$test_dir/.claude/settings.local.json" ]
# Verify the content structure
local settings_content=$(cat "$test_dir/.claude/settings.local.json")
[[ "$settings_content" == *'"enabledMcpjsonServers"'* ]]
[[ "$settings_content" == *'"system-initiative"'* ]]
[[ "$settings_content" == *'"permissions"'* ]]
[[ "$settings_content" == *'"allow"'* ]]
[[ "$settings_content" == *'"mcp__system-initiative__schema-find"'* ]]
[[ "$settings_content" == *'"mcp__system-initiative__component-create"'* ]]
[[ "$settings_content" == *'"deny": []'* ]]
# Check that output indicates file creation
[[ "$output" == *"📄 Creating Claude settings configuration"* ]]
[[ "$output" == *"✅ Created Claude settings at:"* ]]
# Clean up
rm -rf "$test_dir"
}