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:
@@ -4,7 +4,7 @@
|
||||
* Tests:
|
||||
* 1. POST /api/backup returns an octet-stream file
|
||||
* 2. Backup excludes marketplace.db and node_modules
|
||||
* 3. Backup includes .mind files and config.json
|
||||
* 3. Backup includes waggle.db, the memory store and config.json
|
||||
* 4. POST /api/restore with preview mode
|
||||
* 5. POST /api/restore applies restore successfully
|
||||
* 6. Restore rejects corrupted/invalid files
|
||||
@@ -20,7 +20,7 @@ import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import * as crypto from 'node:crypto';
|
||||
import * as zlib from 'node:zlib';
|
||||
import { MindDB, SessionStore, FrameStore } from '@waggle/core';
|
||||
import { PERSONAL_SCOPE } from '@waggle/memory-contract';
|
||||
import { buildLocalServer } from '../src/local/index.js';
|
||||
import {
|
||||
isChatHistoryRestoreBusy,
|
||||
@@ -67,15 +67,6 @@ describe('Backup & Restore (PM-5)', () => {
|
||||
// Create a temp directory for test data
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-backup-test-'));
|
||||
|
||||
// Create personal.mind with test data
|
||||
const personalPath = path.join(tmpDir, 'personal.mind');
|
||||
const mind = new MindDB(personalPath);
|
||||
const sessions = new SessionStore(mind);
|
||||
const frames = new FrameStore(mind);
|
||||
const s1 = sessions.create('backup-test');
|
||||
frames.createIFrame(s1.gop_id, 'Backup test memory content', 'normal');
|
||||
mind.close();
|
||||
|
||||
// Create config.json
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, 'config.json'),
|
||||
@@ -102,8 +93,6 @@ describe('Backup & Restore (PM-5)', () => {
|
||||
}),
|
||||
'utf-8',
|
||||
);
|
||||
const managedDefaultMind = new MindDB(path.join(managedDefaultDir, 'workspace.mind'));
|
||||
managedDefaultMind.close();
|
||||
|
||||
// Create marketplace.db (should be excluded from backup)
|
||||
fs.writeFileSync(path.join(tmpDir, 'marketplace.db'), 'fake marketplace data', 'utf-8');
|
||||
@@ -116,8 +105,9 @@ describe('Backup & Restore (PM-5)', () => {
|
||||
// Create a .tmp file (should be excluded)
|
||||
fs.writeFileSync(path.join(tmpDir, 'something.tmp'), 'temporary', 'utf-8');
|
||||
|
||||
// Build the local server
|
||||
// Build the local server and give it one memory
|
||||
server = await buildLocalServer({ dataDir: tmpDir });
|
||||
await server.memory.remember({ scope: PERSONAL_SCOPE, text: 'Backup test memory content' });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -153,14 +143,14 @@ describe('Backup & Restore (PM-5)', () => {
|
||||
const fileCount = parseInt(res.headers['x-waggle-backup-files'] as string, 10);
|
||||
|
||||
// We should have the following included:
|
||||
// - personal.mind
|
||||
// - waggle.db and the memory store (memory/)
|
||||
// - config.json
|
||||
// - workspaces/ws-1/sessions/session-1.jsonl
|
||||
// - .vault-key (created by VaultStore constructor)
|
||||
// - vault.json (may or may not exist)
|
||||
// - backup-metadata.json (created when first backup was made — but this is the first backup)
|
||||
// Excluded: marketplace.db, node_modules/*, something.tmp
|
||||
expect(fileCount).toBeGreaterThanOrEqual(3); // at minimum: personal.mind, config.json, session file
|
||||
expect(fileCount).toBeGreaterThanOrEqual(3); // at minimum: waggle.db, config.json, session file
|
||||
|
||||
// Verify by doing a restore preview to inspect file list
|
||||
const base64 = res.rawPayload.toString('base64');
|
||||
@@ -180,7 +170,7 @@ describe('Backup & Restore (PM-5)', () => {
|
||||
expect(allFiles.some((f: string) => f.endsWith('.tmp'))).toBe(false);
|
||||
});
|
||||
|
||||
it('backup includes .mind files, config.json, and workspace sessions', async () => {
|
||||
it('backup includes waggle.db, the memory store, config.json, and workspace sessions', async () => {
|
||||
const res = await injectWithAuth(server, {
|
||||
method: 'POST',
|
||||
url: '/api/backup',
|
||||
@@ -197,7 +187,8 @@ describe('Backup & Restore (PM-5)', () => {
|
||||
const allFiles = [...preview.existingFiles, ...preview.newFiles];
|
||||
|
||||
// Check inclusions
|
||||
expect(allFiles.some((f: string) => f === 'personal.mind')).toBe(true);
|
||||
expect(allFiles.some((f: string) => f === 'waggle.db')).toBe(true);
|
||||
expect(allFiles.some((f: string) => f.startsWith('memory/'))).toBe(true);
|
||||
expect(allFiles.some((f: string) => f === 'config.json')).toBe(true);
|
||||
expect(allFiles.some((f: string) => f.includes('session-1.jsonl'))).toBe(true);
|
||||
});
|
||||
@@ -581,13 +572,6 @@ describe('Backup & Restore (PM-5)', () => {
|
||||
const noKeyDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-nokey-test-'));
|
||||
fs.writeFileSync(path.join(noKeyDir, 'config.json'), '{"test": true}', 'utf-8');
|
||||
|
||||
// Create a separate server instance
|
||||
const personalPath = path.join(noKeyDir, 'personal.mind');
|
||||
const mind = new MindDB(personalPath);
|
||||
const sessions = new SessionStore(mind);
|
||||
sessions.create('nokey-test');
|
||||
mind.close();
|
||||
|
||||
// Remove the vault key that VaultStore auto-creates
|
||||
const vaultKeyPath = path.join(noKeyDir, '.vault-key');
|
||||
if (fs.existsSync(vaultKeyPath)) {
|
||||
|
||||
Reference in New Issue
Block a user