-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-deployment.js
More file actions
executable file
·194 lines (173 loc) · 5.7 KB
/
test-deployment.js
File metadata and controls
executable file
·194 lines (173 loc) · 5.7 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
#!/usr/bin/env node
/**
* Test Railway deployment
*/
import https from 'https';
import http from 'http';
const RAILWAY_URL = process.argv[2] || process.env.RAILWAY_URL;
const API_KEY =
process.argv[3] ||
process.env.API_KEY_SECRET ||
'a232e4cfe79628a729ba3e9ce29476422ebefb78f1db46fb7e8a6f11bebf5e0a';
if (!RAILWAY_URL) {
console.error('Usage: node scripts/test-railway.js <RAILWAY_URL> [API_KEY]');
console.error(
'Example: node scripts/test-railway.js https://your-app.railway.app'
);
process.exit(1);
}
console.log(`🧪 Testing Railway deployment at: ${RAILWAY_URL}`);
async function makeRequest(url, options = {}) {
return new Promise((resolve, reject) => {
const client = url.startsWith('https:') ? https : http;
const req = client.request(url, options, (res) => {
let data = '';
res.on('data', (chunk) => (data += chunk));
res.on('end', () => {
try {
resolve({
status: res.statusCode,
headers: res.headers,
data: res.headers['content-type']?.includes('application/json')
? JSON.parse(data)
: data,
});
} catch (e) {
resolve({
status: res.statusCode,
headers: res.headers,
data: data,
});
}
});
});
req.on('error', reject);
if (options.body) {
req.write(options.body);
}
req.end();
});
}
async function runTests() {
console.log('\n📊 Running health checks...\n');
try {
// 1. Health Check
console.log('1. Testing health endpoint...');
const health = await makeRequest(`${RAILWAY_URL}/health`);
if (health.status === 200) {
console.log('✅ Health check passed');
console.log(' Status:', health.data.status);
console.log(' Environment:', health.data.environment);
console.log(' Uptime:', Math.round(health.data.uptime), 'seconds');
} else {
console.log('❌ Health check failed:', health.status);
return;
}
// 2. Authentication Test
console.log('\n2. Testing authentication...');
const authTest = await makeRequest(`${RAILWAY_URL}/api/context/load`, {
method: 'GET',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
});
if (authTest.status === 200) {
console.log('✅ Authentication working');
console.log(' Contexts loaded:', authTest.data.contexts?.length || 0);
} else {
console.log('❌ Authentication failed:', authTest.status);
console.log(' Error:', authTest.data?.error || 'Unknown error');
}
// 3. Save Context Test
console.log('\n3. Testing context save...');
const saveTest = await makeRequest(`${RAILWAY_URL}/api/context/save`, {
method: 'POST',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
content: 'Railway deployment test context',
type: 'test',
metadata: { deployedAt: new Date().toISOString() },
}),
});
if (saveTest.status === 200) {
console.log('✅ Context save working');
console.log(' Context ID:', saveTest.data.id);
} else {
console.log('❌ Context save failed:', saveTest.status);
console.log(' Error:', saveTest.data?.error || 'Unknown error');
}
// 4. MCP Tool Test
console.log('\n4. Testing MCP tool execution...');
const toolTest = await makeRequest(`${RAILWAY_URL}/api/tools/execute`, {
method: 'POST',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
tool: 'load_context',
params: {
query: 'test',
limit: 5,
},
}),
});
if (toolTest.status === 200) {
console.log('✅ MCP tool execution working');
console.log(
' Found contexts:',
toolTest.data.result?.contexts?.length || 0
);
} else {
console.log('❌ MCP tool execution failed:', toolTest.status);
console.log(' Error:', toolTest.data?.error || 'Unknown error');
}
// 5. Analytics Test (if enabled)
console.log('\n5. Testing analytics endpoint...');
const analyticsTest = await makeRequest(`${RAILWAY_URL}/api/analytics`, {
method: 'GET',
headers: {
Authorization: `Bearer ${API_KEY}`,
},
});
if (analyticsTest.status === 200) {
console.log('✅ Analytics working');
console.log(
' Total contexts:',
analyticsTest.data.analytics?.total_contexts || 0
);
} else {
console.log('⚠️ Analytics not available (may be disabled)');
}
console.log('\n🎉 Railway deployment test complete!\n');
console.log(`🔗 Your StackMemory MCP Server is running at: ${RAILWAY_URL}`);
console.log(`🔑 API Key: ${API_KEY.substring(0, 8)}...`);
console.log('\n📋 Claude.ai MCP Configuration:');
console.log(`{
"mcpServers": {
"stackmemory": {
"command": "curl",
"args": [
"-X", "POST",
"-H", "Authorization: Bearer ${API_KEY}",
"-H", "Content-Type: application/json",
"-d", "{\\"tool\\": \\"load_context\\", \\"params\\": {\\"query\\": \\"\\", \\"limit\\": 10}}",
"${RAILWAY_URL}/api/tools/execute"
]
}
}
}`);
} catch (error) {
console.error('❌ Test failed:', error.message);
console.error('\n🔍 Troubleshooting:');
console.error('1. Check if Railway deployment is complete');
console.error('2. Verify environment variables are set');
console.error('3. Check Railway logs for errors');
console.error('4. Ensure PostgreSQL database is connected');
}
}
runTests();