test(server): count memories through the contract instead of mind frames (P1.5)
The persona memory-denial and cron Loop tests counted rows in the legacy personal and workspace minds, which nothing writes any more. Count server.memory per scope (and origin 'loop' for the truncated Loop report) instead, and stop seeding a personal.mind the server no longer opens.
This commit is contained in:
@@ -12,7 +12,7 @@ import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach, vi }
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import { MindDB } from '@waggle/core';
|
||||
import { workspaceScope } from '@waggle/memory-contract';
|
||||
import { buildLocalServer } from '../../src/local/index.js';
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { injectWithAuth } from '../test-utils.js';
|
||||
@@ -36,8 +36,6 @@ describe('cron ai_task executor (#17)', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-ai-task-'));
|
||||
const mind = new MindDB(path.join(tmpDir, 'personal.mind'));
|
||||
mind.close();
|
||||
server = await buildLocalServer({ dataDir: tmpDir });
|
||||
|
||||
const res = await injectWithAuth(server, {
|
||||
@@ -208,11 +206,7 @@ describe('cron ai_task executor (#17)', () => {
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledOnce();
|
||||
expect(server.scheduler.getFailCount(schedule.id)).toBe(1);
|
||||
const mind = server.agentState.getWorkspaceMindDb(wsId);
|
||||
const persisted = mind?.getDatabase().prepare(
|
||||
`SELECT COUNT(*) AS count FROM memory_frames WHERE content LIKE '[Loop:%'`
|
||||
).get() as { count: number } | undefined;
|
||||
expect(persisted?.count ?? 0).toBe(0);
|
||||
expect(await server.memory.count({ scopes: [workspaceScope(wsId)], origin: 'loop' })).toBe(0);
|
||||
});
|
||||
|
||||
it('automatic tick refuses a workspace Loop after the role is downgraded to viewer', async () => {
|
||||
@@ -229,11 +223,8 @@ describe('cron ai_task executor (#17)', () => {
|
||||
server.waggleDb.getDatabase().prepare(
|
||||
"UPDATE cron_schedules SET next_run_at = datetime('now', '-1 minute') WHERE id = ?",
|
||||
).run(schedule.id);
|
||||
const workspaceMind = server.agentState.getWorkspaceMindDb(wsId)!;
|
||||
const countFrames = () => (workspaceMind.getDatabase().prepare(
|
||||
'SELECT COUNT(*) AS count FROM memory_frames',
|
||||
).get() as { count: number }).count;
|
||||
const framesBefore = countFrames();
|
||||
const countMemories = () => server.memory.count({ scopes: [workspaceScope(wsId)] });
|
||||
const memoriesBefore = await countMemories();
|
||||
server.workspaceManager.update(wsId, { teamId: 'team-1', teamRole: 'viewer' });
|
||||
const leaseSpy = vi.spyOn(server.cronStore, 'acquireRunLease');
|
||||
const historyBefore = server.cronStore.getExecutionHistory(schedule.id).length;
|
||||
@@ -243,7 +234,7 @@ describe('cron ai_task executor (#17)', () => {
|
||||
|
||||
expect(executed).toBe(0);
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
expect(countFrames()).toBe(framesBefore);
|
||||
expect(await countMemories()).toBe(memoriesBefore);
|
||||
expect(leaseSpy).not.toHaveBeenCalled();
|
||||
expect(server.cronStore.getExecutionHistory(schedule.id)).toHaveLength(historyBefore);
|
||||
expect(server.cronStore.getById(schedule.id)?.last_run_at).toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user