openclaw/src/agents/auth-profiles/state-observation.test.ts
Altay 531e8362b1
Agents: add fallback error observations (#41337)
Merged via squash.

Prepared head SHA: 852469c82ff28fb0e1be7f1019f5283e712c4283
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
2026-03-10 01:12:10 +03:00

39 lines
1.3 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { resetLogger, setLoggerOverride } from "../../logging/logger.js";
import { logAuthProfileFailureStateChange } from "./state-observation.js";
afterEach(() => {
setLoggerOverride(null);
resetLogger();
});
describe("logAuthProfileFailureStateChange", () => {
it("sanitizes consoleMessage fields before logging", () => {
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
setLoggerOverride({ level: "silent", consoleLevel: "warn" });
logAuthProfileFailureStateChange({
runId: "run-1\nforged\tentry\rtest",
profileId: "openai:profile-1",
provider: "openai\u001b]8;;https://evil.test\u0007",
reason: "overloaded",
previous: undefined,
next: {
errorCount: 1,
cooldownUntil: 1_700_000_060_000,
failureCounts: { overloaded: 1 },
},
now: 1_700_000_000_000,
});
const consoleLine = warnSpy.mock.calls[0]?.[0];
expect(typeof consoleLine).toBe("string");
expect(consoleLine).toContain("runId=run-1 forged entry test");
expect(consoleLine).toContain("provider=openai]8;;https://evil.test");
expect(consoleLine).not.toContain("\n");
expect(consoleLine).not.toContain("\r");
expect(consoleLine).not.toContain("\t");
expect(consoleLine).not.toContain("\u001b");
});
});