Merged via squash. Prepared head SHA: d18356cb8062935090466d4e142ce202381d4ef2 Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
173 lines
5.4 KiB
TypeScript
173 lines
5.4 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { setConsoleSubsystemFilter } from "./console.js";
|
|
import { resetLogger, setLoggerOverride } from "./logger.js";
|
|
import { loggingState } from "./state.js";
|
|
import { createSubsystemLogger } from "./subsystem.js";
|
|
|
|
afterEach(() => {
|
|
setConsoleSubsystemFilter(null);
|
|
setLoggerOverride(null);
|
|
loggingState.rawConsole = null;
|
|
resetLogger();
|
|
});
|
|
|
|
describe("createSubsystemLogger().isEnabled", () => {
|
|
it("returns true for any/file when only file logging would emit", () => {
|
|
setLoggerOverride({ level: "debug", consoleLevel: "silent" });
|
|
const log = createSubsystemLogger("agent/embedded");
|
|
|
|
expect(log.isEnabled("debug")).toBe(true);
|
|
expect(log.isEnabled("debug", "file")).toBe(true);
|
|
expect(log.isEnabled("debug", "console")).toBe(false);
|
|
});
|
|
|
|
it("returns true for any/console when only console logging would emit", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "debug" });
|
|
const log = createSubsystemLogger("agent/embedded");
|
|
|
|
expect(log.isEnabled("debug")).toBe(true);
|
|
expect(log.isEnabled("debug", "console")).toBe(true);
|
|
expect(log.isEnabled("debug", "file")).toBe(false);
|
|
});
|
|
|
|
it("returns false when neither console nor file logging would emit", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "silent" });
|
|
const log = createSubsystemLogger("agent/embedded");
|
|
|
|
expect(log.isEnabled("debug")).toBe(false);
|
|
expect(log.isEnabled("debug", "console")).toBe(false);
|
|
expect(log.isEnabled("debug", "file")).toBe(false);
|
|
});
|
|
|
|
it("honors console subsystem filters for console target", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "info" });
|
|
setConsoleSubsystemFilter(["gateway"]);
|
|
const log = createSubsystemLogger("agent/embedded");
|
|
|
|
expect(log.isEnabled("info", "console")).toBe(false);
|
|
});
|
|
|
|
it("does not apply console subsystem filters to file target", () => {
|
|
setLoggerOverride({ level: "info", consoleLevel: "silent" });
|
|
setConsoleSubsystemFilter(["gateway"]);
|
|
const log = createSubsystemLogger("agent/embedded");
|
|
|
|
expect(log.isEnabled("info", "file")).toBe(true);
|
|
expect(log.isEnabled("info")).toBe(true);
|
|
});
|
|
|
|
it("suppresses probe warnings for embedded subsystems based on structured run metadata", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "warn" });
|
|
const warn = vi.fn();
|
|
loggingState.rawConsole = {
|
|
log: vi.fn(),
|
|
info: vi.fn(),
|
|
warn,
|
|
error: vi.fn(),
|
|
};
|
|
const log = createSubsystemLogger("agent/embedded").child("failover");
|
|
|
|
log.warn("embedded run failover decision", {
|
|
runId: "probe-test-run",
|
|
consoleMessage: "embedded run failover decision",
|
|
});
|
|
|
|
expect(warn).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not suppress probe errors for embedded subsystems", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "error" });
|
|
const error = vi.fn();
|
|
loggingState.rawConsole = {
|
|
log: vi.fn(),
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error,
|
|
};
|
|
const log = createSubsystemLogger("agent/embedded").child("failover");
|
|
|
|
log.error("embedded run failover decision", {
|
|
runId: "probe-test-run",
|
|
consoleMessage: "embedded run failover decision",
|
|
});
|
|
|
|
expect(error).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("suppresses probe warnings for model-fallback child subsystems based on structured run metadata", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "warn" });
|
|
const warn = vi.fn();
|
|
loggingState.rawConsole = {
|
|
log: vi.fn(),
|
|
info: vi.fn(),
|
|
warn,
|
|
error: vi.fn(),
|
|
};
|
|
const log = createSubsystemLogger("model-fallback").child("decision");
|
|
|
|
log.warn("model fallback decision", {
|
|
runId: "probe-test-run",
|
|
consoleMessage: "model fallback decision",
|
|
});
|
|
|
|
expect(warn).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not suppress probe errors for model-fallback child subsystems", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "error" });
|
|
const error = vi.fn();
|
|
loggingState.rawConsole = {
|
|
log: vi.fn(),
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error,
|
|
};
|
|
const log = createSubsystemLogger("model-fallback").child("decision");
|
|
|
|
log.error("model fallback decision", {
|
|
runId: "probe-test-run",
|
|
consoleMessage: "model fallback decision",
|
|
});
|
|
|
|
expect(error).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("still emits non-probe warnings for embedded subsystems", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "warn" });
|
|
const warn = vi.fn();
|
|
loggingState.rawConsole = {
|
|
log: vi.fn(),
|
|
info: vi.fn(),
|
|
warn,
|
|
error: vi.fn(),
|
|
};
|
|
const log = createSubsystemLogger("agent/embedded").child("auth-profiles");
|
|
|
|
log.warn("auth profile failure state updated", {
|
|
runId: "run-123",
|
|
consoleMessage: "auth profile failure state updated",
|
|
});
|
|
|
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("still emits non-probe model-fallback child warnings", () => {
|
|
setLoggerOverride({ level: "silent", consoleLevel: "warn" });
|
|
const warn = vi.fn();
|
|
loggingState.rawConsole = {
|
|
log: vi.fn(),
|
|
info: vi.fn(),
|
|
warn,
|
|
error: vi.fn(),
|
|
};
|
|
const log = createSubsystemLogger("model-fallback").child("decision");
|
|
|
|
log.warn("model fallback decision", {
|
|
runId: "run-123",
|
|
consoleMessage: "model fallback decision",
|
|
});
|
|
|
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|