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:
shumeiko.it
2026-10-24 16:31:25 +02:00
parent c6a9fbf85a
commit f1cde9a32f
2 changed files with 19 additions and 37 deletions

View File

@@ -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,