@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.
@@ -1,1272 +0,0 @@
1
- import { describe, it, 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 { Readable, Writable } from 'node:stream';
7
-
8
- import {
9
- normalizeClientToolSlug,
10
- sanitizeClientName,
11
- sanitizeWorkspaceMetadata,
12
- openUrlInBrowser,
13
- createConnectWizardController,
14
- runCliSetupWizard,
15
- promptHidden,
16
- verifyApiKeyAuth,
17
- } from '../src/wizard.mjs';
18
-
19
- describe('wizard-unit', () => {
20
- let tmpHome;
21
-
22
- beforeEach(() => {
23
- tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'memoreal-wizard-test-'));
24
- });
25
-
26
- afterEach(() => {
27
- if (tmpHome && fs.existsSync(tmpHome)) {
28
- fs.rmSync(tmpHome, { recursive: true, force: true });
29
- }
30
- });
31
-
32
- describe('normalizeClientToolSlug', () => {
33
- it('normalizes common IDE and assistant names case-insensitively', () => {
34
- assert.equal(normalizeClientToolSlug('OpenCode'), 'opencode');
35
- assert.equal(normalizeClientToolSlug('opencode-ai'), 'opencode');
36
- assert.equal(normalizeClientToolSlug('Cursor'), 'cursor');
37
- assert.equal(normalizeClientToolSlug('cursor-agent'), 'cursor');
38
- assert.equal(normalizeClientToolSlug('Claude Code'), 'claude-code');
39
- assert.equal(normalizeClientToolSlug('claude_code'), 'claude-code');
40
- assert.equal(normalizeClientToolSlug('claude-cli'), 'claude-code');
41
- assert.equal(normalizeClientToolSlug('claude'), 'claude-code');
42
- assert.equal(normalizeClientToolSlug('Visual Studio Code'), 'vscode');
43
- assert.equal(normalizeClientToolSlug('vscode'), 'vscode');
44
- assert.equal(normalizeClientToolSlug('VS Code'), 'vscode');
45
- assert.equal(normalizeClientToolSlug('copilot'), 'vscode');
46
- assert.equal(normalizeClientToolSlug('Windsurf'), 'windsurf');
47
- assert.equal(normalizeClientToolSlug('Codeium Windsurf'), 'windsurf');
48
- assert.equal(normalizeClientToolSlug('Zed'), 'zed');
49
- assert.equal(normalizeClientToolSlug('Codex'), 'codex');
50
- assert.equal(normalizeClientToolSlug('codex-cli'), 'codex');
51
- });
52
-
53
- it('returns empty string for unrecognized or invalid input', () => {
54
- assert.equal(normalizeClientToolSlug(''), '');
55
- assert.equal(normalizeClientToolSlug(null), '');
56
- assert.equal(normalizeClientToolSlug(undefined), '');
57
- assert.equal(normalizeClientToolSlug(123), '');
58
- assert.equal(normalizeClientToolSlug('custom-unknown-client'), '');
59
- });
60
- });
61
-
62
- describe('sanitizeClientName', () => {
63
- it('strips invalid characters, collapses spaces, and slices to 80 chars', () => {
64
- assert.equal(sanitizeClientName('OpenCode v1.0.0'), 'OpenCode v1.0.0');
65
- assert.equal(sanitizeClientName(' My Cool Client +Test-1.0 '), 'My Cool Client +Test-1.0');
66
- assert.equal(sanitizeClientName('Cursor<script>alert(1)</script>'), 'Cursorscriptalert1script');
67
- assert.equal(sanitizeClientName('A'.repeat(120)).length, 80);
68
- assert.equal(sanitizeClientName(null), '');
69
- assert.equal(sanitizeClientName(undefined), '');
70
- });
71
- });
72
-
73
- describe('sanitizeWorkspaceMetadata', () => {
74
- it('returns undefined for null, undefined, non-string primitives, and empty/secret strings', () => {
75
- assert.equal(sanitizeWorkspaceMetadata(null), undefined);
76
- assert.equal(sanitizeWorkspaceMetadata(undefined), undefined);
77
- assert.equal(sanitizeWorkspaceMetadata(123), undefined);
78
- assert.equal(sanitizeWorkspaceMetadata(true), undefined);
79
- assert.equal(sanitizeWorkspaceMetadata(''), undefined);
80
- assert.equal(sanitizeWorkspaceMetadata(' '), undefined);
81
- assert.equal(sanitizeWorkspaceMetadata('mem_dev_secret123'), undefined);
82
- assert.equal(sanitizeWorkspaceMetadata('sk-1234567890'), undefined);
83
- assert.equal(sanitizeWorkspaceMetadata('Bearer token12345'), undefined);
84
- });
85
-
86
- it('supports string workspace slug while trimming whitespace and redacting secret patterns', () => {
87
- assert.equal(sanitizeWorkspaceMetadata('acme'), 'acme');
88
- assert.equal(sanitizeWorkspaceMetadata(' acme '), 'acme');
89
- assert.equal(sanitizeWorkspaceMetadata(''), undefined);
90
- assert.equal(sanitizeWorkspaceMetadata('mem_dev_secret123'), undefined);
91
- assert.equal(sanitizeWorkspaceMetadata('sk-12345678'), undefined);
92
- assert.equal(sanitizeWorkspaceMetadata('Bearer secret'), undefined);
93
- });
94
-
95
- it('recursively strips secret properties and raw api_key string patterns', () => {
96
- const input = {
97
- id: 'ws_123',
98
- name: 'Engineering Team',
99
- tier: 'team',
100
- api_key: 'mem_dev_secret_key_123',
101
- apiKey: 'mem_live_another_secret',
102
- secret: 'super-secret-value',
103
- token: 'bearer-token-xyz',
104
- access_token: 'access-token-123',
105
- authorization: 'Bearer mem_live_test',
106
- nested: {
107
- allowed: 'visible-value',
108
- raw_key: 'raw-secret',
109
- customProperty: 'mem_dev_embedded_key_val',
110
- },
111
- items: [
112
- 'regular-item',
113
- 'mem_live_filtered_secret_item',
114
- {
115
- key: 'item-key',
116
- token: 'item-token',
117
- childVal: 'mem_start_filtered_child',
118
- },
119
- ],
120
- };
121
-
122
- const sanitized = sanitizeWorkspaceMetadata(input);
123
-
124
- assert.equal(sanitized.id, 'ws_123');
125
- assert.equal(sanitized.name, 'Engineering Team');
126
- assert.equal(sanitized.tier, 'team');
127
- assert.equal(sanitized.api_key, undefined);
128
- assert.equal(sanitized.apiKey, undefined);
129
- assert.equal(sanitized.secret, undefined);
130
- assert.equal(sanitized.token, undefined);
131
- assert.equal(sanitized.access_token, undefined);
132
- assert.equal(sanitized.authorization, undefined);
133
-
134
- assert.equal(sanitized.nested.allowed, 'visible-value');
135
- assert.equal(sanitized.nested.raw_key, undefined);
136
- assert.equal(sanitized.nested.customProperty, undefined);
137
-
138
- assert.equal(sanitized.items.length, 2);
139
- assert.equal(sanitized.items[0], 'regular-item');
140
- assert.equal(sanitized.items[1].key, 'item-key');
141
- assert.equal(sanitized.items[1].token, undefined);
142
- assert.equal(sanitized.items[1].childVal, undefined);
143
-
144
- // Verify no key matches secret regex and no value matches mem_* key prefix in the serialized json
145
- const json = JSON.stringify(sanitized);
146
- assert.equal(/mem_(dev|live|start|biz|prod|test)_/i.test(json), false);
147
- assert.equal(/(api_?key|raw_?key|secret|token|access_?token|authorization)/i.test(json), false);
148
- });
149
- });
150
-
151
- describe('openUrlInBrowser', () => {
152
- it('returns false when MEMOREAL_NO_BROWSER is "1"', () => {
153
- let spawned = false;
154
- const res = openUrlInBrowser('https://memoreal.kolivri.com/connect?code=ABCD-1234', {
155
- env: { MEMOREAL_NO_BROWSER: '1' },
156
- spawnImpl: () => {
157
- spawned = true;
158
- return { on: () => {}, unref: () => {} };
159
- },
160
- });
161
- assert.equal(res, false);
162
- assert.equal(spawned, false);
163
- });
164
-
165
- it('returns false for invalid or dangerous URLs', () => {
166
- let spawned = false;
167
- const invalidUrls = [
168
- '',
169
- ' ',
170
- 'javascript:alert(1)',
171
- 'file:///etc/passwd',
172
- 'ftp://example.com',
173
- 'https://example.com/foo"bar',
174
- 'https://example.com/<script>',
175
- ];
176
- for (const url of invalidUrls) {
177
- const res = openUrlInBrowser(url, {
178
- env: {},
179
- spawnImpl: () => {
180
- spawned = true;
181
- return { on: () => {}, unref: () => {} };
182
- },
183
- });
184
- assert.equal(res, false);
185
- }
186
- assert.equal(spawned, false);
187
- });
188
-
189
- it('spawns "open" on darwin, "cmd" on win32, and "xdg-open" on linux', () => {
190
- const calls = [];
191
- const mockSpawn = (cmd, args, opts) => {
192
- calls.push({ cmd, args, opts });
193
- return {
194
- on: () => {},
195
- unref: () => {},
196
- };
197
- };
198
-
199
- const testUrl = 'https://memoreal.kolivri.com/connect?code=TEST-1234';
200
-
201
- // Darwin
202
- const resDarwin = openUrlInBrowser(testUrl, {
203
- platform: 'darwin',
204
- env: {},
205
- spawnImpl: mockSpawn,
206
- });
207
- assert.equal(resDarwin, true);
208
- assert.deepEqual(calls[0], {
209
- cmd: 'open',
210
- args: [testUrl],
211
- opts: { detached: true, stdio: 'ignore' },
212
- });
213
-
214
- // Win32
215
- const resWin32 = openUrlInBrowser(testUrl, {
216
- platform: 'win32',
217
- env: {},
218
- spawnImpl: mockSpawn,
219
- });
220
- assert.equal(resWin32, true);
221
- assert.deepEqual(calls[1], {
222
- cmd: 'cmd',
223
- args: ['/c', 'start', '', testUrl],
224
- opts: { detached: true, stdio: 'ignore' },
225
- });
226
-
227
- // Linux
228
- const resLinux = openUrlInBrowser(testUrl, {
229
- platform: 'linux',
230
- env: {},
231
- spawnImpl: mockSpawn,
232
- });
233
- assert.equal(resLinux, true);
234
- assert.deepEqual(calls[2], {
235
- cmd: 'xdg-open',
236
- args: [testUrl],
237
- opts: { detached: true, stdio: 'ignore' },
238
- });
239
- });
240
-
241
- it('handles spawn errors gracefully and returns false without throwing', () => {
242
- const res = openUrlInBrowser('https://example.com', {
243
- env: {},
244
- spawnImpl: () => {
245
- throw new Error('spawn ENOENT');
246
- },
247
- });
248
- assert.equal(res, false);
249
- });
250
- });
251
-
252
- describe('createConnectWizardController', () => {
253
- it('returns already_connected when action is omitted and health check succeeds', async () => {
254
- let healthChecked = false;
255
- const mockFetch = async (url, opts) => {
256
- if (url.endsWith('/v1/health')) {
257
- healthChecked = true;
258
- assert.equal(opts.headers.Authorization, 'Bearer mem_dev_existing_key');
259
- return {
260
- ok: true,
261
- status: 200,
262
- json: async () => ({ status: 'healthy' }),
263
- };
264
- }
265
- throw new Error(`Unexpected fetch URL: ${url}`);
266
- };
267
-
268
- const controller = createConnectWizardController({
269
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
270
- getExistingApiKey: () => 'mem_dev_existing_key',
271
- fetchImpl: mockFetch,
272
- homeDir: tmpHome,
273
- });
274
-
275
- const res = await controller.handleConnectAccount({});
276
- assert.equal(res.status, 'already_connected');
277
- assert.equal(res.api_url, 'https://mock.memoria.kolivri.com');
278
- assert.match(res.message, /already connected/i);
279
- assert.equal(healthChecked, true);
280
-
281
- controller.close();
282
- });
283
-
284
- it('handles action: "status" when not started with or without existing key', async () => {
285
- // 1. Without existing key
286
- const controller1 = createConnectWizardController({
287
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
288
- getExistingApiKey: () => '',
289
- fetchImpl: async () => assert.fail('should not fetch'),
290
- homeDir: tmpHome,
291
- });
292
-
293
- const res1 = await controller1.handleConnectAccount({ action: 'status' });
294
- assert.equal(res1.status, 'not_started');
295
- assert.match(res1.message, /Step 1/);
296
- controller1.close();
297
-
298
- // 2. With existing key and healthy status
299
- const controller2 = createConnectWizardController({
300
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
301
- getExistingApiKey: () => 'mem_dev_valid_key',
302
- fetchImpl: async (url) => {
303
- if (url.endsWith('/v1/health')) {
304
- return { ok: true, status: 200, json: async () => ({ status: 'healthy' }) };
305
- }
306
- throw new Error(`Unexpected fetch ${url}`);
307
- },
308
- homeDir: tmpHome,
309
- });
310
-
311
- const res2 = await controller2.handleConnectAccount({ action: 'status' });
312
- assert.equal(res2.status, 'connected');
313
- assert.match(res2.message, /Step 3/);
314
- controller2.close();
315
- });
316
-
317
- it('does not read config.env behind callback when getExistingApiKey returns empty string', async () => {
318
- const configDir = path.join(tmpHome, '.memoreal');
319
- fs.mkdirSync(configDir, { recursive: true });
320
- fs.writeFileSync(
321
- path.join(configDir, 'config.env'),
322
- 'MEMOREAL_API_KEY="mem_dev_from_saved_file"\n'
323
- );
324
-
325
- let healthFetched = false;
326
- const mockFetch = async (url) => {
327
- if (url.endsWith('/v1/health')) {
328
- healthFetched = true;
329
- return { ok: true, status: 200, json: async () => ({ status: 'healthy' }) };
330
- }
331
- throw new Error(`Unexpected fetch: ${url}`);
332
- };
333
-
334
- const controller = createConnectWizardController({
335
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
336
- getExistingApiKey: () => '',
337
- fetchImpl: mockFetch,
338
- homeDir: tmpHome,
339
- });
340
-
341
- const statusRes = await controller.handleConnectAccount({ action: 'status' });
342
- assert.equal(statusRes.status, 'not_started');
343
- assert.equal(healthFetched, false, 'Should not read config.env or call /v1/health');
344
-
345
- controller.close();
346
- });
347
-
348
- it('completes device flow: action: "start" -> background poll -> approval -> connected status', async () => {
349
- let pollCount = 0;
350
- let approvedCallbackCalled = false;
351
- let browserLaunched = false;
352
-
353
- const mockFetch = async (url, opts) => {
354
- if (url.endsWith('/v1/auth/device/start')) {
355
- const body = JSON.parse(opts.body);
356
- assert.equal(body.client_name, 'OpenCode Test');
357
- assert.equal(body.tool, 'opencode');
358
- return {
359
- ok: true,
360
- status: 200,
361
- json: async () => ({
362
- device_code: 'dev_code_123',
363
- user_code: 'ABCD-9999',
364
- verification_uri: 'https://memoreal.kolivri.com/connect',
365
- verification_uri_complete: 'https://memoreal.kolivri.com/connect?code=ABCD-9999',
366
- expires_in: 300,
367
- interval: 0.05,
368
- }),
369
- };
370
- }
371
-
372
- if (url.endsWith('/v1/auth/device/poll')) {
373
- pollCount++;
374
- const body = JSON.parse(opts.body);
375
- assert.equal(body.device_code, 'dev_code_123');
376
-
377
- if (pollCount === 1) {
378
- return {
379
- ok: true,
380
- status: 200,
381
- json: async () => ({ status: 'pending' }),
382
- };
383
- }
384
-
385
- return {
386
- ok: true,
387
- status: 200,
388
- json: async () => ({
389
- status: 'approved',
390
- api_key: 'mem_dev_newly_paired_key_456',
391
- workspace: {
392
- id: 'ws_789',
393
- name: 'Test Org',
394
- api_key: 'mem_dev_newly_paired_key_456',
395
- },
396
- }),
397
- };
398
- }
399
-
400
- throw new Error(`Unexpected fetch ${url}`);
401
- };
402
-
403
- const controller = createConnectWizardController({
404
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
405
- getExistingApiKey: () => '',
406
- getConnectedClientName: () => 'OpenCode Test',
407
- fetchImpl: mockFetch,
408
- homeDir: tmpHome,
409
- env: { MEMOREAL_HOME: tmpHome },
410
- spawnImpl: (cmd, args) => {
411
- browserLaunched = true;
412
- return { on: () => {}, unref: () => {} };
413
- },
414
- onApproved: ({ apiKey, apiUrl, workspace }) => {
415
- approvedCallbackCalled = true;
416
- assert.equal(apiKey, 'mem_dev_newly_paired_key_456');
417
- assert.equal(apiUrl, 'https://mock.memoria.kolivri.com');
418
- assert.equal(workspace.id, 'ws_789');
419
- assert.equal(workspace.api_key, undefined);
420
- },
421
- });
422
-
423
- // 1. Initiate start
424
- const startRes = await controller.handleConnectAccount({
425
- action: 'start',
426
- client_name: 'OpenCode Test',
427
- });
428
-
429
- assert.equal(startRes.status, 'waiting_for_browser');
430
- assert.equal(startRes.user_code, 'ABCD-9999');
431
- assert.equal(startRes.verification_uri_complete, 'https://memoreal.kolivri.com/connect?code=ABCD-9999');
432
- assert.equal(startRes.browser_opened, true);
433
- assert.equal(browserLaunched, true);
434
- assert.match(startRes.message, /Step 2/);
435
-
436
- // Verify immediate status check before polling completes
437
- const status1 = await controller.handleConnectAccount({ action: 'status' });
438
- assert.equal(status1.status, 'waiting_for_browser');
439
-
440
- // 2. Wait for background polling to finish (2 polls * 50ms = ~100-150ms)
441
- await new Promise((resolve) => setTimeout(resolve, 200));
442
-
443
- assert.equal(approvedCallbackCalled, true);
444
- assert.ok(pollCount >= 2, `Expected at least 2 polls, got ${pollCount}`);
445
-
446
- // 3. Status check after approval
447
- const status2 = await controller.handleConnectAccount({ action: 'status' });
448
- assert.equal(status2.status, 'connected');
449
- assert.match(status2.message, /Step 3/);
450
- assert.equal(status2.workspace.id, 'ws_789');
451
- assert.equal(status2.workspace.api_key, undefined);
452
- // Ensure raw api_key is NEVER returned on status response
453
- assert.equal('api_key' in status2, false);
454
-
455
- // Verify 0600 config file was persisted
456
- const savedConfigFile = path.join(tmpHome, '.memoreal', 'config.env');
457
- assert.ok(fs.existsSync(savedConfigFile), 'Config file must exist');
458
- const savedContent = fs.readFileSync(savedConfigFile, 'utf8');
459
- assert.match(savedContent, /MEMOREAL_API_KEY="mem_dev_newly_paired_key_456"/);
460
-
461
- controller.close();
462
- });
463
-
464
- it('handles device flow with string workspace (e.g. "acme") from /v1/auth/device/poll', async () => {
465
- let pollCount = 0;
466
- let approvedCallbackCalled = false;
467
- let approvedWorkspace = null;
468
-
469
- const mockFetch = async (url, opts) => {
470
- if (url.endsWith('/v1/auth/device/start')) {
471
- return {
472
- ok: true,
473
- status: 200,
474
- json: async () => ({
475
- device_code: 'dev_code_str_ws',
476
- user_code: 'ACME-1234',
477
- verification_uri: 'https://memoreal.kolivri.com/connect',
478
- verification_uri_complete: 'https://memoreal.kolivri.com/connect?code=ACME-1234',
479
- expires_in: 300,
480
- interval: 0.05,
481
- }),
482
- };
483
- }
484
-
485
- if (url.endsWith('/v1/auth/device/poll')) {
486
- pollCount++;
487
- if (pollCount === 1) {
488
- return {
489
- ok: true,
490
- status: 200,
491
- json: async () => ({ status: 'pending' }),
492
- };
493
- }
494
-
495
- return {
496
- ok: true,
497
- status: 200,
498
- json: async () => ({
499
- status: 'approved',
500
- api_key: 'mem_dev_acme_paired_key',
501
- workspace: 'acme',
502
- }),
503
- };
504
- }
505
-
506
- throw new Error(`Unexpected fetch ${url}`);
507
- };
508
-
509
- const controller = createConnectWizardController({
510
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
511
- getExistingApiKey: () => '',
512
- getConnectedClientName: () => 'OpenCode Acme Test',
513
- fetchImpl: mockFetch,
514
- homeDir: tmpHome,
515
- env: { MEMOREAL_HOME: tmpHome },
516
- spawnImpl: () => ({ on: () => {}, unref: () => {} }),
517
- onApproved: ({ apiKey, apiUrl, workspace }) => {
518
- approvedCallbackCalled = true;
519
- approvedWorkspace = workspace;
520
- assert.equal(apiKey, 'mem_dev_acme_paired_key');
521
- assert.equal(apiUrl, 'https://mock.memoria.kolivri.com');
522
- assert.equal(workspace, 'acme');
523
- },
524
- });
525
-
526
- const startRes = await controller.handleConnectAccount({
527
- action: 'start',
528
- client_name: 'OpenCode Acme Test',
529
- });
530
- assert.equal(startRes.status, 'waiting_for_browser');
531
-
532
- await new Promise((resolve) => setTimeout(resolve, 200));
533
-
534
- assert.equal(approvedCallbackCalled, true);
535
- assert.equal(approvedWorkspace, 'acme');
536
-
537
- const status = await controller.handleConnectAccount({ action: 'status' });
538
- assert.equal(status.status, 'connected');
539
- assert.equal(status.workspace, 'acme');
540
- assert.equal('api_key' in status, false);
541
-
542
- controller.close();
543
- });
544
-
545
- it('handles denied and expired polling transitions', async () => {
546
- // Test Denied
547
- let pollCount = 0;
548
- const controllerDenied = createConnectWizardController({
549
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
550
- getExistingApiKey: () => '',
551
- fetchImpl: async (url) => {
552
- if (url.endsWith('/v1/auth/device/start')) {
553
- return {
554
- ok: true,
555
- json: async () => ({
556
- device_code: 'dev_code_denied',
557
- user_code: 'DENY-0001',
558
- verification_uri: 'https://memoreal.kolivri.com/connect',
559
- expires_in: 300,
560
- interval: 0.05,
561
- }),
562
- };
563
- }
564
- if (url.endsWith('/v1/auth/device/poll')) {
565
- return {
566
- ok: true,
567
- json: async () => ({ status: 'denied' }),
568
- };
569
- }
570
- },
571
- homeDir: tmpHome,
572
- env: { MEMOREAL_NO_BROWSER: '1' },
573
- });
574
-
575
- await controllerDenied.handleConnectAccount({ action: 'start' });
576
- await new Promise((r) => setTimeout(r, 120));
577
- const statusDenied = await controllerDenied.handleConnectAccount({ action: 'status' });
578
- assert.equal(statusDenied.status, 'denied');
579
- assert.match(statusDenied.message, /denied/i);
580
- controllerDenied.close();
581
-
582
- // Test Expired
583
- const controllerExpired = createConnectWizardController({
584
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
585
- getExistingApiKey: () => '',
586
- fetchImpl: async (url) => {
587
- if (url.endsWith('/v1/auth/device/start')) {
588
- return {
589
- ok: true,
590
- json: async () => ({
591
- device_code: 'dev_code_expired',
592
- user_code: 'EXPR-0001',
593
- verification_uri: 'https://memoreal.kolivri.com/connect',
594
- expires_in: 300,
595
- interval: 0.05,
596
- }),
597
- };
598
- }
599
- if (url.endsWith('/v1/auth/device/poll')) {
600
- return {
601
- ok: true,
602
- json: async () => ({ status: 'expired' }),
603
- };
604
- }
605
- },
606
- homeDir: tmpHome,
607
- env: { MEMOREAL_NO_BROWSER: '1' },
608
- });
609
-
610
- await controllerExpired.handleConnectAccount({ action: 'start' });
611
- await new Promise((r) => setTimeout(r, 120));
612
- const statusExpired = await controllerExpired.handleConnectAccount({ action: 'status' });
613
- assert.equal(statusExpired.status, 'expired');
614
- assert.match(statusExpired.message, /expired/i);
615
- controllerExpired.close();
616
- });
617
-
618
- it('action omitted: does NOT return already_connected when POST /v1/mcp returns 401 even if /v1/health returns 200', async () => {
619
- let startCalled = false;
620
- const mockFetch = async (url) => {
621
- if (url.endsWith('/v1/mcp')) {
622
- return { ok: false, status: 401, json: async () => ({ error: 'Revoked' }) };
623
- }
624
- if (url.endsWith('/v1/health')) {
625
- return { ok: true, status: 200, json: async () => ({ status: 'healthy' }) };
626
- }
627
- if (url.endsWith('/v1/auth/device/start')) {
628
- startCalled = true;
629
- return {
630
- ok: true,
631
- status: 200,
632
- json: async () => ({
633
- device_code: 'dev_code_fallback',
634
- user_code: 'FALL-1234',
635
- verification_uri: 'https://memoreal.kolivri.com/connect',
636
- expires_in: 300,
637
- interval: 0.05,
638
- }),
639
- };
640
- }
641
- throw new Error(`Unexpected URL: ${url}`);
642
- };
643
-
644
- const controller = createConnectWizardController({
645
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
646
- getExistingApiKey: () => 'mem_dev_revoked_key',
647
- fetchImpl: mockFetch,
648
- homeDir: tmpHome,
649
- env: { MEMOREAL_NO_BROWSER: '1' },
650
- });
651
-
652
- const res = await controller.handleConnectAccount({});
653
- assert.notEqual(res.status, 'already_connected');
654
- assert.equal(res.status, 'waiting_for_browser');
655
- assert.equal(startCalled, true);
656
- controller.close();
657
- });
658
-
659
- it('action: "status" when not_started does NOT return connected when POST /v1/mcp returns 401', async () => {
660
- const mockFetch = async (url) => {
661
- if (url.endsWith('/v1/mcp')) {
662
- return { ok: false, status: 401, json: async () => ({ error: 'Revoked' }) };
663
- }
664
- if (url.endsWith('/v1/health')) {
665
- return { ok: true, status: 200, json: async () => ({ status: 'healthy' }) };
666
- }
667
- throw new Error(`Unexpected URL: ${url}`);
668
- };
669
-
670
- const controller = createConnectWizardController({
671
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
672
- getExistingApiKey: () => 'mem_dev_revoked_key',
673
- fetchImpl: mockFetch,
674
- homeDir: tmpHome,
675
- });
676
-
677
- const res = await controller.handleConnectAccount({ action: 'status' });
678
- assert.equal(res.status, 'not_started');
679
- assert.match(res.message, /Step 1/);
680
- controller.close();
681
- });
682
-
683
- it('safeguards against superseded deviceCode: poll response from older start call is ignored', async () => {
684
- let firstPollResolve = null;
685
- const firstPollPromise = new Promise((resolve) => {
686
- firstPollResolve = resolve;
687
- });
688
-
689
- const approvedCalls = [];
690
-
691
- const mockFetch = async (url, opts) => {
692
- if (url.endsWith('/v1/auth/device/start')) {
693
- const body = JSON.parse(opts.body);
694
- if (body.client_name === 'Client First') {
695
- return {
696
- ok: true,
697
- status: 200,
698
- json: async () => ({
699
- device_code: 'first_device_code',
700
- user_code: 'FIRST-01',
701
- verification_uri: 'https://memoreal.kolivri.com/connect',
702
- expires_in: 300,
703
- interval: 0.05,
704
- }),
705
- };
706
- } else {
707
- return {
708
- ok: true,
709
- status: 200,
710
- json: async () => ({
711
- device_code: 'second_device_code',
712
- user_code: 'SECOND-02',
713
- verification_uri: 'https://memoreal.kolivri.com/connect',
714
- expires_in: 300,
715
- interval: 0.05,
716
- }),
717
- };
718
- }
719
- }
720
-
721
- if (url.endsWith('/v1/auth/device/poll')) {
722
- const body = JSON.parse(opts.body);
723
- if (body.device_code === 'first_device_code') {
724
- await firstPollPromise;
725
- return {
726
- ok: true,
727
- status: 200,
728
- json: async () => ({
729
- status: 'approved',
730
- api_key: 'mem_dev_stale_old_key',
731
- workspace: 'stale_org',
732
- }),
733
- };
734
- }
735
- if (body.device_code === 'second_device_code') {
736
- return {
737
- ok: true,
738
- status: 200,
739
- json: async () => ({
740
- status: 'approved',
741
- api_key: 'mem_dev_fresh_second_key',
742
- workspace: 'fresh_org',
743
- }),
744
- };
745
- }
746
- }
747
-
748
- throw new Error(`Unexpected URL: ${url}`);
749
- };
750
-
751
- const controller = createConnectWizardController({
752
- getApiUrl: () => 'https://mock.memoria.kolivri.com',
753
- getExistingApiKey: () => '',
754
- fetchImpl: mockFetch,
755
- homeDir: tmpHome,
756
- env: { MEMOREAL_NO_BROWSER: '1', MEMOREAL_HOME: tmpHome },
757
- onApproved: (data) => {
758
- approvedCalls.push(data);
759
- },
760
- });
761
-
762
- const res1 = await controller.handleConnectAccount({ action: 'start', client_name: 'Client First' });
763
- assert.equal(res1.user_code, 'FIRST-01');
764
-
765
- const res2 = await controller.handleConnectAccount({ action: 'start', client_name: 'Client Second' });
766
- assert.equal(res2.user_code, 'SECOND-02');
767
-
768
- firstPollResolve();
769
-
770
- await new Promise((resolve) => setTimeout(resolve, 200));
771
-
772
- assert.equal(approvedCalls.length, 1);
773
- assert.equal(approvedCalls[0].apiKey, 'mem_dev_fresh_second_key');
774
- assert.equal(approvedCalls[0].workspace, 'fresh_org');
775
-
776
- const status = await controller.handleConnectAccount({ action: 'status' });
777
- assert.equal(status.status, 'connected');
778
- assert.equal(status.workspace, 'fresh_org');
779
-
780
- controller.close();
781
- });
782
- });
783
-
784
- describe('runCliSetupWizard', () => {
785
- it('--help prints usage and exits cleanly', async () => {
786
- let outputText = '';
787
- const mockOutput = new Writable({
788
- write(chunk, enc, cb) {
789
- outputText += chunk.toString();
790
- cb();
791
- },
792
- });
793
-
794
- const res = await runCliSetupWizard({
795
- argv: ['--help'],
796
- output: mockOutput,
797
- });
798
-
799
- assert.equal(res.ok, true);
800
- assert.equal(res.help, true);
801
- assert.match(outputText, /Usage: memoreal-mcp setup/);
802
- assert.match(outputText, /--browser/);
803
- assert.match(outputText, /--key/);
804
- });
805
-
806
- it('--key flow: saves 0600 config, updates IDEs, and verifies health without printing secret', async () => {
807
- let outputText = '';
808
- const mockOutput = new Writable({
809
- write(chunk, enc, cb) {
810
- outputText += chunk.toString();
811
- cb();
812
- },
813
- });
814
-
815
- let healthRequested = false;
816
- const mockFetch = async (url, opts) => {
817
- if (url.endsWith('/v1/health')) {
818
- healthRequested = true;
819
- assert.equal(opts.headers.Authorization, 'Bearer mem_dev_cli_key_123');
820
- return {
821
- ok: true,
822
- status: 200,
823
- json: async () => ({
824
- status: 'healthy',
825
- workspace: {
826
- id: 'ws_cli_1',
827
- name: 'CLI Workspace',
828
- api_key: 'mem_dev_cli_key_123',
829
- },
830
- }),
831
- };
832
- }
833
- throw new Error(`Unexpected URL: ${url}`);
834
- };
835
-
836
- const res = await runCliSetupWizard({
837
- argv: ['setup', '--key', 'mem_dev_cli_key_123', '--tool', 'cursor', '--api-url', 'https://mock.memoria.kolivri.com'],
838
- output: mockOutput,
839
- homeDir: tmpHome,
840
- env: { MEMOREAL_HOME: tmpHome },
841
- fetchImpl: mockFetch,
842
- });
843
-
844
- assert.equal(res.ok, true);
845
- assert.equal(res.apiUrl, 'https://mock.memoria.kolivri.com');
846
- assert.ok(fs.existsSync(res.configPath));
847
- assert.equal(healthRequested, true);
848
- assert.equal(res.workspace.id, 'ws_cli_1');
849
- assert.equal(res.workspace.api_key, undefined);
850
-
851
- // Verify mode 0600
852
- const stat = fs.statSync(res.configPath);
853
- assert.equal(stat.mode & 0o777, 0o600);
854
-
855
- // CRITICAL: Raw API key must NEVER be printed to terminal output!
856
- assert.equal(outputText.includes('mem_dev_cli_key_123'), false);
857
- assert.match(outputText, /Memoreal Connected Successfully!/);
858
- assert.match(outputText, /API URL:/);
859
- assert.match(outputText, /Config File:/);
860
- });
861
-
862
- it('--browser flow: performs OAuth device pairing, saves config, and prints secret-free summary', async () => {
863
- let outputText = '';
864
- const mockOutput = new Writable({
865
- write(chunk, enc, cb) {
866
- outputText += chunk.toString();
867
- cb();
868
- },
869
- });
870
-
871
- let pollCount = 0;
872
- let browserLaunched = false;
873
-
874
- const mockFetch = async (url, opts) => {
875
- if (url.endsWith('/v1/auth/device/start')) {
876
- return {
877
- ok: true,
878
- status: 200,
879
- json: async () => ({
880
- device_code: 'cli_dev_code_abc',
881
- user_code: 'WIZD-5678',
882
- verification_uri: 'https://memoreal.kolivri.com/connect',
883
- verification_uri_complete: 'https://memoreal.kolivri.com/connect?code=WIZD-5678',
884
- expires_in: 300,
885
- interval: 0.05,
886
- }),
887
- };
888
- }
889
-
890
- if (url.endsWith('/v1/auth/device/poll')) {
891
- pollCount++;
892
- if (pollCount === 1) {
893
- return {
894
- ok: true,
895
- json: async () => ({ status: 'pending' }),
896
- };
897
- }
898
- return {
899
- ok: true,
900
- json: async () => ({
901
- status: 'approved',
902
- api_key: 'mem_dev_paired_cli_key_999',
903
- workspace: {
904
- name: 'Browser Paired Org',
905
- secret: 'should-be-stripped',
906
- },
907
- }),
908
- };
909
- }
910
-
911
- if (url.endsWith('/v1/health')) {
912
- return {
913
- ok: true,
914
- status: 200,
915
- json: async () => ({ status: 'healthy' }),
916
- };
917
- }
918
-
919
- throw new Error(`Unexpected URL: ${url}`);
920
- };
921
-
922
- const res = await runCliSetupWizard({
923
- argv: ['--browser', '--tool', 'opencode'],
924
- output: mockOutput,
925
- homeDir: tmpHome,
926
- env: { MEMOREAL_HOME: tmpHome },
927
- fetchImpl: mockFetch,
928
- spawnImpl: () => {
929
- browserLaunched = true;
930
- return { on: () => {}, unref: () => {} };
931
- },
932
- });
933
-
934
- assert.equal(res.ok, true);
935
- assert.equal(browserLaunched, true);
936
- assert.ok(pollCount >= 2);
937
- assert.equal(res.workspace.name, 'Browser Paired Org');
938
- assert.equal(res.workspace.secret, undefined);
939
-
940
- // Secret check
941
- assert.equal(outputText.includes('mem_dev_paired_cli_key_999'), false);
942
- assert.match(outputText, /Device pairing initialized/);
943
- assert.match(outputText, /User Code:\s+WIZD-5678/);
944
- assert.match(outputText, /Memoreal Connected Successfully!/);
945
- });
946
-
947
- it('--browser flow: handles string workspace (e.g. "acme") from /v1/auth/device/poll', async () => {
948
- let outputText = '';
949
- const mockOutput = new Writable({
950
- write(chunk, enc, cb) {
951
- outputText += chunk.toString();
952
- cb();
953
- },
954
- });
955
-
956
- let pollCount = 0;
957
-
958
- const mockFetch = async (url) => {
959
- if (url.endsWith('/v1/auth/device/start')) {
960
- return {
961
- ok: true,
962
- status: 200,
963
- json: async () => ({
964
- device_code: 'cli_dev_code_str_ws',
965
- user_code: 'ACME-5678',
966
- verification_uri: 'https://memoreal.kolivri.com/connect',
967
- verification_uri_complete: 'https://memoreal.kolivri.com/connect?code=ACME-5678',
968
- expires_in: 300,
969
- interval: 0.05,
970
- }),
971
- };
972
- }
973
-
974
- if (url.endsWith('/v1/auth/device/poll')) {
975
- pollCount++;
976
- if (pollCount === 1) {
977
- return {
978
- ok: true,
979
- json: async () => ({ status: 'pending' }),
980
- };
981
- }
982
- return {
983
- ok: true,
984
- json: async () => ({
985
- status: 'approved',
986
- api_key: 'mem_dev_paired_cli_key_acme',
987
- workspace: 'acme',
988
- }),
989
- };
990
- }
991
-
992
- if (url.endsWith('/v1/health')) {
993
- return {
994
- ok: true,
995
- status: 200,
996
- json: async () => ({ status: 'healthy', workspace: 'acme' }),
997
- };
998
- }
999
-
1000
- throw new Error(`Unexpected URL: ${url}`);
1001
- };
1002
-
1003
- const res = await runCliSetupWizard({
1004
- argv: ['--browser', '--tool', 'opencode'],
1005
- output: mockOutput,
1006
- homeDir: tmpHome,
1007
- env: { MEMOREAL_HOME: tmpHome },
1008
- fetchImpl: mockFetch,
1009
- spawnImpl: () => ({ on: () => {}, unref: () => {} }),
1010
- });
1011
-
1012
- assert.equal(res.ok, true);
1013
- assert.ok(pollCount >= 2);
1014
- assert.equal(res.workspace, 'acme');
1015
- assert.equal(outputText.includes('mem_dev_paired_cli_key_acme'), false);
1016
- assert.match(outputText, /Memoreal Connected Successfully!/);
1017
- });
1018
-
1019
- it('interactive flow: choice [2] allows entering API key via non-TTY stream input', async () => {
1020
- let outputText = '';
1021
- const mockOutput = new Writable({
1022
- write(chunk, enc, cb) {
1023
- outputText += chunk.toString();
1024
- cb();
1025
- },
1026
- });
1027
-
1028
- // User selects '2' (Enter key), then enters key 'mem_dev_interactive_key_555\n'
1029
- const mockInput = Readable.from(['2\n', 'mem_dev_interactive_key_555\n']);
1030
-
1031
- const mockFetch = async (url) => {
1032
- if (url.endsWith('/v1/health')) {
1033
- return {
1034
- ok: true,
1035
- json: async () => ({ status: 'healthy' }),
1036
- };
1037
- }
1038
- throw new Error(`Unexpected URL: ${url}`);
1039
- };
1040
-
1041
- const res = await runCliSetupWizard({
1042
- argv: [],
1043
- input: mockInput,
1044
- output: mockOutput,
1045
- homeDir: tmpHome,
1046
- env: { MEMOREAL_HOME: tmpHome },
1047
- fetchImpl: mockFetch,
1048
- });
1049
-
1050
- assert.equal(res.ok, true);
1051
- assert.ok(fs.existsSync(res.configPath));
1052
- assert.equal(outputText.includes('mem_dev_interactive_key_555'), false);
1053
- assert.match(outputText, /Choose sign-in method:/);
1054
- });
1055
-
1056
- it('interactive flow: choice [1] (or empty Enter) launches browser flow', async () => {
1057
- let outputText = '';
1058
- const mockOutput = new Writable({
1059
- write(chunk, enc, cb) {
1060
- outputText += chunk.toString();
1061
- cb();
1062
- },
1063
- });
1064
-
1065
- const mockInput = Readable.from(['1\n']);
1066
-
1067
- const mockFetch = async (url) => {
1068
- if (url.endsWith('/v1/auth/device/start')) {
1069
- return {
1070
- ok: true,
1071
- status: 200,
1072
- json: async () => ({
1073
- device_code: 'code_choice_1',
1074
- user_code: 'INT1-1234',
1075
- verification_uri: 'https://memoreal.kolivri.com/connect',
1076
- expires_in: 300,
1077
- interval: 0.05,
1078
- }),
1079
- };
1080
- }
1081
- if (url.endsWith('/v1/auth/device/poll')) {
1082
- return {
1083
- ok: true,
1084
- status: 200,
1085
- json: async () => ({
1086
- status: 'approved',
1087
- api_key: 'mem_dev_choice_1_key',
1088
- workspace: { name: 'Interactive Org 1' },
1089
- }),
1090
- };
1091
- }
1092
- if (url.endsWith('/v1/health')) {
1093
- return { ok: true, status: 200, json: async () => ({ status: 'healthy' }) };
1094
- }
1095
- throw new Error(`Unexpected fetch ${url}`);
1096
- };
1097
-
1098
- const res = await runCliSetupWizard({
1099
- argv: [],
1100
- input: mockInput,
1101
- output: mockOutput,
1102
- homeDir: tmpHome,
1103
- env: { MEMOREAL_HOME: tmpHome, MEMOREAL_NO_BROWSER: '1' },
1104
- fetchImpl: mockFetch,
1105
- });
1106
-
1107
- assert.equal(res.ok, true);
1108
- assert.ok(fs.existsSync(res.configPath));
1109
- assert.equal(outputText.includes('mem_dev_choice_1_key'), false);
1110
- assert.match(outputText, /Authorization confirmed!/);
1111
- });
1112
-
1113
- it('--key flow: rejects 401 from POST /v1/mcp even when /v1/health returns 200 and does not save config', async () => {
1114
- const mockFetch = async (url) => {
1115
- if (url.endsWith('/v1/mcp')) {
1116
- return { ok: false, status: 401, json: async () => ({ error: 'Invalid key' }) };
1117
- }
1118
- if (url.endsWith('/v1/health')) {
1119
- return { ok: true, status: 200, json: async () => ({ status: 'healthy' }) };
1120
- }
1121
- throw new Error(`Unexpected URL: ${url}`);
1122
- };
1123
-
1124
- const mockOutput = new Writable({ write(c, e, cb) { cb(); } });
1125
-
1126
- await assert.rejects(
1127
- async () => {
1128
- await runCliSetupWizard({
1129
- argv: ['setup', '--key', 'mem_dev_bad_key'],
1130
- output: mockOutput,
1131
- homeDir: tmpHome,
1132
- env: { MEMOREAL_HOME: tmpHome },
1133
- fetchImpl: mockFetch,
1134
- });
1135
- },
1136
- /Invalid or revoked Memoreal API key \(HTTP 401\)/
1137
- );
1138
-
1139
- const savedConfigFile = path.join(tmpHome, '.memoreal', 'config.env');
1140
- assert.equal(fs.existsSync(savedConfigFile), false, 'Should not persist bad API key to config.env');
1141
- });
1142
-
1143
- it('--key flow: falls back to /v1/health when POST /v1/mcp returns 404', async () => {
1144
- let mcpCalled = false;
1145
- let healthCalled = false;
1146
- const mockFetch = async (url, opts) => {
1147
- if (url.endsWith('/v1/mcp')) {
1148
- mcpCalled = true;
1149
- return { ok: false, status: 404, json: async () => ({ error: 'Not Found' }) };
1150
- }
1151
- if (url.endsWith('/v1/health')) {
1152
- healthCalled = true;
1153
- assert.equal(opts.headers.Authorization, 'Bearer mem_dev_fallback_key');
1154
- return {
1155
- ok: true,
1156
- status: 200,
1157
- json: async () => ({
1158
- status: 'healthy',
1159
- workspace: 'fallback-org',
1160
- }),
1161
- };
1162
- }
1163
- throw new Error(`Unexpected URL: ${url}`);
1164
- };
1165
-
1166
- const mockOutput = new Writable({ write(c, e, cb) { cb(); } });
1167
-
1168
- const res = await runCliSetupWizard({
1169
- argv: ['setup', '--key', 'mem_dev_fallback_key'],
1170
- output: mockOutput,
1171
- homeDir: tmpHome,
1172
- env: { MEMOREAL_HOME: tmpHome },
1173
- fetchImpl: mockFetch,
1174
- });
1175
-
1176
- assert.equal(res.ok, true);
1177
- assert.equal(mcpCalled, true);
1178
- assert.equal(healthCalled, true);
1179
- assert.equal(res.workspace, 'fallback-org');
1180
- assert.ok(fs.existsSync(res.configPath));
1181
- });
1182
- });
1183
-
1184
- describe('verifyApiKeyAuth', () => {
1185
- it('rejects 401 from POST /v1/mcp without falling back to /v1/health', async () => {
1186
- let healthCalled = false;
1187
- const mockFetch = async (url) => {
1188
- if (url.endsWith('/v1/mcp')) {
1189
- return {
1190
- ok: false,
1191
- status: 401,
1192
- json: async () => ({ error: 'Unauthorized' }),
1193
- };
1194
- }
1195
- if (url.endsWith('/v1/health')) {
1196
- healthCalled = true;
1197
- return { ok: true, status: 200, json: async () => ({ status: 'healthy' }) };
1198
- }
1199
- throw new Error(`Unexpected URL: ${url}`);
1200
- };
1201
-
1202
- const res = await verifyApiKeyAuth('https://mock.memoria.kolivri.com', 'mem_dev_revoked_key', { fetchImpl: mockFetch });
1203
- assert.equal(res.ok, false);
1204
- assert.equal(res.status, 401);
1205
- assert.equal(healthCalled, false, 'Must NOT fall back to /v1/health on 401');
1206
- });
1207
-
1208
- it('falls back to /v1/health when POST /v1/mcp returns 404', async () => {
1209
- let mcpCalled = false;
1210
- let healthCalled = false;
1211
- const mockFetch = async (url) => {
1212
- if (url.endsWith('/v1/mcp')) {
1213
- mcpCalled = true;
1214
- return {
1215
- ok: false,
1216
- status: 404,
1217
- json: async () => ({ error: 'Not Found' }),
1218
- };
1219
- }
1220
- if (url.endsWith('/v1/health')) {
1221
- healthCalled = true;
1222
- return { ok: true, status: 200, json: async () => ({ status: 'healthy', workspace: 'acme' }) };
1223
- }
1224
- throw new Error(`Unexpected URL: ${url}`);
1225
- };
1226
-
1227
- const res = await verifyApiKeyAuth('https://mock.memoria.kolivri.com', 'mem_dev_valid_key', { fetchImpl: mockFetch });
1228
- assert.equal(mcpCalled, true);
1229
- assert.equal(healthCalled, true);
1230
- assert.equal(res.ok, true);
1231
- assert.equal(res.status, 200);
1232
- assert.equal(res.data.workspace, 'acme');
1233
- });
1234
- });
1235
-
1236
- describe('promptHidden', () => {
1237
- it('handles input.isTTY = true, strips ANSI escape sequences, and calls pause() on completion', async () => {
1238
- let paused = false;
1239
- let rawMode = null;
1240
- let writtenOutput = '';
1241
-
1242
- const mockOutput = new Writable({
1243
- write(chunk, enc, cb) {
1244
- writtenOutput += chunk.toString();
1245
- cb();
1246
- },
1247
- });
1248
-
1249
- const mockInput = new Readable({
1250
- read() {},
1251
- });
1252
- mockInput.isTTY = true;
1253
- mockInput.setRawMode = (mode) => {
1254
- rawMode = mode;
1255
- };
1256
- mockInput.pause = () => {
1257
- paused = true;
1258
- };
1259
-
1260
- const promptPromise = promptHidden('Enter key: ', mockInput, mockOutput);
1261
-
1262
- mockInput.push(Buffer.from('\x1b[Amem_dev_tty_123\n'));
1263
-
1264
- const result = await promptPromise;
1265
- assert.equal(result, 'mem_dev_tty_123');
1266
- assert.equal(paused, true, 'input.pause() must be called to unref/pause PTY stdin');
1267
- assert.equal(rawMode, false, 'rawMode must be restored to false');
1268
- assert.match(writtenOutput, /Enter key: /);
1269
- assert.match(writtenOutput, /\n/);
1270
- });
1271
- });
1272
- });