test(agent): move the agent suites onto the memory contract (P1.5)

Rewrites the orchestrator, recall, compaction, save_memory and assembler
suites for MemoryStore (createInMemoryMemoryStore; mem0 with the word
embedder for the M3b integration test), string ids, async prompt building
and setWorkspace(). Creation times are set with fake timers, since a write
cannot set its own. Stores of Waggle's own data (identity, traces) are built
on WaggleDB; the session-manager stubs use the new create() signature.

Kept behaviour: importance lane (cap, active scope, temporary exclusion),
profile and event lanes, date window and its fallback, catch-up, injection
blocking of recall and preloaded context, autosave safety, decision consent,
compaction update-in-place, reranker wiring.

New tests: recall with a workspace active versus personal only;
fetchRecentMemories ordering; toRecallFrame; context loader; save_memory
routing, dedup, rate limit, dramatic-claim downgrade and contradiction
scope; search_memory and search_all_workspaces; pattern write-back kinds,
scopes and sign gate; read_other_workspace; reranker off unless
WAGGLE_RERANKER=1, wider rerank pool, failure fallbacks.

Deleted, because the behaviour is gone:
- w46-rawdetail-recall.test.ts: the raw-turn (RAWDETAIL) recall lane.
- orchestrator.test.ts, query_knowledge (3 tests) and the recall-hardening
  M4 "Key Knowledge" test: the knowledge graph is not in v1 (ADR-0002).
- orchestrator-context-frames "profile override": scoring profiles.
- Assertions on I/P frame types, GOP sessions, FTS rows, the "Memory Facts"
  lane, cognify stages and session/entity counts were replaced by the
  equivalent contract-level checks.
This commit is contained in:
shumeiko.it
2026-10-24 12:37:36 +02:00
parent 851502d347
commit ac23bbd7a6
27 changed files with 1426 additions and 922 deletions

View File

@@ -1,28 +1,19 @@
/**
* Skills 2.0 gap K — write-path conflict detection.
*
* When save_memory writes a new frame that contradicts an existing frame
* When save_memory writes a new memory that contradicts an existing one
* (detectContradiction), the save still succeeds but the return string
* carries a [flag: contradicts_existing …] marker.
*/
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import {
MindDB,
IdentityLayer,
AwarenessLayer,
FrameStore,
SessionStore,
KnowledgeGraph,
HybridSearch,
} from '@waggle/core';
import { WaggleDB, IdentityLayer, AwarenessLayer } from '@waggle/core';
import { createInMemoryMemoryStore, PERSONAL_SCOPE, type MemoryStore } from '@waggle/memory-contract';
import { createMindTools } from '../src/tools.js';
import type { ToolDefinition } from '../src/tools.js';
import { MockEmbedder } from '../../hive-mind-core/tests/mind/helpers/mock-embedder.js';
describe('save_memory — gap K (write-path conflict detection)', () => {
let db: MindDB;
let frames: FrameStore;
let sessions: SessionStore;
let waggleDb: WaggleDB;
let memory: MemoryStore;
let tools: ToolDefinition[];
function getSaveMemory(): ToolDefinition {
@@ -32,34 +23,23 @@ describe('save_memory — gap K (write-path conflict detection)', () => {
}
beforeEach(() => {
db = new MindDB(':memory:');
const embedder = new MockEmbedder();
frames = new FrameStore(db);
sessions = new SessionStore(db);
const knowledge = new KnowledgeGraph(db);
const search = new HybridSearch(db, embedder);
waggleDb = new WaggleDB(':memory:');
memory = createInMemoryMemoryStore();
tools = createMindTools({
db,
identity: new IdentityLayer(db),
awareness: new AwarenessLayer(db),
frames,
sessions,
search,
knowledge,
// Intentionally NO cognify → exercises the raw-frame fallback path
// (no LLM-dependent entity extraction in unit tests).
memory,
identity: new IdentityLayer(waggleDb),
awareness: new AwarenessLayer(waggleDb),
});
});
afterEach(() => {
db.close();
waggleDb.close();
});
it('flags contradictions and records a correction signal', async () => {
it('flags contradictions and still saves the memory', async () => {
const save = getSaveMemory();
// Prime with an affirmative decision frame.
// Prime with an affirmative decision.
// Using "enable/disable feature flag rollout users" — the existing
// detectContradiction algorithm needs asymmetric sentiment to fire;
// inputs with "will" in both sides add positive noise that can mask
@@ -85,6 +65,7 @@ describe('save_memory — gap K (write-path conflict detection)', () => {
expect(second).toContain('Memory saved');
// But the return message is annotated
expect(second).toContain('[flag: contradicts_existing');
expect(await memory.count({ scopes: [PERSONAL_SCOPE] })).toBe(2);
});
it('non-contradicting saves are not flagged', async () => {