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();
|
||||
|
||||
@@ -2,7 +2,8 @@ import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { MindDB, WaggleConfig } from '@waggle/core';
|
||||
import { WaggleConfig } from '@waggle/core';
|
||||
import { PERSONAL_SCOPE, workspaceScope, type MemoryScope } from '@waggle/memory-contract';
|
||||
import type { AgentLoopConfig, AgentResponse } from '@waggle/agent';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { PERSONA_CASES } from '../../../../tests/vision/persona-cases.js';
|
||||
@@ -104,8 +105,6 @@ describe('persona acceptance prompt budget', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-persona-budget-'));
|
||||
const mind = new MindDB(path.join(tmpDir, 'personal.mind'));
|
||||
mind.close();
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, 'profile.json'),
|
||||
JSON.stringify({ name: PERSISTED_PROFILE_SENTINEL }),
|
||||
@@ -1282,14 +1281,10 @@ describe('persona acceptance prompt budget', () => {
|
||||
const childName = 'PRIVATE_CHILD_NAME_20260808';
|
||||
const childTask = 'PRIVATE_CHILD_TASK_20260808';
|
||||
const childResult = 'PRIVATE_CHILD_RESULT_20260808';
|
||||
const personalMind = server.multiMind.personal;
|
||||
const workspaceMind = server.mindCache.getOrOpen(collaborationWorkspaceId);
|
||||
expect(workspaceMind).toBeDefined();
|
||||
const frameCount = (mind: MindDB) => (
|
||||
mind.getDatabase().prepare('SELECT COUNT(*) AS count FROM memory_frames').get() as { count: number }
|
||||
).count;
|
||||
const personalBefore = frameCount(personalMind);
|
||||
const workspaceBefore = frameCount(workspaceMind!);
|
||||
const workspaceMemory = workspaceScope(collaborationWorkspaceId);
|
||||
const memoryCount = (scope: MemoryScope) => server.memory.count({ scopes: [scope] });
|
||||
const personalBefore = await memoryCount(PERSONAL_SCOPE);
|
||||
const workspaceBefore = await memoryCount(workspaceMemory);
|
||||
const loopConfigs: AgentLoopConfig[] = [];
|
||||
let childOutput = '';
|
||||
const statusEvents: unknown[] = [];
|
||||
@@ -1359,8 +1354,8 @@ describe('persona acceptance prompt budget', () => {
|
||||
for (const denied of deniedChildTools) {
|
||||
expect(childToolNames, denied).not.toContain(denied);
|
||||
}
|
||||
expect(frameCount(personalMind)).toBe(personalBefore);
|
||||
expect(frameCount(workspaceMind!)).toBe(workspaceBefore);
|
||||
expect(await memoryCount(PERSONAL_SCOPE)).toBe(personalBefore);
|
||||
expect(await memoryCount(workspaceMemory)).toBe(workspaceBefore);
|
||||
const registry = fs.readFileSync(path.join(tmpDir, 'agent-runs.json'), 'utf8');
|
||||
for (const privateContent of [parentTask, childName, childTask, childResult]) {
|
||||
expect(registry, privateContent).not.toContain(privateContent);
|
||||
@@ -1457,14 +1452,10 @@ describe('persona acceptance prompt budget', () => {
|
||||
const stepRole = 'PRIVATE_WORKFLOW_STEP_ROLE_20260808';
|
||||
const stepTask = 'PRIVATE_WORKFLOW_STEP_TASK_20260808';
|
||||
const workerResult = 'PRIVATE_WORKFLOW_WORKER_RESULT_20260808';
|
||||
const personalMind = server.multiMind.personal;
|
||||
const workspaceMind = server.mindCache.getOrOpen(collaborationWorkspaceId);
|
||||
expect(workspaceMind).toBeDefined();
|
||||
const frameCount = (mind: MindDB) => (
|
||||
mind.getDatabase().prepare('SELECT COUNT(*) AS count FROM memory_frames').get() as { count: number }
|
||||
).count;
|
||||
const personalBefore = frameCount(personalMind);
|
||||
const workspaceBefore = frameCount(workspaceMind!);
|
||||
const workspaceMemory = workspaceScope(collaborationWorkspaceId);
|
||||
const memoryCount = (scope: MemoryScope) => server.memory.count({ scopes: [scope] });
|
||||
const personalBefore = await memoryCount(PERSONAL_SCOPE);
|
||||
const workspaceBefore = await memoryCount(workspaceMemory);
|
||||
const loopConfigs: AgentLoopConfig[] = [];
|
||||
let workflowOutput = '';
|
||||
|
||||
@@ -1530,8 +1521,8 @@ describe('persona acceptance prompt budget', () => {
|
||||
expect(workerToolNames).not.toContain('search_memory');
|
||||
expect(workerToolNames).not.toContain('save_memory');
|
||||
expect(workerToolNames).not.toContain('agent_insights');
|
||||
expect(frameCount(personalMind)).toBe(personalBefore);
|
||||
expect(frameCount(workspaceMind!)).toBe(workspaceBefore);
|
||||
expect(await memoryCount(PERSONAL_SCOPE)).toBe(personalBefore);
|
||||
expect(await memoryCount(workspaceMemory)).toBe(workspaceBefore);
|
||||
const registry = fs.readFileSync(path.join(tmpDir, 'agent-runs.json'), 'utf8');
|
||||
for (const privateContent of [
|
||||
parentTask, workflowName, workflowTask, stepName, stepRole, stepTask, workerResult,
|
||||
|
||||
Reference in New Issue
Block a user