@adsim/wordpress-mcp-server 4.5.0 → 4.6.0
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.
- package/README.md +92 -11
- package/dxt/manifest.json +17 -6
- package/index.js +327 -164
- package/package.json +1 -1
- package/src/plugins/IPluginAdapter.js +95 -0
- package/src/plugins/adapters/acf/acfAdapter.js +181 -0
- package/src/plugins/adapters/elementor/elementorAdapter.js +176 -0
- package/src/plugins/contextGuard.js +57 -0
- package/src/plugins/registry.js +94 -0
- package/tests/unit/pluginLayer.test.js +151 -0
- package/tests/unit/plugins/acf/acfAdapter.test.js +205 -0
- package/tests/unit/plugins/acf/acfAdapter.write.test.js +157 -0
- package/tests/unit/plugins/contextGuard.test.js +51 -0
- package/tests/unit/plugins/elementor/elementorAdapter.test.js +206 -0
- package/tests/unit/plugins/iPluginAdapter.test.js +34 -0
- package/tests/unit/plugins/registry.test.js +84 -0
- package/tests/unit/tools/dynamicFiltering.test.js +136 -0
- package/tests/unit/tools/outputCompression.test.js +342 -0
- package/tests/unit/tools/site.test.js +3 -1
- package/tests/unit/tools/siteOptions.test.js +101 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
vi.mock('node-fetch', () => ({ default: vi.fn() }));
|
|
4
|
+
|
|
5
|
+
import fetch from 'node-fetch';
|
|
6
|
+
import { handleToolCall } from '../../../index.js';
|
|
7
|
+
import { mockSuccess, makeRequest, parseResult } from '../../helpers/mockWpRequest.js';
|
|
8
|
+
|
|
9
|
+
function call(name, args = {}) {
|
|
10
|
+
return handleToolCall(makeRequest(name, args));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let consoleSpy;
|
|
14
|
+
beforeEach(() => { fetch.mockReset(); consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); });
|
|
15
|
+
afterEach(() => { consoleSpy.mockRestore(); });
|
|
16
|
+
|
|
17
|
+
// ── Mock data factories ──
|
|
18
|
+
|
|
19
|
+
const mockPage = { id: 10, title: { rendered: 'About' }, slug: 'about', status: 'publish', date: '2024-01-01', link: 'https://test.example.com/about', parent: 0, menu_order: 1, template: '', excerpt: { rendered: 'About page' } };
|
|
20
|
+
|
|
21
|
+
const mockMedia = { id: 1, title: { rendered: 'Logo' }, date: '2024-01-01', mime_type: 'image/png', source_url: 'https://test.example.com/logo.png', alt_text: 'Site logo', media_details: { width: 200, height: 100 } };
|
|
22
|
+
|
|
23
|
+
const mockComment = { id: 100, post: 5, parent: 0, author_name: 'Alice', date: '2024-02-01', status: 'approved', content: { rendered: '<p>Great post!</p>' }, link: 'https://test.example.com/post#comment-100' };
|
|
24
|
+
|
|
25
|
+
const mockCategory = { id: 5, name: 'Tech', slug: 'tech', description: 'Tech articles', parent: 0, count: 12 };
|
|
26
|
+
|
|
27
|
+
const mockTag = { id: 7, name: 'javascript', slug: 'javascript', count: 8 };
|
|
28
|
+
|
|
29
|
+
const mockUser = { id: 1, name: 'Admin', slug: 'admin', link: 'https://test.example.com/author/admin', roles: ['administrator'], avatar_urls: { '96': 'https://test.example.com/avatar.jpg' } };
|
|
30
|
+
|
|
31
|
+
const mockCustomPost = { id: 42, title: { rendered: 'Portfolio Item' }, slug: 'portfolio-item', status: 'publish', date: '2024-03-01', link: 'https://test.example.com/portfolio/portfolio-item', type: 'portfolio', meta: {} };
|
|
32
|
+
|
|
33
|
+
const mockPlugin = { plugin: 'akismet/akismet.php', name: 'Akismet', version: '5.3', status: 'active', author: { rendered: 'Automattic' }, description: { rendered: 'Anti-spam' }, plugin_uri: 'https://akismet.com', requires_wp: '6.0', requires_php: '7.4', network_only: false, textdomain: 'akismet' };
|
|
34
|
+
|
|
35
|
+
const mockTheme = { stylesheet: 'twentytwentyfour', template: 'twentytwentyfour', name: { rendered: 'Twenty Twenty-Four' }, description: { rendered: 'Default theme' }, status: 'active', version: '1.2', author: { rendered: 'WordPress' }, author_uri: '', theme_uri: '', requires_wp: '6.4', requires_php: '7.0', tags: { rendered: ['blog'] } };
|
|
36
|
+
|
|
37
|
+
const mockRevision = { id: 200, parent: 5, date: '2024-04-01', date_gmt: '2024-04-01T00:00:00', modified: '2024-04-01', modified_gmt: '2024-04-01T00:00:00', author: 1, title: { rendered: 'Draft v2' }, excerpt: { rendered: 'Updated excerpt' }, slug: '5-revision-v1' };
|
|
38
|
+
|
|
39
|
+
const mockTypes = { portfolio: { slug: 'portfolio', name: 'Portfolio', rest_base: 'portfolio' } };
|
|
40
|
+
|
|
41
|
+
// =========================================================================
|
|
42
|
+
// wp_list_pages
|
|
43
|
+
// =========================================================================
|
|
44
|
+
|
|
45
|
+
describe('wp_list_pages — output compression', () => {
|
|
46
|
+
it('mode=ids_only returns flat ID array', async () => {
|
|
47
|
+
fetch.mockResolvedValue(mockSuccess([mockPage]));
|
|
48
|
+
const data = parseResult(await call('wp_list_pages', { mode: 'ids_only' }));
|
|
49
|
+
expect(data.mode).toBe('ids_only');
|
|
50
|
+
expect(data.ids).toEqual([10]);
|
|
51
|
+
expect(data.pages).toBeUndefined();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
55
|
+
fetch.mockResolvedValue(mockSuccess([mockPage]));
|
|
56
|
+
const data = parseResult(await call('wp_list_pages', { mode: 'summary' }));
|
|
57
|
+
expect(data.mode).toBe('summary');
|
|
58
|
+
expect(data.pages[0]).toEqual({ id: 10, title: 'About', slug: 'about', status: 'publish', link: 'https://test.example.com/about', parent: 0 });
|
|
59
|
+
expect(data.pages[0].menu_order).toBeUndefined();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('mode=full (default) returns full format', async () => {
|
|
63
|
+
fetch.mockResolvedValue(mockSuccess([mockPage]));
|
|
64
|
+
const data = parseResult(await call('wp_list_pages'));
|
|
65
|
+
expect(data.mode).toBeUndefined();
|
|
66
|
+
expect(data.pages[0].menu_order).toBe(1);
|
|
67
|
+
expect(data.pages[0].template).toBe('');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// =========================================================================
|
|
72
|
+
// wp_list_media
|
|
73
|
+
// =========================================================================
|
|
74
|
+
|
|
75
|
+
describe('wp_list_media — output compression', () => {
|
|
76
|
+
it('mode=ids_only returns flat ID array', async () => {
|
|
77
|
+
fetch.mockResolvedValue(mockSuccess([mockMedia]));
|
|
78
|
+
const data = parseResult(await call('wp_list_media', { mode: 'ids_only' }));
|
|
79
|
+
expect(data.mode).toBe('ids_only');
|
|
80
|
+
expect(data.ids).toEqual([1]);
|
|
81
|
+
expect(data.media).toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
85
|
+
fetch.mockResolvedValue(mockSuccess([mockMedia]));
|
|
86
|
+
const data = parseResult(await call('wp_list_media', { mode: 'summary' }));
|
|
87
|
+
expect(data.mode).toBe('summary');
|
|
88
|
+
expect(data.media[0]).toEqual({ id: 1, title: 'Logo', mime_type: 'image/png', source_url: 'https://test.example.com/logo.png', alt_text: 'Site logo' });
|
|
89
|
+
expect(data.media[0].width).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('mode=full (default) returns full format', async () => {
|
|
93
|
+
fetch.mockResolvedValue(mockSuccess([mockMedia]));
|
|
94
|
+
const data = parseResult(await call('wp_list_media'));
|
|
95
|
+
expect(data.mode).toBeUndefined();
|
|
96
|
+
expect(data.media[0].width).toBe(200);
|
|
97
|
+
expect(data.media[0].height).toBe(100);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// =========================================================================
|
|
102
|
+
// wp_list_comments
|
|
103
|
+
// =========================================================================
|
|
104
|
+
|
|
105
|
+
describe('wp_list_comments — output compression', () => {
|
|
106
|
+
it('mode=ids_only returns flat ID array', async () => {
|
|
107
|
+
fetch.mockResolvedValue(mockSuccess([mockComment]));
|
|
108
|
+
const data = parseResult(await call('wp_list_comments', { mode: 'ids_only' }));
|
|
109
|
+
expect(data.mode).toBe('ids_only');
|
|
110
|
+
expect(data.ids).toEqual([100]);
|
|
111
|
+
expect(data.comments).toBeUndefined();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
115
|
+
fetch.mockResolvedValue(mockSuccess([mockComment]));
|
|
116
|
+
const data = parseResult(await call('wp_list_comments', { mode: 'summary' }));
|
|
117
|
+
expect(data.mode).toBe('summary');
|
|
118
|
+
expect(data.comments[0]).toEqual({ id: 100, post: 5, author_name: 'Alice', date: '2024-02-01', status: 'approved' });
|
|
119
|
+
expect(data.comments[0].content).toBeUndefined();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('mode=full (default) returns full format', async () => {
|
|
123
|
+
fetch.mockResolvedValue(mockSuccess([mockComment]));
|
|
124
|
+
const data = parseResult(await call('wp_list_comments'));
|
|
125
|
+
expect(data.mode).toBeUndefined();
|
|
126
|
+
expect(data.comments[0].content).toBeDefined();
|
|
127
|
+
expect(data.comments[0].link).toBeDefined();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// =========================================================================
|
|
132
|
+
// wp_list_categories
|
|
133
|
+
// =========================================================================
|
|
134
|
+
|
|
135
|
+
describe('wp_list_categories — output compression', () => {
|
|
136
|
+
it('mode=ids_only returns flat ID array', async () => {
|
|
137
|
+
fetch.mockResolvedValue(mockSuccess([mockCategory]));
|
|
138
|
+
const data = parseResult(await call('wp_list_categories', { mode: 'ids_only' }));
|
|
139
|
+
expect(data.mode).toBe('ids_only');
|
|
140
|
+
expect(data.ids).toEqual([5]);
|
|
141
|
+
expect(data.categories).toBeUndefined();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
145
|
+
fetch.mockResolvedValue(mockSuccess([mockCategory]));
|
|
146
|
+
const data = parseResult(await call('wp_list_categories', { mode: 'summary' }));
|
|
147
|
+
expect(data.mode).toBe('summary');
|
|
148
|
+
expect(data.categories[0]).toEqual({ id: 5, name: 'Tech', slug: 'tech', count: 12, parent: 0 });
|
|
149
|
+
expect(data.categories[0].description).toBeUndefined();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('mode=full (default) returns full format', async () => {
|
|
153
|
+
fetch.mockResolvedValue(mockSuccess([mockCategory]));
|
|
154
|
+
const data = parseResult(await call('wp_list_categories'));
|
|
155
|
+
expect(data.mode).toBeUndefined();
|
|
156
|
+
expect(data.categories[0].description).toBe('Tech articles');
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// =========================================================================
|
|
161
|
+
// wp_list_tags
|
|
162
|
+
// =========================================================================
|
|
163
|
+
|
|
164
|
+
describe('wp_list_tags — output compression', () => {
|
|
165
|
+
it('mode=ids_only returns flat ID array', async () => {
|
|
166
|
+
fetch.mockResolvedValue(mockSuccess([mockTag]));
|
|
167
|
+
const data = parseResult(await call('wp_list_tags', { mode: 'ids_only' }));
|
|
168
|
+
expect(data.mode).toBe('ids_only');
|
|
169
|
+
expect(data.ids).toEqual([7]);
|
|
170
|
+
expect(data.tags).toBeUndefined();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
174
|
+
fetch.mockResolvedValue(mockSuccess([mockTag]));
|
|
175
|
+
const data = parseResult(await call('wp_list_tags', { mode: 'summary' }));
|
|
176
|
+
expect(data.mode).toBe('summary');
|
|
177
|
+
expect(data.tags[0]).toEqual({ id: 7, name: 'javascript', slug: 'javascript', count: 8 });
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('mode=full (default) returns full format', async () => {
|
|
181
|
+
fetch.mockResolvedValue(mockSuccess([mockTag]));
|
|
182
|
+
const data = parseResult(await call('wp_list_tags'));
|
|
183
|
+
expect(data.mode).toBeUndefined();
|
|
184
|
+
expect(data.tags[0].id).toBe(7);
|
|
185
|
+
expect(data.tags[0].count).toBe(8);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// =========================================================================
|
|
190
|
+
// wp_list_users
|
|
191
|
+
// =========================================================================
|
|
192
|
+
|
|
193
|
+
describe('wp_list_users — output compression', () => {
|
|
194
|
+
it('mode=ids_only returns flat ID array', async () => {
|
|
195
|
+
fetch.mockResolvedValue(mockSuccess([mockUser]));
|
|
196
|
+
const data = parseResult(await call('wp_list_users', { mode: 'ids_only' }));
|
|
197
|
+
expect(data.mode).toBe('ids_only');
|
|
198
|
+
expect(data.ids).toEqual([1]);
|
|
199
|
+
expect(data.users).toBeUndefined();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
203
|
+
fetch.mockResolvedValue(mockSuccess([mockUser]));
|
|
204
|
+
const data = parseResult(await call('wp_list_users', { mode: 'summary' }));
|
|
205
|
+
expect(data.mode).toBe('summary');
|
|
206
|
+
expect(data.users[0]).toEqual({ id: 1, name: 'Admin', slug: 'admin', roles: ['administrator'] });
|
|
207
|
+
expect(data.users[0].avatar).toBeUndefined();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('mode=full (default) returns full format', async () => {
|
|
211
|
+
fetch.mockResolvedValue(mockSuccess([mockUser]));
|
|
212
|
+
const data = parseResult(await call('wp_list_users'));
|
|
213
|
+
expect(data.mode).toBeUndefined();
|
|
214
|
+
expect(data.users[0].link).toBeDefined();
|
|
215
|
+
expect(data.users[0].avatar).toBeDefined();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// =========================================================================
|
|
220
|
+
// wp_list_custom_posts
|
|
221
|
+
// =========================================================================
|
|
222
|
+
|
|
223
|
+
describe('wp_list_custom_posts — output compression', () => {
|
|
224
|
+
it('mode=ids_only returns flat ID array', async () => {
|
|
225
|
+
mockSuccess(mockTypes);
|
|
226
|
+
mockSuccess([mockCustomPost]);
|
|
227
|
+
const data = parseResult(await call('wp_list_custom_posts', { post_type: 'portfolio', mode: 'ids_only' }));
|
|
228
|
+
expect(data.mode).toBe('ids_only');
|
|
229
|
+
expect(data.ids).toEqual([42]);
|
|
230
|
+
expect(data.posts).toBeUndefined();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
234
|
+
mockSuccess(mockTypes);
|
|
235
|
+
mockSuccess([mockCustomPost]);
|
|
236
|
+
const data = parseResult(await call('wp_list_custom_posts', { post_type: 'portfolio', mode: 'summary' }));
|
|
237
|
+
expect(data.mode).toBe('summary');
|
|
238
|
+
expect(data.posts[0]).toEqual({ id: 42, title: 'Portfolio Item', slug: 'portfolio-item', date: '2024-03-01', status: 'publish', link: 'https://test.example.com/portfolio/portfolio-item' });
|
|
239
|
+
expect(data.posts[0].type).toBeUndefined();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('mode=full (default) returns full format', async () => {
|
|
243
|
+
mockSuccess(mockTypes);
|
|
244
|
+
mockSuccess([mockCustomPost]);
|
|
245
|
+
const data = parseResult(await call('wp_list_custom_posts', { post_type: 'portfolio' }));
|
|
246
|
+
expect(data.mode).toBeUndefined();
|
|
247
|
+
expect(data.posts[0].type).toBe('portfolio');
|
|
248
|
+
expect(data.posts[0].meta).toEqual({});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// =========================================================================
|
|
253
|
+
// wp_list_plugins
|
|
254
|
+
// =========================================================================
|
|
255
|
+
|
|
256
|
+
describe('wp_list_plugins — output compression', () => {
|
|
257
|
+
it('mode=ids_only returns flat plugin slug array', async () => {
|
|
258
|
+
fetch.mockResolvedValue(mockSuccess([mockPlugin]));
|
|
259
|
+
const data = parseResult(await call('wp_list_plugins', { mode: 'ids_only' }));
|
|
260
|
+
expect(data.mode).toBe('ids_only');
|
|
261
|
+
expect(data.ids).toEqual(['akismet/akismet.php']);
|
|
262
|
+
expect(data.plugins).toBeUndefined();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
266
|
+
fetch.mockResolvedValue(mockSuccess([mockPlugin]));
|
|
267
|
+
const data = parseResult(await call('wp_list_plugins', { mode: 'summary' }));
|
|
268
|
+
expect(data.mode).toBe('summary');
|
|
269
|
+
expect(data.plugins[0]).toEqual({ plugin: 'akismet/akismet.php', name: 'Akismet', status: 'active', version: '5.3' });
|
|
270
|
+
expect(data.plugins[0].author).toBeUndefined();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('mode=full (default) returns full format', async () => {
|
|
274
|
+
fetch.mockResolvedValue(mockSuccess([mockPlugin]));
|
|
275
|
+
const data = parseResult(await call('wp_list_plugins'));
|
|
276
|
+
expect(data.mode).toBeUndefined();
|
|
277
|
+
expect(data.active).toBe(1);
|
|
278
|
+
expect(data.inactive).toBe(0);
|
|
279
|
+
expect(data.plugins[0].author).toBeDefined();
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// =========================================================================
|
|
284
|
+
// wp_list_themes
|
|
285
|
+
// =========================================================================
|
|
286
|
+
|
|
287
|
+
describe('wp_list_themes — output compression', () => {
|
|
288
|
+
it('mode=ids_only returns flat stylesheet array', async () => {
|
|
289
|
+
fetch.mockResolvedValue(mockSuccess([mockTheme]));
|
|
290
|
+
const data = parseResult(await call('wp_list_themes', { mode: 'ids_only' }));
|
|
291
|
+
expect(data.mode).toBe('ids_only');
|
|
292
|
+
expect(data.ids).toEqual(['twentytwentyfour']);
|
|
293
|
+
expect(data.themes).toBeUndefined();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
297
|
+
fetch.mockResolvedValue(mockSuccess([mockTheme]));
|
|
298
|
+
const data = parseResult(await call('wp_list_themes', { mode: 'summary' }));
|
|
299
|
+
expect(data.mode).toBe('summary');
|
|
300
|
+
expect(data.themes[0]).toEqual({ stylesheet: 'twentytwentyfour', name: 'Twenty Twenty-Four', status: 'active', version: '1.2' });
|
|
301
|
+
expect(data.themes[0].author).toBeUndefined();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('mode=full (default) returns full format', async () => {
|
|
305
|
+
fetch.mockResolvedValue(mockSuccess([mockTheme]));
|
|
306
|
+
const data = parseResult(await call('wp_list_themes'));
|
|
307
|
+
expect(data.mode).toBeUndefined();
|
|
308
|
+
expect(data.active_theme).toBe('Twenty Twenty-Four');
|
|
309
|
+
expect(data.themes[0].author).toBeDefined();
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// =========================================================================
|
|
314
|
+
// wp_list_revisions
|
|
315
|
+
// =========================================================================
|
|
316
|
+
|
|
317
|
+
describe('wp_list_revisions — output compression', () => {
|
|
318
|
+
it('mode=ids_only returns flat ID array', async () => {
|
|
319
|
+
fetch.mockResolvedValue(mockSuccess([mockRevision]));
|
|
320
|
+
const data = parseResult(await call('wp_list_revisions', { post_id: 5, mode: 'ids_only' }));
|
|
321
|
+
expect(data.mode).toBe('ids_only');
|
|
322
|
+
expect(data.ids).toEqual([200]);
|
|
323
|
+
expect(data.revisions).toBeUndefined();
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('mode=summary returns compact object with expected keys', async () => {
|
|
327
|
+
fetch.mockResolvedValue(mockSuccess([mockRevision]));
|
|
328
|
+
const data = parseResult(await call('wp_list_revisions', { post_id: 5, mode: 'summary' }));
|
|
329
|
+
expect(data.mode).toBe('summary');
|
|
330
|
+
expect(data.revisions[0]).toEqual({ id: 200, date: '2024-04-01', author: 1 });
|
|
331
|
+
expect(data.revisions[0].slug).toBeUndefined();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('mode=full (default) returns full format', async () => {
|
|
335
|
+
fetch.mockResolvedValue(mockSuccess([mockRevision]));
|
|
336
|
+
const data = parseResult(await call('wp_list_revisions', { post_id: 5 }));
|
|
337
|
+
expect(data.mode).toBeUndefined();
|
|
338
|
+
expect(data.note).toBeDefined();
|
|
339
|
+
expect(data.revisions[0].slug).toBe('5-revision-v1');
|
|
340
|
+
expect(data.revisions[0].author).toBe(1);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
@@ -80,7 +80,9 @@ describe('wp_site_info', () => {
|
|
|
80
80
|
|
|
81
81
|
// Server info
|
|
82
82
|
expect(data.server.mcp_version).toBeDefined();
|
|
83
|
-
expect(data.server.
|
|
83
|
+
expect(data.server.tools_total).toBe(86);
|
|
84
|
+
expect(typeof data.server.tools_exposed).toBe('number');
|
|
85
|
+
expect(Array.isArray(data.server.filtered_out)).toBe(true);
|
|
84
86
|
});
|
|
85
87
|
|
|
86
88
|
it('SUCCESS — enterprise_controls reflect WP_READ_ONLY env var', async () => {
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
vi.mock('node-fetch', () => ({ default: vi.fn() }));
|
|
4
|
+
|
|
5
|
+
import fetch from 'node-fetch';
|
|
6
|
+
import { handleToolCall } from '../../../index.js';
|
|
7
|
+
import { mockSuccess, mockError, makeRequest, parseResult, getAuditLogs } from '../../helpers/mockWpRequest.js';
|
|
8
|
+
|
|
9
|
+
function call(name, args = {}) {
|
|
10
|
+
return handleToolCall(makeRequest(name, args));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let consoleSpy;
|
|
14
|
+
const envBackup = {};
|
|
15
|
+
|
|
16
|
+
function saveEnv(...keys) {
|
|
17
|
+
keys.forEach(k => { envBackup[k] = process.env[k]; });
|
|
18
|
+
}
|
|
19
|
+
function restoreEnv() {
|
|
20
|
+
Object.entries(envBackup).forEach(([k, v]) => {
|
|
21
|
+
if (v === undefined) delete process.env[k];
|
|
22
|
+
else process.env[k] = v;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
fetch.mockReset();
|
|
28
|
+
consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
29
|
+
saveEnv('WP_READ_ONLY');
|
|
30
|
+
});
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
consoleSpy.mockRestore();
|
|
33
|
+
restoreEnv();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ── Mock data ──
|
|
37
|
+
|
|
38
|
+
const mockSettings = {
|
|
39
|
+
title: 'My Site',
|
|
40
|
+
description: 'Just another WordPress site',
|
|
41
|
+
url: 'https://test.example.com',
|
|
42
|
+
email: 'admin@test.example.com',
|
|
43
|
+
timezone_string: 'Europe/Brussels',
|
|
44
|
+
date_format: 'Y-m-d',
|
|
45
|
+
time_format: 'H:i',
|
|
46
|
+
language: 'en_US',
|
|
47
|
+
posts_per_page: 10,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// =========================================================================
|
|
51
|
+
// wp_get_site_options
|
|
52
|
+
// =========================================================================
|
|
53
|
+
|
|
54
|
+
describe('wp_get_site_options', () => {
|
|
55
|
+
it('returns all options when no keys parameter', async () => {
|
|
56
|
+
fetch.mockResolvedValue(mockSuccess(mockSettings));
|
|
57
|
+
const data = parseResult(await call('wp_get_site_options'));
|
|
58
|
+
expect(data.title).toBe('My Site');
|
|
59
|
+
expect(data.description).toBe('Just another WordPress site');
|
|
60
|
+
expect(data.timezone_string).toBe('Europe/Brussels');
|
|
61
|
+
expect(Object.keys(data).length).toBe(Object.keys(mockSettings).length);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('filters to requested keys only', async () => {
|
|
65
|
+
fetch.mockResolvedValue(mockSuccess(mockSettings));
|
|
66
|
+
const data = parseResult(await call('wp_get_site_options', { keys: ['title', 'language'] }));
|
|
67
|
+
expect(data.title).toBe('My Site');
|
|
68
|
+
expect(data.language).toBe('en_US');
|
|
69
|
+
expect(Object.keys(data)).toEqual(['title', 'language']);
|
|
70
|
+
expect(data.email).toBeUndefined();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('handles 403 (insufficient permissions)', async () => {
|
|
74
|
+
mockError(403, '{"code":"rest_forbidden","message":"Sorry, you are not allowed to manage options."}');
|
|
75
|
+
const res = await call('wp_get_site_options');
|
|
76
|
+
expect(res.isError).toBe(true);
|
|
77
|
+
expect(res.content[0].text).toContain('403');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('logs correct audit format to stderr', async () => {
|
|
81
|
+
fetch.mockResolvedValue(mockSuccess(mockSettings));
|
|
82
|
+
await call('wp_get_site_options', { keys: ['title'] });
|
|
83
|
+
const logs = getAuditLogs();
|
|
84
|
+
const entry = logs.find(l => l.tool === 'wp_get_site_options');
|
|
85
|
+
expect(entry).toBeDefined();
|
|
86
|
+
expect(entry.action).toBe('read_options');
|
|
87
|
+
expect(entry.status).toBe('success');
|
|
88
|
+
expect(typeof entry.latency_ms).toBe('number');
|
|
89
|
+
expect(entry.params.keys_requested).toBe(1);
|
|
90
|
+
expect(entry.params.keys_returned).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('is NOT blocked by WP_READ_ONLY=true', async () => {
|
|
94
|
+
process.env.WP_READ_ONLY = 'true';
|
|
95
|
+
fetch.mockResolvedValue(mockSuccess(mockSettings));
|
|
96
|
+
const res = await call('wp_get_site_options');
|
|
97
|
+
expect(res.isError).toBeUndefined();
|
|
98
|
+
const data = parseResult(res);
|
|
99
|
+
expect(data.title).toBe('My Site');
|
|
100
|
+
});
|
|
101
|
+
});
|