@daileyos/mcp-server 1.21.1 → 1.21.4

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.
Files changed (181) hide show
  1. package/dist/api.d.ts +7 -0
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +37 -3
  4. package/dist/api.js.map +1 -1
  5. package/dist/context.d.ts +8 -0
  6. package/dist/context.d.ts.map +1 -0
  7. package/dist/context.js +6 -0
  8. package/dist/context.js.map +1 -0
  9. package/dist/http.d.ts +5 -0
  10. package/dist/http.d.ts.map +1 -0
  11. package/dist/http.js +193 -0
  12. package/dist/http.js.map +1 -0
  13. package/dist/index.js +32 -163
  14. package/dist/index.js.map +1 -1
  15. package/dist/server.d.ts +9 -0
  16. package/dist/server.d.ts.map +1 -0
  17. package/dist/server.js +165 -0
  18. package/dist/server.js.map +1 -0
  19. package/dist/tools/accounts.d.ts +4 -1
  20. package/dist/tools/accounts.d.ts.map +1 -1
  21. package/dist/tools/accounts.js +57 -53
  22. package/dist/tools/accounts.js.map +1 -1
  23. package/dist/tools/ai.d.ts.map +1 -1
  24. package/dist/tools/ai.js +7 -1
  25. package/dist/tools/ai.js.map +1 -1
  26. package/dist/tools/auth.d.ts.map +1 -1
  27. package/dist/tools/auth.js +25 -6
  28. package/dist/tools/auth.js.map +1 -1
  29. package/dist/tools/backups.d.ts.map +1 -1
  30. package/dist/tools/backups.js +3 -1
  31. package/dist/tools/backups.js.map +1 -1
  32. package/dist/tools/build-logs.d.ts.map +1 -1
  33. package/dist/tools/build-logs.js +3 -1
  34. package/dist/tools/build-logs.js.map +1 -1
  35. package/dist/tools/credentials-reveal.d.ts.map +1 -1
  36. package/dist/tools/credentials-reveal.js +3 -1
  37. package/dist/tools/credentials-reveal.js.map +1 -1
  38. package/dist/tools/dailey-images.js +3 -3
  39. package/dist/tools/dailey-images.js.map +1 -1
  40. package/dist/tools/db-migrate.js +5 -5
  41. package/dist/tools/db-migrate.js.map +1 -1
  42. package/dist/tools/db.d.ts.map +1 -1
  43. package/dist/tools/db.js +17 -1
  44. package/dist/tools/db.js.map +1 -1
  45. package/dist/tools/deploy-status.d.ts.map +1 -1
  46. package/dist/tools/deploy-status.js +3 -1
  47. package/dist/tools/deploy-status.js.map +1 -1
  48. package/dist/tools/deploy.d.ts.map +1 -1
  49. package/dist/tools/deploy.js +9 -1
  50. package/dist/tools/deploy.js.map +1 -1
  51. package/dist/tools/domains.d.ts.map +1 -1
  52. package/dist/tools/domains.js +3 -1
  53. package/dist/tools/domains.js.map +1 -1
  54. package/dist/tools/email.d.ts.map +1 -1
  55. package/dist/tools/email.js +7 -1
  56. package/dist/tools/email.js.map +1 -1
  57. package/dist/tools/env.d.ts.map +1 -1
  58. package/dist/tools/env.js +5 -1
  59. package/dist/tools/env.js.map +1 -1
  60. package/dist/tools/environments.js +3 -3
  61. package/dist/tools/environments.js.map +1 -1
  62. package/dist/tools/exec-run.d.ts.map +1 -1
  63. package/dist/tools/exec-run.js +7 -1
  64. package/dist/tools/exec-run.js.map +1 -1
  65. package/dist/tools/images.d.ts.map +1 -1
  66. package/dist/tools/images.js +5 -1
  67. package/dist/tools/images.js.map +1 -1
  68. package/dist/tools/lifecycle.d.ts.map +1 -1
  69. package/dist/tools/lifecycle.js +5 -1
  70. package/dist/tools/lifecycle.js.map +1 -1
  71. package/dist/tools/links.d.ts.map +1 -1
  72. package/dist/tools/links.js +3 -1
  73. package/dist/tools/links.js.map +1 -1
  74. package/dist/tools/platform.d.ts.map +1 -1
  75. package/dist/tools/platform.js +3 -1
  76. package/dist/tools/platform.js.map +1 -1
  77. package/dist/tools/processes.d.ts.map +1 -1
  78. package/dist/tools/processes.js +11 -1
  79. package/dist/tools/processes.js.map +1 -1
  80. package/dist/tools/projects.d.ts.map +1 -1
  81. package/dist/tools/projects.js +36 -12
  82. package/dist/tools/projects.js.map +1 -1
  83. package/dist/tools/resource-config.d.ts.map +1 -1
  84. package/dist/tools/resource-config.js +3 -1
  85. package/dist/tools/resource-config.js.map +1 -1
  86. package/dist/tools/scale.d.ts.map +1 -1
  87. package/dist/tools/scale.js +3 -1
  88. package/dist/tools/scale.js.map +1 -1
  89. package/dist/tools/storage.d.ts.map +1 -1
  90. package/dist/tools/storage.js +11 -1
  91. package/dist/tools/storage.js.map +1 -1
  92. package/dist/tools/support.d.ts.map +1 -1
  93. package/dist/tools/support.js +3 -1
  94. package/dist/tools/support.js.map +1 -1
  95. package/dist/tools/usage.d.ts.map +1 -1
  96. package/dist/tools/usage.js +3 -1
  97. package/dist/tools/usage.js.map +1 -1
  98. package/dist/tools/wordpress-import.d.ts.map +1 -1
  99. package/dist/tools/wordpress-import.js +3 -1
  100. package/dist/tools/wordpress-import.js.map +1 -1
  101. package/dist/tools/wordpress-migrate.d.ts.map +1 -1
  102. package/dist/tools/wordpress-migrate.js +3 -1
  103. package/dist/tools/wordpress-migrate.js.map +1 -1
  104. package/dist/tools/wordpress-snapshot.d.ts.map +1 -1
  105. package/dist/tools/wordpress-snapshot.js +9 -1
  106. package/dist/tools/wordpress-snapshot.js.map +1 -1
  107. package/dist/tools/wordpress-targeting.d.ts.map +1 -1
  108. package/dist/tools/wordpress-targeting.js +22 -7
  109. package/dist/tools/wordpress-targeting.js.map +1 -1
  110. package/package.json +7 -3
  111. package/.github/workflows/publish.yml +0 -120
  112. package/claude-config.json +0 -13
  113. package/dist/tools/buddy.d.ts +0 -3
  114. package/dist/tools/buddy.d.ts.map +0 -1
  115. package/dist/tools/buddy.js +0 -765
  116. package/dist/tools/buddy.js.map +0 -1
  117. package/dist/tools/payments.d.ts +0 -3
  118. package/dist/tools/payments.d.ts.map +0 -1
  119. package/dist/tools/payments.js +0 -96
  120. package/dist/tools/payments.js.map +0 -1
  121. package/dist/tools/redis.d.ts +0 -3
  122. package/dist/tools/redis.d.ts.map +0 -1
  123. package/dist/tools/redis.js +0 -72
  124. package/dist/tools/redis.js.map +0 -1
  125. package/src/api.ts +0 -255
  126. package/src/index.ts +0 -247
  127. package/src/tools/accounts.ts +0 -111
  128. package/src/tools/addons.ts +0 -124
  129. package/src/tools/admin.ts +0 -42
  130. package/src/tools/ai.ts +0 -83
  131. package/src/tools/analyze.ts +0 -108
  132. package/src/tools/auth.ts +0 -177
  133. package/src/tools/backups.ts +0 -84
  134. package/src/tools/billing.ts +0 -34
  135. package/src/tools/build-logs.ts +0 -65
  136. package/src/tools/bundle.ts +0 -129
  137. package/src/tools/cli.ts +0 -76
  138. package/src/tools/credentials-reveal.ts +0 -64
  139. package/src/tools/credits.ts +0 -97
  140. package/src/tools/dailey-images.ts +0 -151
  141. package/src/tools/db-migrate.ts +0 -211
  142. package/src/tools/db.ts +0 -391
  143. package/src/tools/deploy-status.ts +0 -247
  144. package/src/tools/deploy.ts +0 -101
  145. package/src/tools/diagnose.ts +0 -567
  146. package/src/tools/domains.ts +0 -156
  147. package/src/tools/email.ts +0 -101
  148. package/src/tools/env.ts +0 -205
  149. package/src/tools/environments.ts +0 -138
  150. package/src/tools/exec-run.ts +0 -91
  151. package/src/tools/images.ts +0 -221
  152. package/src/tools/lifecycle.ts +0 -75
  153. package/src/tools/links.ts +0 -69
  154. package/src/tools/platform.ts +0 -209
  155. package/src/tools/processes.ts +0 -182
  156. package/src/tools/project-transfer.ts +0 -129
  157. package/src/tools/projects.ts +0 -287
  158. package/src/tools/resource-config.ts +0 -84
  159. package/src/tools/scale.ts +0 -33
  160. package/src/tools/storage.ts +0 -281
  161. package/src/tools/support.ts +0 -42
  162. package/src/tools/usage.ts +0 -128
  163. package/src/tools/wordpress-import.ts +0 -174
  164. package/src/tools/wordpress-live-edit.ts +0 -250
  165. package/src/tools/wordpress-migrate.ts +0 -104
  166. package/src/tools/wordpress-snapshot.ts +0 -225
  167. package/src/tools/wordpress-targeting.ts +0 -173
  168. package/src/upload.ts +0 -35
  169. package/src/version.ts +0 -70
  170. package/test/wordpress-import.test.ts +0 -223
  171. package/test/wordpress-live-edit.test.ts +0 -159
  172. package/test/wordpress-targeting.test.ts +0 -127
  173. package/tests/dailey-images.test.mjs +0 -156
  174. package/tests/environments.test.mjs +0 -230
  175. package/tests/mcp-protocol-smoke.mjs +0 -149
  176. package/tests/new-tools-smoke.mjs +0 -217
  177. package/tests/pack1-mcp-preflight.test.mjs +0 -184
  178. package/tests/pack6-smoke.mjs +0 -222
  179. package/tests/wp-snapshot-labels.test.mjs +0 -21
  180. package/tests/wp-snapshot.test.mjs +0 -261
  181. package/tsconfig.json +0 -19
@@ -1,127 +0,0 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- // Minimal fake McpServer: registerWordPressTargetingTools calls
5
- // server.tool(name, description, schema, handler) three times — capture the
6
- // handler for each tool by name.
7
- function makeFakeServer() {
8
- const handlers = new Map<string, (args: any) => Promise<{ content: Array<{ type: 'text'; text: string }> }>>();
9
- const server = {
10
- tool: (name: string, _desc: string, _schema: unknown, h: (args: any) => any) => {
11
- handlers.set(name, h);
12
- },
13
- };
14
- return { server, getHandler: (name: string) => handlers.get(name)! };
15
- }
16
-
17
- // Shared active-account state so setActiveAccount/getActiveAccount behave like
18
- // the real session-scoped store while under mock.
19
- function makeApiMock() {
20
- const calls: Array<{ method: string; path: string; body?: unknown }> = [];
21
- let active: string | undefined;
22
- return {
23
- calls,
24
- getActive: () => active,
25
- namedExports: {
26
- apiRequest: async (method: string, path: string, body?: unknown) => {
27
- calls.push({ method, path, body });
28
- if (path === '/projects') {
29
- return { ok: true, status: 200, data: { id: 'proj_wp1', name: (body as any).name, slug: 'my-blog', status: 'pending', repo_url: (body as any).repo_url, build_id: 'b1' } };
30
- }
31
- if (path === '/projects/wp/list') {
32
- return { ok: true, status: 200, data: { projects: [
33
- { project_id: 'proj_wp1', slug: 'my-blog', domain: 'my-blog.dailey.cloud', env: 'prod', db_name: 'wp_myblog', namespace: 'cust-abc', active_account: active ?? null },
34
- ] } };
35
- }
36
- if (path === '/projects/wp/resolve?ref=my-blog') {
37
- return { ok: true, status: 200, data: { project_id: 'proj_wp1', slug: 'my-blog', domain: 'my-blog.dailey.cloud', env: 'prod', db_name: 'wp_myblog', namespace: 'cust-abc', active_account: active ?? null } };
38
- }
39
- if (path === '/projects/wp/resolve?ref=ghost') {
40
- return { ok: false, status: 404, data: { error: 'not found' } };
41
- }
42
- throw new Error(`unexpected apiRequest call: ${method} ${path}`);
43
- },
44
- formatError: (res: any) => JSON.stringify(res),
45
- textResult: (text: string) => ({ content: [{ type: 'text' as const, text }] }),
46
- jsonResult: (data: unknown) => ({ content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }] }),
47
- getActiveAccount: () => active,
48
- setActiveAccount: (v: string | undefined) => { active = v && v.trim() ? v.trim() : undefined; },
49
- },
50
- };
51
- }
52
-
53
- test('dailey_create_wordpress POSTs /projects with the hardened WP catalog body and returns admin URL + account', async (t) => {
54
- const mock = makeApiMock();
55
- t.mock.module('../src/api.js', { namedExports: mock.namedExports });
56
-
57
- const { registerWordPressTargetingTools } = await import('../src/tools/wordpress-targeting.js?t=create');
58
- const { server, getHandler } = makeFakeServer();
59
- registerWordPressTargetingTools(server as any);
60
-
61
- const result = await getHandler('dailey_create_wordpress')({ name: 'My Blog', account: 'acme' });
62
- const text = result.content[0].text;
63
-
64
- const post = mock.calls.find((c) => c.path === '/projects');
65
- assert.ok(post, 'must POST /projects');
66
- assert.deepStrictEqual(post!.body, {
67
- name: 'My Blog',
68
- repo_url: 'wordpress:6-apache',
69
- needs_database: true,
70
- needs_storage: true,
71
- });
72
- assert.match(text, /https:\/\/my-blog\.dailey\.cloud\/wp-admin/);
73
- assert.match(text, /WORDPRESS_ADMIN_PASSWORD/);
74
- assert.match(text, /Account:\s+acme/, 'surfaces the effective account');
75
- });
76
-
77
- test('dailey_wp_list calls GET /projects/wp/list and surfaces active_account + projects', async (t) => {
78
- const mock = makeApiMock();
79
- t.mock.module('../src/api.js', { namedExports: mock.namedExports });
80
-
81
- const { registerWordPressTargetingTools } = await import('../src/tools/wordpress-targeting.js?t=list');
82
- const { server, getHandler } = makeFakeServer();
83
- registerWordPressTargetingTools(server as any);
84
-
85
- const result = await getHandler('dailey_wp_list')({ account: 'acme' });
86
- const parsed = JSON.parse(result.content[0].text);
87
-
88
- assert.deepStrictEqual(mock.calls.map((c) => `${c.method} ${c.path}`), ['GET /projects/wp/list']);
89
- assert.strictEqual(parsed.active_account, 'acme');
90
- assert.strictEqual(parsed.count, 1);
91
- assert.strictEqual(parsed.projects[0].slug, 'my-blog');
92
- });
93
-
94
- test('dailey_wp_target echoes the resolved identity for a valid ref', async (t) => {
95
- const mock = makeApiMock();
96
- t.mock.module('../src/api.js', { namedExports: mock.namedExports });
97
-
98
- const { registerWordPressTargetingTools } = await import('../src/tools/wordpress-targeting.js?t=target-ok');
99
- const { server, getHandler } = makeFakeServer();
100
- registerWordPressTargetingTools(server as any);
101
-
102
- const result = await getHandler('dailey_wp_target')({ project: 'my-blog' });
103
- const parsed = JSON.parse(result.content[0].text);
104
-
105
- assert.strictEqual(parsed.resolved, true);
106
- assert.strictEqual(parsed.target.project_id, 'proj_wp1');
107
- assert.strictEqual(parsed.target.db_name, 'wp_myblog');
108
- assert.strictEqual(parsed.target.domain, 'my-blog.dailey.cloud');
109
- assert.match(parsed.confirm, /db=wp_myblog/);
110
- });
111
-
112
- test('dailey_wp_target returns a clear not-found on 404 pointing at dailey_wp_list', async (t) => {
113
- const mock = makeApiMock();
114
- t.mock.module('../src/api.js', { namedExports: mock.namedExports });
115
-
116
- const { registerWordPressTargetingTools } = await import('../src/tools/wordpress-targeting.js?t=target-404');
117
- const { server, getHandler } = makeFakeServer();
118
- registerWordPressTargetingTools(server as any);
119
-
120
- const result = await getHandler('dailey_wp_target')({ project: 'ghost', account: 'acme' });
121
- const parsed = JSON.parse(result.content[0].text);
122
-
123
- assert.strictEqual(parsed.resolved, false);
124
- assert.strictEqual(parsed.active_account, 'acme');
125
- assert.match(parsed.message, /No WordPress project matching 'ghost'/);
126
- assert.match(parsed.message, /dailey_wp_list/);
127
- });
@@ -1,156 +0,0 @@
1
- /**
2
- * Dailey Images (AI generation) MCP tools — two-layer test.
3
- *
4
- * Layer 1 (protocol smoke): spawns dist/index.js, does the MCP handshake,
5
- * calls tools/list, and asserts dailey_images_generate / dailey_images_enable /
6
- * dailey_images_info appear with correct input schemas. No credentials needed.
7
- *
8
- * Layer 2 (in-process registration checks): imports the compiled module,
9
- * stubs McpServer.tool(), and verifies names, schemas, and descriptions.
10
- *
11
- * Run:
12
- * node --test tests/dailey-images.test.mjs
13
- */
14
-
15
- import { test, describe } from 'node:test';
16
- import assert from 'node:assert/strict';
17
- import { spawn } from 'node:child_process';
18
- import { join, dirname } from 'node:path';
19
- import { fileURLToPath } from 'node:url';
20
-
21
- const __dirname = dirname(fileURLToPath(import.meta.url));
22
- const BINARY = join(__dirname, '..', 'dist', 'index.js');
23
-
24
- // ── Layer 1: protocol smoke (tools/list) ───────────────────────────────────
25
-
26
- describe('dailey images MCP tools — protocol smoke', { concurrency: false }, () => {
27
- test('generate/enable/info appear in tools/list with input schemas', async () => {
28
- const child = spawn('node', [BINARY], {
29
- env: {
30
- ...process.env,
31
- DAILEY_EMAIL: process.env.DAILEY_EMAIL || 'smoke@example.com',
32
- DAILEY_PASSWORD: process.env.DAILEY_PASSWORD || 'smoke-password',
33
- DAILEY_API_TOKEN: process.env.DAILEY_API_TOKEN || '',
34
- DAILEY_API_URL: process.env.DAILEY_API_URL || 'https://os.dailey.cloud/api',
35
- },
36
- stdio: ['pipe', 'pipe', 'pipe'],
37
- });
38
-
39
- let buffer = '';
40
- let nextId = 1;
41
- const pending = new Map();
42
-
43
- child.stdout.on('data', (chunk) => {
44
- buffer += chunk.toString();
45
- const lines = buffer.split('\n');
46
- buffer = lines.pop();
47
- for (const line of lines) {
48
- if (!line.trim()) continue;
49
- try {
50
- const msg = JSON.parse(line);
51
- if (msg.id != null && pending.has(msg.id)) {
52
- const { resolve } = pending.get(msg.id);
53
- pending.delete(msg.id);
54
- resolve(msg);
55
- }
56
- } catch { /* ignore non-JSON lines */ }
57
- }
58
- });
59
-
60
- child.stderr.on('data', (_chunk) => { /* suppress */ });
61
-
62
- function send(method, params, timeoutMs = 10000) {
63
- return new Promise((resolve, reject) => {
64
- const id = nextId++;
65
- const timer = setTimeout(() => {
66
- if (pending.has(id)) {
67
- pending.delete(id);
68
- reject(new Error(`Timeout waiting for ${method}`));
69
- }
70
- }, timeoutMs);
71
- pending.set(id, {
72
- resolve: (v) => { clearTimeout(timer); resolve(v); },
73
- reject,
74
- });
75
- child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
76
- });
77
- }
78
-
79
- try {
80
- await send('initialize', {
81
- protocolVersion: '2024-11-05',
82
- capabilities: {},
83
- clientInfo: { name: 'dailey-images-smoke', version: '1.0.0' },
84
- });
85
- child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
86
-
87
- const toolsMsg = await send('tools/list', {});
88
- const tools = toolsMsg.result?.tools ?? [];
89
- const toolMap = Object.fromEntries(tools.map((t) => [t.name, t]));
90
-
91
- for (const name of ['dailey_images_generate', 'dailey_images_enable', 'dailey_images_info']) {
92
- assert.ok(toolMap[name], `Expected tool "${name}" in tools/list`);
93
- assert.ok(toolMap[name].inputSchema?.properties, `${name} must have inputSchema.properties`);
94
- assert.ok('project' in toolMap[name].inputSchema.properties, `${name} must have project param`);
95
- }
96
-
97
- // generate: prompt required; model enum; n optional
98
- const gen = toolMap['dailey_images_generate'];
99
- assert.ok('prompt' in gen.inputSchema.properties, 'generate must have prompt param');
100
- assert.ok('model' in gen.inputSchema.properties, 'generate must have model param');
101
- assert.ok('n' in gen.inputSchema.properties, 'generate must have n param');
102
- const genRequired = gen.inputSchema.required ?? [];
103
- assert.ok(genRequired.includes('project'), 'project must be required');
104
- assert.ok(genRequired.includes('prompt'), 'prompt must be required');
105
- assert.ok(!genRequired.includes('model'), 'model must be optional');
106
- assert.ok(!genRequired.includes('n'), 'n must be optional');
107
- // model is an enum with the two tiers
108
- const modelEnum = gen.inputSchema.properties.model.enum;
109
- assert.deepEqual(modelEnum, ['dailey-fast', 'dailey-pro'], 'model enum must be the two tiers');
110
- } finally {
111
- child.kill();
112
- }
113
- });
114
- });
115
-
116
- // ── Layer 2: in-process registration checks ────────────────────────────────
117
-
118
- describe('dailey images tools — registration', { concurrency: false }, () => {
119
- test('registers all three tools with the right shapes', async () => {
120
- const registrations = [];
121
- const stubServer = {
122
- tool(name, description, schema, handler) {
123
- registrations.push({ name, description, schema, handler });
124
- },
125
- };
126
-
127
- const mod = await import(join(__dirname, '..', 'dist', 'tools', 'dailey-images.js'));
128
- mod.registerDaileyImagesTools(stubServer);
129
-
130
- const byName = Object.fromEntries(registrations.map((r) => [r.name, r]));
131
-
132
- const gen = byName['dailey_images_generate'];
133
- assert.ok(gen, 'dailey_images_generate must be registered');
134
- assert.ok(typeof gen.handler === 'function', 'generate handler must be a function');
135
- assert.ok(gen.schema?.project && gen.schema?.prompt, 'generate must have project + prompt');
136
- // metered cost is called out in the description
137
- assert.match(gen.description, /2¢/, 'generate description must mention 2¢ (fast)');
138
- assert.match(gen.description, /10¢/, 'generate description must mention 10¢ (pro)');
139
- assert.match(gen.description, /prepaid credits/i, 'generate description must mention prepaid credits');
140
- // prompt required, model optional
141
- const promptOptional = gen.schema.prompt?._def?.typeName === 'ZodOptional'
142
- || (typeof gen.schema.prompt?.isOptional === 'function' && gen.schema.prompt.isOptional());
143
- assert.ok(!promptOptional, 'prompt must NOT be optional');
144
- const modelOptional = gen.schema.model?._def?.typeName === 'ZodOptional'
145
- || (typeof gen.schema.model?.isOptional === 'function' && gen.schema.model.isOptional());
146
- assert.ok(modelOptional, 'model must be optional');
147
-
148
- const enable = byName['dailey_images_enable'];
149
- assert.ok(enable, 'dailey_images_enable must be registered');
150
- assert.ok(enable.schema?.project, 'enable must have project param');
151
-
152
- const info = byName['dailey_images_info'];
153
- assert.ok(info, 'dailey_images_info must be registered');
154
- assert.ok(info.schema?.project, 'info must have project param');
155
- });
156
- });
@@ -1,230 +0,0 @@
1
- /**
2
- * environments + dailey_wp_clone MCP tools — two-layer test.
3
- *
4
- * Layer 1 (protocol smoke): spawns dist/index.js, does the MCP handshake,
5
- * calls tools/list, and asserts dailey_environments and dailey_wp_clone appear
6
- * with correct input schemas. No real credentials needed.
7
- *
8
- * Layer 2 (in-process schema/logic checks): imports the compiled module,
9
- * stubs McpServer.tool(), and verifies descriptions, schemas, and confirm-gate
10
- * logic via source inspection.
11
- *
12
- * Run:
13
- * node --test tests/environments.test.mjs
14
- */
15
-
16
- import { test, describe } from 'node:test';
17
- import assert from 'node:assert/strict';
18
- import { spawn } from 'node:child_process';
19
- import { join, dirname } from 'node:path';
20
- import { fileURLToPath } from 'node:url';
21
- import { readFileSync } from 'node:fs';
22
-
23
- const __dirname = dirname(fileURLToPath(import.meta.url));
24
- const BINARY = join(__dirname, '..', 'dist', 'index.js');
25
-
26
- // ── Layer 1: protocol smoke (tools/list) ───────────────────────────────────
27
-
28
- describe('environments MCP tools — protocol smoke', { concurrency: false }, () => {
29
- test('dailey_environments and dailey_wp_clone appear in tools/list with input schemas', async () => {
30
- const child = spawn('node', [BINARY], {
31
- env: {
32
- ...process.env,
33
- DAILEY_EMAIL: process.env.DAILEY_EMAIL || 'smoke@example.com',
34
- DAILEY_PASSWORD: process.env.DAILEY_PASSWORD || 'smoke-password',
35
- DAILEY_API_TOKEN: process.env.DAILEY_API_TOKEN || '',
36
- DAILEY_API_URL: process.env.DAILEY_API_URL || 'https://os.dailey.cloud/api',
37
- },
38
- stdio: ['pipe', 'pipe', 'pipe'],
39
- });
40
-
41
- let buffer = '';
42
- let nextId = 1;
43
- const pending = new Map();
44
-
45
- child.stdout.on('data', (chunk) => {
46
- buffer += chunk.toString();
47
- const lines = buffer.split('\n');
48
- buffer = lines.pop();
49
- for (const line of lines) {
50
- if (!line.trim()) continue;
51
- try {
52
- const msg = JSON.parse(line);
53
- if (msg.id != null && pending.has(msg.id)) {
54
- const { resolve } = pending.get(msg.id);
55
- pending.delete(msg.id);
56
- resolve(msg);
57
- }
58
- } catch { /* ignore non-JSON lines */ }
59
- }
60
- });
61
-
62
- child.stderr.on('data', (_chunk) => { /* suppress */ });
63
-
64
- function send(method, params, timeoutMs = 10000) {
65
- return new Promise((resolve, reject) => {
66
- const id = nextId++;
67
- const timer = setTimeout(() => {
68
- if (pending.has(id)) {
69
- pending.delete(id);
70
- reject(new Error(`Timeout waiting for ${method}`));
71
- }
72
- }, timeoutMs);
73
- pending.set(id, {
74
- resolve: (v) => { clearTimeout(timer); resolve(v); },
75
- reject,
76
- });
77
- child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
78
- });
79
- }
80
-
81
- try {
82
- // MCP handshake
83
- await send('initialize', {
84
- protocolVersion: '2024-11-05',
85
- capabilities: {},
86
- clientInfo: { name: 'environments-smoke', version: '1.0.0' },
87
- });
88
- child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
89
-
90
- // List tools
91
- const toolsMsg = await send('tools/list', {});
92
- const tools = toolsMsg.result?.tools ?? [];
93
- const names = new Set(tools.map((t) => t.name));
94
-
95
- const expected = ['dailey_environments', 'dailey_wp_clone'];
96
-
97
- for (const name of expected) {
98
- assert.ok(names.has(name), `Expected tool "${name}" in tools/list`);
99
- }
100
-
101
- const toolMap = Object.fromEntries(tools.map((t) => [t.name, t]));
102
-
103
- // dailey_environments: must have 'project' param
104
- const envTool = toolMap['dailey_environments'];
105
- assert.ok(envTool.inputSchema?.properties, 'dailey_environments must have inputSchema.properties');
106
- assert.ok('project' in envTool.inputSchema.properties, 'dailey_environments must have project param');
107
-
108
- // dailey_wp_clone: must have 'project' (required) + optional 'confirm_token'
109
- const cloneTool = toolMap['dailey_wp_clone'];
110
- assert.ok(cloneTool.inputSchema?.properties, 'dailey_wp_clone must have inputSchema.properties');
111
- assert.ok('project' in cloneTool.inputSchema.properties, 'dailey_wp_clone must have project param');
112
- assert.ok('confirm_token' in cloneTool.inputSchema.properties, 'dailey_wp_clone must have confirm_token param');
113
-
114
- // confirm_token must be optional (not in required[])
115
- const required = cloneTool.inputSchema.required ?? [];
116
- assert.ok(!required.includes('confirm_token'), 'confirm_token must not be in required[]');
117
- assert.ok(required.includes('project'), 'project must be in required[]');
118
-
119
- } finally {
120
- child.kill();
121
- }
122
- });
123
- });
124
-
125
- // ── Layer 2: in-process registration checks ────────────────────────────────
126
-
127
- describe('dailey_environments — registration', { concurrency: false }, () => {
128
- test('registers with correct name and has project param', async () => {
129
- const registrations = [];
130
- const stubServer = {
131
- tool(name, description, schema, handler) {
132
- registrations.push({ name, description, schema, handler });
133
- },
134
- };
135
-
136
- const mod = await import(join(__dirname, '..', 'dist', 'tools', 'environments.js'));
137
- mod.registerEnvironmentTools(stubServer);
138
-
139
- const env = registrations.find((r) => r.name === 'dailey_environments');
140
- assert.ok(env, 'dailey_environments must be registered');
141
- assert.ok(env.schema?.project, 'dailey_environments must have project in schema');
142
- assert.ok(typeof env.handler === 'function', 'dailey_environments handler must be a function');
143
- });
144
- });
145
-
146
- describe('dailey_wp_clone — confirm-gate logic', { concurrency: false }, () => {
147
- test('confirm_token is optional in schema', async () => {
148
- const registrations = [];
149
- const stubServer = {
150
- tool(name, description, schema, handler) {
151
- registrations.push({ name, description, schema, handler });
152
- },
153
- };
154
-
155
- const mod = await import(join(__dirname, '..', 'dist', 'tools', 'environments.js'));
156
- mod.registerEnvironmentTools(stubServer);
157
-
158
- const clone = registrations.find((r) => r.name === 'dailey_wp_clone');
159
- assert.ok(clone, 'dailey_wp_clone must be registered');
160
-
161
- // Description mentions DESTRUCTIVE and two-phase
162
- assert.match(clone.description, /DESTRUCTIVE/i, 'Description must mention DESTRUCTIVE');
163
- assert.match(clone.description, /two-phase|two phase/i, 'Description must mention two-phase');
164
- assert.match(clone.description, /confirm_token/, 'Description must mention confirm_token');
165
-
166
- // confirm_token must be ZodOptional
167
- const confirmField = clone.schema?.confirm_token;
168
- assert.ok(confirmField, 'confirm_token must be in schema');
169
- const isOptional =
170
- confirmField?._def?.typeName === 'ZodOptional' ||
171
- (typeof confirmField?.isOptional === 'function' && confirmField.isOptional());
172
- assert.ok(isOptional, 'confirm_token must be ZodOptional (.optional())');
173
-
174
- // project is required (ZodString, not ZodOptional)
175
- const projectField = clone.schema?.project;
176
- assert.ok(projectField, 'project must be in schema');
177
- const projectIsOptional =
178
- projectField?._def?.typeName === 'ZodOptional' ||
179
- (typeof projectField?.isOptional === 'function' && projectField.isOptional());
180
- assert.ok(!projectIsOptional, 'project must NOT be optional');
181
- });
182
-
183
- test('compiled source: preview route before execute route, confirm_token guard present', async () => {
184
- const src = readFileSync(join(__dirname, '..', 'dist', 'tools', 'environments.js'), 'utf8');
185
-
186
- // confirm_token guard exists
187
- assert.ok(
188
- src.includes('if (!confirm_token)'),
189
- 'Compiled output must contain `if (!confirm_token)` branch guard',
190
- );
191
-
192
- // preview route referenced
193
- assert.ok(
194
- src.includes('/wp/clone/preview'),
195
- 'Compiled output must reference /wp/clone/preview',
196
- );
197
-
198
- // execute route referenced
199
- assert.ok(
200
- src.includes('/wp/clone'),
201
- 'Compiled output must reference /wp/clone execute route',
202
- );
203
-
204
- // preview appears before execute in file (branch ordering)
205
- const previewIdx = src.indexOf('/wp/clone/preview');
206
- // execute route: find the non-preview occurrence
207
- let searchFrom = 0;
208
- let executeIdx = -1;
209
- while (true) {
210
- const idx = src.indexOf('/wp/clone', searchFrom);
211
- if (idx === -1) break;
212
- if (!src.slice(idx).startsWith('/wp/clone/preview')) {
213
- executeIdx = idx;
214
- break;
215
- }
216
- searchFrom = idx + 1;
217
- }
218
- assert.ok(executeIdx !== -1, 'Must find /wp/clone execute route in compiled output');
219
- assert.ok(
220
- previewIdx < executeIdx,
221
- `Preview route (idx ${previewIdx}) must appear before execute route (idx ${executeIdx})`,
222
- );
223
-
224
- // confirmation: 'CLONE' is in the execute path
225
- assert.ok(
226
- src.includes("confirmation: 'CLONE'") || src.includes('confirmation:"CLONE"'),
227
- "Execute path must pass confirmation: 'CLONE'",
228
- );
229
- });
230
- });
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * End-to-end MCP-protocol smoke test.
4
- *
5
- * Spawns the compiled MCP server, speaks the JSON-RPC stdio protocol, lists
6
- * all tools, and calls a representative read-only tool. This exercises the
7
- * actual MCP surface LLMs see.
8
- */
9
- import { spawn } from 'node:child_process';
10
- import path from 'node:path';
11
-
12
- const binary = path.resolve(new URL('.', import.meta.url).pathname, '..', 'dist/index.js');
13
-
14
- const env = {
15
- ...process.env,
16
- DAILEY_API_URL: process.env.DAILEY_API_URL || 'https://os.dailey.cloud/api',
17
- DAILEY_EMAIL: process.env.DAILEY_EMAIL,
18
- DAILEY_PASSWORD: process.env.DAILEY_PASSWORD,
19
- };
20
-
21
- if (!env.DAILEY_EMAIL || !env.DAILEY_PASSWORD) {
22
- console.error('DAILEY_EMAIL and DAILEY_PASSWORD must be set');
23
- process.exit(1);
24
- }
25
-
26
- const child = spawn('node', [binary], { env, stdio: ['pipe', 'pipe', 'pipe'] });
27
-
28
- let nextId = 1;
29
- const pending = new Map();
30
- let buffer = '';
31
-
32
- child.stdout.on('data', (chunk) => {
33
- buffer += chunk.toString();
34
- const lines = buffer.split('\n');
35
- buffer = lines.pop();
36
- for (const line of lines) {
37
- if (!line.trim()) continue;
38
- try {
39
- const msg = JSON.parse(line);
40
- if (msg.id && pending.has(msg.id)) {
41
- const { resolve } = pending.get(msg.id);
42
- pending.delete(msg.id);
43
- resolve(msg);
44
- }
45
- } catch { /* ignore */ }
46
- }
47
- });
48
-
49
- child.stderr.on('data', (chunk) => {
50
- process.stderr.write(`[mcp-server] ${chunk}`);
51
- });
52
-
53
- function send(method, params) {
54
- return new Promise((resolve, reject) => {
55
- const id = nextId++;
56
- pending.set(id, { resolve, reject });
57
- child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
58
- setTimeout(() => {
59
- if (pending.has(id)) {
60
- pending.delete(id);
61
- reject(new Error(`Timeout waiting for ${method}`));
62
- }
63
- }, 15000);
64
- });
65
- }
66
-
67
- async function main() {
68
- console.log('Spawning MCP server...');
69
-
70
- // MCP handshake
71
- const init = await send('initialize', {
72
- protocolVersion: '2024-11-05',
73
- capabilities: {},
74
- clientInfo: { name: 'smoke-test', version: '1.0.0' },
75
- });
76
- console.log(`✓ initialized (server: ${init.result?.serverInfo?.name} v${init.result?.serverInfo?.version})`);
77
-
78
- // Notify initialized (required by some clients)
79
- child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
80
-
81
- // List tools
82
- const toolsMsg = await send('tools/list', {});
83
- const tools = toolsMsg.result?.tools || [];
84
- console.log(`✓ tools/list returned ${tools.length} tools`);
85
-
86
- const expected = [
87
- 'dailey_whoami',
88
- 'dailey_list_projects',
89
- 'dailey_project_info',
90
- 'dailey_deploy_status',
91
- 'dailey_build_logs',
92
- 'dailey_processes',
93
- 'dailey_process_logs',
94
- 'dailey_process_restart',
95
- 'dailey_process_metrics',
96
- 'dailey_process_resources',
97
- 'dailey_pause',
98
- 'dailey_resume',
99
- 'dailey_backups',
100
- 'dailey_resource_config',
101
- 'dailey_service_links',
102
- 'dailey_reveal_credential',
103
- 'dailey_analyze_repo',
104
- 'dailey_db_validate',
105
- 'dailey_db_tunnel',
106
- 'dailey_scale',
107
- 'dailey_domains',
108
- ];
109
-
110
- const names = new Set(tools.map((t) => t.name));
111
- const missing = expected.filter((n) => !names.has(n));
112
- if (missing.length) {
113
- console.log(`✗ missing tools: ${missing.join(', ')}`);
114
- process.exit(1);
115
- }
116
- console.log(`✓ all expected new tools registered`);
117
-
118
- // Call a real tool — dailey_whoami — to verify end-to-end flow.
119
- const whoamiMsg = await send('tools/call', { name: 'dailey_whoami', arguments: {} });
120
- const text = whoamiMsg.result?.content?.[0]?.text || '';
121
- if (!text.includes('@') && !text.toLowerCase().includes('email')) {
122
- console.log(`✗ dailey_whoami returned unexpected output: ${text.slice(0, 100)}`);
123
- process.exit(1);
124
- }
125
- console.log(`✓ dailey_whoami call succeeded (${text.split('\n')[0]})`);
126
-
127
- // Call a new tool — dailey_analyze_repo on nginx:alpine.
128
- const analyzeMsg = await send('tools/call', {
129
- name: 'dailey_analyze_repo',
130
- arguments: { repo_url: 'nginx:alpine' },
131
- });
132
- const analyzeText = analyzeMsg.result?.content?.[0]?.text || '';
133
- if (!analyzeText.includes('Analysis') || !analyzeText.includes('nginx:alpine')) {
134
- console.log(`✗ dailey_analyze_repo returned unexpected output: ${analyzeText.slice(0, 200)}`);
135
- process.exit(1);
136
- }
137
- console.log(`✓ dailey_analyze_repo call succeeded`);
138
-
139
- child.kill();
140
- console.log('');
141
- console.log(`All checks passed. ${tools.length} tools registered, new tools callable.`);
142
- process.exit(0);
143
- }
144
-
145
- main().catch((err) => {
146
- console.error('TEST CRASH:', err);
147
- child.kill();
148
- process.exit(2);
149
- });