mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 05:52:45 +00:00
refactor: dedupe agent and reply runtimes
This commit is contained in:
@@ -10,27 +10,16 @@ import {
|
||||
setLoggerOverride,
|
||||
} from "../logging.js";
|
||||
import { loggingState } from "./state.js";
|
||||
|
||||
type ConsoleSnapshot = {
|
||||
log: typeof console.log;
|
||||
info: typeof console.info;
|
||||
warn: typeof console.warn;
|
||||
error: typeof console.error;
|
||||
debug: typeof console.debug;
|
||||
trace: typeof console.trace;
|
||||
};
|
||||
import {
|
||||
captureConsoleSnapshot,
|
||||
type ConsoleSnapshot,
|
||||
restoreConsoleSnapshot,
|
||||
} from "./test-helpers/console-snapshot.js";
|
||||
|
||||
let snapshot: ConsoleSnapshot;
|
||||
|
||||
beforeEach(() => {
|
||||
snapshot = {
|
||||
log: console.log,
|
||||
info: console.info,
|
||||
warn: console.warn,
|
||||
error: console.error,
|
||||
debug: console.debug,
|
||||
trace: console.trace,
|
||||
};
|
||||
snapshot = captureConsoleSnapshot();
|
||||
loggingState.consolePatched = false;
|
||||
loggingState.forceConsoleToStderr = false;
|
||||
loggingState.consoleTimestampPrefix = false;
|
||||
@@ -39,12 +28,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
console.log = snapshot.log;
|
||||
console.info = snapshot.info;
|
||||
console.warn = snapshot.warn;
|
||||
console.error = snapshot.error;
|
||||
console.debug = snapshot.debug;
|
||||
console.trace = snapshot.trace;
|
||||
restoreConsoleSnapshot(snapshot);
|
||||
loggingState.consolePatched = false;
|
||||
loggingState.forceConsoleToStderr = false;
|
||||
loggingState.consoleTimestampPrefix = false;
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
captureConsoleSnapshot,
|
||||
type ConsoleSnapshot,
|
||||
restoreConsoleSnapshot,
|
||||
} from "./test-helpers/console-snapshot.js";
|
||||
|
||||
vi.mock("./config.js", () => ({
|
||||
readLoggingConfig: () => undefined,
|
||||
@@ -16,15 +21,6 @@ vi.mock("./logger.js", () => ({
|
||||
}));
|
||||
|
||||
let loadConfigCalls = 0;
|
||||
type ConsoleSnapshot = {
|
||||
log: typeof console.log;
|
||||
info: typeof console.info;
|
||||
warn: typeof console.warn;
|
||||
error: typeof console.error;
|
||||
debug: typeof console.debug;
|
||||
trace: typeof console.trace;
|
||||
};
|
||||
|
||||
let originalIsTty: boolean | undefined;
|
||||
let originalOpenClawTestConsole: string | undefined;
|
||||
let snapshot: ConsoleSnapshot;
|
||||
@@ -38,14 +34,7 @@ beforeAll(async () => {
|
||||
|
||||
beforeEach(() => {
|
||||
loadConfigCalls = 0;
|
||||
snapshot = {
|
||||
log: console.log,
|
||||
info: console.info,
|
||||
warn: console.warn,
|
||||
error: console.error,
|
||||
debug: console.debug,
|
||||
trace: console.trace,
|
||||
};
|
||||
snapshot = captureConsoleSnapshot();
|
||||
originalIsTty = process.stdout.isTTY;
|
||||
originalOpenClawTestConsole = process.env.OPENCLAW_TEST_CONSOLE;
|
||||
process.env.OPENCLAW_TEST_CONSOLE = "1";
|
||||
@@ -53,6 +42,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
<<<<<<< HEAD
|
||||
console.log = snapshot.log;
|
||||
console.info = snapshot.info;
|
||||
console.warn = snapshot.warn;
|
||||
@@ -64,6 +54,16 @@ afterEach(() => {
|
||||
} else {
|
||||
process.env.OPENCLAW_TEST_CONSOLE = originalOpenClawTestConsole;
|
||||
}
|
||||
||||||| parent of 4a741746c (refactor: dedupe agent and reply runtimes)
|
||||
console.log = snapshot.log;
|
||||
console.info = snapshot.info;
|
||||
console.warn = snapshot.warn;
|
||||
console.error = snapshot.error;
|
||||
console.debug = snapshot.debug;
|
||||
console.trace = snapshot.trace;
|
||||
=======
|
||||
restoreConsoleSnapshot(snapshot);
|
||||
>>>>>>> 4a741746c (refactor: dedupe agent and reply runtimes)
|
||||
Object.defineProperty(process.stdout, "isTTY", { value: originalIsTty, configurable: true });
|
||||
logging.setConsoleConfigLoaderForTests();
|
||||
vi.restoreAllMocks();
|
||||
|
||||
28
src/logging/test-helpers/console-snapshot.ts
Normal file
28
src/logging/test-helpers/console-snapshot.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
export type ConsoleSnapshot = {
|
||||
log: typeof console.log;
|
||||
info: typeof console.info;
|
||||
warn: typeof console.warn;
|
||||
error: typeof console.error;
|
||||
debug: typeof console.debug;
|
||||
trace: typeof console.trace;
|
||||
};
|
||||
|
||||
export function captureConsoleSnapshot(): ConsoleSnapshot {
|
||||
return {
|
||||
log: console.log,
|
||||
info: console.info,
|
||||
warn: console.warn,
|
||||
error: console.error,
|
||||
debug: console.debug,
|
||||
trace: console.trace,
|
||||
};
|
||||
}
|
||||
|
||||
export function restoreConsoleSnapshot(snapshot: ConsoleSnapshot): void {
|
||||
console.log = snapshot.log;
|
||||
console.info = snapshot.info;
|
||||
console.warn = snapshot.warn;
|
||||
console.error = snapshot.error;
|
||||
console.debug = snapshot.debug;
|
||||
console.trace = snapshot.trace;
|
||||
}
|
||||
Reference in New Issue
Block a user