refactor(server): search memory through the contract in artifacts, agent runs, route proposals and onboarding (P1.5)
- Artifact Center related search lists personal and workspace memories through server.memory and finds related chat sessions in the session files (UF-034). - /api/agent/run searches the requested workspace's memory, or personal memory when no known workspace is given. - Executor briefs search only the workspace's own memory and leave out temporary memories in the query; route proposals no longer borrow a mind from the cache. - Onboarding treats any personal memory as evidence of prior use. - The service no longer creates personal.mind on a fresh install, and isFirstRun also looks for waggle.db.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* P4 (UX-Refactor) — server-authoritative onboarding status.
|
||||
*
|
||||
* THE clean-install pin: a freshly-booted server (ensureDefault already seeded
|
||||
* the default workspace, personal mind empty, no flag) must report
|
||||
* the default workspace, personal memory empty, no flag) must report
|
||||
* completed:false — the workspace-count heuristic this replaces reported the
|
||||
* seeded stub as a "returning user" and silently skipped the wizard for every
|
||||
* brand-new production install (S4 founder flag, confirmed in P4).
|
||||
@@ -12,13 +12,13 @@ import Fastify from 'fastify';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import { MindDB, FrameStore, SessionStore } from '@waggle/core';
|
||||
import { createInMemoryMemoryStore, PERSONAL_SCOPE, type MemoryStore } from '@waggle/memory-contract';
|
||||
import { onboardingRoutes } from '../../src/local/routes/onboarding.js';
|
||||
|
||||
function createTestServer(dataDir: string, db: MindDB, workspaces: Array<{ id: string }>) {
|
||||
function createTestServer(dataDir: string, memory: MemoryStore, workspaces: Array<{ id: string }>) {
|
||||
const server = Fastify({ logger: false });
|
||||
server.decorate('localConfig', { dataDir });
|
||||
server.decorate('multiMind', { personal: db });
|
||||
server.decorate('memory', memory);
|
||||
server.decorate('workspaceManager', { list: () => workspaces });
|
||||
server.register(onboardingRoutes);
|
||||
return server;
|
||||
@@ -26,31 +26,30 @@ function createTestServer(dataDir: string, db: MindDB, workspaces: Array<{ id: s
|
||||
|
||||
describe('GET/POST /api/onboarding (P4 clean-install fix)', () => {
|
||||
let tmp: string;
|
||||
let db: MindDB;
|
||||
let memory: MemoryStore;
|
||||
let server: ReturnType<typeof Fastify>;
|
||||
// The boot-seeded default workspace is ALWAYS present (ensureDefault).
|
||||
const seededOnly = [{ id: 'default-workspace' }];
|
||||
|
||||
beforeEach(() => {
|
||||
tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-onb-test-'));
|
||||
db = new MindDB(':memory:');
|
||||
memory = createInMemoryMemoryStore();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await server.close();
|
||||
db.close();
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('CLEAN INSTALL: seeded default workspace + empty mind + no flag → completed:false', async () => {
|
||||
server = createTestServer(tmp, db, seededOnly);
|
||||
it('CLEAN INSTALL: seeded default workspace + empty memory + no flag → completed:false', async () => {
|
||||
server = createTestServer(tmp, memory, seededOnly);
|
||||
const res = await server.inject({ method: 'GET', url: '/api/onboarding/status' });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json()).toEqual({ completed: false, source: 'none' });
|
||||
});
|
||||
|
||||
it('completion flag → completed:true (the POST stamp round-trip)', async () => {
|
||||
server = createTestServer(tmp, db, seededOnly);
|
||||
server = createTestServer(tmp, memory, seededOnly);
|
||||
const post = await server.inject({ method: 'POST', url: '/api/onboarding/complete' });
|
||||
expect(post.statusCode).toBe(200);
|
||||
expect(fs.existsSync(path.join(tmp, 'first-launch.flag'))).toBe(true);
|
||||
@@ -59,24 +58,22 @@ describe('GET/POST /api/onboarding (P4 clean-install fix)', () => {
|
||||
expect(res.json()).toEqual({ completed: true, source: 'flag' });
|
||||
});
|
||||
|
||||
it('legacy evidence: any frame in the personal mind → completed:true', async () => {
|
||||
const sessions = new SessionStore(db);
|
||||
const gop = sessions.create().gop_id;
|
||||
new FrameStore(db).createIFrame(gop, 'Real prior usage.', 'normal');
|
||||
server = createTestServer(tmp, db, seededOnly);
|
||||
it('legacy evidence: any personal memory → completed:true', async () => {
|
||||
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Real prior usage.' });
|
||||
server = createTestServer(tmp, memory, seededOnly);
|
||||
|
||||
const res = await server.inject({ method: 'GET', url: '/api/onboarding/status' });
|
||||
expect(res.json()).toEqual({ completed: true, source: 'legacy-evidence' });
|
||||
});
|
||||
|
||||
it('legacy evidence: user-created workspaces beyond the seeded default → completed:true', async () => {
|
||||
server = createTestServer(tmp, db, [...seededOnly, { id: 'my-real-project' }]);
|
||||
server = createTestServer(tmp, memory, [...seededOnly, { id: 'my-real-project' }]);
|
||||
const res = await server.inject({ method: 'GET', url: '/api/onboarding/status' });
|
||||
expect(res.json()).toEqual({ completed: true, source: 'legacy-evidence' });
|
||||
});
|
||||
|
||||
it('POST is idempotent', async () => {
|
||||
server = createTestServer(tmp, db, seededOnly);
|
||||
server = createTestServer(tmp, memory, seededOnly);
|
||||
await server.inject({ method: 'POST', url: '/api/onboarding/complete' });
|
||||
const second = await server.inject({ method: 'POST', url: '/api/onboarding/complete' });
|
||||
expect(second.statusCode).toBe(200);
|
||||
@@ -84,18 +81,16 @@ describe('GET/POST /api/onboarding (P4 clean-install fix)', () => {
|
||||
});
|
||||
|
||||
it('PENDING LATCH: wizard-origin writes after the first status call never flip it (review chain)', async () => {
|
||||
server = createTestServer(tmp, db, seededOnly);
|
||||
server = createTestServer(tmp, memory, seededOnly);
|
||||
// First status call on the clean install stamps the pending latch.
|
||||
const first = await server.inject({ method: 'GET', url: '/api/onboarding/status' });
|
||||
expect(first.json()).toEqual({ completed: false, source: 'none' });
|
||||
expect(fs.existsSync(path.join(tmp, 'onboarding-pending.flag'))).toBe(true);
|
||||
|
||||
// The wizard's step-1 profile write (PUT /api/profile → 'User identity:'
|
||||
// frame) — the exact pre-completion evidence the review verified. With
|
||||
// memory) — the exact pre-completion evidence the review verified. With
|
||||
// the latch, it must NOT turn the user into a "returning user".
|
||||
const sessions = new SessionStore(db);
|
||||
const gop = sessions.create().gop_id;
|
||||
new FrameStore(db).createIFrame(gop, 'User identity: Name: New User', 'important');
|
||||
await memory.remember({ scope: PERSONAL_SCOPE, text: 'User identity: Name: New User', importance: 'important' });
|
||||
|
||||
const after = await server.inject({ method: 'GET', url: '/api/onboarding/status' });
|
||||
expect(after.json()).toEqual({ completed: false, source: 'pending' });
|
||||
@@ -108,10 +103,8 @@ describe('GET/POST /api/onboarding (P4 clean-install fix)', () => {
|
||||
});
|
||||
|
||||
it('the latch never fires for a REAL returning user (evidence wins on first contact)', async () => {
|
||||
const sessions = new SessionStore(db);
|
||||
const gop = sessions.create().gop_id;
|
||||
new FrameStore(db).createIFrame(gop, 'Genuine prior usage.', 'normal');
|
||||
server = createTestServer(tmp, db, seededOnly);
|
||||
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Genuine prior usage.' });
|
||||
server = createTestServer(tmp, memory, seededOnly);
|
||||
|
||||
const res = await server.inject({ method: 'GET', url: '/api/onboarding/status' });
|
||||
expect(res.json()).toEqual({ completed: true, source: 'legacy-evidence' });
|
||||
|
||||
Reference in New Issue
Block a user