109 lines
2.5 KiB
JavaScript
109 lines
2.5 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
parseMemoryPgvectorSmokeArgs,
|
|
runMemoryPgvectorSmokeCli,
|
|
} from './smoke-memory-v2-pgvector.mjs';
|
|
|
|
function writableBuffer() {
|
|
let value = '';
|
|
return {
|
|
write(chunk) {
|
|
value += String(chunk);
|
|
},
|
|
value() {
|
|
return value;
|
|
},
|
|
};
|
|
}
|
|
|
|
test('parseMemoryPgvectorSmokeArgs defaults to safe existing-schema smoke', () => {
|
|
assert.deepEqual(parseMemoryPgvectorSmokeArgs([]), {
|
|
tableName: 'memory_embeddings',
|
|
dimensions: 3,
|
|
createSchema: false,
|
|
createExtension: false,
|
|
cleanup: true,
|
|
urlEnv: 'MEMORY_PGVECTOR_DATABASE_URL',
|
|
help: false,
|
|
});
|
|
});
|
|
|
|
test('parseMemoryPgvectorSmokeArgs maps local setup options', () => {
|
|
assert.deepEqual(
|
|
parseMemoryPgvectorSmokeArgs([
|
|
'--table',
|
|
'memory_smoke',
|
|
'--dimensions',
|
|
'4',
|
|
'--create-schema',
|
|
'--create-extension',
|
|
'--keep-rows',
|
|
'--url-env',
|
|
'TEST_PG_URL',
|
|
]),
|
|
{
|
|
tableName: 'memory_smoke',
|
|
dimensions: 4,
|
|
createSchema: true,
|
|
createExtension: true,
|
|
cleanup: false,
|
|
urlEnv: 'TEST_PG_URL',
|
|
help: false,
|
|
},
|
|
);
|
|
});
|
|
|
|
test('runMemoryPgvectorSmokeCli requires explicit pgvector URL', async () => {
|
|
await assert.rejects(
|
|
() => runMemoryPgvectorSmokeCli([], {}, { stdout: writableBuffer() }),
|
|
/MEMORY_PGVECTOR_DATABASE_URL/,
|
|
);
|
|
});
|
|
|
|
test('runMemoryPgvectorSmokeCli opens pool, runs smoke, and closes pool', async () => {
|
|
const stdout = writableBuffer();
|
|
let poolEnded = false;
|
|
class FakePool {
|
|
constructor(options) {
|
|
this.options = options;
|
|
}
|
|
|
|
async query(sql) {
|
|
if (/SELECT id, content, type, created_at/.test(sql)) {
|
|
return {
|
|
rows: [{
|
|
id: 1,
|
|
content: 'memory-v2 smoke near vector',
|
|
type: 'smoke',
|
|
score: 1,
|
|
}],
|
|
};
|
|
}
|
|
return { rows: [] };
|
|
}
|
|
|
|
async end() {
|
|
poolEnded = true;
|
|
}
|
|
}
|
|
|
|
const result = await runMemoryPgvectorSmokeCli(
|
|
['--create-schema', '--create-extension'],
|
|
{ MEMORY_PGVECTOR_DATABASE_URL: 'postgresql://local/memory' },
|
|
{
|
|
stdout,
|
|
async importPg(specifier) {
|
|
assert.equal(specifier, 'pg');
|
|
return { Pool: FakePool };
|
|
},
|
|
},
|
|
);
|
|
const output = JSON.parse(stdout.value());
|
|
|
|
assert.equal(result.ok, true);
|
|
assert.equal(output.ok, true);
|
|
assert.equal(output.expectedTopText, 'memory-v2 smoke near vector');
|
|
assert.equal(poolEnded, true);
|
|
});
|