Waggle kept its own tables in the memory database. Before the memory
engine can be replaced by mem0 they need a home of their own.
- add WaggleDB (<dataDir>/waggle.db). Automations, notifications, held
actions, skill hashes, thumbs feedback, cost tracking, the profile card
and awareness items live there. Their stores take a WaggleDB, so passing
a memory database is a type error.
- the profile card and awareness items are now per scope ('personal' or
'workspace:<id>') in one table each, instead of one table per .mind file
- on the first start, copy these tables from personal.mind and every
workspace.mind (importLegacyMindData). The legacy files are only read,
each scope is copied once and a table only while its target is empty.
- copy the logger, injection scanner, external-memory ingress guard,
WorkspaceManager and the embedders from @waggle/hive-mind-core into
@waggle/core, which now re-exports its own copies
- point the server, agent orchestrator and CLI at waggle.db; update the
tests that seeded these tables in a memory database
ADR-0007 records the layout and the licensing question about the copied
files.
116 lines
3.5 KiB
TypeScript
116 lines
3.5 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
import * as os from 'node:os';
|
|
import { WaggleDB } from '../src/waggle-db.js';
|
|
import { SkillHashStore, computeSkillHash } from '../src/skill-hashes.js';
|
|
|
|
describe('SkillHashStore', () => {
|
|
let tmpDir: string;
|
|
let db: WaggleDB;
|
|
let store: SkillHashStore;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-skill-hash-'));
|
|
db = new WaggleDB(path.join(tmpDir, 'waggle.db'));
|
|
store = new SkillHashStore(db);
|
|
});
|
|
|
|
afterEach(() => {
|
|
db.close();
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('setHash + getHash round-trips correctly', () => {
|
|
const hash = computeSkillHash('# My Skill\nDo something useful');
|
|
store.setHash('my-skill', hash);
|
|
|
|
const stored = store.getHash('my-skill');
|
|
expect(stored).toBeDefined();
|
|
expect(stored!.name).toBe('my-skill');
|
|
expect(stored!.hash).toBe(hash);
|
|
expect(stored!.verified_at).toBeTruthy();
|
|
});
|
|
|
|
it('computeSkillHash produces consistent SHA-256', () => {
|
|
const content = '# Draft Memo\nHelp the user draft professional memos.';
|
|
const hash1 = computeSkillHash(content);
|
|
const hash2 = computeSkillHash(content);
|
|
|
|
expect(hash1).toBe(hash2);
|
|
// SHA-256 hex is 64 characters
|
|
expect(hash1).toHaveLength(64);
|
|
// Should be hex string
|
|
expect(hash1).toMatch(/^[0-9a-f]{64}$/);
|
|
});
|
|
|
|
it('checkAll detects changed skill', () => {
|
|
const originalContent = '# Skill v1\nOriginal content';
|
|
store.verify('changed-skill', originalContent);
|
|
|
|
const result = store.checkAll([
|
|
{ name: 'changed-skill', content: '# Skill v2\nModified content' },
|
|
]);
|
|
|
|
expect(result.changed).toEqual(['changed-skill']);
|
|
expect(result.added).toEqual([]);
|
|
expect(result.removed).toEqual([]);
|
|
});
|
|
|
|
it('checkAll detects new (added) skill', () => {
|
|
const result = store.checkAll([
|
|
{ name: 'brand-new-skill', content: '# New Skill\nFresh content' },
|
|
]);
|
|
|
|
expect(result.added).toEqual(['brand-new-skill']);
|
|
expect(result.changed).toEqual([]);
|
|
expect(result.removed).toEqual([]);
|
|
});
|
|
|
|
it('checkAll detects removed skill', () => {
|
|
store.verify('old-skill', '# Old Skill\nGone now');
|
|
|
|
const result = store.checkAll([]);
|
|
|
|
expect(result.removed).toEqual(['old-skill']);
|
|
expect(result.changed).toEqual([]);
|
|
expect(result.added).toEqual([]);
|
|
});
|
|
|
|
it('checkAll returns empty when nothing changed', () => {
|
|
const content = '# Stable Skill\nNothing changed here';
|
|
store.verify('stable-skill', content);
|
|
|
|
const result = store.checkAll([
|
|
{ name: 'stable-skill', content },
|
|
]);
|
|
|
|
expect(result.changed).toEqual([]);
|
|
expect(result.added).toEqual([]);
|
|
expect(result.removed).toEqual([]);
|
|
});
|
|
|
|
it('verify updates hash to current content', () => {
|
|
const v1 = '# Skill v1';
|
|
const v2 = '# Skill v2';
|
|
store.verify('evolving-skill', v1);
|
|
|
|
const hashBefore = store.getHash('evolving-skill')!.hash;
|
|
expect(hashBefore).toBe(computeSkillHash(v1));
|
|
|
|
store.verify('evolving-skill', v2);
|
|
|
|
const hashAfter = store.getHash('evolving-skill')!.hash;
|
|
expect(hashAfter).toBe(computeSkillHash(v2));
|
|
expect(hashAfter).not.toBe(hashBefore);
|
|
});
|
|
|
|
it('removeHash cleans up', () => {
|
|
store.verify('doomed-skill', '# Doomed');
|
|
expect(store.getHash('doomed-skill')).toBeDefined();
|
|
|
|
store.removeHash('doomed-skill');
|
|
expect(store.getHash('doomed-skill')).toBeUndefined();
|
|
});
|
|
});
|