@daileyos/mcp-server 1.20.0 → 1.20.2

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 (40) hide show
  1. package/.github/workflows/publish.yml +10 -3
  2. package/dist/index.js +6 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/tools/buddy.d.ts +3 -0
  5. package/dist/tools/buddy.d.ts.map +1 -0
  6. package/dist/tools/buddy.js +765 -0
  7. package/dist/tools/buddy.js.map +1 -0
  8. package/dist/tools/dailey-images.d.ts +14 -0
  9. package/dist/tools/dailey-images.d.ts.map +1 -0
  10. package/dist/tools/dailey-images.js +87 -0
  11. package/dist/tools/dailey-images.js.map +1 -0
  12. package/dist/tools/environments.d.ts +3 -0
  13. package/dist/tools/environments.d.ts.map +1 -0
  14. package/dist/tools/environments.js +75 -0
  15. package/dist/tools/environments.js.map +1 -0
  16. package/dist/tools/payments.d.ts +3 -0
  17. package/dist/tools/payments.d.ts.map +1 -0
  18. package/dist/tools/payments.js +96 -0
  19. package/dist/tools/payments.js.map +1 -0
  20. package/dist/tools/redis.d.ts +3 -0
  21. package/dist/tools/redis.d.ts.map +1 -0
  22. package/dist/tools/redis.js +72 -0
  23. package/dist/tools/redis.js.map +1 -0
  24. package/dist/tools/wordpress-import.d.ts +3 -0
  25. package/dist/tools/wordpress-import.d.ts.map +1 -0
  26. package/dist/tools/wordpress-import.js +151 -0
  27. package/dist/tools/wordpress-import.js.map +1 -0
  28. package/dist/tools/wordpress-snapshot.d.ts.map +1 -1
  29. package/dist/tools/wordpress-snapshot.js +5 -4
  30. package/dist/tools/wordpress-snapshot.js.map +1 -1
  31. package/package.json +5 -2
  32. package/src/index.ts +6 -0
  33. package/src/tools/dailey-images.ts +151 -0
  34. package/src/tools/environments.ts +138 -0
  35. package/src/tools/wordpress-import.ts +174 -0
  36. package/src/tools/wordpress-snapshot.ts +8 -4
  37. package/test/wordpress-import.test.ts +223 -0
  38. package/tests/dailey-images.test.mjs +156 -0
  39. package/tests/environments.test.mjs +230 -0
  40. package/tests/wp-snapshot-labels.test.mjs +21 -0
@@ -0,0 +1,223 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+
7
+ // A minimal fake McpServer: registerWordPressImportTools only calls
8
+ // server.tool(name, description, schema, handler) — capture the handler.
9
+ function makeFakeServer() {
10
+ let handler: ((args: any) => Promise<{ content: Array<{ type: 'text'; text: string }> }>) | undefined;
11
+ const server = {
12
+ tool: (_name: string, _desc: string, _schema: unknown, h: typeof handler) => {
13
+ handler = h;
14
+ },
15
+ };
16
+ return { server, getHandler: () => handler! };
17
+ }
18
+
19
+ function blockedReport() {
20
+ return {
21
+ format: 'local-zip' as const,
22
+ source: { old_url: 'https://oldsite.example', table_prefix: 'wp_', wp_version: null, php_version: null, db_charset: null, multisite: false },
23
+ sizes: { db_bytes: 100, wp_content_bytes: 200, file_count: 5 },
24
+ target: { mode: 'auto-provision' as const, new_url: '' },
25
+ findings: [{ level: 'block' as const, code: 'exec-bit', message: 'executable file found' }],
26
+ verdict: 'blocked' as const,
27
+ };
28
+ }
29
+
30
+ function readyReport() {
31
+ return {
32
+ format: 'local-zip' as const,
33
+ source: { old_url: 'https://oldsite.example', table_prefix: 'wp_', wp_version: null, php_version: null, db_charset: null, multisite: false },
34
+ sizes: { db_bytes: 100, wp_content_bytes: 200, file_count: 5 },
35
+ target: { mode: 'auto-provision' as const, new_url: '' },
36
+ findings: [],
37
+ verdict: 'ready' as const,
38
+ };
39
+ }
40
+
41
+ function fakeStageResult(dbFile: string, contentFile: string) {
42
+ return {
43
+ dbFile,
44
+ contentFile,
45
+ params: { old_url: 'https://oldsite.example', table_prefix: 'wp_', wp_version: null, php_version: null, db_charset: null, multisite: false },
46
+ cleanup: async () => {},
47
+ };
48
+ }
49
+
50
+ test('action=analyze returns the BundleReport and issues no upload/run calls', async (t) => {
51
+ const calls: string[] = [];
52
+
53
+ t.mock.module('@daileyos/wp-bundle', {
54
+ namedExports: {
55
+ analyze: async () => blockedReport(),
56
+ stage: async () => { throw new Error('stage should not be called for analyze'); },
57
+ detect: async () => 'local-zip',
58
+ adapterFor: () => { throw new Error('not used'); },
59
+ },
60
+ });
61
+ t.mock.module('../src/api.js', {
62
+ namedExports: {
63
+ apiRequest: async (method: string, path: string) => {
64
+ calls.push(`${method} ${path}`);
65
+ throw new Error('apiRequest should not be called for action=analyze');
66
+ },
67
+ formatError: (res: any) => JSON.stringify(res),
68
+ textResult: (text: string) => ({ content: [{ type: 'text' as const, text }] }),
69
+ },
70
+ });
71
+ t.mock.module('../src/upload.js', {
72
+ namedExports: {
73
+ putFileToPresignedUrl: async () => { throw new Error('upload should not be called for action=analyze'); },
74
+ },
75
+ });
76
+
77
+ // Cache-bust: each test mocks the same specifiers differently, and Node's
78
+ // ESM loader caches by resolved specifier — a bare re-import would reuse
79
+ // the module instance (and its already-bound imports) from whichever test
80
+ // imported it first. A unique query string forces a fresh instantiation
81
+ // that picks up THIS test's mocks.
82
+ const { registerWordPressImportTools } = await import(`../src/tools/wordpress-import.js?t=analyze`);
83
+ const { server, getHandler } = makeFakeServer();
84
+ registerWordPressImportTools(server as any);
85
+
86
+ const dir = mkdtempSync(join(tmpdir(), 'wp-import-test-'));
87
+ const bundleFile = join(dir, 'bundle.zip');
88
+ writeFileSync(bundleFile, 'fake bundle bytes');
89
+
90
+ try {
91
+ const result = await getHandler()({ action: 'analyze', bundle_file: bundleFile });
92
+ const text = result.content[0].text;
93
+ assert.match(text, /Verdict: blocked/);
94
+ assert.match(text, /exec-bit/);
95
+ assert.strictEqual(calls.length, 0, 'analyze must not call apiRequest');
96
+ } finally {
97
+ rmSync(dir, { recursive: true, force: true });
98
+ }
99
+ });
100
+
101
+ test('action=migrate refuses on a blocked verdict without allow_unsafe, before any /run call', async (t) => {
102
+ const calls: string[] = [];
103
+
104
+ t.mock.module('@daileyos/wp-bundle', {
105
+ namedExports: {
106
+ analyze: async () => blockedReport(),
107
+ stage: async () => { throw new Error('stage should not be called when refused pre-flight'); },
108
+ detect: async () => 'local-zip',
109
+ adapterFor: () => { throw new Error('not used'); },
110
+ },
111
+ });
112
+ t.mock.module('../src/api.js', {
113
+ namedExports: {
114
+ apiRequest: async (method: string, path: string) => {
115
+ calls.push(`${method} ${path}`);
116
+ throw new Error('apiRequest should not be called when the verdict is blocked and allow_unsafe is not set');
117
+ },
118
+ formatError: (res: any) => JSON.stringify(res),
119
+ textResult: (text: string) => ({ content: [{ type: 'text' as const, text }] }),
120
+ },
121
+ });
122
+ t.mock.module('../src/upload.js', {
123
+ namedExports: {
124
+ putFileToPresignedUrl: async () => { throw new Error('upload should not be called'); },
125
+ },
126
+ });
127
+
128
+ const { registerWordPressImportTools } = await import(`../src/tools/wordpress-import.js?t=blocked`);
129
+ const { server, getHandler } = makeFakeServer();
130
+ registerWordPressImportTools(server as any);
131
+
132
+ const dir = mkdtempSync(join(tmpdir(), 'wp-import-test-'));
133
+ const bundleFile = join(dir, 'bundle.zip');
134
+ writeFileSync(bundleFile, 'fake bundle bytes');
135
+
136
+ try {
137
+ const result = await getHandler()({ action: 'migrate', bundle_file: bundleFile, confirm: true });
138
+ const text = result.content[0].text;
139
+ assert.match(text, /BLOCKED/);
140
+ assert.match(text, /allow_unsafe/);
141
+ assert.strictEqual(calls.length, 0, 'a blocked verdict must refuse before any customer-api call, including /run');
142
+ } finally {
143
+ rmSync(dir, { recursive: true, force: true });
144
+ }
145
+ });
146
+
147
+ test('action=migrate happy path calls provision-target -> start -> PUT x2 -> scan -> run -> status, in order', async (t) => {
148
+ const calls: string[] = [];
149
+ const puts: string[] = [];
150
+ const dir = mkdtempSync(join(tmpdir(), 'wp-import-test-'));
151
+ const bundleFile = join(dir, 'bundle.zip');
152
+ const dbFile = join(dir, 'db.sql');
153
+ const contentFile = join(dir, 'wp-content.tar.gz');
154
+ writeFileSync(bundleFile, 'fake bundle bytes');
155
+ writeFileSync(dbFile, 'fake db');
156
+ writeFileSync(contentFile, 'fake content');
157
+
158
+ t.mock.module('@daileyos/wp-bundle', {
159
+ namedExports: {
160
+ analyze: async () => readyReport(),
161
+ stage: async () => fakeStageResult(dbFile, contentFile),
162
+ detect: async () => 'local-zip',
163
+ adapterFor: () => { throw new Error('not used'); },
164
+ },
165
+ });
166
+ t.mock.module('../src/api.js', {
167
+ namedExports: {
168
+ apiRequest: async (method: string, path: string) => {
169
+ calls.push(`${method} ${path}`);
170
+ if (path === '/projects/wordpress/provision-target') {
171
+ return { ok: true, status: 200, data: { ok: true, project_id: 'proj_new', slug: 'x', new_url: 'https://x.dailey.cloud', ready: true, note: '' } };
172
+ }
173
+ if (path === '/projects/proj_new/migrate/wordpress') {
174
+ return {
175
+ ok: true, status: 200, data: {
176
+ migration_id: 'mig1',
177
+ db_upload: { url: 'https://upload.example/db', key: 'k1', headers: {}, max_bytes: 999 },
178
+ content_upload: { url: 'https://upload.example/content', key: 'k2', headers: {}, max_bytes: 999 },
179
+ },
180
+ };
181
+ }
182
+ if (path === '/projects/proj_new/migrate/wordpress/mig1/scan') {
183
+ return { ok: true, status: 200, data: { ok: true, verdict: 'clean', findings: [] } };
184
+ }
185
+ if (path === '/projects/proj_new/migrate/wordpress/mig1/run') {
186
+ return { ok: true, status: 202, data: { ok: true, migration_id: 'mig1', new_url: 'https://x.dailey.cloud' } };
187
+ }
188
+ if (path === '/projects/proj_new/migrate/wordpress/mig1') {
189
+ return { ok: true, status: 200, data: { status: 'succeeded' } };
190
+ }
191
+ throw new Error(`unexpected apiRequest call: ${method} ${path}`);
192
+ },
193
+ formatError: (res: any) => JSON.stringify(res),
194
+ textResult: (text: string) => ({ content: [{ type: 'text' as const, text }] }),
195
+ },
196
+ });
197
+ t.mock.module('../src/upload.js', {
198
+ namedExports: {
199
+ putFileToPresignedUrl: async (url: string) => { puts.push(url); },
200
+ },
201
+ });
202
+
203
+ const { registerWordPressImportTools } = await import(`../src/tools/wordpress-import.js?t=happy`);
204
+ const { server, getHandler } = makeFakeServer();
205
+ registerWordPressImportTools(server as any);
206
+
207
+ try {
208
+ const result = await getHandler()({ action: 'migrate', bundle_file: bundleFile, confirm: true });
209
+ const text = result.content[0].text;
210
+ assert.match(text, /succeeded/i);
211
+
212
+ assert.deepStrictEqual(calls, [
213
+ 'POST /projects/wordpress/provision-target',
214
+ 'POST /projects/proj_new/migrate/wordpress',
215
+ 'POST /projects/proj_new/migrate/wordpress/mig1/scan',
216
+ 'POST /projects/proj_new/migrate/wordpress/mig1/run',
217
+ 'GET /projects/proj_new/migrate/wordpress/mig1',
218
+ ]);
219
+ assert.deepStrictEqual(puts, ['https://upload.example/db', 'https://upload.example/content']);
220
+ } finally {
221
+ rmSync(dir, { recursive: true, force: true });
222
+ }
223
+ });
@@ -0,0 +1,156 @@
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
+ });
@@ -0,0 +1,230 @@
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
+ });
@@ -0,0 +1,21 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { registerWordPressSnapshotTools } from '../dist/tools/wordpress-snapshot.js';
4
+
5
+ function collect() {
6
+ const regs = [];
7
+ registerWordPressSnapshotTools({ tool: (name, description, schema, handler) => regs.push({ name, description, schema, handler }) });
8
+ return regs;
9
+ }
10
+
11
+ test('dailey_wp_snapshot exposes an optional label param', () => {
12
+ const reg = collect().find((r) => r.name === 'dailey_wp_snapshot');
13
+ assert.ok(reg, 'tool must be registered');
14
+ assert.ok('label' in reg.schema, 'schema must include a label field');
15
+ });
16
+
17
+ test('dailey_wp_snapshots source references reason + label columns', async () => {
18
+ const src = await import('node:fs').then((fs) => fs.readFileSync(new URL('../dist/tools/wordpress-snapshot.js', import.meta.url), 'utf8'));
19
+ assert.ok(/reason/i.test(src), 'list output should surface provenance (reason)');
20
+ assert.ok(/label/i.test(src), 'list output should surface label');
21
+ });