From 37f030a671ea7ee72b40582fc04dc67cbc3a70c8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 00:33:40 +0000 Subject: [PATCH] perf(test): fold console prefix tests into logger suite --- src/logger.test.ts | 35 +++++++++++++++++++++++++++++- src/logging/console-prefix.test.ts | 30 ------------------------- 2 files changed, 34 insertions(+), 31 deletions(-) delete mode 100644 src/logging/console-prefix.test.ts diff --git a/src/logger.test.ts b/src/logger.test.ts index 2777a3950d..faa5d5d97a 100644 --- a/src/logger.test.ts +++ b/src/logger.test.ts @@ -6,7 +6,12 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import type { RuntimeEnv } from "./runtime.js"; import { isVerbose, isYes, logVerbose, setVerbose, setYes } from "./globals.js"; import { logDebug, logError, logInfo, logSuccess, logWarn } from "./logger.js"; -import { DEFAULT_LOG_DIR, resetLogger, setLoggerOverride } from "./logging.js"; +import { + DEFAULT_LOG_DIR, + resetLogger, + setLoggerOverride, + stripRedundantSubsystemPrefixForConsole, +} from "./logging.js"; describe("logger helpers", () => { afterEach(() => { @@ -116,6 +121,34 @@ describe("globals", () => { }); }); +describe("stripRedundantSubsystemPrefixForConsole", () => { + it("drops ':' prefix", () => { + expect(stripRedundantSubsystemPrefixForConsole("discord: hello", "discord")).toBe("hello"); + }); + + it("drops ':' prefix case-insensitively", () => { + expect(stripRedundantSubsystemPrefixForConsole("WhatsApp: hello", "whatsapp")).toBe("hello"); + }); + + it("drops ' ' prefix", () => { + expect(stripRedundantSubsystemPrefixForConsole("discord gateway: closed", "discord")).toBe( + "gateway: closed", + ); + }); + + it("drops '[subsystem]' prefix", () => { + expect(stripRedundantSubsystemPrefixForConsole("[discord] connection stalled", "discord")).toBe( + "connection stalled", + ); + }); + + it("keeps messages that do not start with the subsystem", () => { + expect(stripRedundantSubsystemPrefixForConsole("discordant: hello", "discord")).toBe( + "discordant: hello", + ); + }); +}); + function pathForTest() { const file = path.join(os.tmpdir(), `openclaw-log-${crypto.randomUUID()}.log`); fs.mkdirSync(path.dirname(file), { recursive: true }); diff --git a/src/logging/console-prefix.test.ts b/src/logging/console-prefix.test.ts deleted file mode 100644 index 3bc3b13df9..0000000000 --- a/src/logging/console-prefix.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { stripRedundantSubsystemPrefixForConsole } from "../logging.js"; - -describe("stripRedundantSubsystemPrefixForConsole", () => { - it("drops ':' prefix", () => { - expect(stripRedundantSubsystemPrefixForConsole("discord: hello", "discord")).toBe("hello"); - }); - - it("drops ':' prefix case-insensitively", () => { - expect(stripRedundantSubsystemPrefixForConsole("WhatsApp: hello", "whatsapp")).toBe("hello"); - }); - - it("drops ' ' prefix", () => { - expect(stripRedundantSubsystemPrefixForConsole("discord gateway: closed", "discord")).toBe( - "gateway: closed", - ); - }); - - it("drops '[subsystem]' prefix", () => { - expect(stripRedundantSubsystemPrefixForConsole("[discord] connection stalled", "discord")).toBe( - "connection stalled", - ); - }); - - it("keeps messages that do not start with the subsystem", () => { - expect(stripRedundantSubsystemPrefixForConsole("discordant: hello", "discord")).toBe( - "discordant: hello", - ); - }); -});