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.
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import Database from 'better-sqlite3';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { AwarenessLayer } from '../src/awareness.js';
|
||||
import { CronStore } from '../src/cron-store.js';
|
||||
import { ExecutionTraceStore } from '../src/execution-traces.js';
|
||||
import { IdentityLayer } from '../src/identity.js';
|
||||
import { WaggleDB, workspaceDataScope } from '../src/waggle-db.js';
|
||||
import { importLegacyMindData } from '../src/waggle-db-import.js';
|
||||
|
||||
let tmpDir: string;
|
||||
|
||||
@@ -65,65 +61,3 @@ describe('profile and awareness scopes', () => {
|
||||
db.close();
|
||||
});
|
||||
});
|
||||
|
||||
describe('importLegacyMindData', () => {
|
||||
function legacyMind(file: string, setup: (db: Database.Database) => void): string {
|
||||
const p = path.join(tmpDir, file);
|
||||
const db = new Database(p);
|
||||
setup(db);
|
||||
db.close();
|
||||
return p;
|
||||
}
|
||||
|
||||
it('copies app tables, the profile and awareness once, and leaves the source unchanged', () => {
|
||||
const personalPath = legacyMind('personal.mind', (db) => {
|
||||
db.exec(`
|
||||
CREATE TABLE identity (id INTEGER PRIMARY KEY CHECK (id = 1), name TEXT NOT NULL, role TEXT NOT NULL DEFAULT '',
|
||||
department TEXT NOT NULL DEFAULT '', personality TEXT NOT NULL DEFAULT '', capabilities TEXT NOT NULL DEFAULT '',
|
||||
system_prompt TEXT NOT NULL DEFAULT '', created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now')));
|
||||
INSERT INTO identity (id, name, role) VALUES (1, 'Ana', 'Founder');
|
||||
CREATE TABLE awareness (id INTEGER PRIMARY KEY AUTOINCREMENT, category TEXT NOT NULL, content TEXT NOT NULL,
|
||||
priority INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL DEFAULT (datetime('now')), expires_at TEXT);
|
||||
INSERT INTO awareness (category, content) VALUES ('task', 'Draft the plan');
|
||||
CREATE TABLE feedback_entries (id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL,
|
||||
message_index INTEGER NOT NULL, rating TEXT NOT NULL, reason TEXT, detail TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')));
|
||||
INSERT INTO feedback_entries (session_id, message_index, rating) VALUES ('s1', 2, 'up');
|
||||
`);
|
||||
// App tables created by the real stores, as the legacy personal.mind had them.
|
||||
const legacy = { getDatabase: () => db } as unknown as WaggleDB;
|
||||
new CronStore(legacy).create({ name: 'Morning briefing', cronExpr: '0 8 * * *', jobType: 'proactive' });
|
||||
new ExecutionTraceStore(legacy).start({ sessionId: 's1', input: 'hi' });
|
||||
});
|
||||
const wsPath = legacyMind('workspace.mind', (db) => {
|
||||
db.exec(`CREATE TABLE awareness (id INTEGER PRIMARY KEY AUTOINCREMENT, category TEXT NOT NULL, content TEXT NOT NULL,
|
||||
priority INTEGER NOT NULL DEFAULT 0, metadata TEXT NOT NULL DEFAULT '{}', created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
expires_at TEXT);
|
||||
INSERT INTO awareness (category, content) VALUES ('pending', 'Review the contract');`);
|
||||
});
|
||||
const before = fs.readFileSync(personalPath);
|
||||
|
||||
const db = new WaggleDB(path.join(tmpDir, 'waggle.db'));
|
||||
const sources = [
|
||||
{ path: personalPath, scope: 'personal' as const },
|
||||
{ path: wsPath, scope: workspaceDataScope('alpha') },
|
||||
{ path: path.join(tmpDir, 'missing.mind'), scope: workspaceDataScope('ghost') },
|
||||
];
|
||||
const reports = importLegacyMindData(db, sources);
|
||||
|
||||
expect(reports.map(r => r.status)).toEqual(['imported', 'imported', 'missing']);
|
||||
expect(new IdentityLayer(db).get()).toMatchObject({ name: 'Ana', role: 'Founder', scope: 'personal' });
|
||||
expect(new AwarenessLayer(db).getAll().map(i => i.content)).toEqual(['Draft the plan']);
|
||||
expect(new AwarenessLayer(db, workspaceDataScope('alpha')).getAll().map(i => i.content)).toEqual(['Review the contract']);
|
||||
expect(new CronStore(db).list().map(s => s.name)).toEqual(['Morning briefing']);
|
||||
expect(db.getDatabase().prepare('SELECT COUNT(*) AS n FROM feedback_entries').get()).toEqual({ n: 1 });
|
||||
expect(db.getDatabase().prepare('SELECT COUNT(*) AS n FROM execution_traces').get()).toEqual({ n: 1 });
|
||||
expect(fs.readFileSync(personalPath).equals(before)).toBe(true);
|
||||
|
||||
const again = importLegacyMindData(db, sources);
|
||||
expect(again.map(r => r.status)).toEqual(['already-imported', 'already-imported', 'missing']);
|
||||
expect(new CronStore(db).list()).toHaveLength(1);
|
||||
db.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user