test(server): check waggle.db and the memory store instead of mind files (P1.5)
- trust wiring: read install_audit from waggle.db through the server; the old checks read a legacy personal.mind that nothing writes any more. - data dir: a fresh install is marked by waggle.db, not personal.mind. - backup: expect waggle.db and memory/ in the archive. - cross-platform: replace the MindDB block with waggle.db checks (file, WAL, foreign keys) and memory round trips (plain, Unicode, 100 KB) through server.memory. FTS5 and session CRUD were legacy-engine features. - store fixtures (install audit, cron) open WaggleDB instead of MindDB.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
* 3. SPA fallback (index.html for unknown paths)
|
||||
* 4. WebSocket endpoint exists
|
||||
* 5. SSE notification stream works
|
||||
* 6. Mind DB creates and reads on any OS
|
||||
* 6. waggle.db and the memory store create and read on any OS
|
||||
* 7. Vault encryption works on any OS
|
||||
*/
|
||||
|
||||
@@ -18,8 +18,9 @@ import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import { MindDB, FrameStore, SessionStore, VaultStore } from '@waggle/core';
|
||||
import { VaultStore, WaggleDB } from '@waggle/core';
|
||||
import { getConnectorCredential, setConnectorCredential } from '@waggle/agent';
|
||||
import { PERSONAL_SCOPE } from '@waggle/memory-contract';
|
||||
import { buildLocalServer } from '../src/local/index.js';
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { injectWithAuth } from './test-utils.js';
|
||||
@@ -45,15 +46,6 @@ describe('Cross-Platform Verification', () => {
|
||||
beforeAll(async () => {
|
||||
tmpDir = createTmpDir('xplat');
|
||||
|
||||
// Create personal.mind so the server can boot
|
||||
const personalPath = path.join(tmpDir, 'personal.mind');
|
||||
const mind = new MindDB(personalPath);
|
||||
const sessions = new SessionStore(mind);
|
||||
const frames = new FrameStore(mind);
|
||||
const s = sessions.create('xplat-test');
|
||||
frames.createIFrame(s.gop_id, 'Cross-platform test memory frame', 'normal');
|
||||
mind.close();
|
||||
|
||||
// Ensure no Tauri globals exist
|
||||
// (globalThis.__TAURI__ should be undefined in Node.js)
|
||||
expect((globalThis as { __TAURI__?: unknown }).__TAURI__).toBeUndefined();
|
||||
@@ -215,121 +207,70 @@ describe('Cross-Platform Verification', () => {
|
||||
expect(typeof server.eventBus.emit).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
// ── 6. Memory Store ──────────────────────────────────────────────
|
||||
|
||||
describe('memory store', () => {
|
||||
it('writes and reads memories correctly', async () => {
|
||||
const [change] = await server.memory.remember({
|
||||
scope: PERSONAL_SCOPE,
|
||||
text: 'Cross-platform memory content',
|
||||
});
|
||||
|
||||
const retrieved = await server.memory.get(change.record.id);
|
||||
expect(retrieved?.text).toBe('Cross-platform memory content');
|
||||
});
|
||||
|
||||
it('handles Unicode content correctly', async () => {
|
||||
const unicodeContent = 'Tschuss! Bonjour! Konnichiwa! Emoji test: special chars: <>&"\'';
|
||||
const [change] = await server.memory.remember({ scope: PERSONAL_SCOPE, text: unicodeContent });
|
||||
|
||||
const retrieved = await server.memory.get(change.record.id);
|
||||
expect(retrieved?.text).toBe(unicodeContent);
|
||||
});
|
||||
|
||||
it('handles large content blocks', async () => {
|
||||
// Create a 100KB content block
|
||||
const largeContent = 'A'.repeat(100_000);
|
||||
const [change] = await server.memory.remember({ scope: PERSONAL_SCOPE, text: largeContent });
|
||||
|
||||
const retrieved = await server.memory.get(change.record.id);
|
||||
expect(retrieved?.text.length).toBe(100_000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ── 6. Mind DB Cross-Platform ───────────────────────────────────────────
|
||||
// ── 6. waggle.db Cross-Platform ─────────────────────────────────────────
|
||||
|
||||
describe('Mind DB cross-platform', () => {
|
||||
describe('waggle.db cross-platform', () => {
|
||||
let tmpDir: string;
|
||||
let mind: MindDB;
|
||||
let db: WaggleDB;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTmpDir('mind-xplat');
|
||||
const dbPath = path.join(tmpDir, 'test.mind');
|
||||
mind = new MindDB(dbPath);
|
||||
tmpDir = createTmpDir('waggle-db-xplat');
|
||||
db = WaggleDB.openInDataDir(tmpDir);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mind.close();
|
||||
db.close();
|
||||
cleanupDir(tmpDir);
|
||||
});
|
||||
|
||||
it('creates a .mind file on any OS', () => {
|
||||
const dbPath = path.join(tmpDir, 'test.mind');
|
||||
expect(fs.existsSync(dbPath)).toBe(true);
|
||||
});
|
||||
|
||||
it('writes and reads frames correctly', () => {
|
||||
const sessions = new SessionStore(mind);
|
||||
const frames = new FrameStore(mind);
|
||||
|
||||
const session = sessions.create('xplat-project');
|
||||
const frame = frames.createIFrame(session.gop_id, 'Cross-platform frame content', 'normal');
|
||||
|
||||
expect(frame.id).toBeGreaterThan(0);
|
||||
expect(frame.content).toBe('Cross-platform frame content');
|
||||
expect(frame.frame_type).toBe('I');
|
||||
|
||||
// Read back
|
||||
const retrieved = frames.getById(frame.id);
|
||||
expect(retrieved).toBeDefined();
|
||||
expect(retrieved!.content).toBe('Cross-platform frame content');
|
||||
});
|
||||
|
||||
it('FTS5 search works on any OS', () => {
|
||||
const sessions = new SessionStore(mind);
|
||||
const frames = new FrameStore(mind);
|
||||
|
||||
const session = sessions.create('fts-xplat');
|
||||
frames.createIFrame(session.gop_id, 'SQLite full text search verification', 'normal');
|
||||
frames.createIFrame(session.gop_id, 'Another unrelated frame about cooking', 'normal');
|
||||
|
||||
// Search using FTS5
|
||||
const raw = mind.getDatabase();
|
||||
const results = raw.prepare(`
|
||||
SELECT mf.* FROM memory_frames mf
|
||||
INNER JOIN memory_frames_fts fts ON mf.id = fts.rowid
|
||||
WHERE memory_frames_fts MATCH ?
|
||||
`).all('SQLite');
|
||||
|
||||
expect(results.length).toBe(1);
|
||||
expect((results[0] as { content: string }).content).toContain('SQLite');
|
||||
it('creates waggle.db on any OS', () => {
|
||||
expect(fs.existsSync(path.join(tmpDir, 'waggle.db'))).toBe(true);
|
||||
});
|
||||
|
||||
it('WAL mode is enabled', () => {
|
||||
const raw = mind.getDatabase();
|
||||
const raw = db.getDatabase();
|
||||
const mode = raw.pragma('journal_mode', { simple: true });
|
||||
expect(mode).toBe('wal');
|
||||
});
|
||||
|
||||
it('foreign keys are enforced', () => {
|
||||
const raw = mind.getDatabase();
|
||||
const raw = db.getDatabase();
|
||||
const fk = raw.pragma('foreign_keys', { simple: true });
|
||||
expect(fk).toBe(1);
|
||||
});
|
||||
|
||||
it('sessions CRUD works on any OS', () => {
|
||||
const sessions = new SessionStore(mind);
|
||||
|
||||
// Create
|
||||
const session = sessions.create('xplat-crud');
|
||||
expect(session.gop_id).toBeDefined();
|
||||
expect(session.status).toBe('active');
|
||||
|
||||
// Close
|
||||
const closed = sessions.close(session.gop_id, 'Test complete');
|
||||
expect(closed.status).toBe('closed');
|
||||
expect(closed.summary).toBe('Test complete');
|
||||
|
||||
// Archive
|
||||
const archived = sessions.archive(session.gop_id);
|
||||
expect(archived.status).toBe('archived');
|
||||
});
|
||||
|
||||
it('handles Unicode content correctly', () => {
|
||||
const sessions = new SessionStore(mind);
|
||||
const frames = new FrameStore(mind);
|
||||
|
||||
const session = sessions.create('unicode-test');
|
||||
const unicodeContent = 'Tschuss! Bonjour! Konnichiwa! Emoji test: special chars: <>&"\'';
|
||||
const frame = frames.createIFrame(session.gop_id, unicodeContent, 'normal');
|
||||
|
||||
const retrieved = frames.getById(frame.id);
|
||||
expect(retrieved!.content).toBe(unicodeContent);
|
||||
});
|
||||
|
||||
it('handles large content blocks', () => {
|
||||
const sessions = new SessionStore(mind);
|
||||
const frames = new FrameStore(mind);
|
||||
|
||||
const session = sessions.create('large-content');
|
||||
// Create a 100KB content block
|
||||
const largeContent = 'A'.repeat(100_000);
|
||||
const frame = frames.createIFrame(session.gop_id, largeContent, 'normal');
|
||||
|
||||
const retrieved = frames.getById(frame.id);
|
||||
expect(retrieved!.content.length).toBe(100_000);
|
||||
});
|
||||
});
|
||||
|
||||
// ── 7. Vault Encryption Cross-Platform ──────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user