@kolivri/memoreal-mcp 1.0.2 → 1.1.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/.claude-plugin/plugin.json +9 -0
- package/.cursor-plugin/plugin.json +2 -2
- package/CLAUDE.md +29 -29
- package/README.md +188 -11
- package/agents/memoreal.md +25 -9
- package/agents/memoria.md +25 -9
- package/bin/memoreal-hook.mjs +483 -0
- package/bin/memoreal-ns +54 -4
- package/bin/memoreal-ns.cmd +2 -0
- package/bin/memoreal-ns.mjs +945 -0
- package/bin/memoria-ns +54 -5
- package/hooks/hooks.json +11 -11
- package/install.sh +565 -119
- package/manifest.json +1 -1
- package/opencode/memoreal-hooks.js +266 -381
- package/opencode/memoria-hooks.js +45 -10
- package/package.json +26 -1
- package/rules/memoreal.mdc +20 -4
- package/rules/memoria.mdc +6 -3
- package/server.json +2 -2
- package/skills/memoreal-connect/SKILL.md +178 -2
- package/skills/memoria-connect/SKILL.md +178 -2
- package/src/bootstrap.mjs +2850 -0
- package/src/config-store.mjs +1156 -93
- package/src/schemas.mjs +429 -1
- package/src/server.mjs +238 -23
- package/src/wizard.mjs +100 -6
- package/.actor/Dockerfile +0 -6
- package/.actor/actor.json +0 -15
- package/.actor/input_schema.json +0 -92
- package/Dockerfile +0 -5
- package/prd/001-rebrand-memoreal-mcp.md +0 -132
- package/prd/002-connect-oauth-wizard.md +0 -259
- package/test/apify-actor.test.mjs +0 -429
- package/test/config-store.test.mjs +0 -680
- package/test/connect-wizard.test.mjs +0 -936
- package/test/hooks-onboarding.test.mjs +0 -1039
- package/test/memoria-mcp.test.mjs +0 -376
- package/test/wizard-unit.test.mjs +0 -1272
|
@@ -1,936 +0,0 @@
|
|
|
1
|
-
import { describe, it, before, after, beforeEach, afterEach } from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import os from 'node:os';
|
|
6
|
-
import http from 'node:http';
|
|
7
|
-
import cp from 'node:child_process';
|
|
8
|
-
import readline from 'node:readline';
|
|
9
|
-
import { fileURLToPath } from 'node:url';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
isPlaceholderApiKey,
|
|
13
|
-
POLITE_ONBOARDING_ACTION,
|
|
14
|
-
} from '../src/config-store.mjs';
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
buildReadSuffix,
|
|
18
|
-
buildWriteSuffix,
|
|
19
|
-
buildEditSuffix,
|
|
20
|
-
fetchSessionStartContext,
|
|
21
|
-
ONBOARDING_WIZARD_PROMPT,
|
|
22
|
-
MemorealHooksPlugin,
|
|
23
|
-
setup,
|
|
24
|
-
} from '../opencode/memoria-hooks.js';
|
|
25
|
-
|
|
26
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
27
|
-
const __dirname = path.dirname(__filename);
|
|
28
|
-
const PKG_ROOT = path.resolve(__dirname, '..');
|
|
29
|
-
const SERVER_PATH = path.join(PKG_ROOT, 'src', 'server.mjs');
|
|
30
|
-
|
|
31
|
-
function createStdioMcpClient(envOverrides = {}, cwdOverride = PKG_ROOT) {
|
|
32
|
-
const child = cp.spawn(process.execPath, [SERVER_PATH], {
|
|
33
|
-
cwd: cwdOverride,
|
|
34
|
-
env: {
|
|
35
|
-
...process.env,
|
|
36
|
-
...envOverrides,
|
|
37
|
-
},
|
|
38
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const rl = readline.createInterface({
|
|
42
|
-
input: child.stdout,
|
|
43
|
-
crlfDelay: Infinity,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const pending = new Map();
|
|
47
|
-
let stderrOutput = '';
|
|
48
|
-
|
|
49
|
-
child.stderr.on('data', (d) => {
|
|
50
|
-
stderrOutput += d.toString();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
rl.on('line', (line) => {
|
|
54
|
-
const trimmed = line.trim();
|
|
55
|
-
if (!trimmed) return;
|
|
56
|
-
try {
|
|
57
|
-
const msg = JSON.parse(trimmed);
|
|
58
|
-
if (msg.id !== undefined && pending.has(msg.id)) {
|
|
59
|
-
const { resolve } = pending.get(msg.id);
|
|
60
|
-
pending.delete(msg.id);
|
|
61
|
-
resolve(msg);
|
|
62
|
-
}
|
|
63
|
-
} catch {
|
|
64
|
-
// Ignore unparseable lines
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
let nextId = 1;
|
|
69
|
-
|
|
70
|
-
function request(method, params = {}) {
|
|
71
|
-
const id = nextId++;
|
|
72
|
-
return new Promise((resolve, reject) => {
|
|
73
|
-
const timer = setTimeout(() => {
|
|
74
|
-
pending.delete(id);
|
|
75
|
-
reject(
|
|
76
|
-
new Error(
|
|
77
|
-
`Timeout waiting for JSON-RPC response to ${method} (id=${id}). Stderr: ${stderrOutput}`
|
|
78
|
-
)
|
|
79
|
-
);
|
|
80
|
-
}, 5000);
|
|
81
|
-
|
|
82
|
-
pending.set(id, {
|
|
83
|
-
resolve: (msg) => {
|
|
84
|
-
clearTimeout(timer);
|
|
85
|
-
resolve(msg);
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function close() {
|
|
94
|
-
rl.close();
|
|
95
|
-
child.stdin.end();
|
|
96
|
-
await new Promise((resolve) => {
|
|
97
|
-
child.once('close', resolve);
|
|
98
|
-
setTimeout(() => {
|
|
99
|
-
try {
|
|
100
|
-
child.kill('SIGTERM');
|
|
101
|
-
} catch {}
|
|
102
|
-
resolve();
|
|
103
|
-
}, 500);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return { request, close, child, getStderr: () => stderrOutput };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function runCliProcess(args, { env = {}, input = '' } = {}) {
|
|
111
|
-
return new Promise((resolve, reject) => {
|
|
112
|
-
const child = cp.spawn(process.execPath, [SERVER_PATH, ...args], {
|
|
113
|
-
cwd: PKG_ROOT,
|
|
114
|
-
env: { ...process.env, ...env },
|
|
115
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
let stdout = '';
|
|
119
|
-
let stderr = '';
|
|
120
|
-
|
|
121
|
-
child.stdout.on('data', (d) => {
|
|
122
|
-
stdout += d.toString();
|
|
123
|
-
});
|
|
124
|
-
child.stderr.on('data', (d) => {
|
|
125
|
-
stderr += d.toString();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
if (input) {
|
|
129
|
-
child.stdin.write(input);
|
|
130
|
-
}
|
|
131
|
-
child.stdin.end();
|
|
132
|
-
|
|
133
|
-
child.on('error', reject);
|
|
134
|
-
child.on('close', (code, signal) => {
|
|
135
|
-
resolve({ code, signal, stdout, stderr });
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
describe('WS-5: End-to-End Connect Wizard, Hot-Reload, CLI & Quiet-Hooks Suite', () => {
|
|
141
|
-
let mockServer;
|
|
142
|
-
let mockUrl;
|
|
143
|
-
let mockState;
|
|
144
|
-
|
|
145
|
-
before(async () => {
|
|
146
|
-
mockState = {
|
|
147
|
-
startRequests: [],
|
|
148
|
-
pollRequests: [],
|
|
149
|
-
healthRequests: [],
|
|
150
|
-
mcpRequests: [],
|
|
151
|
-
pollCount: 0,
|
|
152
|
-
customPollQueue: [],
|
|
153
|
-
return401ForMcp: false,
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
mockServer = http.createServer((req, res) => {
|
|
157
|
-
let rawBody = '';
|
|
158
|
-
req.on('data', (chunk) => {
|
|
159
|
-
rawBody += chunk;
|
|
160
|
-
});
|
|
161
|
-
req.on('end', () => {
|
|
162
|
-
let body = {};
|
|
163
|
-
try {
|
|
164
|
-
if (rawBody) body = JSON.parse(rawBody);
|
|
165
|
-
} catch {}
|
|
166
|
-
|
|
167
|
-
const urlPath = req.url || '';
|
|
168
|
-
|
|
169
|
-
if (urlPath === '/v1/auth/device/start') {
|
|
170
|
-
mockState.startRequests.push({ headers: req.headers, body });
|
|
171
|
-
const deviceCode = `dev_code_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
|
|
172
|
-
const userCode = `CODE-${Math.random().toString(36).slice(2, 6).toUpperCase()}`;
|
|
173
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
174
|
-
res.end(
|
|
175
|
-
JSON.stringify({
|
|
176
|
-
device_code: deviceCode,
|
|
177
|
-
user_code: userCode,
|
|
178
|
-
verification_uri: `${mockUrl}/connect`,
|
|
179
|
-
verification_uri_complete: `${mockUrl}/connect?code=${userCode}`,
|
|
180
|
-
expires_in: 300,
|
|
181
|
-
interval: 0.05,
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (urlPath === '/v1/auth/device/poll') {
|
|
188
|
-
mockState.pollRequests.push({ headers: req.headers, body });
|
|
189
|
-
|
|
190
|
-
if (mockState.customPollQueue.length > 0) {
|
|
191
|
-
const resp = mockState.customPollQueue.shift();
|
|
192
|
-
res.writeHead(resp.status || 200, { 'Content-Type': 'application/json' });
|
|
193
|
-
res.end(JSON.stringify(resp.body));
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
mockState.pollCount++;
|
|
198
|
-
if (mockState.pollCount <= 1) {
|
|
199
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
200
|
-
res.end(JSON.stringify({ status: 'pending' }));
|
|
201
|
-
} else {
|
|
202
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
203
|
-
res.end(
|
|
204
|
-
JSON.stringify({
|
|
205
|
-
status: 'approved',
|
|
206
|
-
api_key: 'mem_dev_e2e_paired_secret_777',
|
|
207
|
-
workspace: {
|
|
208
|
-
id: 'org_1',
|
|
209
|
-
name: 'Kolivri',
|
|
210
|
-
api_key: 'mem_dev_e2e_paired_secret_777',
|
|
211
|
-
secret: 'hidden_secret',
|
|
212
|
-
},
|
|
213
|
-
})
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (urlPath === '/v1/health') {
|
|
220
|
-
mockState.healthRequests.push({ headers: req.headers, body });
|
|
221
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
222
|
-
res.end(
|
|
223
|
-
JSON.stringify({
|
|
224
|
-
status: 'ok',
|
|
225
|
-
memory_count: 42,
|
|
226
|
-
used_calls_30d: 5,
|
|
227
|
-
api_call_limit: 1000,
|
|
228
|
-
})
|
|
229
|
-
);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (urlPath === '/v1/mcp') {
|
|
234
|
-
mockState.mcpRequests.push({ headers: req.headers, body });
|
|
235
|
-
if (mockState.return401ForMcp) {
|
|
236
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
237
|
-
res.end(
|
|
238
|
-
JSON.stringify({
|
|
239
|
-
error: { message: 'Invalid or expired API token' },
|
|
240
|
-
})
|
|
241
|
-
);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
245
|
-
res.end(
|
|
246
|
-
JSON.stringify({
|
|
247
|
-
jsonrpc: '2.0',
|
|
248
|
-
id: body.id || null,
|
|
249
|
-
result: {
|
|
250
|
-
content: [
|
|
251
|
-
{
|
|
252
|
-
type: 'text',
|
|
253
|
-
text: JSON.stringify({
|
|
254
|
-
id: 'mem_123',
|
|
255
|
-
namespace: body?.params?.arguments?.namespace || 'default',
|
|
256
|
-
salience: 0.5,
|
|
257
|
-
ok: true,
|
|
258
|
-
}),
|
|
259
|
-
},
|
|
260
|
-
],
|
|
261
|
-
},
|
|
262
|
-
})
|
|
263
|
-
);
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
268
|
-
res.end(JSON.stringify({ error: `Not found: ${urlPath}` }));
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
await new Promise((resolve) => {
|
|
273
|
-
mockServer.listen(0, '127.0.0.1', () => {
|
|
274
|
-
const port = mockServer.address().port;
|
|
275
|
-
mockUrl = `http://127.0.0.1:${port}`;
|
|
276
|
-
resolve();
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
after(async () => {
|
|
282
|
-
if (mockServer) {
|
|
283
|
-
await new Promise((resolve) => mockServer.close(resolve));
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
beforeEach(() => {
|
|
288
|
-
mockState.startRequests = [];
|
|
289
|
-
mockState.pollRequests = [];
|
|
290
|
-
mockState.healthRequests = [];
|
|
291
|
-
mockState.mcpRequests = [];
|
|
292
|
-
mockState.pollCount = 0;
|
|
293
|
-
mockState.customPollQueue = [];
|
|
294
|
-
mockState.return401ForMcp = false;
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('1. performs stdio MCP connect_account + clientInfo.name + zero-restart hot-reload with 0600 config and IDE merges', async () => {
|
|
298
|
-
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'memoreal-e2e-home1-'));
|
|
299
|
-
try {
|
|
300
|
-
// Pre-create IDE configurations in tempHome:
|
|
301
|
-
// - .cursor/mcp.json (with existing otherServer entry)
|
|
302
|
-
const cursorDir = path.join(tempHome, '.cursor');
|
|
303
|
-
fs.mkdirSync(cursorDir, { recursive: true });
|
|
304
|
-
fs.writeFileSync(
|
|
305
|
-
path.join(cursorDir, 'mcp.json'),
|
|
306
|
-
JSON.stringify({
|
|
307
|
-
mcpServers: {
|
|
308
|
-
otherServer: { command: 'node', args: ['other.js'] },
|
|
309
|
-
},
|
|
310
|
-
}, null, 2)
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
// - Library/Application Support/Claude/claude_desktop_config.json
|
|
314
|
-
const claudeDesktopDir = path.join(tempHome, 'Library', 'Application Support', 'Claude');
|
|
315
|
-
fs.mkdirSync(claudeDesktopDir, { recursive: true });
|
|
316
|
-
fs.writeFileSync(
|
|
317
|
-
path.join(claudeDesktopDir, 'claude_desktop_config.json'),
|
|
318
|
-
JSON.stringify({ mcpServers: {} }, null, 2)
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
// - .claude.json (existing file)
|
|
322
|
-
fs.writeFileSync(
|
|
323
|
-
path.join(tempHome, '.claude.json'),
|
|
324
|
-
JSON.stringify({ mcpServers: {} }, null, 2)
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
// - .codeium/windsurf/mcp_config.json
|
|
328
|
-
const windsurfDir = path.join(tempHome, '.codeium', 'windsurf');
|
|
329
|
-
fs.mkdirSync(windsurfDir, { recursive: true });
|
|
330
|
-
fs.writeFileSync(
|
|
331
|
-
path.join(windsurfDir, 'mcp_config.json'),
|
|
332
|
-
JSON.stringify({ mcpServers: {} }, null, 2)
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
// - malformed .vscode/mcp.json containing "{ invalid json"
|
|
336
|
-
const vscodeDir = path.join(tempHome, '.vscode');
|
|
337
|
-
fs.mkdirSync(vscodeDir, { recursive: true });
|
|
338
|
-
const malformedVscodePath = path.join(vscodeDir, 'mcp.json');
|
|
339
|
-
fs.writeFileSync(malformedVscodePath, '{ invalid json');
|
|
340
|
-
|
|
341
|
-
// DO NOT pre-create .config/opencode so preferredTool === "opencode" auto-creation is proven!
|
|
342
|
-
|
|
343
|
-
// Spawn stdio MCP client
|
|
344
|
-
const client = createStdioMcpClient({
|
|
345
|
-
MEMOREAL_HOME: tempHome,
|
|
346
|
-
MEMOREAL_API_URL: mockUrl,
|
|
347
|
-
MEMOREAL_NO_BROWSER: '1',
|
|
348
|
-
MEMOREAL_API_KEY: '',
|
|
349
|
-
MEMORIA_API_KEY: '',
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
try {
|
|
353
|
-
// Send initialize with clientInfo: { name: 'OpenCode', version: '2.0.0' }
|
|
354
|
-
const initRes = await client.request('initialize', {
|
|
355
|
-
protocolVersion: '2024-11-05',
|
|
356
|
-
clientInfo: { name: 'OpenCode', version: '2.0.0' },
|
|
357
|
-
});
|
|
358
|
-
assert.equal(initRes.result.serverInfo.name, '@kolivri/memoreal-mcp');
|
|
359
|
-
|
|
360
|
-
// Call connect_account({ action: 'status' }) -> assert status === 'not_started' and raw api_key is absent
|
|
361
|
-
const statusRes1 = await client.request('tools/call', {
|
|
362
|
-
name: 'connect_account',
|
|
363
|
-
arguments: { action: 'status' },
|
|
364
|
-
});
|
|
365
|
-
assert.equal(statusRes1.result.isError, false);
|
|
366
|
-
const s1 = JSON.parse(statusRes1.result.content[0].text);
|
|
367
|
-
assert.equal(s1.status, 'not_started');
|
|
368
|
-
assert.match(s1.message, /Step 1/);
|
|
369
|
-
assert.equal('api_key' in s1, false);
|
|
370
|
-
assert.equal(JSON.stringify(s1).includes('mem_dev_'), false);
|
|
371
|
-
|
|
372
|
-
// Call connect_account({ action: 'start' })
|
|
373
|
-
const startRes = await client.request('tools/call', {
|
|
374
|
-
name: 'connect_account',
|
|
375
|
-
arguments: { action: 'start' },
|
|
376
|
-
});
|
|
377
|
-
assert.equal(startRes.result.isError, false);
|
|
378
|
-
const startData = JSON.parse(startRes.result.content[0].text);
|
|
379
|
-
assert.equal(startData.status, 'waiting_for_browser');
|
|
380
|
-
assert.ok(startData.user_code);
|
|
381
|
-
assert.ok(startData.verification_uri_complete);
|
|
382
|
-
assert.match(startData.message, /Step 2/);
|
|
383
|
-
assert.match(startData.message, /I clicked Authorize — Verify/);
|
|
384
|
-
assert.equal(JSON.stringify(startRes).includes('mem_dev_'), false);
|
|
385
|
-
|
|
386
|
-
// Verify mock /v1/auth/device/start received { client_name: 'OpenCode', tool: 'opencode' }
|
|
387
|
-
assert.ok(mockState.startRequests.length >= 1);
|
|
388
|
-
const startReqBody = mockState.startRequests[0].body;
|
|
389
|
-
assert.equal(startReqBody.client_name, 'OpenCode');
|
|
390
|
-
assert.equal(startReqBody.tool, 'opencode');
|
|
391
|
-
|
|
392
|
-
// Poll connect_account({ action: 'status' }) until status === 'connected'
|
|
393
|
-
let connectedStatus = null;
|
|
394
|
-
for (let i = 0; i < 30; i++) {
|
|
395
|
-
await new Promise((resolve) => setTimeout(resolve, 60));
|
|
396
|
-
const pollStatusRes = await client.request('tools/call', {
|
|
397
|
-
name: 'connect_account',
|
|
398
|
-
arguments: { action: 'status' },
|
|
399
|
-
});
|
|
400
|
-
const parsed = JSON.parse(pollStatusRes.result.content[0].text);
|
|
401
|
-
if (parsed.status === 'connected') {
|
|
402
|
-
connectedStatus = parsed;
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
assert.ok(connectedStatus, 'Must transition to status: "connected"');
|
|
408
|
-
assert.equal(connectedStatus.status, 'connected');
|
|
409
|
-
assert.equal(connectedStatus.workspace.name, 'Kolivri');
|
|
410
|
-
assert.match(connectedStatus.message, /Step 3/);
|
|
411
|
-
assert.match(connectedStatus.message, /Yes — Index repo now \(Recommended\)/);
|
|
412
|
-
|
|
413
|
-
// Assert 'mem_dev_e2e_paired_secret_777' and 'hidden_secret' NEVER appear anywhere in JSON.stringify(statusResponse)
|
|
414
|
-
const serializedStatus = JSON.stringify(connectedStatus);
|
|
415
|
-
assert.equal(serializedStatus.includes('mem_dev_e2e_paired_secret_777'), false);
|
|
416
|
-
assert.equal(serializedStatus.includes('hidden_secret'), false);
|
|
417
|
-
|
|
418
|
-
// Immediately in the SAME stdio MCP child process (zero restart!), call encode_memory
|
|
419
|
-
const encodeRes = await client.request('tools/call', {
|
|
420
|
-
name: 'encode_memory',
|
|
421
|
-
arguments: { content: 'Hot-reloaded memory!' },
|
|
422
|
-
});
|
|
423
|
-
assert.equal(encodeRes.result.isError, false);
|
|
424
|
-
assert.ok(mockState.mcpRequests.length >= 1);
|
|
425
|
-
const lastMcpHeader = mockState.mcpRequests[mockState.mcpRequests.length - 1].headers;
|
|
426
|
-
assert.equal(lastMcpHeader.authorization, 'Bearer mem_dev_e2e_paired_secret_777');
|
|
427
|
-
|
|
428
|
-
// Call connect_account({}) (with action omitted) -> assert status === 'already_connected' after pinging /v1/mcp
|
|
429
|
-
const mcpCountBeforeAlready = mockState.mcpRequests.length;
|
|
430
|
-
const alreadyRes = await client.request('tools/call', {
|
|
431
|
-
name: 'connect_account',
|
|
432
|
-
arguments: {},
|
|
433
|
-
});
|
|
434
|
-
const alreadyData = JSON.parse(alreadyRes.result.content[0].text);
|
|
435
|
-
assert.equal(alreadyData.status, 'already_connected');
|
|
436
|
-
assert.match(alreadyData.message, /already connected/i);
|
|
437
|
-
assert.ok(mockState.mcpRequests.length > mcpCountBeforeAlready, 'Must have pinged POST /v1/mcp');
|
|
438
|
-
const lastMcpPing = mockState.mcpRequests[mockState.mcpRequests.length - 1];
|
|
439
|
-
assert.equal(lastMcpPing.headers.authorization, 'Bearer mem_dev_e2e_paired_secret_777');
|
|
440
|
-
|
|
441
|
-
// Verify config.env permissions under MEMOREAL_HOME
|
|
442
|
-
const memorealEnv = path.join(tempHome, '.memoreal', 'config.env');
|
|
443
|
-
const memoriaEnv = path.join(tempHome, '.memoria', 'config.env');
|
|
444
|
-
assert.ok(fs.existsSync(memorealEnv));
|
|
445
|
-
assert.ok(fs.existsSync(memoriaEnv));
|
|
446
|
-
|
|
447
|
-
if (process.platform !== 'win32') {
|
|
448
|
-
const memorealDirStat = fs.statSync(path.join(tempHome, '.memoreal'));
|
|
449
|
-
assert.equal(memorealDirStat.mode & 0o777, 0o700);
|
|
450
|
-
const memorealFileStat = fs.statSync(memorealEnv);
|
|
451
|
-
assert.equal(memorealFileStat.mode & 0o777, 0o600);
|
|
452
|
-
const memoriaFileStat = fs.statSync(memoriaEnv);
|
|
453
|
-
assert.equal(memoriaFileStat.mode & 0o777, 0o600);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// Verify OpenCode native config: .config/opencode/opencode.json
|
|
457
|
-
const opencodeJsonPath = path.join(tempHome, '.config', 'opencode', 'opencode.json');
|
|
458
|
-
assert.ok(fs.existsSync(opencodeJsonPath));
|
|
459
|
-
const opencodeConfig = JSON.parse(fs.readFileSync(opencodeJsonPath, 'utf8'));
|
|
460
|
-
assert.equal(opencodeConfig.mcp.memoreal.type, 'remote');
|
|
461
|
-
assert.equal(opencodeConfig.mcp.memoreal.url, `${mockUrl}/v1/mcp`);
|
|
462
|
-
assert.equal(opencodeConfig.mcp.memoreal.enabled, true);
|
|
463
|
-
assert.deepEqual(opencodeConfig.mcp.memoreal.headers, {
|
|
464
|
-
Authorization: 'Bearer mem_dev_e2e_paired_secret_777',
|
|
465
|
-
});
|
|
466
|
-
assert.equal(opencodeConfig.mcpServers, undefined, 'Must NEVER contain .mcpServers');
|
|
467
|
-
|
|
468
|
-
// Verify .cursor/mcp.json (+ .bak preserving otherServer)
|
|
469
|
-
const cursorMcp = JSON.parse(fs.readFileSync(path.join(cursorDir, 'mcp.json'), 'utf8'));
|
|
470
|
-
assert.equal(cursorMcp.mcpServers.memoreal.type, 'http');
|
|
471
|
-
assert.equal(cursorMcp.mcpServers.memoreal.url, `${mockUrl}/v1/mcp`);
|
|
472
|
-
assert.equal(cursorMcp.mcpServers.otherServer.command, 'node');
|
|
473
|
-
assert.ok(fs.existsSync(path.join(cursorDir, 'mcp.json.bak')));
|
|
474
|
-
|
|
475
|
-
// Verify .codeium/windsurf/mcp_config.json (+ .bak)
|
|
476
|
-
const windsurfMcp = JSON.parse(fs.readFileSync(path.join(windsurfDir, 'mcp_config.json'), 'utf8'));
|
|
477
|
-
assert.equal(windsurfMcp.mcpServers.memoreal.type, 'http');
|
|
478
|
-
assert.ok(fs.existsSync(path.join(windsurfDir, 'mcp_config.json.bak')));
|
|
479
|
-
|
|
480
|
-
// Verify Claude Desktop (+ .bak)
|
|
481
|
-
const desktopMcp = JSON.parse(fs.readFileSync(path.join(claudeDesktopDir, 'claude_desktop_config.json'), 'utf8'));
|
|
482
|
-
assert.equal(desktopMcp.mcpServers.memoreal.type, 'http');
|
|
483
|
-
assert.ok(fs.existsSync(path.join(claudeDesktopDir, 'claude_desktop_config.json.bak')));
|
|
484
|
-
|
|
485
|
-
// Verify .claude.json (+ .bak)
|
|
486
|
-
const claudeMcp = JSON.parse(fs.readFileSync(path.join(tempHome, '.claude.json'), 'utf8'));
|
|
487
|
-
assert.equal(claudeMcp.mcpServers.memoreal.type, 'http');
|
|
488
|
-
assert.ok(fs.existsSync(path.join(tempHome, '.claude.json.bak')));
|
|
489
|
-
|
|
490
|
-
// Verify malformed .vscode/mcp.json remains untouched
|
|
491
|
-
assert.equal(fs.readFileSync(malformedVscodePath, 'utf8'), '{ invalid json');
|
|
492
|
-
assert.equal(fs.existsSync(malformedVscodePath + '.bak'), false);
|
|
493
|
-
} finally {
|
|
494
|
-
await client.close();
|
|
495
|
-
}
|
|
496
|
-
} finally {
|
|
497
|
-
fs.rmSync(tempHome, { recursive: true, force: true });
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
it('2. handles string workspace payload (e.g. acme) from /v1/auth/device/poll and asserts status connected with string workspace', async () => {
|
|
502
|
-
mockState.customPollQueue = [
|
|
503
|
-
{ status: 200, body: { status: 'pending' } },
|
|
504
|
-
{
|
|
505
|
-
status: 200,
|
|
506
|
-
body: {
|
|
507
|
-
status: 'approved',
|
|
508
|
-
api_key: 'mem_dev_e2e_string_ws_888',
|
|
509
|
-
workspace: 'acme',
|
|
510
|
-
},
|
|
511
|
-
},
|
|
512
|
-
];
|
|
513
|
-
|
|
514
|
-
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'memoreal-e2e-string-ws-'));
|
|
515
|
-
const client = createStdioMcpClient({
|
|
516
|
-
MEMOREAL_HOME: tempHome,
|
|
517
|
-
MEMOREAL_API_URL: mockUrl,
|
|
518
|
-
MEMOREAL_NO_BROWSER: '1',
|
|
519
|
-
MEMOREAL_API_KEY: '',
|
|
520
|
-
MEMORIA_API_KEY: '',
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
try {
|
|
524
|
-
await client.request('initialize', {
|
|
525
|
-
protocolVersion: '2024-11-05',
|
|
526
|
-
clientInfo: { name: 'OpenCode', version: '2.0.0' },
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
const startRes = await client.request('tools/call', {
|
|
530
|
-
name: 'connect_account',
|
|
531
|
-
arguments: { action: 'start' },
|
|
532
|
-
});
|
|
533
|
-
assert.equal(startRes.result.isError, false);
|
|
534
|
-
|
|
535
|
-
let connectedStatus = null;
|
|
536
|
-
for (let i = 0; i < 30; i++) {
|
|
537
|
-
await new Promise((resolve) => setTimeout(resolve, 60));
|
|
538
|
-
const pollStatusRes = await client.request('tools/call', {
|
|
539
|
-
name: 'connect_account',
|
|
540
|
-
arguments: { action: 'status' },
|
|
541
|
-
});
|
|
542
|
-
const parsed = JSON.parse(pollStatusRes.result.content[0].text);
|
|
543
|
-
if (parsed.status === 'connected') {
|
|
544
|
-
connectedStatus = parsed;
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
assert.ok(connectedStatus, 'Must transition to status: "connected"');
|
|
550
|
-
assert.equal(connectedStatus.status, 'connected');
|
|
551
|
-
assert.equal(connectedStatus.workspace, 'acme');
|
|
552
|
-
assert.match(connectedStatus.message, /Step 3/);
|
|
553
|
-
assert.match(connectedStatus.message, /Yes — Index repo now \(Recommended\)/);
|
|
554
|
-
|
|
555
|
-
// Assert raw key is NEVER exposed in status response
|
|
556
|
-
const serializedStatus = JSON.stringify(connectedStatus);
|
|
557
|
-
assert.equal(serializedStatus.includes('mem_dev_e2e_string_ws_888'), false);
|
|
558
|
-
|
|
559
|
-
// Verify immediate zero-restart hot-reload for encode_memory
|
|
560
|
-
const encodeRes = await client.request('tools/call', {
|
|
561
|
-
name: 'encode_memory',
|
|
562
|
-
arguments: { content: 'String workspace memory hot-reload!' },
|
|
563
|
-
});
|
|
564
|
-
assert.equal(encodeRes.result.isError, false);
|
|
565
|
-
assert.ok(mockState.mcpRequests.length >= 1);
|
|
566
|
-
const lastMcpHeader = mockState.mcpRequests[mockState.mcpRequests.length - 1].headers;
|
|
567
|
-
assert.equal(lastMcpHeader.authorization, 'Bearer mem_dev_e2e_string_ws_888');
|
|
568
|
-
|
|
569
|
-
// Verify config.env was written with mode 0600
|
|
570
|
-
const memorealEnv = path.join(tempHome, '.memoreal', 'config.env');
|
|
571
|
-
assert.ok(fs.existsSync(memorealEnv));
|
|
572
|
-
if (process.platform !== 'win32') {
|
|
573
|
-
const memorealFileStat = fs.statSync(memorealEnv);
|
|
574
|
-
assert.equal(memorealFileStat.mode & 0o777, 0o600);
|
|
575
|
-
}
|
|
576
|
-
} finally {
|
|
577
|
-
await client.close();
|
|
578
|
-
fs.rmSync(tempHome, { recursive: true, force: true });
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
|
|
582
|
-
it('3. forwards host IDE clientInfo.name as exact tool slugs to POST /v1/auth/device/start', async () => {
|
|
583
|
-
const ideCases = [
|
|
584
|
-
{ name: 'Cursor', expectedSlug: 'cursor', expectedClient: 'Cursor' },
|
|
585
|
-
{ name: 'claude-code', expectedSlug: 'claude-code', expectedClient: 'claude-code' },
|
|
586
|
-
{ name: 'Visual Studio Code', expectedSlug: 'vscode', expectedClient: 'Visual Studio Code' },
|
|
587
|
-
{ name: 'Windsurf', expectedSlug: 'windsurf', expectedClient: 'Windsurf' },
|
|
588
|
-
{ name: 'Zed', expectedSlug: 'zed', expectedClient: 'Zed' },
|
|
589
|
-
{ name: 'OpenAI Codex', expectedSlug: 'codex', expectedClient: 'OpenAI Codex' },
|
|
590
|
-
];
|
|
591
|
-
|
|
592
|
-
for (const testCase of ideCases) {
|
|
593
|
-
mockState.startRequests = [];
|
|
594
|
-
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'memoreal-ide-test-'));
|
|
595
|
-
const client = createStdioMcpClient({
|
|
596
|
-
MEMOREAL_HOME: tempHome,
|
|
597
|
-
MEMOREAL_API_URL: mockUrl,
|
|
598
|
-
MEMOREAL_NO_BROWSER: '1',
|
|
599
|
-
MEMOREAL_API_KEY: '',
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
try {
|
|
603
|
-
await client.request('initialize', {
|
|
604
|
-
protocolVersion: '2024-11-05',
|
|
605
|
-
clientInfo: { name: testCase.name, version: '1.0.0' },
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
await client.request('tools/call', {
|
|
609
|
-
name: 'connect_account',
|
|
610
|
-
arguments: { action: 'start' },
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
assert.ok(mockState.startRequests.length >= 1);
|
|
614
|
-
const req = mockState.startRequests[0].body;
|
|
615
|
-
assert.equal(req.tool, testCase.expectedSlug, `Tool slug mismatch for ${testCase.name}`);
|
|
616
|
-
assert.equal(req.client_name, testCase.expectedClient);
|
|
617
|
-
} finally {
|
|
618
|
-
await client.close();
|
|
619
|
-
fs.rmSync(tempHome, { recursive: true, force: true });
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
it('4. rejects placeholder keys, delivers HTTP 401 onboarding guidance & hot-reloads cross-process from CLI', async () => {
|
|
625
|
-
// Assert placeholder key filter unit coverage
|
|
626
|
-
const samplePlaceholders = [
|
|
627
|
-
'mem_dev_your_key_here',
|
|
628
|
-
'mem_dev_...',
|
|
629
|
-
'YOUR_API_KEY',
|
|
630
|
-
'<MEMOREAL_API_KEY>',
|
|
631
|
-
];
|
|
632
|
-
for (const ph of samplePlaceholders) {
|
|
633
|
-
assert.equal(isPlaceholderApiKey(ph), true);
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
const tempHome2 = fs.mkdtempSync(path.join(os.tmpdir(), 'memoreal-e2e-home2-'));
|
|
637
|
-
|
|
638
|
-
// Spawn stdio MCP server with placeholder key
|
|
639
|
-
const stdioClient = createStdioMcpClient({
|
|
640
|
-
MEMOREAL_HOME: tempHome2,
|
|
641
|
-
MEMOREAL_API_URL: mockUrl,
|
|
642
|
-
MEMOREAL_NO_BROWSER: '1',
|
|
643
|
-
MEMOREAL_API_KEY: 'mem_dev_your_key_here',
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
try {
|
|
647
|
-
await stdioClient.request('initialize', {
|
|
648
|
-
protocolVersion: '2024-11-05',
|
|
649
|
-
clientInfo: { name: 'Claude Code', version: '1.0.0' },
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
// Verify encode_memory fails with missing key and 3-Click Wizard guidance
|
|
653
|
-
const failRes = await stdioClient.request('tools/call', {
|
|
654
|
-
name: 'encode_memory',
|
|
655
|
-
arguments: { content: 'Should fail with placeholder key' },
|
|
656
|
-
});
|
|
657
|
-
assert.equal(failRes.result.isError, true);
|
|
658
|
-
const errText = failRes.result.content[0].text;
|
|
659
|
-
assert.match(errText, /Missing Memoreal API key: set MEMOREAL_API_KEY/);
|
|
660
|
-
assert.match(errText, /Polite Onboarding Action/);
|
|
661
|
-
assert.match(errText, /Step 1/);
|
|
662
|
-
assert.match(errText, /Step 2/);
|
|
663
|
-
assert.match(errText, /Step 3/);
|
|
664
|
-
|
|
665
|
-
// WHILE stdioClient REMAINS RUNNING, spawn node src/server.mjs setup --browser
|
|
666
|
-
const cliRes = await runCliProcess(['setup', '--browser'], {
|
|
667
|
-
env: {
|
|
668
|
-
MEMOREAL_HOME: tempHome2,
|
|
669
|
-
MEMOREAL_API_URL: mockUrl,
|
|
670
|
-
MEMOREAL_NO_BROWSER: '1',
|
|
671
|
-
},
|
|
672
|
-
});
|
|
673
|
-
|
|
674
|
-
assert.equal(cliRes.code, 0, `CLI setup failed: ${cliRes.stderr}`);
|
|
675
|
-
assert.match(cliRes.stdout, /Memoreal Connected Successfully!/);
|
|
676
|
-
assert.equal(cliRes.stdout.includes('mem_dev_e2e_paired_secret_777'), false);
|
|
677
|
-
assert.equal(cliRes.stderr.includes('mem_dev_e2e_paired_secret_777'), false);
|
|
678
|
-
|
|
679
|
-
// Verify config.env was created with mode 0600
|
|
680
|
-
const cfgPath = path.join(tempHome2, '.memoreal', 'config.env');
|
|
681
|
-
assert.ok(fs.existsSync(cfgPath));
|
|
682
|
-
if (process.platform !== 'win32') {
|
|
683
|
-
assert.equal(fs.statSync(cfgPath).mode & 0o777, 0o600);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// Verify POST /v1/mcp was verified by CLI
|
|
687
|
-
assert.ok(mockState.mcpRequests.length >= 1);
|
|
688
|
-
|
|
689
|
-
// Immediately call encode_memory on the ALREADY-RUNNING stdio MCP server!
|
|
690
|
-
// (Tests cross-process dynamic hot-reload from disk without restart)
|
|
691
|
-
const hotReloadRes = await stdioClient.request('tools/call', {
|
|
692
|
-
name: 'encode_memory',
|
|
693
|
-
arguments: { content: 'Hot-reloaded across process boundary!' },
|
|
694
|
-
});
|
|
695
|
-
assert.equal(hotReloadRes.result.isError, false);
|
|
696
|
-
const lastMcp = mockState.mcpRequests[mockState.mcpRequests.length - 1];
|
|
697
|
-
assert.equal(lastMcp.headers.authorization, 'Bearer mem_dev_e2e_paired_secret_777');
|
|
698
|
-
|
|
699
|
-
// Verify Cloud HTTP 401 response handling
|
|
700
|
-
mockState.return401ForMcp = true;
|
|
701
|
-
const http401Res = await stdioClient.request('tools/call', {
|
|
702
|
-
name: 'encode_memory',
|
|
703
|
-
arguments: { content: 'Will get 401 from Cloud' },
|
|
704
|
-
});
|
|
705
|
-
assert.equal(http401Res.result.isError, true);
|
|
706
|
-
const err401Text = http401Res.result.content[0].text;
|
|
707
|
-
assert.match(err401Text, /401/);
|
|
708
|
-
assert.match(err401Text, /Missing Memoreal API key: set MEMOREAL_API_KEY/);
|
|
709
|
-
assert.match(err401Text, /Polite Onboarding Action/);
|
|
710
|
-
assert.match(err401Text, /Step 1/);
|
|
711
|
-
mockState.return401ForMcp = false;
|
|
712
|
-
} finally {
|
|
713
|
-
mockState.return401ForMcp = false;
|
|
714
|
-
await stdioClient.close();
|
|
715
|
-
fs.rmSync(tempHome2, { recursive: true, force: true });
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
// Also test node src/server.mjs login with choice [2] stdin input in isolated tempHome3
|
|
719
|
-
const tempHome3 = fs.mkdtempSync(path.join(os.tmpdir(), 'memoreal-e2e-home3-'));
|
|
720
|
-
try {
|
|
721
|
-
const loginRes = await runCliProcess(['login'], {
|
|
722
|
-
env: {
|
|
723
|
-
MEMOREAL_HOME: tempHome3,
|
|
724
|
-
MEMOREAL_API_URL: mockUrl,
|
|
725
|
-
MEMOREAL_NO_BROWSER: '1',
|
|
726
|
-
},
|
|
727
|
-
input: '2\nmem_dev_stdin_key_999\n',
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
assert.equal(loginRes.code, 0, `CLI login failed: ${loginRes.stderr}`);
|
|
731
|
-
assert.match(loginRes.stdout, /Memoreal Connected Successfully!/);
|
|
732
|
-
assert.equal(loginRes.stdout.includes('mem_dev_stdin_key_999'), false);
|
|
733
|
-
assert.equal(loginRes.stderr.includes('mem_dev_stdin_key_999'), false);
|
|
734
|
-
|
|
735
|
-
const loginCfgPath = path.join(tempHome3, '.memoreal', 'config.env');
|
|
736
|
-
assert.ok(fs.existsSync(loginCfgPath));
|
|
737
|
-
if (process.platform !== 'win32') {
|
|
738
|
-
assert.equal(fs.statSync(loginCfgPath).mode & 0o777, 0o600);
|
|
739
|
-
}
|
|
740
|
-
} finally {
|
|
741
|
-
fs.rmSync(tempHome3, { recursive: true, force: true });
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
|
|
745
|
-
it('5. verifies bundled hooks & skills stay silent when unregistered, emit 3-Click Wizard on SessionStart, and omit brain.kolivri.com', async () => {
|
|
746
|
-
const tempHooksHome = fs.mkdtempSync(path.join(os.tmpdir(), 'memoreal-hooks-e2e-'));
|
|
747
|
-
try {
|
|
748
|
-
// 1. Hooks stay completely silent on Read/Write/Edit when unregistered
|
|
749
|
-
assert.equal(buildReadSuffix('src/server.mjs', 'test-ns', tempHooksHome), '');
|
|
750
|
-
assert.equal(buildWriteSuffix('src/server.mjs', 'test-ns', tempHooksHome), '');
|
|
751
|
-
assert.equal(buildEditSuffix('src/server.mjs', 'test-ns', tempHooksHome), '');
|
|
752
|
-
|
|
753
|
-
// 2. SessionStart emits the 3-Click Interactive In-Chat Wizard guidance
|
|
754
|
-
const sessionStartCtx = await fetchSessionStartContext(process.cwd(), tempHooksHome);
|
|
755
|
-
assert.equal(sessionStartCtx, ONBOARDING_WIZARD_PROMPT);
|
|
756
|
-
assert.match(sessionStartCtx, /3-Click Interactive In-Chat Wizard/);
|
|
757
|
-
assert.match(sessionStartCtx, /AskUserQuestion \(Claude Code\) or question \(OpenCode & Cursor\)/);
|
|
758
|
-
assert.match(sessionStartCtx, /Step 1/);
|
|
759
|
-
assert.match(sessionStartCtx, /Step 2/);
|
|
760
|
-
assert.match(sessionStartCtx, /Step 3/);
|
|
761
|
-
assert.ok(sessionStartCtx.includes('https://memoreal.kolivri.com/connect?tool=opencode'));
|
|
762
|
-
assert.ok(sessionStartCtx.includes('tool: "opencode"'));
|
|
763
|
-
assert.ok(sessionStartCtx.includes('client_name: "OpenCode"'));
|
|
764
|
-
assert.ok(ONBOARDING_WIZARD_PROMPT.includes('https://memoreal.kolivri.com/connect?tool=opencode'));
|
|
765
|
-
assert.ok(ONBOARDING_WIZARD_PROMPT.includes('tool: "opencode"'));
|
|
766
|
-
assert.ok(ONBOARDING_WIZARD_PROMPT.includes('client_name: "OpenCode"'));
|
|
767
|
-
|
|
768
|
-
// 3. hooks/hooks.json exists and contains 3-Click Wizard SessionStart
|
|
769
|
-
const hooksJsonPath = path.join(PKG_ROOT, 'hooks', 'hooks.json');
|
|
770
|
-
assert.ok(fs.existsSync(hooksJsonPath));
|
|
771
|
-
const hooksJsonContent = fs.readFileSync(hooksJsonPath, 'utf8');
|
|
772
|
-
assert.match(hooksJsonContent, /3-Click Interactive In-Chat Wizard/);
|
|
773
|
-
assert.match(hooksJsonContent, /AskUserQuestion/);
|
|
774
|
-
|
|
775
|
-
function getAllFilesRecursive(dir) {
|
|
776
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
777
|
-
const files = [];
|
|
778
|
-
for (const entry of entries) {
|
|
779
|
-
const fullPath = path.join(dir, entry.name);
|
|
780
|
-
if (entry.isDirectory()) {
|
|
781
|
-
files.push(...getAllFilesRecursive(fullPath));
|
|
782
|
-
} else if (entry.isFile()) {
|
|
783
|
-
files.push(fullPath);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
return files;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
// 4. skills/memoreal-connect/SKILL.md AND skills/memoria-connect/SKILL.md both exist
|
|
790
|
-
const connectSkillPath = path.join(PKG_ROOT, 'skills', 'memoreal-connect', 'SKILL.md');
|
|
791
|
-
assert.ok(fs.existsSync(connectSkillPath));
|
|
792
|
-
const connectSkillContent = fs.readFileSync(connectSkillPath, 'utf8');
|
|
793
|
-
assert.match(connectSkillContent, /3-Click Interactive In-Chat Wizard/);
|
|
794
|
-
assert.match(connectSkillContent, /connect_account/);
|
|
795
|
-
assert.match(connectSkillContent, /AskUserQuestion/);
|
|
796
|
-
|
|
797
|
-
const legacyConnectSkillPath = path.join(PKG_ROOT, 'skills', 'memoria-connect', 'SKILL.md');
|
|
798
|
-
assert.ok(fs.existsSync(legacyConnectSkillPath), 'skills/memoria-connect/SKILL.md must exist');
|
|
799
|
-
const legacyConnectContent = fs.readFileSync(legacyConnectSkillPath, 'utf8');
|
|
800
|
-
assert.match(legacyConnectContent, /3-Click Interactive In-Chat Wizard/);
|
|
801
|
-
assert.match(legacyConnectContent, /connect_account/);
|
|
802
|
-
|
|
803
|
-
// 5. Recursively scan EVERY file inside skills/ and assert ZERO files contain brain.kolivri.com
|
|
804
|
-
const skillsDir = path.join(PKG_ROOT, 'skills');
|
|
805
|
-
const allSkillFiles = getAllFilesRecursive(skillsDir);
|
|
806
|
-
assert.ok(allSkillFiles.length >= 2, 'Must scan skills directory');
|
|
807
|
-
for (const skillFile of allSkillFiles) {
|
|
808
|
-
const fileContent = fs.readFileSync(skillFile, 'utf8');
|
|
809
|
-
assert.equal(
|
|
810
|
-
fileContent.includes('brain.kolivri.com'),
|
|
811
|
-
false,
|
|
812
|
-
`Skill file ${path.relative(PKG_ROOT, skillFile)} must NOT contain brain.kolivri.com`
|
|
813
|
-
);
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
// 6. skills/memoreal-doctor/SKILL.md omits brain.kolivri.com and guides to connect_account / setup
|
|
817
|
-
const doctorSkillPath = path.join(PKG_ROOT, 'skills', 'memoreal-doctor', 'SKILL.md');
|
|
818
|
-
assert.ok(fs.existsSync(doctorSkillPath));
|
|
819
|
-
const doctorSkillContent = fs.readFileSync(doctorSkillPath, 'utf8');
|
|
820
|
-
assert.equal(
|
|
821
|
-
doctorSkillContent.includes('brain.kolivri.com'),
|
|
822
|
-
false,
|
|
823
|
-
'memoreal-doctor must NEVER reference brain.kolivri.com'
|
|
824
|
-
);
|
|
825
|
-
assert.match(doctorSkillContent, /connect_account/);
|
|
826
|
-
assert.match(doctorSkillContent, /npx -y @kolivri\/memoreal-mcp setup/);
|
|
827
|
-
|
|
828
|
-
// 7. Verify in-process MemorealHooksPlugin & setup with PRD_FLASH_LEAF_WORKER cleared and restored
|
|
829
|
-
const savedLeafWorker = process.env.PRD_FLASH_LEAF_WORKER;
|
|
830
|
-
delete process.env.PRD_FLASH_LEAF_WORKER;
|
|
831
|
-
try {
|
|
832
|
-
const plugin = await MemorealHooksPlugin({ directory: process.cwd() });
|
|
833
|
-
const pluginOutput = { system: [] };
|
|
834
|
-
await plugin['experimental.chat.system.transform']({ sessionID: 'test-session-e2e' }, pluginOutput);
|
|
835
|
-
assert.equal(pluginOutput.system.length, 1);
|
|
836
|
-
assert.equal(pluginOutput.system[0], ONBOARDING_WIZARD_PROMPT);
|
|
837
|
-
|
|
838
|
-
// Turn 2 stays silent
|
|
839
|
-
const pluginOutput2 = { system: [] };
|
|
840
|
-
await plugin['experimental.chat.system.transform']({ sessionID: 'test-session-e2e' }, pluginOutput2);
|
|
841
|
-
assert.equal(pluginOutput2.system.length, 0);
|
|
842
|
-
|
|
843
|
-
// V2 setup hook test
|
|
844
|
-
const contextHandlers = [];
|
|
845
|
-
const mockCtx = {
|
|
846
|
-
location: { directory: process.cwd() },
|
|
847
|
-
session: {
|
|
848
|
-
hook: async (name, handler) => {
|
|
849
|
-
if (name === 'context') contextHandlers.push(handler);
|
|
850
|
-
},
|
|
851
|
-
},
|
|
852
|
-
tool: { hook: async () => {} },
|
|
853
|
-
event: { subscribe: async function* () {} },
|
|
854
|
-
};
|
|
855
|
-
const cleanup = await setup(mockCtx);
|
|
856
|
-
assert.equal(typeof cleanup, 'function');
|
|
857
|
-
assert.equal(contextHandlers.length, 1);
|
|
858
|
-
const v2Event = { sessionID: 'test-session-v2-e2e', system: [] };
|
|
859
|
-
await contextHandlers[0](v2Event);
|
|
860
|
-
assert.equal(v2Event.system.length, 1);
|
|
861
|
-
assert.equal(v2Event.system[0].text, ONBOARDING_WIZARD_PROMPT);
|
|
862
|
-
cleanup();
|
|
863
|
-
} finally {
|
|
864
|
-
if (savedLeafWorker !== undefined) {
|
|
865
|
-
process.env.PRD_FLASH_LEAF_WORKER = savedLeafWorker;
|
|
866
|
-
} else {
|
|
867
|
-
delete process.env.PRD_FLASH_LEAF_WORKER;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
} finally {
|
|
871
|
-
fs.rmSync(tempHooksHome, { recursive: true, force: true });
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
it('6. detects 401 on POST /v1/mcp: connect_account({}) with stale key initiates fresh device pairing and CLI setup --key exits non-zero', async () => {
|
|
876
|
-
// 1. Set mockState.return401ForMcp = true (even while /v1/health returns 200!)
|
|
877
|
-
mockState.return401ForMcp = true;
|
|
878
|
-
|
|
879
|
-
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'memoreal-e2e-stale-key-'));
|
|
880
|
-
try {
|
|
881
|
-
const client = createStdioMcpClient({
|
|
882
|
-
MEMOREAL_HOME: tempHome,
|
|
883
|
-
MEMOREAL_API_URL: mockUrl,
|
|
884
|
-
MEMOREAL_NO_BROWSER: '1',
|
|
885
|
-
MEMOREAL_API_KEY: 'mem_dev_stale_revoked_key',
|
|
886
|
-
});
|
|
887
|
-
|
|
888
|
-
try {
|
|
889
|
-
await client.request('initialize', {
|
|
890
|
-
protocolVersion: '2024-11-05',
|
|
891
|
-
clientInfo: { name: 'OpenCode', version: '2.0.0' },
|
|
892
|
-
});
|
|
893
|
-
|
|
894
|
-
const mcpCountBefore = mockState.mcpRequests.length;
|
|
895
|
-
const startCountBefore = mockState.startRequests.length;
|
|
896
|
-
|
|
897
|
-
// Calling connect_account({}) (action omitted) with a stale/revoked key
|
|
898
|
-
const connectRes = await client.request('tools/call', {
|
|
899
|
-
name: 'connect_account',
|
|
900
|
-
arguments: {},
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
assert.equal(connectRes.result.isError, false);
|
|
904
|
-
const connectData = JSON.parse(connectRes.result.content[0].text);
|
|
905
|
-
|
|
906
|
-
// Does NOT return already_connected
|
|
907
|
-
assert.notEqual(connectData.status, 'already_connected');
|
|
908
|
-
// Instead detects 401 on POST /v1/mcp and initiates a fresh waiting_for_browser device pairing flow
|
|
909
|
-
assert.equal(connectData.status, 'waiting_for_browser');
|
|
910
|
-
assert.ok(connectData.user_code);
|
|
911
|
-
assert.ok(connectData.verification_uri_complete);
|
|
912
|
-
assert.ok(mockState.mcpRequests.length > mcpCountBefore, 'Must have recorded POST /v1/mcp ping');
|
|
913
|
-
const lastMcp = mockState.mcpRequests[mockState.mcpRequests.length - 1];
|
|
914
|
-
assert.equal(lastMcp.headers.authorization, 'Bearer mem_dev_stale_revoked_key');
|
|
915
|
-
assert.ok(mockState.startRequests.length > startCountBefore, 'Must have initiated device flow via /v1/auth/device/start');
|
|
916
|
-
} finally {
|
|
917
|
-
await client.close();
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
// 2. node src/server.mjs setup --key mem_dev_revoked_key exits non-zero when /v1/mcp returns 401
|
|
921
|
-
const cliRes = await runCliProcess(['setup', '--key', 'mem_dev_revoked_key'], {
|
|
922
|
-
env: {
|
|
923
|
-
MEMOREAL_HOME: tempHome,
|
|
924
|
-
MEMOREAL_API_URL: mockUrl,
|
|
925
|
-
MEMOREAL_NO_BROWSER: '1',
|
|
926
|
-
},
|
|
927
|
-
});
|
|
928
|
-
|
|
929
|
-
assert.notEqual(cliRes.code, 0, 'CLI setup --key must exit non-zero when /v1/mcp returns 401');
|
|
930
|
-
assert.match(cliRes.stderr, /Invalid or revoked Memoreal API key/);
|
|
931
|
-
assert.match(cliRes.stderr, /401/);
|
|
932
|
-
} finally {
|
|
933
|
-
fs.rmSync(tempHome, { recursive: true, force: true });
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
});
|