import assert from 'node:assert/strict'; import test from 'node:test'; import { parseMemoryV2ConfigGapArgs, runMemoryV2ConfigGapCli, } from './check-memory-v2-config-gaps.mjs'; function writableBuffer() { let value = ''; return { write(chunk) { value += String(chunk); }, value() { return value; }, }; } test('parseMemoryV2ConfigGapArgs validates options', () => { assert.deepEqual( parseMemoryV2ConfigGapArgs(['--backend', 'qdrant', '--format', 'shell']), { backend: 'qdrant', format: 'shell', help: false }, ); assert.throws(() => parseMemoryV2ConfigGapArgs(['--backend', 'bad']), /--backend must be one of/); assert.throws(() => parseMemoryV2ConfigGapArgs(['--format', 'xml']), /--format must be json or shell/); }); test('runMemoryV2ConfigGapCli reports missing env vars in json mode', async () => { const stdout = writableBuffer(); const code = await runMemoryV2ConfigGapCli({ argv: ['--backend', 'mem0'], env: {}, stdout, }); const report = JSON.parse(stdout.value()); assert.equal(code, 1); assert.equal(report.ok, false); assert.equal(report.reports[0].backend, 'mem0'); assert.ok(report.reports[0].missing.includes('MEMORY_MEM0_API_KEY')); }); test('runMemoryV2ConfigGapCli emits export template in shell mode', async () => { const stdout = writableBuffer(); const code = await runMemoryV2ConfigGapCli({ argv: ['--backend', 'qdrant', '--format', 'shell'], env: {}, stdout, }); assert.equal(code, 1); assert.match(stdout.value(), /export MEMORY_BACKEND='qdrant'/); assert.match(stdout.value(), /export MEMORY_QDRANT_URL='http:\/\/127\.0\.0\.1:6333'/); });