Files
waggle-os/packages/core/tests/logger.test.ts
shumeiko.it 0fef37ac53 chore(core): mark the files copied from hive-mind-core as Apache-2.0
The logger, injection scanner, ingress guard, WorkspaceManager, embedders,
recall helpers and execution traces came from @waggle/hive-mind-core
(Apache-2.0); awareness, identity and parts of WaggleDB were adapted from
it. They keep Apache-2.0: an SPDX header with the original copyright line
and the source file, packages/core/LICENSE.md listing them,
LICENSE-APACHE with the full text, and "MIT AND Apache-2.0" in
package.json. A test keeps the list and the headers in step. No code
changes.

Logs UF-069: the hive-mind-core LICENSE is an abridged Apache text.
2026-11-04 10:19:05 +01:00

51 lines
2.1 KiB
TypeScript

// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 Marko Marković · Egzakta Group · waggle-os.ai
// Copied from @waggle/hive-mind-core tests/logger.test.ts and changed for @waggle/core.
/**
* Logger stderr-routing tests.
*
* stdout is reserved for program data (MCP stdio transports, 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 });
});
});