Files
waggle-os/packages/server/tests/local/identity.test.ts
shumeiko.it ad2ca875cb feat(core): give Waggle its own database, apart from memory (P1.5)
Waggle kept its own tables in the memory database. Before the memory
engine can be replaced by mem0 they need a home of their own.

- add WaggleDB (<dataDir>/waggle.db). Automations, notifications, held
  actions, skill hashes, thumbs feedback, cost tracking, the profile card
  and awareness items live there. Their stores take a WaggleDB, so passing
  a memory database is a type error.
- the profile card and awareness items are now per scope ('personal' or
  'workspace:<id>') in one table each, instead of one table per .mind file
- on the first start, copy these tables from personal.mind and every
  workspace.mind (importLegacyMindData). The legacy files are only read,
  each scope is copied once and a table only while its target is empty.
- copy the logger, injection scanner, external-memory ingress guard,
  WorkspaceManager and the embedders from @waggle/hive-mind-core into
  @waggle/core, which now re-exports its own copies
- point the server, agent orchestrator and CLI at waggle.db; update the
  tests that seeded these tables in a memory database

ADR-0007 records the layout and the licensing question about the copied
files.
2026-10-23 14:31:28 +02:00

90 lines
3.2 KiB
TypeScript

// CC Sesija A §2.5 Task A15 — identity sidecar route smoke + shape tests.
//
// Brief: briefs/2026-04-30-cc-sesija-A-waggle-apps-web-integration.md §2.5 Task A15
//
// Validates the A1.1 follow-up route exports a plugin function and the
// placeholder shape it returns matches the contract Tauri command +
// adapter.getIdentity() expect.
import { describe, it, expect, afterEach } from 'vitest';
import Fastify from 'fastify';
import { WaggleDB } from '@waggle/core';
import { identityRoutes } from '../../src/local/routes/identity.js';
describe('POST /api/identity — merge-on-update', () => {
let db: WaggleDB;
let server: ReturnType<typeof Fastify>;
afterEach(async () => {
await server.close();
db.close();
});
function boot() {
db = new WaggleDB(':memory:');
server = Fastify({ logger: false });
server.decorate('waggleDb', db);
server.register(identityRoutes);
}
it('a partial write keeps the stored values for omitted fields', async () => {
boot();
const first = await server.inject({
method: 'POST', url: '/api/identity',
payload: { name: 'Marko', role: 'Founder', department: 'Egzakta' },
});
expect(first.statusCode).toBe(200);
// The onboarding wizard re-run sends name only — role/department must
// survive (the old `body.x ?? ''` semantics silently wiped them).
const partial = await server.inject({
method: 'POST', url: '/api/identity',
payload: { name: 'Marko M.' },
});
expect(partial.statusCode).toBe(200);
const body = partial.json();
expect(body.name).toBe('Marko M.');
expect(body.role).toBe('Founder');
expect(body.department).toBe('Egzakta');
});
it('an explicit empty string still clears a field', async () => {
boot();
await server.inject({
method: 'POST', url: '/api/identity',
payload: { name: 'Marko', role: 'Founder' },
});
const cleared = await server.inject({
method: 'POST', url: '/api/identity',
payload: { role: '' },
});
expect(cleared.json().role).toBe('');
expect(cleared.json().name).toBe('Marko');
});
});
describe('identity.ts route module', () => {
it('exports identityRoutes plugin function', async () => {
const mod = await import('../../src/local/routes/identity.js');
expect(mod.identityRoutes).toBeDefined();
expect(typeof mod.identityRoutes).toBe('function');
});
it('IdentityLayer is exported from @waggle/core for the route to consume', async () => {
const { IdentityLayer } = await import('@waggle/core');
expect(IdentityLayer).toBeDefined();
expect(typeof IdentityLayer).toBe('function'); // class constructor
});
it('IdentityLayer exposes the API the identity route uses', async () => {
const { IdentityLayer } = await import('@waggle/core');
// Verify the methods the route calls actually exist on the prototype —
// catches schema drift before the route fails at runtime in production.
const proto = IdentityLayer.prototype as Record<string, unknown>;
expect(typeof proto.exists).toBe('function');
expect(typeof proto.get).toBe('function');
expect(typeof proto.create).toBe('function');
expect(typeof proto.update).toBe('function');
});
});