Files
waggle-os/packages/core/tests/logger.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

49 lines
2.0 KiB
TypeScript

/**
* Logger stderr-routing tests.
*
* Reverse-ported from OSS hive-mind (oss-drift triage R1, 2026-06-11).
* stdout is reserved for program data (MCP stdio transport in
* hive-mind-mcp-server, CLI --json envelopes) — a library log line on
* stdout corrupts machine consumers, so every level must land on stderr.
*/
import { describe, it, expect, vi, afterEach } from 'vitest';
import { createCoreLogger, type CoreLogger } from '../src/logger.js';
describe('createCoreLogger', () => {
afterEach(() => vi.restoreAllMocks());
it('routes every level to stderr — never the stdout-bound console methods', () => {
const info = vi.spyOn(console, 'info').mockImplementation(() => {});
const debug = vi.spyOn(console, 'debug').mockImplementation(() => {});
const log = vi.spyOn(console, 'log').mockImplementation(() => {});
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
const logger: CoreLogger = createCoreLogger('test');
logger.info('hello');
logger.debug('dbg');
logger.warn('careful');
logger.error('boom');
// None of the stdout-bound console methods may be used.
expect(info).not.toHaveBeenCalled();
expect(debug).not.toHaveBeenCalled();
expect(log).not.toHaveBeenCalled();
// Diagnostics land on stderr (console.error / console.warn).
expect(error).toHaveBeenCalledTimes(3); // info + debug + error
expect(warn).toHaveBeenCalledTimes(1);
});
it('keeps the [waggle:tag] prefix on messages', () => {
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
createCoreLogger('embedding').info('probing');
expect(error).toHaveBeenCalledWith('[waggle:embedding] probing');
});
it('passes structured data through as a second argument', () => {
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
createCoreLogger('pipeline').info('done', { frames: 5 });
expect(error).toHaveBeenCalledWith('[waggle:pipeline] done', { frames: 5 });
});
});