mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 13:40:44 +00:00
test: tighten logging assertions
This commit is contained in:
@@ -50,18 +50,20 @@ describe("diagnostic log events", () => {
|
||||
unsubscribe();
|
||||
|
||||
expect(received).toHaveLength(1);
|
||||
expect(received[0]).toMatchObject({
|
||||
type: "log.record",
|
||||
level: "INFO",
|
||||
message: "hello diagnostic logs",
|
||||
attributes: {
|
||||
subsystem: "diagnostic",
|
||||
runId: "run-1",
|
||||
},
|
||||
trace: {
|
||||
traceId: TRACE_ID,
|
||||
spanId: SPAN_ID,
|
||||
},
|
||||
const [event] = received;
|
||||
if (!event) {
|
||||
throw new Error("missing diagnostic log event");
|
||||
}
|
||||
expect(event.type).toBe("log.record");
|
||||
expect(event.level).toBe("INFO");
|
||||
expect(event.message).toBe("hello diagnostic logs");
|
||||
expect(event.attributes).toStrictEqual({
|
||||
subsystem: "diagnostic",
|
||||
runId: "run-1",
|
||||
});
|
||||
expect(event.trace).toStrictEqual({
|
||||
traceId: TRACE_ID,
|
||||
spanId: SPAN_ID,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -121,17 +123,9 @@ describe("diagnostic log events", () => {
|
||||
expect(event.attributes?.token).not.toBe(secret);
|
||||
expect(String(event.attributes?.token)).toContain("…");
|
||||
expect(String(event.attributes?.longValue).length).toBeLessThanOrEqual(2100);
|
||||
expect(event.attributes).toEqual(
|
||||
expect.not.objectContaining({
|
||||
nested: expect.anything(),
|
||||
"bad key": expect.anything(),
|
||||
}),
|
||||
);
|
||||
expect(event).toEqual(
|
||||
expect.not.objectContaining({
|
||||
argsJson: expect.anything(),
|
||||
}),
|
||||
);
|
||||
expect(Object.hasOwn(event.attributes ?? {}, "nested")).toBe(false);
|
||||
expect(Object.hasOwn(event.attributes ?? {}, "bad key")).toBe(false);
|
||||
expect(Object.hasOwn(event, "argsJson")).toBe(false);
|
||||
});
|
||||
|
||||
it("drops sensitive, blocked, and excess log attribute keys without copying large objects", async () => {
|
||||
|
||||
@@ -124,10 +124,7 @@ describe("getChildLogger minLevel inheritance", () => {
|
||||
|
||||
logging.toPinoLikeLogger(base, "info").child({ component: "test" });
|
||||
|
||||
expect(getSubLoggerSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
minLevel: logging.levelToMinLevel("error"),
|
||||
}),
|
||||
);
|
||||
expect(getSubLoggerSpy).toHaveBeenCalledOnce();
|
||||
expect(getSubLoggerSpy.mock.calls[0]?.[0]?.minLevel).toBe(logging.levelToMinLevel("error"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,11 +55,9 @@ describe("getResolvedLoggerSettings", () => {
|
||||
|
||||
const settings = logging.getResolvedLoggerSettings();
|
||||
|
||||
expect(settings).toMatchObject({
|
||||
level: "debug",
|
||||
file: "/tmp/openclaw-configured.log",
|
||||
maxFileBytes: 2048,
|
||||
});
|
||||
expect(settings.level).toBe("debug");
|
||||
expect(settings.file).toBe("/tmp/openclaw-configured.log");
|
||||
expect(settings.maxFileBytes).toBe(2048);
|
||||
});
|
||||
|
||||
it("uses defaults when no logging config is available", () => {
|
||||
|
||||
@@ -15,13 +15,11 @@ describe("parseLogLine", () => {
|
||||
|
||||
const parsed = parseLogLine(line);
|
||||
|
||||
expect(parsed).toMatchObject({
|
||||
time: "2026-01-09T01:38:41.523Z",
|
||||
level: "info",
|
||||
subsystem: "gateway/channels/demo-channel",
|
||||
message: '{"subsystem":"gateway/channels/demo-channel"} connected',
|
||||
raw: line,
|
||||
});
|
||||
expect(parsed?.time).toBe("2026-01-09T01:38:41.523Z");
|
||||
expect(parsed?.level).toBe("info");
|
||||
expect(parsed?.subsystem).toBe("gateway/channels/demo-channel");
|
||||
expect(parsed?.message).toBe('{"subsystem":"gateway/channels/demo-channel"} connected');
|
||||
expect(parsed?.raw).toBe(line);
|
||||
});
|
||||
|
||||
it("falls back to meta timestamp when top-level time is missing", () => {
|
||||
|
||||
Reference in New Issue
Block a user