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 fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { MindDB } from '@waggle/core';
|
import { workspaceScope } from '@waggle/memory-contract';
|
||||||
import { buildLocalServer } from '../../src/local/index.js';
|
import { buildLocalServer } from '../../src/local/index.js';
|
||||||
import type { FastifyInstance } from 'fastify';
|
import type { FastifyInstance } from 'fastify';
|
||||||
import { injectWithAuth } from '../test-utils.js';
|
import { injectWithAuth } from '../test-utils.js';
|
||||||
@@ -36,8 +36,6 @@ describe('cron ai_task executor (#17)', () => {
|
|||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-ai-task-'));
|
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 });
|
server = await buildLocalServer({ dataDir: tmpDir });
|
||||||
|
|
||||||
const res = await injectWithAuth(server, {
|
const res = await injectWithAuth(server, {
|
||||||
@@ -208,11 +206,7 @@ describe('cron ai_task executor (#17)', () => {
|
|||||||
});
|
});
|
||||||
expect(fetchMock).toHaveBeenCalledOnce();
|
expect(fetchMock).toHaveBeenCalledOnce();
|
||||||
expect(server.scheduler.getFailCount(schedule.id)).toBe(1);
|
expect(server.scheduler.getFailCount(schedule.id)).toBe(1);
|
||||||
const mind = server.agentState.getWorkspaceMindDb(wsId);
|
expect(await server.memory.count({ scopes: [workspaceScope(wsId)], origin: 'loop' })).toBe(0);
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('automatic tick refuses a workspace Loop after the role is downgraded to viewer', async () => {
|
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(
|
server.waggleDb.getDatabase().prepare(
|
||||||
"UPDATE cron_schedules SET next_run_at = datetime('now', '-1 minute') WHERE id = ?",
|
"UPDATE cron_schedules SET next_run_at = datetime('now', '-1 minute') WHERE id = ?",
|
||||||
).run(schedule.id);
|
).run(schedule.id);
|
||||||
const workspaceMind = server.agentState.getWorkspaceMindDb(wsId)!;
|
const countMemories = () => server.memory.count({ scopes: [workspaceScope(wsId)] });
|
||||||
const countFrames = () => (workspaceMind.getDatabase().prepare(
|
const memoriesBefore = await countMemories();
|
||||||
'SELECT COUNT(*) AS count FROM memory_frames',
|
|
||||||
).get() as { count: number }).count;
|
|
||||||
const framesBefore = countFrames();
|
|
||||||
server.workspaceManager.update(wsId, { teamId: 'team-1', teamRole: 'viewer' });
|
server.workspaceManager.update(wsId, { teamId: 'team-1', teamRole: 'viewer' });
|
||||||
const leaseSpy = vi.spyOn(server.cronStore, 'acquireRunLease');
|
const leaseSpy = vi.spyOn(server.cronStore, 'acquireRunLease');
|
||||||
const historyBefore = server.cronStore.getExecutionHistory(schedule.id).length;
|
const historyBefore = server.cronStore.getExecutionHistory(schedule.id).length;
|
||||||
@@ -243,7 +234,7 @@ describe('cron ai_task executor (#17)', () => {
|
|||||||
|
|
||||||
expect(executed).toBe(0);
|
expect(executed).toBe(0);
|
||||||
expect(fetchMock).not.toHaveBeenCalled();
|
expect(fetchMock).not.toHaveBeenCalled();
|
||||||
expect(countFrames()).toBe(framesBefore);
|
expect(await countMemories()).toBe(memoriesBefore);
|
||||||
expect(leaseSpy).not.toHaveBeenCalled();
|
expect(leaseSpy).not.toHaveBeenCalled();
|
||||||
expect(server.cronStore.getExecutionHistory(schedule.id)).toHaveLength(historyBefore);
|
expect(server.cronStore.getExecutionHistory(schedule.id)).toHaveLength(historyBefore);
|
||||||
expect(server.cronStore.getById(schedule.id)?.last_run_at).toBeNull();
|
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 os from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import type { FastifyInstance } from 'fastify';
|
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 type { AgentLoopConfig, AgentResponse } from '@waggle/agent';
|
||||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import { PERSONA_CASES } from '../../../../tests/vision/persona-cases.js';
|
import { PERSONA_CASES } from '../../../../tests/vision/persona-cases.js';
|
||||||
@@ -104,8 +105,6 @@ describe('persona acceptance prompt budget', () => {
|
|||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-persona-budget-'));
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-persona-budget-'));
|
||||||
const mind = new MindDB(path.join(tmpDir, 'personal.mind'));
|
|
||||||
mind.close();
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(tmpDir, 'profile.json'),
|
path.join(tmpDir, 'profile.json'),
|
||||||
JSON.stringify({ name: PERSISTED_PROFILE_SENTINEL }),
|
JSON.stringify({ name: PERSISTED_PROFILE_SENTINEL }),
|
||||||
@@ -1282,14 +1281,10 @@ describe('persona acceptance prompt budget', () => {
|
|||||||
const childName = 'PRIVATE_CHILD_NAME_20260808';
|
const childName = 'PRIVATE_CHILD_NAME_20260808';
|
||||||
const childTask = 'PRIVATE_CHILD_TASK_20260808';
|
const childTask = 'PRIVATE_CHILD_TASK_20260808';
|
||||||
const childResult = 'PRIVATE_CHILD_RESULT_20260808';
|
const childResult = 'PRIVATE_CHILD_RESULT_20260808';
|
||||||
const personalMind = server.multiMind.personal;
|
const workspaceMemory = workspaceScope(collaborationWorkspaceId);
|
||||||
const workspaceMind = server.mindCache.getOrOpen(collaborationWorkspaceId);
|
const memoryCount = (scope: MemoryScope) => server.memory.count({ scopes: [scope] });
|
||||||
expect(workspaceMind).toBeDefined();
|
const personalBefore = await memoryCount(PERSONAL_SCOPE);
|
||||||
const frameCount = (mind: MindDB) => (
|
const workspaceBefore = await memoryCount(workspaceMemory);
|
||||||
mind.getDatabase().prepare('SELECT COUNT(*) AS count FROM memory_frames').get() as { count: number }
|
|
||||||
).count;
|
|
||||||
const personalBefore = frameCount(personalMind);
|
|
||||||
const workspaceBefore = frameCount(workspaceMind!);
|
|
||||||
const loopConfigs: AgentLoopConfig[] = [];
|
const loopConfigs: AgentLoopConfig[] = [];
|
||||||
let childOutput = '';
|
let childOutput = '';
|
||||||
const statusEvents: unknown[] = [];
|
const statusEvents: unknown[] = [];
|
||||||
@@ -1359,8 +1354,8 @@ describe('persona acceptance prompt budget', () => {
|
|||||||
for (const denied of deniedChildTools) {
|
for (const denied of deniedChildTools) {
|
||||||
expect(childToolNames, denied).not.toContain(denied);
|
expect(childToolNames, denied).not.toContain(denied);
|
||||||
}
|
}
|
||||||
expect(frameCount(personalMind)).toBe(personalBefore);
|
expect(await memoryCount(PERSONAL_SCOPE)).toBe(personalBefore);
|
||||||
expect(frameCount(workspaceMind!)).toBe(workspaceBefore);
|
expect(await memoryCount(workspaceMemory)).toBe(workspaceBefore);
|
||||||
const registry = fs.readFileSync(path.join(tmpDir, 'agent-runs.json'), 'utf8');
|
const registry = fs.readFileSync(path.join(tmpDir, 'agent-runs.json'), 'utf8');
|
||||||
for (const privateContent of [parentTask, childName, childTask, childResult]) {
|
for (const privateContent of [parentTask, childName, childTask, childResult]) {
|
||||||
expect(registry, privateContent).not.toContain(privateContent);
|
expect(registry, privateContent).not.toContain(privateContent);
|
||||||
@@ -1457,14 +1452,10 @@ describe('persona acceptance prompt budget', () => {
|
|||||||
const stepRole = 'PRIVATE_WORKFLOW_STEP_ROLE_20260808';
|
const stepRole = 'PRIVATE_WORKFLOW_STEP_ROLE_20260808';
|
||||||
const stepTask = 'PRIVATE_WORKFLOW_STEP_TASK_20260808';
|
const stepTask = 'PRIVATE_WORKFLOW_STEP_TASK_20260808';
|
||||||
const workerResult = 'PRIVATE_WORKFLOW_WORKER_RESULT_20260808';
|
const workerResult = 'PRIVATE_WORKFLOW_WORKER_RESULT_20260808';
|
||||||
const personalMind = server.multiMind.personal;
|
const workspaceMemory = workspaceScope(collaborationWorkspaceId);
|
||||||
const workspaceMind = server.mindCache.getOrOpen(collaborationWorkspaceId);
|
const memoryCount = (scope: MemoryScope) => server.memory.count({ scopes: [scope] });
|
||||||
expect(workspaceMind).toBeDefined();
|
const personalBefore = await memoryCount(PERSONAL_SCOPE);
|
||||||
const frameCount = (mind: MindDB) => (
|
const workspaceBefore = await memoryCount(workspaceMemory);
|
||||||
mind.getDatabase().prepare('SELECT COUNT(*) AS count FROM memory_frames').get() as { count: number }
|
|
||||||
).count;
|
|
||||||
const personalBefore = frameCount(personalMind);
|
|
||||||
const workspaceBefore = frameCount(workspaceMind!);
|
|
||||||
const loopConfigs: AgentLoopConfig[] = [];
|
const loopConfigs: AgentLoopConfig[] = [];
|
||||||
let workflowOutput = '';
|
let workflowOutput = '';
|
||||||
|
|
||||||
@@ -1530,8 +1521,8 @@ describe('persona acceptance prompt budget', () => {
|
|||||||
expect(workerToolNames).not.toContain('search_memory');
|
expect(workerToolNames).not.toContain('search_memory');
|
||||||
expect(workerToolNames).not.toContain('save_memory');
|
expect(workerToolNames).not.toContain('save_memory');
|
||||||
expect(workerToolNames).not.toContain('agent_insights');
|
expect(workerToolNames).not.toContain('agent_insights');
|
||||||
expect(frameCount(personalMind)).toBe(personalBefore);
|
expect(await memoryCount(PERSONAL_SCOPE)).toBe(personalBefore);
|
||||||
expect(frameCount(workspaceMind!)).toBe(workspaceBefore);
|
expect(await memoryCount(workspaceMemory)).toBe(workspaceBefore);
|
||||||
const registry = fs.readFileSync(path.join(tmpDir, 'agent-runs.json'), 'utf8');
|
const registry = fs.readFileSync(path.join(tmpDir, 'agent-runs.json'), 'utf8');
|
||||||
for (const privateContent of [
|
for (const privateContent of [
|
||||||
parentTask, workflowName, workflowTask, stepName, stepRole, stepTask, workerResult,
|
parentTask, workflowName, workflowTask, stepName, stepRole, stepTask, workerResult,
|
||||||
|
|||||||
Reference in New Issue
Block a user