Files
openclaw/src/plugins/runtime/runtime-logging.test.ts
100menotu001 f52db027a0 fix(discord): log component registry error details
Log structured details when Discord persistent component registry state falls back after a store failure.

- Format Error name, message, stack, and cause metadata at the Discord registry warning call site.
- Forward plugin runtime logger metadata to the underlying child logger.
- Add focused regression coverage for the Discord fallback warning and runtime logging adapter.
- Add changelog credit for @100menotu001.

Fixes #84185.

Co-authored-by: OpenClaw Contributor <100menotu001@users.noreply.github.com>
Co-authored-by: Craig <froelich@craigs.mac.studio.froho>
2026-05-21 22:13:14 +01:00

56 lines
1.7 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const loggingMocks = vi.hoisted(() => {
const childLogger = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};
return {
childLogger,
getChildLogger: vi.fn(() => childLogger),
};
});
vi.mock("../../globals.js", () => ({
shouldLogVerbose: vi.fn(() => false),
}));
vi.mock("../../logging.js", () => ({
getChildLogger: loggingMocks.getChildLogger,
}));
let createRuntimeLogging: typeof import("./runtime-logging.js").createRuntimeLogging;
beforeEach(async () => {
vi.clearAllMocks();
loggingMocks.getChildLogger.mockReturnValue(loggingMocks.childLogger);
({ createRuntimeLogging } = await import("./runtime-logging.js"));
});
describe("createRuntimeLogging", () => {
it("forwards structured metadata to child loggers", () => {
const logging = createRuntimeLogging();
const logger = logging.getChildLogger({ plugin: "discord" }, { level: "warn" });
const meta = {
errorName: "Error",
errorCauseName: "TypeError",
};
logger.debug?.("debug details", meta);
logger.info("info details", meta);
logger.warn("warn details", meta);
logger.error("error details", meta);
expect(loggingMocks.getChildLogger).toHaveBeenCalledWith(
{ plugin: "discord" },
{ level: "warn" },
);
expect(loggingMocks.childLogger.debug).toHaveBeenCalledWith(meta, "debug details");
expect(loggingMocks.childLogger.info).toHaveBeenCalledWith(meta, "info details");
expect(loggingMocks.childLogger.warn).toHaveBeenCalledWith(meta, "warn details");
expect(loggingMocks.childLogger.error).toHaveBeenCalledWith(meta, "error details");
});
});