@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.
- package/dist/api.d.ts +7 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +37 -3
- package/dist/api.js.map +1 -1
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +6 -0
- package/dist/context.js.map +1 -0
- package/dist/http.d.ts +5 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +193 -0
- package/dist/http.js.map +1 -0
- package/dist/index.js +32 -163
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +165 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/accounts.d.ts +4 -1
- package/dist/tools/accounts.d.ts.map +1 -1
- package/dist/tools/accounts.js +57 -53
- package/dist/tools/accounts.js.map +1 -1
- package/dist/tools/ai.d.ts.map +1 -1
- package/dist/tools/ai.js +7 -1
- package/dist/tools/ai.js.map +1 -1
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +25 -6
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/backups.d.ts.map +1 -1
- package/dist/tools/backups.js +3 -1
- package/dist/tools/backups.js.map +1 -1
- package/dist/tools/build-logs.d.ts.map +1 -1
- package/dist/tools/build-logs.js +3 -1
- package/dist/tools/build-logs.js.map +1 -1
- package/dist/tools/credentials-reveal.d.ts.map +1 -1
- package/dist/tools/credentials-reveal.js +3 -1
- package/dist/tools/credentials-reveal.js.map +1 -1
- package/dist/tools/dailey-images.js +3 -3
- package/dist/tools/dailey-images.js.map +1 -1
- package/dist/tools/db-migrate.js +5 -5
- package/dist/tools/db-migrate.js.map +1 -1
- package/dist/tools/db.d.ts.map +1 -1
- package/dist/tools/db.js +17 -1
- package/dist/tools/db.js.map +1 -1
- package/dist/tools/deploy-status.d.ts.map +1 -1
- package/dist/tools/deploy-status.js +3 -1
- package/dist/tools/deploy-status.js.map +1 -1
- package/dist/tools/deploy.d.ts.map +1 -1
- package/dist/tools/deploy.js +9 -1
- package/dist/tools/deploy.js.map +1 -1
- package/dist/tools/domains.d.ts.map +1 -1
- package/dist/tools/domains.js +3 -1
- package/dist/tools/domains.js.map +1 -1
- package/dist/tools/email.d.ts.map +1 -1
- package/dist/tools/email.js +7 -1
- package/dist/tools/email.js.map +1 -1
- package/dist/tools/env.d.ts.map +1 -1
- package/dist/tools/env.js +5 -1
- package/dist/tools/env.js.map +1 -1
- package/dist/tools/environments.js +3 -3
- package/dist/tools/environments.js.map +1 -1
- package/dist/tools/exec-run.d.ts.map +1 -1
- package/dist/tools/exec-run.js +7 -1
- package/dist/tools/exec-run.js.map +1 -1
- package/dist/tools/images.d.ts.map +1 -1
- package/dist/tools/images.js +5 -1
- package/dist/tools/images.js.map +1 -1
- package/dist/tools/lifecycle.d.ts.map +1 -1
- package/dist/tools/lifecycle.js +5 -1
- package/dist/tools/lifecycle.js.map +1 -1
- package/dist/tools/links.d.ts.map +1 -1
- package/dist/tools/links.js +3 -1
- package/dist/tools/links.js.map +1 -1
- package/dist/tools/platform.d.ts.map +1 -1
- package/dist/tools/platform.js +3 -1
- package/dist/tools/platform.js.map +1 -1
- package/dist/tools/processes.d.ts.map +1 -1
- package/dist/tools/processes.js +11 -1
- package/dist/tools/processes.js.map +1 -1
- package/dist/tools/projects.d.ts.map +1 -1
- package/dist/tools/projects.js +36 -12
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/resource-config.d.ts.map +1 -1
- package/dist/tools/resource-config.js +3 -1
- package/dist/tools/resource-config.js.map +1 -1
- package/dist/tools/scale.d.ts.map +1 -1
- package/dist/tools/scale.js +3 -1
- package/dist/tools/scale.js.map +1 -1
- package/dist/tools/storage.d.ts.map +1 -1
- package/dist/tools/storage.js +11 -1
- package/dist/tools/storage.js.map +1 -1
- package/dist/tools/support.d.ts.map +1 -1
- package/dist/tools/support.js +3 -1
- package/dist/tools/support.js.map +1 -1
- package/dist/tools/usage.d.ts.map +1 -1
- package/dist/tools/usage.js +3 -1
- package/dist/tools/usage.js.map +1 -1
- package/dist/tools/wordpress-import.d.ts.map +1 -1
- package/dist/tools/wordpress-import.js +3 -1
- package/dist/tools/wordpress-import.js.map +1 -1
- package/dist/tools/wordpress-migrate.d.ts.map +1 -1
- package/dist/tools/wordpress-migrate.js +3 -1
- package/dist/tools/wordpress-migrate.js.map +1 -1
- package/dist/tools/wordpress-snapshot.d.ts.map +1 -1
- package/dist/tools/wordpress-snapshot.js +9 -1
- package/dist/tools/wordpress-snapshot.js.map +1 -1
- package/dist/tools/wordpress-targeting.d.ts.map +1 -1
- package/dist/tools/wordpress-targeting.js +22 -7
- package/dist/tools/wordpress-targeting.js.map +1 -1
- package/package.json +7 -3
- package/.github/workflows/publish.yml +0 -120
- package/claude-config.json +0 -13
- package/dist/tools/buddy.d.ts +0 -3
- package/dist/tools/buddy.d.ts.map +0 -1
- package/dist/tools/buddy.js +0 -765
- package/dist/tools/buddy.js.map +0 -1
- package/dist/tools/payments.d.ts +0 -3
- package/dist/tools/payments.d.ts.map +0 -1
- package/dist/tools/payments.js +0 -96
- package/dist/tools/payments.js.map +0 -1
- package/dist/tools/redis.d.ts +0 -3
- package/dist/tools/redis.d.ts.map +0 -1
- package/dist/tools/redis.js +0 -72
- package/dist/tools/redis.js.map +0 -1
- package/src/api.ts +0 -255
- package/src/index.ts +0 -247
- package/src/tools/accounts.ts +0 -111
- package/src/tools/addons.ts +0 -124
- package/src/tools/admin.ts +0 -42
- package/src/tools/ai.ts +0 -83
- package/src/tools/analyze.ts +0 -108
- package/src/tools/auth.ts +0 -177
- package/src/tools/backups.ts +0 -84
- package/src/tools/billing.ts +0 -34
- package/src/tools/build-logs.ts +0 -65
- package/src/tools/bundle.ts +0 -129
- package/src/tools/cli.ts +0 -76
- package/src/tools/credentials-reveal.ts +0 -64
- package/src/tools/credits.ts +0 -97
- package/src/tools/dailey-images.ts +0 -151
- package/src/tools/db-migrate.ts +0 -211
- package/src/tools/db.ts +0 -391
- package/src/tools/deploy-status.ts +0 -247
- package/src/tools/deploy.ts +0 -101
- package/src/tools/diagnose.ts +0 -567
- package/src/tools/domains.ts +0 -156
- package/src/tools/email.ts +0 -101
- package/src/tools/env.ts +0 -205
- package/src/tools/environments.ts +0 -138
- package/src/tools/exec-run.ts +0 -91
- package/src/tools/images.ts +0 -221
- package/src/tools/lifecycle.ts +0 -75
- package/src/tools/links.ts +0 -69
- package/src/tools/platform.ts +0 -209
- package/src/tools/processes.ts +0 -182
- package/src/tools/project-transfer.ts +0 -129
- package/src/tools/projects.ts +0 -287
- package/src/tools/resource-config.ts +0 -84
- package/src/tools/scale.ts +0 -33
- package/src/tools/storage.ts +0 -281
- package/src/tools/support.ts +0 -42
- package/src/tools/usage.ts +0 -128
- package/src/tools/wordpress-import.ts +0 -174
- package/src/tools/wordpress-live-edit.ts +0 -250
- package/src/tools/wordpress-migrate.ts +0 -104
- package/src/tools/wordpress-snapshot.ts +0 -225
- package/src/tools/wordpress-targeting.ts +0 -173
- package/src/upload.ts +0 -35
- package/src/version.ts +0 -70
- package/test/wordpress-import.test.ts +0 -223
- package/test/wordpress-live-edit.test.ts +0 -159
- package/test/wordpress-targeting.test.ts +0 -127
- package/tests/dailey-images.test.mjs +0 -156
- package/tests/environments.test.mjs +0 -230
- package/tests/mcp-protocol-smoke.mjs +0 -149
- package/tests/new-tools-smoke.mjs +0 -217
- package/tests/pack1-mcp-preflight.test.mjs +0 -184
- package/tests/pack6-smoke.mjs +0 -222
- package/tests/wp-snapshot-labels.test.mjs +0 -21
- package/tests/wp-snapshot.test.mjs +0 -261
- package/tsconfig.json +0 -19
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
apiRequest,
|
|
5
|
-
formatError,
|
|
6
|
-
textResult,
|
|
7
|
-
jsonResult,
|
|
8
|
-
getActiveAccount,
|
|
9
|
-
setActiveAccount,
|
|
10
|
-
} from '../api.js';
|
|
11
|
-
|
|
12
|
-
// The hardened WordPress catalog template is resolved by the deploy-service from
|
|
13
|
-
// this image name — it wires the MySQL DB + persistent wp-content volume +
|
|
14
|
-
// generated admin creds. Do NOT change without the paired catalog entry.
|
|
15
|
-
const WORDPRESS_CATALOG_IMAGE = 'wordpress:6-apache';
|
|
16
|
-
|
|
17
|
-
interface CreatedProject {
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
slug?: string;
|
|
21
|
-
status?: string;
|
|
22
|
-
repo_url?: string;
|
|
23
|
-
url?: string;
|
|
24
|
-
build_id?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// A WordPress project as returned by the targeting spine
|
|
28
|
-
// (customer-api feat/wp-targeting-spine).
|
|
29
|
-
interface WpProject {
|
|
30
|
-
project_id: string;
|
|
31
|
-
slug: string;
|
|
32
|
-
domain: string;
|
|
33
|
-
env: string;
|
|
34
|
-
db_name: string;
|
|
35
|
-
namespace: string;
|
|
36
|
-
active_account: string | null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface WpListResponse {
|
|
40
|
-
projects: WpProject[];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// If the caller passed an explicit `account`, adopt it as the acting-as target
|
|
44
|
-
// for this session (same mechanism as dailey_use_account — sends X-Dailey-Account
|
|
45
|
-
// on every subsequent request). Returns the EFFECTIVE account so every tool
|
|
46
|
-
// result can surface it and targeting is never ambiguous.
|
|
47
|
-
function scopeAccount(account?: string): string | null {
|
|
48
|
-
if (account && account.trim()) {
|
|
49
|
-
setActiveAccount(account.trim());
|
|
50
|
-
}
|
|
51
|
-
return getActiveAccount() ?? null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function registerWordPressTargetingTools(server: McpServer) {
|
|
55
|
-
// ── Tool 1 — Scenario 1: create a fresh hardened WordPress site ──────────
|
|
56
|
-
server.tool(
|
|
57
|
-
'dailey_create_wordpress',
|
|
58
|
-
'Create a brand-new hardened WordPress site in the effective account (respects the account set by dailey_use_account, or the optional `account` arg here). POSTs the standard project-create endpoint with the WordPress catalog image so the deploy-service provisions the MySQL database, a persistent wp-content volume, and generated admin credentials. Prefer this over dailey_wordpress_import when you just need a fresh site (import is for migrating an existing bundle). Returns the project_id, slug, the wp-admin URL, and the effective account. The generated admin password is retrievable via dailey_reveal_credential (key WORDPRESS_ADMIN_PASSWORD).',
|
|
59
|
-
{
|
|
60
|
-
name: z.string().describe('Project name for the new WordPress site'),
|
|
61
|
-
account: z
|
|
62
|
-
.string()
|
|
63
|
-
.optional()
|
|
64
|
-
.describe('Acting-as target: slug or id of a managed account to create the site in (must be in your fleet from dailey_accounts). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
65
|
-
},
|
|
66
|
-
async ({ name, account }) => {
|
|
67
|
-
const activeAccount = scopeAccount(account);
|
|
68
|
-
|
|
69
|
-
// Reuse the exact dailey_create_project call shape (POST /projects) but
|
|
70
|
-
// with the hardened WordPress catalog inputs. The deploy-service resolves
|
|
71
|
-
// the catalog template by image name and wires DB + storage + admin creds.
|
|
72
|
-
const res = await apiRequest<CreatedProject>('POST', '/projects', {
|
|
73
|
-
name,
|
|
74
|
-
repo_url: WORDPRESS_CATALOG_IMAGE,
|
|
75
|
-
needs_database: true,
|
|
76
|
-
needs_storage: true,
|
|
77
|
-
});
|
|
78
|
-
if (!res.ok) return textResult(formatError(res));
|
|
79
|
-
|
|
80
|
-
const p = res.data;
|
|
81
|
-
const slug = p.slug || '';
|
|
82
|
-
const adminUrl = slug ? `https://${slug}.dailey.cloud/wp-admin` : '(slug pending — check dailey_project_info)';
|
|
83
|
-
|
|
84
|
-
return textResult(
|
|
85
|
-
[
|
|
86
|
-
`WordPress site created!`,
|
|
87
|
-
``,
|
|
88
|
-
`Project ID: ${p.id}`,
|
|
89
|
-
`Name: ${p.name}`,
|
|
90
|
-
`Slug: ${slug || '(pending)'}`,
|
|
91
|
-
`Status: ${p.status || 'pending'}`,
|
|
92
|
-
`Admin URL: ${adminUrl}`,
|
|
93
|
-
`Account: ${activeAccount ?? 'self'}`,
|
|
94
|
-
...(p.build_id ? [`Build: ${p.build_id} (auto-queued — watch with dailey_deploy_status)`] : []),
|
|
95
|
-
``,
|
|
96
|
-
`The generated admin password is retrievable via:`,
|
|
97
|
-
` dailey_reveal_credential(project_id="${p.id}", key="WORDPRESS_ADMIN_PASSWORD")`,
|
|
98
|
-
`Every reveal is audited and returns a masked preview by default.`,
|
|
99
|
-
].join('\n'),
|
|
100
|
-
);
|
|
101
|
-
},
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// ── Tool 2 — list WordPress projects (targeting spine) ───────────────────
|
|
105
|
-
server.tool(
|
|
106
|
-
'dailey_wp_list',
|
|
107
|
-
'List the WordPress projects in the effective account. Call this instead of guessing a WP site from the generic dailey_list_projects — it returns only WordPress projects with their targeting identity (project_id, slug, domain, env, db_name, namespace) and prominently the active_account you are operating in. NOTE: requires the paired customer-api feat/wp-targeting-spine deploy; until that ships this returns 404 (expected — both merge together).',
|
|
108
|
-
{
|
|
109
|
-
account: z
|
|
110
|
-
.string()
|
|
111
|
-
.optional()
|
|
112
|
-
.describe('Acting-as target: slug or id of a managed account to list within (must be in your fleet from dailey_accounts). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
113
|
-
},
|
|
114
|
-
async ({ account }) => {
|
|
115
|
-
const activeAccount = scopeAccount(account);
|
|
116
|
-
|
|
117
|
-
const res = await apiRequest<WpListResponse>('GET', '/projects/wp/list');
|
|
118
|
-
if (!res.ok) return jsonResult({ active_account: activeAccount, error: formatError(res) });
|
|
119
|
-
|
|
120
|
-
const projects = res.data.projects ?? [];
|
|
121
|
-
return jsonResult({
|
|
122
|
-
active_account: activeAccount,
|
|
123
|
-
count: projects.length,
|
|
124
|
-
projects,
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// ── Tool 3 — resolve/confirm a WordPress target (targeting spine) ────────
|
|
130
|
-
server.tool(
|
|
131
|
-
'dailey_wp_target',
|
|
132
|
-
'Resolve a WordPress project reference (id OR slug) to its exact targeting identity and echo it back: project_id, slug, domain, env, db_name, namespace, and active_account. CALL THIS BEFORE ANY DESTRUCTIVE WordPress action (import, restore, clone, delete, db writes) to confirm you are about to act on the RIGHT domain/database/account — this is the fix for editing the wrong site. If no WordPress project matches the ref in the active account, returns a clear not-found pointing you at dailey_wp_list. NOTE: requires the paired customer-api feat/wp-targeting-spine deploy; until that ships this returns 404 (expected — both merge together).',
|
|
133
|
-
{
|
|
134
|
-
project: z.string().describe('The WordPress project to resolve — its id OR slug'),
|
|
135
|
-
account: z
|
|
136
|
-
.string()
|
|
137
|
-
.optional()
|
|
138
|
-
.describe('Acting-as target: slug or id of a managed account to resolve within (must be in your fleet from dailey_accounts). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
139
|
-
},
|
|
140
|
-
async ({ project, account }) => {
|
|
141
|
-
const activeAccount = scopeAccount(account);
|
|
142
|
-
|
|
143
|
-
const res = await apiRequest<WpProject & { error?: string }>(
|
|
144
|
-
'GET',
|
|
145
|
-
`/projects/wp/resolve?ref=${encodeURIComponent(project)}`,
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
if (res.status === 404) {
|
|
149
|
-
return jsonResult({
|
|
150
|
-
active_account: activeAccount,
|
|
151
|
-
resolved: false,
|
|
152
|
-
message: `No WordPress project matching '${project}' in account '${activeAccount ?? 'self'}' — call dailey_wp_list to see the options.`,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
if (!res.ok) return jsonResult({ active_account: activeAccount, resolved: false, error: formatError(res) });
|
|
156
|
-
|
|
157
|
-
const t = res.data;
|
|
158
|
-
return jsonResult({
|
|
159
|
-
active_account: t.active_account ?? activeAccount,
|
|
160
|
-
resolved: true,
|
|
161
|
-
target: {
|
|
162
|
-
project_id: t.project_id,
|
|
163
|
-
slug: t.slug,
|
|
164
|
-
domain: t.domain,
|
|
165
|
-
env: t.env,
|
|
166
|
-
db_name: t.db_name,
|
|
167
|
-
namespace: t.namespace,
|
|
168
|
-
},
|
|
169
|
-
confirm: `About to act on ${t.domain} (db=${t.db_name}, env=${t.env}) in account '${t.active_account ?? activeAccount ?? 'self'}'. Verify this is the intended site before any destructive action.`,
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
);
|
|
173
|
-
}
|
package/src/upload.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createReadStream, statSync } from 'node:fs';
|
|
2
|
-
import { request } from 'node:https';
|
|
3
|
-
import { URL } from 'node:url';
|
|
4
|
-
|
|
5
|
-
/** Stream a local file to a presigned PUT URL. S3/R2 presigned PUTs require
|
|
6
|
-
* Content-Length (no chunked encoding), so this uses https.request, not fetch. */
|
|
7
|
-
export function putFileToPresignedUrl(
|
|
8
|
-
presignedUrl: string,
|
|
9
|
-
filePath: string,
|
|
10
|
-
headers: Record<string, string> = {},
|
|
11
|
-
onProgress?: (sentBytes: number, totalBytes: number) => void,
|
|
12
|
-
): Promise<void> {
|
|
13
|
-
const total = statSync(filePath).size;
|
|
14
|
-
if (total <= 0) return Promise.reject(new Error(`${filePath} is empty`));
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const u = new URL(presignedUrl);
|
|
17
|
-
const req = request(
|
|
18
|
-
{ method: 'PUT', hostname: u.hostname, path: u.pathname + u.search, headers: { ...headers, 'Content-Length': total } },
|
|
19
|
-
(res) => {
|
|
20
|
-
let body = '';
|
|
21
|
-
res.on('data', (c) => { body += c; });
|
|
22
|
-
res.on('end', () => {
|
|
23
|
-
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) resolve();
|
|
24
|
-
else reject(new Error(`Upload failed: HTTP ${res.statusCode} ${body.slice(0, 300)}`));
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
);
|
|
28
|
-
req.on('error', reject);
|
|
29
|
-
let sent = 0;
|
|
30
|
-
const stream = createReadStream(filePath);
|
|
31
|
-
stream.on('data', (chunk) => { sent += (chunk as Buffer).length; onProgress?.(sent, total); });
|
|
32
|
-
stream.on('error', reject);
|
|
33
|
-
stream.pipe(req);
|
|
34
|
-
});
|
|
35
|
-
}
|
package/src/version.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Version identity + staleness self-check.
|
|
3
|
-
*
|
|
4
|
-
* WHY (2026-07-13 dogfood incident): sessions silently ran a months-old MCP
|
|
5
|
-
* (global-install shadowing + stale npx cache), so the agent was missing ~35
|
|
6
|
-
* tools and told the customer the platform had no AI. Staleness must never be
|
|
7
|
-
* silent again:
|
|
8
|
-
* - OWN_VERSION is read from package.json (the server previously hardcoded a
|
|
9
|
-
* stale string) and sent on every API request as X-Dailey-Client-Version,
|
|
10
|
-
* so the platform can see exactly which versions are live in the field.
|
|
11
|
-
* - checkForNewerVersion() asks the npm registry (fail-open, hard timeout)
|
|
12
|
-
* whether this copy is behind; the caller surfaces the notice to the AGENT
|
|
13
|
-
* via server instructions, so the agent itself tells the user to update.
|
|
14
|
-
*/
|
|
15
|
-
import { createRequire } from 'node:module';
|
|
16
|
-
|
|
17
|
-
const require = createRequire(import.meta.url);
|
|
18
|
-
|
|
19
|
-
export const OWN_VERSION: string = (() => {
|
|
20
|
-
try {
|
|
21
|
-
return require('../package.json').version ?? '0.0.0';
|
|
22
|
-
} catch {
|
|
23
|
-
return '0.0.0';
|
|
24
|
-
}
|
|
25
|
-
})();
|
|
26
|
-
|
|
27
|
-
/** Numeric semver compare (a<b → -1). Non-numeric parts compare as 0. */
|
|
28
|
-
function cmpSemver(a: string, b: string): number {
|
|
29
|
-
const pa = a.split('.').map((x) => parseInt(x, 10) || 0);
|
|
30
|
-
const pb = b.split('.').map((x) => parseInt(x, 10) || 0);
|
|
31
|
-
for (let i = 0; i < 3; i++) {
|
|
32
|
-
if ((pa[i] ?? 0) < (pb[i] ?? 0)) return -1;
|
|
33
|
-
if ((pa[i] ?? 0) > (pb[i] ?? 0)) return 1;
|
|
34
|
-
}
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Returns the newer registry version when this copy is outdated, else null.
|
|
40
|
-
* Fail-open: any network error / timeout returns null (never blocks startup).
|
|
41
|
-
*/
|
|
42
|
-
export async function checkForNewerVersion(timeoutMs = 1500): Promise<string | null> {
|
|
43
|
-
try {
|
|
44
|
-
const ctrl = new AbortController();
|
|
45
|
-
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
46
|
-
const res = await fetch('https://registry.npmjs.org/@daileyos%2Fmcp-server/latest', {
|
|
47
|
-
signal: ctrl.signal,
|
|
48
|
-
headers: { Accept: 'application/json' },
|
|
49
|
-
});
|
|
50
|
-
clearTimeout(timer);
|
|
51
|
-
if (!res.ok) return null;
|
|
52
|
-
const data = (await res.json()) as { version?: string };
|
|
53
|
-
const latest = data?.version;
|
|
54
|
-
if (latest && cmpSemver(OWN_VERSION, latest) < 0) return latest;
|
|
55
|
-
return null;
|
|
56
|
-
} catch {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** The notice shown to the agent (via server instructions) when outdated. */
|
|
62
|
-
export function outdatedNotice(latest: string): string {
|
|
63
|
-
return (
|
|
64
|
-
`NOTE: this Dailey OS MCP server is v${OWN_VERSION}, but v${latest} is available. ` +
|
|
65
|
-
`Some platform tools/documentation may be missing from this session. ` +
|
|
66
|
-
`Tell the user: "My Dailey OS tools are outdated (v${OWN_VERSION} vs v${latest}) — ` +
|
|
67
|
-
`restart the app to pick up the latest," and prefer verifying capabilities with ` +
|
|
68
|
-
`dailey_platform_info / dailey_os_guide rather than assuming a feature does not exist.`
|
|
69
|
-
);
|
|
70
|
-
}
|
|
@@ -1,223 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
// Minimal fake McpServer: registerWordPressLiveEditTools 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
|
-
const IDENTITY = {
|
|
18
|
-
project_id: 'proj_wp1',
|
|
19
|
-
slug: 'my-blog',
|
|
20
|
-
domain: 'my-blog.dailey.cloud',
|
|
21
|
-
env: 'prod',
|
|
22
|
-
db_name: 'wp_myblog',
|
|
23
|
-
namespace: 'cust-abc',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Shared active-account state + a router that mimics the two-phase server:
|
|
27
|
-
// a mutating POST without confirm_token returns a preview envelope; the same
|
|
28
|
-
// POST WITH confirm_token executes.
|
|
29
|
-
function makeApiMock() {
|
|
30
|
-
const calls: Array<{ method: string; path: string; body?: any }> = [];
|
|
31
|
-
let active: string | undefined;
|
|
32
|
-
return {
|
|
33
|
-
calls,
|
|
34
|
-
namedExports: {
|
|
35
|
-
apiRequest: async (method: string, path: string, body?: any) => {
|
|
36
|
-
calls.push({ method, path, body });
|
|
37
|
-
|
|
38
|
-
// read-only routes
|
|
39
|
-
if (path.endsWith('/wp/files/list')) {
|
|
40
|
-
return { ok: true, status: 200, data: { path: body?.path ?? '/', entries: [{ name: 'style.css', type: 'file', size: 12, path: '/style.css' }] } };
|
|
41
|
-
}
|
|
42
|
-
if (path.endsWith('/wp/files/read')) {
|
|
43
|
-
return { ok: true, status: 200, data: { path: body.path, encoding: 'utf8', content: 'body{}', size: 6 } };
|
|
44
|
-
}
|
|
45
|
-
if (path.endsWith('/wp/media/list')) {
|
|
46
|
-
return { ok: true, status: 200, data: { path: body?.path ?? '/', entries: [] } };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// mutating routes — two-phase
|
|
50
|
-
const mutating = ['/wp/files/write', '/wp/files/delete', '/wp/media/upload', '/wp/cli'];
|
|
51
|
-
if (mutating.some((m) => path.endsWith(m))) {
|
|
52
|
-
const isCliRead = path.endsWith('/wp/cli') && !body?.allow_write;
|
|
53
|
-
if (isCliRead) {
|
|
54
|
-
return { ok: true, status: 200, data: { stdout: 'https://my-blog.dailey.cloud', stderr: '', exit_code: 0, write: false } };
|
|
55
|
-
}
|
|
56
|
-
if (!body?.confirm_token) {
|
|
57
|
-
return { ok: true, status: 200, data: { preview: true, confirm_token: 'tok_abc123', identity: IDENTITY, change: { op: path } } };
|
|
58
|
-
}
|
|
59
|
-
// executed
|
|
60
|
-
return { ok: true, status: 200, data: { ok: true, path: body.path, snapshot_id: 'snap_1', confirm_token_used: body.confirm_token } };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
throw new Error(`unexpected apiRequest call: ${method} ${path}`);
|
|
64
|
-
},
|
|
65
|
-
formatError: (res: any) => JSON.stringify(res),
|
|
66
|
-
textResult: (text: string) => ({ content: [{ type: 'text' as const, text }] }),
|
|
67
|
-
jsonResult: (data: unknown) => ({ content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }] }),
|
|
68
|
-
getActiveAccount: () => active,
|
|
69
|
-
setActiveAccount: (v: string | undefined) => { active = v && v.trim() ? v.trim() : undefined; },
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
test('dailey_wp_files list posts to /wp/files/list and surfaces active_account', async (t) => {
|
|
75
|
-
const mock = makeApiMock();
|
|
76
|
-
t.mock.module('../src/api.js', { namedExports: mock.namedExports });
|
|
77
|
-
|
|
78
|
-
const { registerWordPressLiveEditTools } = await import('../src/tools/wordpress-live-edit.js?t=files-list');
|
|
79
|
-
const { server, getHandler } = makeFakeServer();
|
|
80
|
-
registerWordPressLiveEditTools(server as any);
|
|
81
|
-
|
|
82
|
-
const result = await getHandler('dailey_wp_files')({ project: 'proj_wp1', action: 'list', account: 'acme' });
|
|
83
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
84
|
-
|
|
85
|
-
assert.strictEqual(mock.calls[0].path, '/projects/proj_wp1/wp/files/list');
|
|
86
|
-
assert.strictEqual(mock.calls[0].method, 'POST');
|
|
87
|
-
assert.strictEqual(parsed.active_account, 'acme');
|
|
88
|
-
assert.strictEqual(parsed.entries[0].name, 'style.css');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('dailey_wp_files write is two-phase: preview (no token) then execute (with token)', async (t) => {
|
|
92
|
-
const mock = makeApiMock();
|
|
93
|
-
t.mock.module('../src/api.js', { namedExports: mock.namedExports });
|
|
94
|
-
|
|
95
|
-
const { registerWordPressLiveEditTools } = await import('../src/tools/wordpress-live-edit.js?t=files-write');
|
|
96
|
-
const { server, getHandler } = makeFakeServer();
|
|
97
|
-
registerWordPressLiveEditTools(server as any);
|
|
98
|
-
|
|
99
|
-
// Phase 1 — no confirm_token → preview with identity echo + token, no mutation.
|
|
100
|
-
const preview = await getHandler('dailey_wp_files')({ project: 'proj_wp1', action: 'write', path: '/style.css', content: 'body{color:red}' });
|
|
101
|
-
const text = preview.content[0].text;
|
|
102
|
-
assert.match(text, /PREVIEW ONLY/);
|
|
103
|
-
assert.match(text, /my-blog\.dailey\.cloud/, 'echoes domain');
|
|
104
|
-
assert.match(text, /wp_myblog/, 'echoes db_name');
|
|
105
|
-
assert.match(text, /confirm_token: tok_abc123/);
|
|
106
|
-
const writeCall = mock.calls.find((c) => c.path.endsWith('/wp/files/write'));
|
|
107
|
-
assert.strictEqual(writeCall!.body.confirm_token, undefined, 'phase 1 must NOT send a confirm_token');
|
|
108
|
-
|
|
109
|
-
// Phase 2 — relay the real token → executes.
|
|
110
|
-
const executed = await getHandler('dailey_wp_files')({ project: 'proj_wp1', action: 'write', path: '/style.css', content: 'body{color:red}', confirm_token: 'tok_abc123' });
|
|
111
|
-
const parsed = JSON.parse(executed.content[0].text);
|
|
112
|
-
assert.strictEqual(parsed.ok, true);
|
|
113
|
-
assert.strictEqual(parsed.snapshot_id, 'snap_1');
|
|
114
|
-
assert.strictEqual(parsed.confirm_token_used, 'tok_abc123');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('dailey_wp_media upload is two-phase', async (t) => {
|
|
118
|
-
const mock = makeApiMock();
|
|
119
|
-
t.mock.module('../src/api.js', { namedExports: mock.namedExports });
|
|
120
|
-
|
|
121
|
-
const { registerWordPressLiveEditTools } = await import('../src/tools/wordpress-live-edit.js?t=media');
|
|
122
|
-
const { server, getHandler } = makeFakeServer();
|
|
123
|
-
registerWordPressLiveEditTools(server as any);
|
|
124
|
-
|
|
125
|
-
const preview = await getHandler('dailey_wp_media')({ project: 'proj_wp1', action: 'upload', filename: 'logo.png', content_base64: 'AAAA' });
|
|
126
|
-
assert.match(preview.content[0].text, /PREVIEW ONLY/);
|
|
127
|
-
assert.match(preview.content[0].text, /confirm_token: tok_abc123/);
|
|
128
|
-
|
|
129
|
-
const executed = await getHandler('dailey_wp_media')({ project: 'proj_wp1', action: 'upload', filename: 'logo.png', content_base64: 'AAAA', confirm_token: 'tok_abc123' });
|
|
130
|
-
const parsed = JSON.parse(executed.content[0].text);
|
|
131
|
-
assert.strictEqual(parsed.ok, true);
|
|
132
|
-
assert.strictEqual(parsed.active_account, 'self');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('dailey_wp_cli read-only runs immediately; write is two-phase', async (t) => {
|
|
136
|
-
const mock = makeApiMock();
|
|
137
|
-
t.mock.module('../src/api.js', { namedExports: mock.namedExports });
|
|
138
|
-
|
|
139
|
-
const { registerWordPressLiveEditTools } = await import('../src/tools/wordpress-live-edit.js?t=cli');
|
|
140
|
-
const { server, getHandler } = makeFakeServer();
|
|
141
|
-
registerWordPressLiveEditTools(server as any);
|
|
142
|
-
|
|
143
|
-
// read-only: no allow_write → executes immediately
|
|
144
|
-
const read = await getHandler('dailey_wp_cli')({ project: 'proj_wp1', args: ['option', 'get', 'siteurl'] });
|
|
145
|
-
const readParsed = JSON.parse(read.content[0].text);
|
|
146
|
-
assert.strictEqual(readParsed.exit_code, 0);
|
|
147
|
-
assert.strictEqual(readParsed.write, false);
|
|
148
|
-
assert.strictEqual(mock.calls[0].body.args[0], 'option');
|
|
149
|
-
|
|
150
|
-
// write: allow_write true, no token → preview
|
|
151
|
-
const preview = await getHandler('dailey_wp_cli')({ project: 'proj_wp1', args: ['plugin', 'activate', 'akismet'], allow_write: true });
|
|
152
|
-
assert.match(preview.content[0].text, /PREVIEW ONLY/);
|
|
153
|
-
assert.match(preview.content[0].text, /confirm_token: tok_abc123/);
|
|
154
|
-
|
|
155
|
-
// write with token → executes
|
|
156
|
-
const executed = await getHandler('dailey_wp_cli')({ project: 'proj_wp1', args: ['plugin', 'activate', 'akismet'], allow_write: true, confirm_token: 'tok_abc123' });
|
|
157
|
-
const parsed = JSON.parse(executed.content[0].text);
|
|
158
|
-
assert.strictEqual(parsed.ok, true);
|
|
159
|
-
});
|