Files
waggle-os/packages/core/tests/waggle-db.test.ts
shumeiko.it a8250cb375 refactor: drop the one-time copy of legacy .mind data
The first start copied Waggle's tables and the memories of the commercial
edition's .mind files into waggle.db and mem0. The product is still in
development and nobody has data to bring over, so both copies, their tests
and the legacy creation-time field are gone. ADR-0007 records the change.
2026-10-28 12:35:41 +01:00

64 lines
2.4 KiB
TypeScript

import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { AwarenessLayer } from '../src/awareness.js';
import { IdentityLayer } from '../src/identity.js';
import { WaggleDB, workspaceDataScope } from '../src/waggle-db.js';
let tmpDir: string;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-db-test-'));
});
afterEach(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});
describe('WaggleDB', () => {
it('creates waggle.db in the data directory and keeps meta values', () => {
const db = WaggleDB.openInDataDir(path.join(tmpDir, 'data'));
db.setMeta('k', 'v1');
db.setMeta('k', 'v2');
expect(db.getMeta('k')).toBe('v2');
expect(db.getMeta('missing')).toBeNull();
db.close();
expect(fs.existsSync(path.join(tmpDir, 'data', 'waggle.db'))).toBe(true);
});
it('rejects an empty workspace id', () => {
expect(() => workspaceDataScope(' ')).toThrow(TypeError);
});
});
describe('profile and awareness scopes', () => {
it('keeps one profile per scope', () => {
const db = new WaggleDB(':memory:');
const personal = new IdentityLayer(db);
const ws = new IdentityLayer(db, workspaceDataScope('alpha'));
personal.create({ name: 'Ana', role: 'Founder', department: '', personality: '', capabilities: '', system_prompt: '' });
expect(ws.exists()).toBe(false);
ws.create({ name: 'Alpha team', role: '', department: '', personality: '', capabilities: '', system_prompt: '' });
expect(personal.update({ role: 'CEO' }).role).toBe('CEO');
expect(ws.get().name).toBe('Alpha team');
expect(personal.toContext()).toContain('Role: CEO');
db.close();
});
it('keeps awareness items apart and refuses cross-scope edits', () => {
const db = new WaggleDB(':memory:');
const personal = new AwarenessLayer(db);
const ws = new AwarenessLayer(db, workspaceDataScope('alpha'));
const item = ws.add('task', 'Ship the beta', 2, undefined, { status: 'open' });
personal.add('pending', 'Reply to Marko');
expect(ws.getAll().map(i => i.content)).toEqual(['Ship the beta']);
expect(personal.countOpen()).toBe(1);
expect(personal.get(item.id)).toBeUndefined();
personal.remove(item.id);
expect(ws.get(item.id)).toBeDefined();
expect(ws.updateMetadata(item.id, { result: 'done' }).metadata).toContain('"result":"done"');
db.close();
});
});