mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 03:40:20 +00:00
test: stabilize model warning sanitizer checks
This commit is contained in:
33
src/logging/test-helpers/warn-log-capture.ts
Normal file
33
src/logging/test-helpers/warn-log-capture.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import {
|
||||
registerLogTransport,
|
||||
resetLogger,
|
||||
setLoggerOverride,
|
||||
type LogTransportRecord,
|
||||
} from "../logger.js";
|
||||
|
||||
export function createWarnLogCapture(prefix: string) {
|
||||
const records: LogTransportRecord[] = [];
|
||||
setLoggerOverride({
|
||||
level: "warn",
|
||||
consoleLevel: "silent",
|
||||
file: path.join(os.tmpdir(), `${prefix}-${process.pid}-${Date.now()}.log`),
|
||||
});
|
||||
const unregister = registerLogTransport((record) => {
|
||||
records.push(record);
|
||||
});
|
||||
return {
|
||||
findText(needle: string): string | undefined {
|
||||
return records
|
||||
.flatMap((record) => Object.values(record))
|
||||
.filter((value): value is string => typeof value === "string")
|
||||
.find((value) => value.includes(needle));
|
||||
},
|
||||
cleanup() {
|
||||
unregister();
|
||||
setLoggerOverride(null);
|
||||
resetLogger();
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user