TauriTavern/tests/database-api-contract.test.mjs
Darkatse c899f6405d refactor(database): integrate TriviumDB through a native adapter
Move database ownership, blocking IO and TQL binding into tt-adapter-triviumdb
and upgrade the native engine to 0.8.8. Preserve the plugin API capabilities
with awaited open, numeric IDs and explicit shared-namespace lifecycle.

Coordinate archive IO with database maintenance and restore each namespace
as a complete file group. Keep behavior tests for persistence, parameter
binding, transactions and recovery instead of per-method forwarding tests.

Validated with pnpm run check and tauri-pilot against the macOS app using
the real data root; temporary test namespaces were removed afterward.
2026-09-18 01:42:56 -04:00

34 lines
1.5 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { createDbApi } from '../src/tauri/main/api/db.js';
test('database handles become available only after native open, and opening errors propagate', async () => {
const opened = Promise.withResolvers();
const api = createDbApi({ safeInvoke: () => opened.promise });
let delivered = false;
const opening = api.open('memory', { dim: 2, syncMode: 'full' }).then(handle => {
delivered = true;
return handle;
});
await Promise.resolve();
assert.equal(delivered, false);
opened.resolve({ namespace: 'memory', dim: 2, options: { dim: 2, syncMode: 'full' } });
await opening;
assert.equal(delivered, true);
const failed = createDbApi({ safeInvoke: async () => { throw new Error('disk unavailable'); } });
await assert.rejects(failed.open('memory'), /disk unavailable/);
});
test('text search separates query text from config and translates the filter alias', async () => {
const requests = [];
const api = createDbApi({ safeInvoke: async (_command, { request }) => {
requests.push(structuredClone(request));
return request.type === 'open' ? { namespace: 'memory', dim: 2, options: { dim: 2 } } : null;
} });
const db = await api.open('memory', { dim: 2 });
await db.search(null, { queryText: 'memory', filter: { kind: 'fact' } });
assert.deepEqual(requests[1].operation, {
type: 'search', vector: null, queryText: 'memory', config: { payloadFilter: { kind: 'fact' } },
});
});