@daileyos/mcp-server 1.9.2 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Pack 6 smoke test — dailey_diagnose tool + remediation hints.
4
+ *
5
+ * Two layers:
6
+ * 1. Pure-unit: verify remediationFor() returns the right hint for known
7
+ * status codes and error patterns. No network needed.
8
+ * 2. End-to-end: spawn the MCP stdio server, list tools, call
9
+ * dailey_diagnose against a real project, parse the JSON output.
10
+ *
11
+ * Usage:
12
+ * DAILEY_EMAIL=... DAILEY_PASSWORD=... node tests/pack6-smoke.mjs
13
+ */
14
+ import { spawn } from 'node:child_process';
15
+ import path from 'node:path';
16
+
17
+ const here = path.resolve(new URL('.', import.meta.url).pathname);
18
+ const binary = path.resolve(here, '..', 'dist/index.js');
19
+
20
+ // ── Layer 1: remediationFor unit checks ─────────────────────────────
21
+ const { remediationFor } = await import(path.resolve(here, '..', 'dist/api.js'));
22
+
23
+ let unitPassed = 0;
24
+ let unitFailed = 0;
25
+ function unit(name, predicate) {
26
+ if (predicate) {
27
+ console.log(` ✓ ${name}`);
28
+ unitPassed++;
29
+ } else {
30
+ console.log(` ✗ ${name}`);
31
+ unitFailed++;
32
+ }
33
+ }
34
+
35
+ console.log('Unit: remediationFor()');
36
+ unit('423 → account-locked hint', /account locked/i.test(remediationFor(423, {}) || ''));
37
+ unit('429 → rate-limited hint', /rate limited|retry-after/i.test(remediationFor(429, {}) || ''));
38
+ unit('401 → token hint', /token expired|dailey login/i.test(remediationFor(401, {}) || ''));
39
+ unit('403 → token hint', /token expired|dailey login/i.test(remediationFor(403, {}) || ''));
40
+ unit('502 → unreachable hint', /unreachable/i.test(remediationFor(502, {}) || ''));
41
+ unit(
42
+ 'AlreadyExists registry → retry hint',
43
+ /retry .dailey_deploy./i.test(
44
+ remediationFor(500, { error: 'AlreadyExists: blob upload to registry failed' }) || '',
45
+ ),
46
+ );
47
+ unit(
48
+ 'SignatureDoesNotMatch → storage refresh',
49
+ /storage.*refresh|24h/i.test(
50
+ remediationFor(403, { error: 'SignatureDoesNotMatch on PUT' }) || '',
51
+ ),
52
+ );
53
+ unit(
54
+ 'CrashLoopBackOff → app_logs',
55
+ /app_logs/i.test(remediationFor(500, { error: 'pod CrashLoopBackOff' }) || ''),
56
+ );
57
+ unit(
58
+ 'ENOTFOUND → unreachable',
59
+ /unreachable/i.test(remediationFor(0, 'fetch failed: ENOTFOUND os.dailey.cloud') || ''),
60
+ );
61
+ unit('200 → no hint', remediationFor(200, {}) === null);
62
+ unit('404 unrecognized → no hint', remediationFor(404, { error: 'Project not found' }) === null);
63
+
64
+ console.log('');
65
+
66
+ // ── Layer 2: end-to-end MCP smoke ───────────────────────────────────
67
+ const env = {
68
+ ...process.env,
69
+ DAILEY_API_URL: process.env.DAILEY_API_URL || 'https://os.dailey.cloud/api',
70
+ DAILEY_EMAIL: process.env.DAILEY_EMAIL,
71
+ DAILEY_PASSWORD: process.env.DAILEY_PASSWORD,
72
+ };
73
+
74
+ if (!env.DAILEY_EMAIL || !env.DAILEY_PASSWORD) {
75
+ console.log('(skip e2e — DAILEY_EMAIL/DAILEY_PASSWORD not set)');
76
+ process.exit(unitFailed === 0 ? 0 : 1);
77
+ }
78
+
79
+ const child = spawn('node', [binary], { env, stdio: ['pipe', 'pipe', 'pipe'] });
80
+ let nextId = 1;
81
+ const pending = new Map();
82
+ let buffer = '';
83
+
84
+ child.stdout.on('data', (chunk) => {
85
+ buffer += chunk.toString();
86
+ const lines = buffer.split('\n');
87
+ buffer = lines.pop();
88
+ for (const line of lines) {
89
+ if (!line.trim()) continue;
90
+ try {
91
+ const msg = JSON.parse(line);
92
+ if (msg.id && pending.has(msg.id)) {
93
+ const { resolve } = pending.get(msg.id);
94
+ pending.delete(msg.id);
95
+ resolve(msg);
96
+ }
97
+ } catch {}
98
+ }
99
+ });
100
+
101
+ child.stderr.on('data', (chunk) => {
102
+ // Quiet — but surface unexpected stack traces
103
+ const s = chunk.toString();
104
+ if (/error|throw|TypeError/i.test(s)) process.stderr.write(`[mcp] ${s}`);
105
+ });
106
+
107
+ function send(method, params, timeoutMs = 30000) {
108
+ return new Promise((resolve, reject) => {
109
+ const id = nextId++;
110
+ pending.set(id, { resolve, reject });
111
+ child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
112
+ setTimeout(() => {
113
+ if (pending.has(id)) {
114
+ pending.delete(id);
115
+ reject(new Error(`Timeout waiting for ${method}`));
116
+ }
117
+ }, timeoutMs);
118
+ });
119
+ }
120
+
121
+ let e2ePassed = 0;
122
+ let e2eFailed = 0;
123
+ function e2e(name, predicate, detail) {
124
+ if (predicate) {
125
+ console.log(` ✓ ${name}${detail ? ' — ' + detail : ''}`);
126
+ e2ePassed++;
127
+ } else {
128
+ console.log(` ✗ ${name}${detail ? ' — ' + detail : ''}`);
129
+ e2eFailed++;
130
+ }
131
+ }
132
+
133
+ try {
134
+ console.log('E2E: MCP stdio server');
135
+ await send('initialize', {
136
+ protocolVersion: '2024-11-05',
137
+ capabilities: {},
138
+ clientInfo: { name: 'pack6-smoke', version: '1.0.0' },
139
+ });
140
+ child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
141
+
142
+ const toolsMsg = await send('tools/list', {});
143
+ const tools = toolsMsg.result?.tools || [];
144
+ const names = new Set(tools.map((t) => t.name));
145
+ e2e('dailey_diagnose registered', names.has('dailey_diagnose'), `${tools.length} tools total`);
146
+
147
+ // Find a project to diagnose
148
+ const listMsg = await send('tools/call', { name: 'dailey_list_projects', arguments: {} });
149
+ const listText = listMsg.result?.content?.[0]?.text || '';
150
+ // Format: lines after divider; first column is the UUID. Pick the first.
151
+ const idMatch = listText.match(/^([0-9a-f]{8}-[0-9a-f-]+)/m);
152
+ if (!idMatch) {
153
+ console.log(' ⊘ no project to diagnose — skipping invocation tests');
154
+ } else {
155
+ const projectId = idMatch[1];
156
+ const slugMatch = listText.match(new RegExp(`^${projectId}\\s+\\S+\\s+(\\S+)`, 'm'));
157
+ const slug = slugMatch?.[1];
158
+ console.log(` Using project: ${projectId}${slug ? ' (slug: ' + slug + ')' : ''}`);
159
+
160
+ // by ID
161
+ const byId = await send(
162
+ 'tools/call',
163
+ { name: 'dailey_diagnose', arguments: { project: projectId } },
164
+ 60000,
165
+ );
166
+ const byIdText = byId.result?.content?.[0]?.text || '';
167
+ let byIdJson = null;
168
+ try { byIdJson = JSON.parse(byIdText); } catch {}
169
+ e2e('dailey_diagnose by ID returns valid JSON', !!byIdJson);
170
+ e2e(
171
+ 'has top-level summary',
172
+ typeof byIdJson?.summary === 'string' && byIdJson.summary.length > 0,
173
+ byIdJson?.summary?.slice(0, 60),
174
+ );
175
+ e2e(
176
+ 'verdict is healthy/degraded/broken',
177
+ ['healthy', 'degraded', 'broken'].includes(byIdJson?.verdict),
178
+ byIdJson?.verdict,
179
+ );
180
+ e2e('has 6 lane checks', byIdJson && Object.keys(byIdJson.checks || {}).length === 6);
181
+ e2e('matched_by=id', byIdJson?.matched_by === 'id');
182
+
183
+ // by slug (if we found one)
184
+ if (slug) {
185
+ const bySlug = await send(
186
+ 'tools/call',
187
+ { name: 'dailey_diagnose', arguments: { project: slug } },
188
+ 60000,
189
+ );
190
+ const bySlugText = bySlug.result?.content?.[0]?.text || '';
191
+ let bySlugJson = null;
192
+ try { bySlugJson = JSON.parse(bySlugText); } catch {}
193
+ e2e('dailey_diagnose by slug returns valid JSON', !!bySlugJson);
194
+ e2e('matched_by=slug', bySlugJson?.matched_by === 'slug');
195
+ e2e('resolved to same project_id', bySlugJson?.project_id === projectId);
196
+ }
197
+
198
+ // bogus → broken with hint
199
+ const bogus = await send(
200
+ 'tools/call',
201
+ { name: 'dailey_diagnose', arguments: { project: 'definitely-not-a-real-slug-xyz123' } },
202
+ 30000,
203
+ );
204
+ const bogusText = bogus.result?.content?.[0]?.text || '';
205
+ let bogusJson = null;
206
+ try { bogusJson = JSON.parse(bogusText); } catch {}
207
+ e2e('bogus slug → verdict=broken', bogusJson?.verdict === 'broken');
208
+ e2e('bogus slug → matched_by=none', bogusJson?.matched_by === 'none');
209
+ }
210
+
211
+ child.kill();
212
+ } catch (err) {
213
+ console.error('E2E CRASH:', err.message);
214
+ child.kill();
215
+ e2eFailed++;
216
+ }
217
+
218
+ console.log('');
219
+ console.log('─'.repeat(60));
220
+ console.log(`Unit: ${unitPassed} passed, ${unitFailed} failed`);
221
+ console.log(`E2E: ${e2ePassed} passed, ${e2eFailed} failed`);
222
+ process.exit(unitFailed + e2eFailed === 0 ? 0 : 1);