- 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.
123 lines
5.8 KiB
TypeScript
123 lines
5.8 KiB
TypeScript
/**
|
|
* P4 (UX-Refactor) — server-authoritative onboarding status.
|
|
*
|
|
* THE clean-install pin: a freshly-booted server (ensureDefault already seeded
|
|
* 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).
|
|
*/
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import Fastify from 'fastify';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import os from 'node:os';
|
|
import { createInMemoryMemoryStore, PERSONAL_SCOPE, type MemoryStore } from '@waggle/memory-contract';
|
|
import { onboardingRoutes } from '../../src/local/routes/onboarding.js';
|
|
|
|
function createTestServer(dataDir: string, memory: MemoryStore, workspaces: Array<{ id: string }>) {
|
|
const server = Fastify({ logger: false });
|
|
server.decorate('localConfig', { dataDir });
|
|
server.decorate('memory', memory);
|
|
server.decorate('workspaceManager', { list: () => workspaces });
|
|
server.register(onboardingRoutes);
|
|
return server;
|
|
}
|
|
|
|
describe('GET/POST /api/onboarding (P4 clean-install fix)', () => {
|
|
let tmp: string;
|
|
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-'));
|
|
memory = createInMemoryMemoryStore();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await server.close();
|
|
fs.rmSync(tmp, { recursive: true, force: true });
|
|
});
|
|
|
|
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, 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);
|
|
|
|
const res = await server.inject({ method: 'GET', url: '/api/onboarding/status' });
|
|
expect(res.json()).toEqual({ completed: true, source: 'flag' });
|
|
});
|
|
|
|
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, 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, 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);
|
|
expect(second.json()).toEqual({ completed: true });
|
|
});
|
|
|
|
it('PENDING LATCH: wizard-origin writes after the first status call never flip it (review chain)', async () => {
|
|
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:'
|
|
// memory) — the exact pre-completion evidence the review verified. With
|
|
// the latch, it must NOT turn the user into a "returning user".
|
|
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' });
|
|
|
|
// Completion clears the latch and stamps the flag.
|
|
await server.inject({ method: 'POST', url: '/api/onboarding/complete' });
|
|
expect(fs.existsSync(path.join(tmp, 'onboarding-pending.flag'))).toBe(false);
|
|
const done = await server.inject({ method: 'GET', url: '/api/onboarding/status' });
|
|
expect(done.json()).toEqual({ completed: true, source: 'flag' });
|
|
});
|
|
|
|
it('the latch never fires for a REAL returning user (evidence wins on first contact)', async () => {
|
|
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' });
|
|
expect(fs.existsSync(path.join(tmp, 'onboarding-pending.flag'))).toBe(false);
|
|
});
|
|
|
|
it('registration pin: the real server wires onboardingRoutes (drop = red)', () => {
|
|
const indexSrc = fs.readFileSync(
|
|
path.resolve(import.meta.dirname, '..', '..', 'src', 'local', 'index.ts'),
|
|
'utf-8',
|
|
);
|
|
expect(indexSrc).toContain("import { onboardingRoutes } from './routes/onboarding.js'");
|
|
expect(indexSrc).toContain('server.register(onboardingRoutes)');
|
|
});
|
|
});
|