test(core): drop the legacy memory engine from core tests (P1.5)

- install audit: build fixtures on WaggleDB, the store's real home; drop the
  substrate SCHEMA_SQL parity half and the two MindDB-only recovery cases
  for rows stranded in install_audit__mig_old.
- workspace manager: create() and ensure() no longer leave a workspace.mind;
  getMindPath tests create the legacy file themselves. Drop the
  MultiMindCache cases (reopen of a missing mind, post-resolution junction
  swap): they tested the legacy cache, not the manager.
- transformers model load: use core's own in-process reranker.
This commit is contained in:
shumeiko.it
2026-10-24 13:33:27 +02:00
parent 52ee21ddb5
commit c6a9fbf85a
4 changed files with 36 additions and 163 deletions

View File

@@ -1,30 +1,21 @@
/**
* InstallAuditStore tests.
*
* Relocated here from packages/hive-mind-core/tests/mind/ — commit 05c9ec3
* ("relocate substrate tests") moved this test to hive-mind-core, but the
* source (`install-audit.ts`) stayed in @waggle/core and imports MindDB FROM
* @waggle/hive-mind-core. hive-mind-core cannot depend back on @waggle/core
* (dependency inversion + breaks the OSS parity model), so the relocated test
* imported a non-existent `../../src/install-audit.js` and the entire suite
* silently failed at collection — masking the FIX-3 CHECK-drift regression.
* Its correct home is alongside the source, in @waggle/core.
* InstallAuditStore tests. The audit trail lives in waggle.db (ADR-0007).
*/
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 { MindDB } from '@waggle/hive-mind-core';
import { WaggleDB } from '../src/waggle-db.js';
import { InstallAuditStore, type RecordAuditInput } from '../src/install-audit.js';
describe('InstallAuditStore', () => {
let tmpDir: string;
let db: MindDB;
let db: WaggleDB;
let store: InstallAuditStore;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-audit-'));
db = new MindDB(path.join(tmpDir, 'test.mind'));
db = new WaggleDB(path.join(tmpDir, 'waggle.db'));
store = new InstallAuditStore(db);
});
@@ -56,11 +47,10 @@ describe('InstallAuditStore', () => {
it("migrates a legacy-CHECK table to accept 'uninstalled' (P5/D4)", () => {
const tmp2 = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-audit-legacy-'));
const legacyDb = new MindDB(path.join(tmp2, 'legacy.mind'));
const legacyDb = new WaggleDB(path.join(tmp2, 'waggle.db'));
const raw = legacyDb.getDatabase();
// Simulate a pre-P5 install: drop the migrated table and recreate it with
// the OLD narrower action CHECK (no 'uninstalled'), seeding one row.
raw.exec('DROP TABLE IF EXISTS install_audit');
// Simulate a pre-P5 install: create the table with the OLD narrower action
// CHECK (no 'uninstalled'), seeding one row.
raw.exec(`
CREATE TABLE install_audit (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -290,7 +280,7 @@ describe('InstallAuditStore — legacy CHECK migration', () => {
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-audit-mig-'));
dbPath = path.join(tmpDir, 'legacy.mind');
dbPath = path.join(tmpDir, 'waggle.db');
});
afterEach(() => {
@@ -313,13 +303,12 @@ describe('InstallAuditStore — legacy CHECK migration', () => {
)`;
it('rebuilds a legacy install_audit table (narrow CHECK) and preserves rows', () => {
// 1. Create the mind DB, then forcibly downgrade install_audit to the
// historical 4-value CHECK with one legacy row — simulating a real
// user .mind created before connector/marketplace existed.
// 1. Create install_audit with the historical 4-value CHECK and one legacy
// row — the shape of an audit table created before connector/marketplace
// existed.
{
const seed = new MindDB(dbPath);
const seed = new WaggleDB(dbPath);
const raw = seed.getDatabase();
raw.prepare('DROP TABLE IF EXISTS install_audit').run();
raw.prepare(OLD_DDL).run();
raw.prepare(`INSERT INTO install_audit
(capability_name, capability_type, source, risk_level, trust_source, approval_class, action, initiator, detail)
@@ -327,8 +316,8 @@ describe('InstallAuditStore — legacy CHECK migration', () => {
seed.close();
}
// 2. Reopen — runMigrations() must rebuild install_audit with the widened CHECK.
const db = new MindDB(dbPath);
// 2. Reopen — the store must rebuild install_audit with the widened CHECK.
const db = new WaggleDB(dbPath);
const store = new InstallAuditStore(db);
const legacy = store.getByCapability('legacy-skill');
@@ -347,10 +336,8 @@ describe('InstallAuditStore — legacy CHECK migration', () => {
});
// M2 (UX-Refactor Phase 4 / C15): the FIX-3-era DDL had every list widened
// EXCEPT risk_level — the exact shape real .minds created between FIX-3
// (2026-05-17) and Phase 4 are in. Only the new "'low', 'medium', 'high',
// 'critical'" sentinel triggers this rebuild ('critical' alone appears in
// approval_class, so it is NOT the key).
// EXCEPT risk_level — the exact shape of audit tables created between FIX-3
// (2026-05-17) and Phase 4.
const FIX3_ERA_DDL = `CREATE TABLE install_audit (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL DEFAULT (datetime('now')),
@@ -368,9 +355,8 @@ describe('InstallAuditStore — legacy CHECK migration', () => {
it("M2: rebuilds a FIX-3-era table (risk_level missing 'critical') and preserves rows", () => {
{
const seed = new MindDB(dbPath);
const seed = new WaggleDB(dbPath);
const raw = seed.getDatabase();
raw.prepare('DROP TABLE IF EXISTS install_audit').run();
raw.prepare(FIX3_ERA_DDL).run();
raw.prepare(`INSERT INTO install_audit
(capability_name, capability_type, source, risk_level, trust_source, approval_class, action, initiator, detail)
@@ -383,8 +369,8 @@ describe('InstallAuditStore — legacy CHECK migration', () => {
seed.close();
}
// Reopen — runMigrations() must rebuild keyed on the M2 sentinel.
const db = new MindDB(dbPath);
// Reopen — the store must rebuild the table with the widened CHECK.
const db = new WaggleDB(dbPath);
const store = new InstallAuditStore(db);
const legacy = store.getByCapability('legacy-mcp');
@@ -401,7 +387,7 @@ describe('InstallAuditStore — legacy CHECK migration', () => {
db.close();
// Idempotence: a second reopen must NOT rebuild again (rows + ids stable).
const db2 = new MindDB(dbPath);
const db2 = new WaggleDB(dbPath);
const store2 = new InstallAuditStore(db2);
const all = store2.getAll();
expect(all).toHaveLength(2);
@@ -414,66 +400,4 @@ describe('InstallAuditStore — legacy CHECK migration', () => {
})).not.toThrow();
db2.close();
});
// The rebuild now runs in ONE transaction, so a crash mid-rebuild rolls
// back — but DBs damaged by a PRE-transactional crashed rebuild exist in the
// wild with all rows stranded in install_audit__mig_old. These lock the
// recovery the FIX-3 comment always promised but never performed.
const LEGACY_ROW_INSERT = (table: string) => `INSERT INTO ${table}
(capability_name, capability_type, source, risk_level, trust_source, approval_class, action, initiator, detail)
VALUES ('stranded','mcp','marketplace','high','security-gate','blocked','blocked','system','pre-crash row')`;
it('recovers rows stranded by a crash between RENAME and recreate (install_audit missing)', () => {
{
const seed = new MindDB(dbPath);
const raw = seed.getDatabase();
raw.prepare('DROP TABLE IF EXISTS install_audit').run();
raw.prepare(FIX3_ERA_DDL).run();
raw.prepare(LEGACY_ROW_INSERT('install_audit')).run();
// Simulate the pre-transactional crash: renamed aside, then process died
// before SCHEMA_SQL recreated install_audit.
raw.prepare('ALTER TABLE install_audit RENAME TO install_audit__mig_old').run();
seed.close();
}
const db = new MindDB(dbPath);
const store = new InstallAuditStore(db);
// Rows restored AND the rebuild completed (the restored table had the
// FIX-3-era DDL, so the M2 sentinel re-triggered the rebuild)
const rows = store.getByCapability('stranded');
expect(rows).toHaveLength(1);
expect(rows[0].detail).toBe('pre-crash row');
expect(() => store.record({
capabilityName: 'post-recovery', capabilityType: 'mcp', source: 'mcp',
riskLevel: 'critical', trustSource: 'security-gate', approvalClass: 'blocked',
action: 'blocked', initiator: 'system',
})).not.toThrow();
// No stale __mig_old left to be destroyed by a future rebuild
const leftover = db.getDatabase().prepare(
"SELECT name FROM sqlite_master WHERE type='table' AND name='install_audit__mig_old'",
).get();
expect(leftover).toBeUndefined();
db.close();
});
it('recovers rows stranded by a crash between recreate and copy-back (fresh empty install_audit)', () => {
{
const seed = new MindDB(dbPath); // creates the CURRENT empty install_audit
const raw = seed.getDatabase();
raw.prepare(FIX3_ERA_DDL.replace('CREATE TABLE install_audit', 'CREATE TABLE install_audit__mig_old')).run();
raw.prepare(LEGACY_ROW_INSERT('install_audit__mig_old')).run();
seed.close();
}
const db = new MindDB(dbPath);
const store = new InstallAuditStore(db);
const rows = store.getByCapability('stranded');
expect(rows).toHaveLength(1);
expect(rows[0].detail).toBe('pre-crash row');
const leftover = db.getDatabase().prepare(
"SELECT name FROM sqlite_master WHERE type='table' AND name='install_audit__mig_old'",
).get();
expect(leftover).toBeUndefined();
db.close();
});
});