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:
|
* Tests:
|
||||||
* 1. POST /api/backup returns an octet-stream file
|
* 1. POST /api/backup returns an octet-stream file
|
||||||
* 2. Backup excludes marketplace.db and node_modules
|
* 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
|
* 4. POST /api/restore with preview mode
|
||||||
* 5. POST /api/restore applies restore successfully
|
* 5. POST /api/restore applies restore successfully
|
||||||
* 6. Restore rejects corrupted/invalid files
|
* 6. Restore rejects corrupted/invalid files
|
||||||
@@ -20,7 +20,7 @@ import path from 'node:path';
|
|||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import * as crypto from 'node:crypto';
|
import * as crypto from 'node:crypto';
|
||||||
import * as zlib from 'node:zlib';
|
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 { buildLocalServer } from '../src/local/index.js';
|
||||||
import {
|
import {
|
||||||
isChatHistoryRestoreBusy,
|
isChatHistoryRestoreBusy,
|
||||||
@@ -67,15 +67,6 @@ describe('Backup & Restore (PM-5)', () => {
|
|||||||
// Create a temp directory for test data
|
// Create a temp directory for test data
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-backup-test-'));
|
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
|
// Create config.json
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(tmpDir, 'config.json'),
|
path.join(tmpDir, 'config.json'),
|
||||||
@@ -102,8 +93,6 @@ describe('Backup & Restore (PM-5)', () => {
|
|||||||
}),
|
}),
|
||||||
'utf-8',
|
'utf-8',
|
||||||
);
|
);
|
||||||
const managedDefaultMind = new MindDB(path.join(managedDefaultDir, 'workspace.mind'));
|
|
||||||
managedDefaultMind.close();
|
|
||||||
|
|
||||||
// Create marketplace.db (should be excluded from backup)
|
// Create marketplace.db (should be excluded from backup)
|
||||||
fs.writeFileSync(path.join(tmpDir, 'marketplace.db'), 'fake marketplace data', 'utf-8');
|
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)
|
// Create a .tmp file (should be excluded)
|
||||||
fs.writeFileSync(path.join(tmpDir, 'something.tmp'), 'temporary', 'utf-8');
|
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 });
|
server = await buildLocalServer({ dataDir: tmpDir });
|
||||||
|
await server.memory.remember({ scope: PERSONAL_SCOPE, text: 'Backup test memory content' });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
@@ -153,14 +143,14 @@ describe('Backup & Restore (PM-5)', () => {
|
|||||||
const fileCount = parseInt(res.headers['x-waggle-backup-files'] as string, 10);
|
const fileCount = parseInt(res.headers['x-waggle-backup-files'] as string, 10);
|
||||||
|
|
||||||
// We should have the following included:
|
// We should have the following included:
|
||||||
// - personal.mind
|
// - waggle.db and the memory store (memory/)
|
||||||
// - config.json
|
// - config.json
|
||||||
// - workspaces/ws-1/sessions/session-1.jsonl
|
// - workspaces/ws-1/sessions/session-1.jsonl
|
||||||
// - .vault-key (created by VaultStore constructor)
|
// - .vault-key (created by VaultStore constructor)
|
||||||
// - vault.json (may or may not exist)
|
// - vault.json (may or may not exist)
|
||||||
// - backup-metadata.json (created when first backup was made — but this is the first backup)
|
// - backup-metadata.json (created when first backup was made — but this is the first backup)
|
||||||
// Excluded: marketplace.db, node_modules/*, something.tmp
|
// 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
|
// Verify by doing a restore preview to inspect file list
|
||||||
const base64 = res.rawPayload.toString('base64');
|
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);
|
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, {
|
const res = await injectWithAuth(server, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/api/backup',
|
url: '/api/backup',
|
||||||
@@ -197,7 +187,8 @@ describe('Backup & Restore (PM-5)', () => {
|
|||||||
const allFiles = [...preview.existingFiles, ...preview.newFiles];
|
const allFiles = [...preview.existingFiles, ...preview.newFiles];
|
||||||
|
|
||||||
// Check inclusions
|
// 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 === 'config.json')).toBe(true);
|
||||||
expect(allFiles.some((f: string) => f.includes('session-1.jsonl'))).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-'));
|
const noKeyDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-nokey-test-'));
|
||||||
fs.writeFileSync(path.join(noKeyDir, 'config.json'), '{"test": true}', 'utf-8');
|
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
|
// Remove the vault key that VaultStore auto-creates
|
||||||
const vaultKeyPath = path.join(noKeyDir, '.vault-key');
|
const vaultKeyPath = path.join(noKeyDir, '.vault-key');
|
||||||
if (fs.existsSync(vaultKeyPath)) {
|
if (fs.existsSync(vaultKeyPath)) {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { MindDB, SessionStore, FrameStore } from '@waggle/core';
|
|
||||||
import { buildLocalServer } from '../src/local/index.js';
|
import { buildLocalServer } from '../src/local/index.js';
|
||||||
import type { FastifyInstance } from 'fastify';
|
import type { FastifyInstance } from 'fastify';
|
||||||
import { injectWithAuth, resetRateLimiter } from './test-utils.js';
|
import { injectWithAuth, resetRateLimiter } from './test-utils.js';
|
||||||
@@ -26,15 +25,6 @@ describe('Backup Streaming (CQ-010)', () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-backup-stream-test-'));
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-backup-stream-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('stream-test');
|
|
||||||
frames.createIFrame(s1.gop_id, 'Streaming backup test memory', 'normal');
|
|
||||||
mind.close();
|
|
||||||
|
|
||||||
// Create config.json
|
// Create config.json
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(tmpDir, 'config.json'),
|
path.join(tmpDir, 'config.json'),
|
||||||
@@ -73,7 +63,7 @@ describe('Backup Streaming (CQ-010)', () => {
|
|||||||
describe('enumerateFiles', () => {
|
describe('enumerateFiles', () => {
|
||||||
it('collects file metadata without loading content', () => {
|
it('collects file metadata without loading content', () => {
|
||||||
const metas = enumerateFiles(tmpDir);
|
const metas = enumerateFiles(tmpDir);
|
||||||
expect(metas.length).toBeGreaterThanOrEqual(28); // 25 batch files + mind + config + session + vault files
|
expect(metas.length).toBeGreaterThanOrEqual(28); // 25 batch files + waggle.db + config + session + vault files
|
||||||
|
|
||||||
// Every entry has path, fullPath, sizeBytes but no content property
|
// Every entry has path, fullPath, sizeBytes but no content property
|
||||||
for (const meta of metas) {
|
for (const meta of metas) {
|
||||||
@@ -103,13 +93,6 @@ describe('Backup Streaming (CQ-010)', () => {
|
|||||||
// a real test we just verify the 413 code path exists in the route)
|
// a real test we just verify the 413 code path exists in the route)
|
||||||
const hugeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-huge-test-'));
|
const hugeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-huge-test-'));
|
||||||
|
|
||||||
// Create personal.mind (required)
|
|
||||||
const personalPath = path.join(hugeDir, 'personal.mind');
|
|
||||||
const mind = new MindDB(personalPath);
|
|
||||||
const sessions = new SessionStore(mind);
|
|
||||||
sessions.create('huge-test');
|
|
||||||
mind.close();
|
|
||||||
|
|
||||||
// Create a file just big enough to trigger the cap check
|
// Create a file just big enough to trigger the cap check
|
||||||
// We won't actually create 500MB — instead we create a small server and
|
// We won't actually create 500MB — instead we create a small server and
|
||||||
// verify the route handler checks size properly via the header
|
// verify the route handler checks size properly via the header
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
* 3. SPA fallback (index.html for unknown paths)
|
* 3. SPA fallback (index.html for unknown paths)
|
||||||
* 4. WebSocket endpoint exists
|
* 4. WebSocket endpoint exists
|
||||||
* 5. SSE notification stream works
|
* 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
|
* 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 fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import os from 'node:os';
|
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 { getConnectorCredential, setConnectorCredential } from '@waggle/agent';
|
||||||
|
import { PERSONAL_SCOPE } from '@waggle/memory-contract';
|
||||||
import { buildLocalServer } from '../src/local/index.js';
|
import { buildLocalServer } from '../src/local/index.js';
|
||||||
import type { FastifyInstance } from 'fastify';
|
import type { FastifyInstance } from 'fastify';
|
||||||
import { injectWithAuth } from './test-utils.js';
|
import { injectWithAuth } from './test-utils.js';
|
||||||
@@ -45,15 +46,6 @@ describe('Cross-Platform Verification', () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
tmpDir = createTmpDir('xplat');
|
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
|
// Ensure no Tauri globals exist
|
||||||
// (globalThis.__TAURI__ should be undefined in Node.js)
|
// (globalThis.__TAURI__ should be undefined in Node.js)
|
||||||
expect((globalThis as { __TAURI__?: unknown }).__TAURI__).toBeUndefined();
|
expect((globalThis as { __TAURI__?: unknown }).__TAURI__).toBeUndefined();
|
||||||
@@ -215,121 +207,70 @@ describe('Cross-Platform Verification', () => {
|
|||||||
expect(typeof server.eventBus.emit).toBe('function');
|
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 tmpDir: string;
|
||||||
let mind: MindDB;
|
let db: WaggleDB;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
tmpDir = createTmpDir('mind-xplat');
|
tmpDir = createTmpDir('waggle-db-xplat');
|
||||||
const dbPath = path.join(tmpDir, 'test.mind');
|
db = WaggleDB.openInDataDir(tmpDir);
|
||||||
mind = new MindDB(dbPath);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mind.close();
|
db.close();
|
||||||
cleanupDir(tmpDir);
|
cleanupDir(tmpDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates a .mind file on any OS', () => {
|
it('creates waggle.db on any OS', () => {
|
||||||
const dbPath = path.join(tmpDir, 'test.mind');
|
expect(fs.existsSync(path.join(tmpDir, 'waggle.db'))).toBe(true);
|
||||||
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('WAL mode is enabled', () => {
|
it('WAL mode is enabled', () => {
|
||||||
const raw = mind.getDatabase();
|
const raw = db.getDatabase();
|
||||||
const mode = raw.pragma('journal_mode', { simple: true });
|
const mode = raw.pragma('journal_mode', { simple: true });
|
||||||
expect(mode).toBe('wal');
|
expect(mode).toBe('wal');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('foreign keys are enforced', () => {
|
it('foreign keys are enforced', () => {
|
||||||
const raw = mind.getDatabase();
|
const raw = db.getDatabase();
|
||||||
const fk = raw.pragma('foreign_keys', { simple: true });
|
const fk = raw.pragma('foreign_keys', { simple: true });
|
||||||
expect(fk).toBe(1);
|
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 ──────────────────────────────────
|
// ── 7. Vault Encryption Cross-Platform ──────────────────────────────────
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ describe('startService honors WAGGLE_DATA_DIR (D11 integration)', () => {
|
|||||||
server = result.server;
|
server = result.server;
|
||||||
|
|
||||||
// The env-pointed dir got the install, ~/.waggle got nothing new from us.
|
// The env-pointed dir got the install, ~/.waggle got nothing new from us.
|
||||||
expect(fs.existsSync(path.join(envDir, 'personal.mind'))).toBe(true);
|
expect(fs.existsSync(path.join(envDir, 'waggle.db'))).toBe(true);
|
||||||
expect(server.localConfig.dataDir).toBe(envDir);
|
expect(server.localConfig.dataDir).toBe(envDir);
|
||||||
|
|
||||||
// The ratified D11 deliverable is the LOG LINE itself — pin it (review
|
// The ratified D11 deliverable is the LOG LINE itself — pin it (review
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import Fastify from 'fastify';
|
|||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import * as os from 'node:os';
|
import * as os from 'node:os';
|
||||||
import { MindDB, CronStore } from '@waggle/core';
|
import { WaggleDB, CronStore } from '@waggle/core';
|
||||||
import { approvalRoutes } from '../../src/local/routes/approval.js';
|
import { approvalRoutes } from '../../src/local/routes/approval.js';
|
||||||
import { securityMiddleware } from '../../src/local/security-middleware.js';
|
import { securityMiddleware } from '../../src/local/security-middleware.js';
|
||||||
import {
|
import {
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
|
|
||||||
describe('approval routes — held actions (L2 union)', () => {
|
describe('approval routes — held actions (L2 union)', () => {
|
||||||
let tmpDir: string;
|
let tmpDir: string;
|
||||||
let db: MindDB;
|
let db: WaggleDB;
|
||||||
let store: CronStore;
|
let store: CronStore;
|
||||||
let server: ReturnType<typeof Fastify>;
|
let server: ReturnType<typeof Fastify>;
|
||||||
let pendingApprovals: Map<string, { toolName: string; input: Record<string, unknown>; timestamp: number; riskLevel?: 'low' | 'medium' | 'high' | 'critical'; resolve: (v: boolean) => void }>;
|
let pendingApprovals: Map<string, { toolName: string; input: Record<string, unknown>; timestamp: number; riskLevel?: 'low' | 'medium' | 'high' | 'critical'; resolve: (v: boolean) => void }>;
|
||||||
@@ -25,7 +25,7 @@ describe('approval routes — held actions (L2 union)', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-appr-'));
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-appr-'));
|
||||||
db = new MindDB(path.join(tmpDir, 'test.mind'));
|
db = new WaggleDB(path.join(tmpDir, 'waggle.db'));
|
||||||
store = new CronStore(db);
|
store = new CronStore(db);
|
||||||
pendingApprovals = new Map();
|
pendingApprovals = new Map();
|
||||||
execSpy = vi.fn(async () => 'email sent');
|
execSpy = vi.fn(async () => 'email sent');
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import Fastify from 'fastify';
|
import Fastify from 'fastify';
|
||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from 'node:events';
|
||||||
import { MindDB, CronStore, type CronSchedule } from '@waggle/core';
|
import { WaggleDB, CronStore, type CronSchedule } from '@waggle/core';
|
||||||
import { LocalScheduler, makeRecordExecutionCallback } from '../../src/local/cron.js';
|
import { LocalScheduler, makeRecordExecutionCallback } from '../../src/local/cron.js';
|
||||||
import { cronRoutes } from '../../src/local/routes/cron.js';
|
import { cronRoutes } from '../../src/local/routes/cron.js';
|
||||||
import { notificationRoutes } from '../../src/local/routes/notifications.js';
|
import { notificationRoutes } from '../../src/local/routes/notifications.js';
|
||||||
@@ -32,7 +32,7 @@ import { automationRoutes } from '../../src/local/routes/automations.js';
|
|||||||
import { securityMiddleware } from '../../src/local/security-middleware.js';
|
import { securityMiddleware } from '../../src/local/security-middleware.js';
|
||||||
|
|
||||||
describe('Automations alias routes (Phase 3)', () => {
|
describe('Automations alias routes (Phase 3)', () => {
|
||||||
let db: MindDB;
|
let db: WaggleDB;
|
||||||
let cronStore: CronStore;
|
let cronStore: CronStore;
|
||||||
let scheduler: LocalScheduler;
|
let scheduler: LocalScheduler;
|
||||||
let executed: CronSchedule[];
|
let executed: CronSchedule[];
|
||||||
@@ -42,7 +42,7 @@ describe('Automations alias routes (Phase 3)', () => {
|
|||||||
let literalGlobalIsViewer: boolean;
|
let literalGlobalIsViewer: boolean;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = new MindDB(':memory:');
|
db = new WaggleDB(':memory:');
|
||||||
cronStore = new CronStore(db);
|
cronStore = new CronStore(db);
|
||||||
executed = [];
|
executed = [];
|
||||||
failNext = false;
|
failNext = false;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* connect-audit, and the GET /api/connectors lastSyncAt enrichment.
|
* connect-audit, and the GET /api/connectors lastSyncAt enrichment.
|
||||||
*
|
*
|
||||||
* Real VaultStore in a tmpdir + real ConnectorRegistry with a BaseConnector
|
* Real VaultStore in a tmpdir + real ConnectorRegistry with a BaseConnector
|
||||||
* fake + real InstallAuditStore over MindDB(':memory:'), real route plugin,
|
* fake + real InstallAuditStore over WaggleDB(':memory:'), real route plugin,
|
||||||
* server.inject — same harness style as the Phase-3 suites.
|
* server.inject — same harness style as the Phase-3 suites.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ import Fastify from 'fastify';
|
|||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import * as os from 'node:os';
|
import * as os from 'node:os';
|
||||||
import { MindDB, InstallAuditStore, VaultStore, type SecretStore } from '@waggle/core';
|
import { WaggleDB, InstallAuditStore, VaultStore, type SecretStore } from '@waggle/core';
|
||||||
import {
|
import {
|
||||||
ConnectorRegistry,
|
ConnectorRegistry,
|
||||||
BaseConnector,
|
BaseConnector,
|
||||||
@@ -68,7 +68,7 @@ describe('Connector routes — Phase 4 extensions', () => {
|
|||||||
let vault: VaultStore;
|
let vault: VaultStore;
|
||||||
let registry: ConnectorRegistry;
|
let registry: ConnectorRegistry;
|
||||||
let connector: TestConnector;
|
let connector: TestConnector;
|
||||||
let db: MindDB;
|
let db: WaggleDB;
|
||||||
let auditStore: InstallAuditStore;
|
let auditStore: InstallAuditStore;
|
||||||
let server: ReturnType<typeof Fastify>;
|
let server: ReturnType<typeof Fastify>;
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ describe('Connector routes — Phase 4 extensions', () => {
|
|||||||
connector = new TestConnector();
|
connector = new TestConnector();
|
||||||
registry = new ConnectorRegistry(vault);
|
registry = new ConnectorRegistry(vault);
|
||||||
registry.register(connector);
|
registry.register(connector);
|
||||||
db = new MindDB(':memory:');
|
db = new WaggleDB(':memory:');
|
||||||
auditStore = new InstallAuditStore(db);
|
auditStore = new InstallAuditStore(db);
|
||||||
|
|
||||||
server = Fastify({ logger: false });
|
server = Fastify({ logger: false });
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||||
import Fastify from 'fastify';
|
import Fastify from 'fastify';
|
||||||
import { MindDB, InstallAuditStore, type RecordAuditInput } from '@waggle/core';
|
import { WaggleDB, InstallAuditStore, type RecordAuditInput } from '@waggle/core';
|
||||||
import { extendRoutes } from '../../src/local/routes/extend.js';
|
import { extendRoutes } from '../../src/local/routes/extend.js';
|
||||||
import { marketplaceRoutes } from '../../src/local/routes/marketplace.js';
|
import { marketplaceRoutes } from '../../src/local/routes/marketplace.js';
|
||||||
|
|
||||||
describe('Extend routes (Phase 4)', () => {
|
describe('Extend routes (Phase 4)', () => {
|
||||||
let db: MindDB;
|
let db: WaggleDB;
|
||||||
let auditStore: InstallAuditStore;
|
let auditStore: InstallAuditStore;
|
||||||
let server: ReturnType<typeof Fastify>;
|
let server: ReturnType<typeof Fastify>;
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ describe('Extend routes (Phase 4)', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = new MindDB(':memory:');
|
db = new WaggleDB(':memory:');
|
||||||
auditStore = new InstallAuditStore(db);
|
auditStore = new InstallAuditStore(db);
|
||||||
|
|
||||||
server = Fastify({ logger: false });
|
server = Fastify({ logger: false });
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* MCP Hub REST API tests (UX-Refactor Phase 4, S08/S17).
|
* MCP Hub REST API tests (UX-Refactor Phase 4, S08/S17).
|
||||||
*
|
*
|
||||||
* Harness mirrors the Phase-3 automations/agents style: bare Fastify + real
|
* Harness mirrors the Phase-3 automations/agents style: bare Fastify + real
|
||||||
* stores (MindDB ':memory:' InstallAuditStore, real McpRuntime with the same
|
* stores (WaggleDB ':memory:' InstallAuditStore, real McpRuntime with the same
|
||||||
* DI'd PassThrough mock-spawn the agent runtime tests use, real tmp-dir
|
* DI'd PassThrough mock-spawn the agent runtime tests use, real tmp-dir
|
||||||
* .mcp.json store) + the REAL route plugins, exercised via server.inject.
|
* .mcp.json store) + the REAL route plugins, exercised via server.inject.
|
||||||
*
|
*
|
||||||
@@ -19,7 +19,7 @@ import * as path from 'node:path';
|
|||||||
import * as os from 'node:os';
|
import * as os from 'node:os';
|
||||||
import { PassThrough } from 'node:stream';
|
import { PassThrough } from 'node:stream';
|
||||||
import Database from 'better-sqlite3';
|
import Database from 'better-sqlite3';
|
||||||
import { MindDB } from '@waggle/core';
|
import { WaggleDB } from '@waggle/core';
|
||||||
import { InstallAuditStore } from '@waggle/core';
|
import { InstallAuditStore } from '@waggle/core';
|
||||||
import { MCP_CATALOG } from '@waggle/shared';
|
import { MCP_CATALOG } from '@waggle/shared';
|
||||||
import { SecurityGate } from '@waggle/marketplace';
|
import { SecurityGate } from '@waggle/marketplace';
|
||||||
@@ -200,7 +200,7 @@ function createFakeMarketplace() {
|
|||||||
|
|
||||||
describe('MCP Hub routes (Phase 4)', () => {
|
describe('MCP Hub routes (Phase 4)', () => {
|
||||||
let tmpDir: string;
|
let tmpDir: string;
|
||||||
let db: MindDB;
|
let db: WaggleDB;
|
||||||
let auditStore: InstallAuditStore;
|
let auditStore: InstallAuditStore;
|
||||||
let runtime: McpRuntime;
|
let runtime: McpRuntime;
|
||||||
let processSettlementConfirmed: boolean;
|
let processSettlementConfirmed: boolean;
|
||||||
@@ -236,7 +236,7 @@ describe('MCP Hub routes (Phase 4)', () => {
|
|||||||
childProcess.execFileSync.mockReset();
|
childProcess.execFileSync.mockReset();
|
||||||
mcpConfigFailure.remove = null;
|
mcpConfigFailure.remove = null;
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-mcps-'));
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-mcps-'));
|
||||||
db = new MindDB(':memory:');
|
db = new WaggleDB(':memory:');
|
||||||
auditStore = new InstallAuditStore(db);
|
auditStore = new InstallAuditStore(db);
|
||||||
processSettlementConfirmed = true;
|
processSettlementConfirmed = true;
|
||||||
runtime = new McpRuntime({
|
runtime = new McpRuntime({
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Validates that:
|
* Validates that:
|
||||||
* 1. InstallAuditStore is instantiated and wired at runtime
|
* 1. InstallAuditStore is instantiated and wired at runtime
|
||||||
* 2. Install operations record audit entries in the .mind DB
|
* 2. Install operations record audit entries in waggle.db
|
||||||
* 3. Existing non-trust approvals remain backward-compatible
|
* 3. Existing non-trust approvals remain backward-compatible
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -11,8 +11,6 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import Database from 'better-sqlite3';
|
|
||||||
import { MindDB } from '@waggle/core';
|
|
||||||
import { buildLocalServer } from '../../src/local/index.js';
|
import { buildLocalServer } from '../../src/local/index.js';
|
||||||
import type { FastifyInstance } from 'fastify';
|
import type { FastifyInstance } from 'fastify';
|
||||||
import { injectWithAuth } from '../test-utils.js';
|
import { injectWithAuth } from '../test-utils.js';
|
||||||
@@ -24,11 +22,6 @@ describe('Trust Model Runtime Wiring', () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-trust-wire-'));
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-trust-wire-'));
|
||||||
|
|
||||||
// Create personal.mind
|
|
||||||
const personalPath = path.join(tmpDir, 'personal.mind');
|
|
||||||
const mind = new MindDB(personalPath);
|
|
||||||
mind.close();
|
|
||||||
|
|
||||||
// Create skills dir with marker to prevent auto-install of starter skills
|
// Create skills dir with marker to prevent auto-install of starter skills
|
||||||
const skillsDir = path.join(tmpDir, 'skills');
|
const skillsDir = path.join(tmpDir, 'skills');
|
||||||
fs.mkdirSync(skillsDir, { recursive: true });
|
fs.mkdirSync(skillsDir, { recursive: true });
|
||||||
@@ -44,12 +37,9 @@ describe('Trust Model Runtime Wiring', () => {
|
|||||||
|
|
||||||
describe('Audit store wiring', () => {
|
describe('Audit store wiring', () => {
|
||||||
it('install_audit table exists after server startup', () => {
|
it('install_audit table exists after server startup', () => {
|
||||||
const personalPath = path.join(tmpDir, 'personal.mind');
|
const table = server.waggleDb.getDatabase().prepare(
|
||||||
const db = new Database(personalPath);
|
|
||||||
const table = db.prepare(
|
|
||||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='install_audit'",
|
"SELECT name FROM sqlite_master WHERE type='table' AND name='install_audit'",
|
||||||
).get() as { name: string } | undefined;
|
).get() as { name: string } | undefined;
|
||||||
db.close();
|
|
||||||
expect(table).toBeDefined();
|
expect(table).toBeDefined();
|
||||||
expect(table!.name).toBe('install_audit');
|
expect(table!.name).toBe('install_audit');
|
||||||
});
|
});
|
||||||
@@ -98,10 +88,7 @@ describe('Trust Model Runtime Wiring', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('duplicate install does not create new audit entries', async () => {
|
it('duplicate install does not create new audit entries', async () => {
|
||||||
const personalPath = path.join(tmpDir, 'personal.mind');
|
const before = server.auditStore.getAll().length;
|
||||||
const db1 = new Database(personalPath);
|
|
||||||
const before = (db1.prepare("SELECT count(*) as c FROM install_audit").get() as { c: number }).c;
|
|
||||||
db1.close();
|
|
||||||
|
|
||||||
// Try to install already-installed skill
|
// Try to install already-installed skill
|
||||||
const res = await injectWithAuth(server, {
|
const res = await injectWithAuth(server, {
|
||||||
@@ -110,9 +97,7 @@ describe('Trust Model Runtime Wiring', () => {
|
|||||||
});
|
});
|
||||||
expect(res.statusCode).toBe(409);
|
expect(res.statusCode).toBe(409);
|
||||||
|
|
||||||
const db2 = new Database(personalPath);
|
const after = server.auditStore.getAll().length;
|
||||||
const after = (db2.prepare("SELECT count(*) as c FROM install_audit").get() as { c: number }).c;
|
|
||||||
db2.close();
|
|
||||||
|
|
||||||
// Server route handles duplicate before reaching skill-tools,
|
// Server route handles duplicate before reaching skill-tools,
|
||||||
// so no new audit entries should be created via the API route
|
// so no new audit entries should be created via the API route
|
||||||
|
|||||||
Reference in New Issue
Block a user