Files
memind/scripts/setup-memory-v2-pgvector-schema.test.mjs
T
2026-07-03 09:46:03 +08:00

72 lines
1.9 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
parseMemoryPgvectorSchemaArgs,
runMemoryPgvectorSchemaCli,
} from './setup-memory-v2-pgvector-schema.mjs';
test('parseMemoryPgvectorSchemaArgs defaults to dry-run safe settings', () => {
assert.deepEqual(parseMemoryPgvectorSchemaArgs([]), {
apply: false,
tableName: 'memory_embeddings',
dimensions: 1536,
createExtension: false,
createVectorIndex: false,
urlEnv: 'MEMORY_PGVECTOR_DATABASE_URL',
help: false,
});
});
test('parseMemoryPgvectorSchemaArgs maps explicit schema options', () => {
assert.deepEqual(
parseMemoryPgvectorSchemaArgs([
'--apply',
'--table',
'memory_embeddings_local',
'--dimensions',
'768',
'--create-extension',
'--create-vector-index',
'--url-env',
'LOCAL_MEMORY_PG_URL',
]),
{
apply: true,
tableName: 'memory_embeddings_local',
dimensions: 768,
createExtension: true,
createVectorIndex: true,
urlEnv: 'LOCAL_MEMORY_PG_URL',
help: false,
},
);
});
test('runMemoryPgvectorSchemaCli dry-run prints SQL without requiring database url', async () => {
const lines = [];
const originalLog = console.log;
console.log = (line = '') => {
lines.push(String(line));
};
try {
const result = await runMemoryPgvectorSchemaCli([
'--table',
'memory_embeddings',
'--dimensions',
'1536',
], {});
assert.deepEqual(result, { ok: true, mode: 'dry-run', statements: 3 });
assert.match(lines.join('\n'), /No database changes were made/);
assert.match(lines.join('\n'), /CREATE TABLE IF NOT EXISTS "memory_embeddings"/);
} finally {
console.log = originalLog;
}
});
test('runMemoryPgvectorSchemaCli apply requires explicit PostgreSQL url env', async () => {
await assert.rejects(
() => runMemoryPgvectorSchemaCli(['--apply'], {}),
/MEMORY_PGVECTOR_DATABASE_URL/,
);
});