mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-23 21:18:11 +00:00
Matrix-js: quiet verify logs unless verbose
This commit is contained in:
@@ -6,6 +6,7 @@ const bootstrapMatrixVerificationMock = vi.fn();
|
||||
const getMatrixRoomKeyBackupStatusMock = vi.fn();
|
||||
const getMatrixVerificationStatusMock = vi.fn();
|
||||
const restoreMatrixRoomKeyBackupMock = vi.fn();
|
||||
const setMatrixSdkLogModeMock = vi.fn();
|
||||
const verifyMatrixRecoveryKeyMock = vi.fn();
|
||||
|
||||
vi.mock("./matrix/actions/verification.js", () => ({
|
||||
@@ -16,6 +17,10 @@ vi.mock("./matrix/actions/verification.js", () => ({
|
||||
verifyMatrixRecoveryKey: (...args: unknown[]) => verifyMatrixRecoveryKeyMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock("./matrix/client/logging.js", () => ({
|
||||
setMatrixSdkLogMode: (...args: unknown[]) => setMatrixSdkLogModeMock(...args),
|
||||
}));
|
||||
|
||||
let registerMatrixJsCli: typeof import("./cli.js").registerMatrixJsCli;
|
||||
|
||||
function buildProgram(): Command {
|
||||
@@ -140,6 +145,8 @@ describe("matrix-js CLI verification commands", () => {
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
`Recovery key created at: ${formatExpectedLocalTimestamp(recoveryCreatedAt)}`,
|
||||
);
|
||||
expect(console.log).toHaveBeenCalledWith("Diagnostics:");
|
||||
expect(setMatrixSdkLogModeMock).toHaveBeenCalledWith("default");
|
||||
});
|
||||
|
||||
it("prints local timezone timestamps for verify bootstrap and device output in verbose mode", async () => {
|
||||
@@ -242,7 +249,9 @@ describe("matrix-js CLI verification commands", () => {
|
||||
`Recovery key created at: ${formatExpectedLocalTimestamp(recoveryCreatedAt)}`,
|
||||
);
|
||||
expect(console.log).not.toHaveBeenCalledWith("Pending verifications: 0");
|
||||
expect(console.log).not.toHaveBeenCalledWith("Diagnostics:");
|
||||
expect(console.log).toHaveBeenCalledWith("Backup: active and trusted on this device");
|
||||
expect(setMatrixSdkLogModeMock).toHaveBeenCalledWith("quiet");
|
||||
});
|
||||
|
||||
it("prints backup health lines for verify backup status in verbose mode", async () => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
restoreMatrixRoomKeyBackup,
|
||||
verifyMatrixRecoveryKey,
|
||||
} from "./matrix/actions/verification.js";
|
||||
import { setMatrixSdkLogMode } from "./matrix/client/logging.js";
|
||||
|
||||
let matrixJsCliExitScheduled = false;
|
||||
|
||||
@@ -43,6 +44,10 @@ function printTimestamp(label: string, value: string | null | undefined): void {
|
||||
}
|
||||
}
|
||||
|
||||
function configureCliLogMode(verbose: boolean): void {
|
||||
setMatrixSdkLogMode(verbose ? "default" : "quiet");
|
||||
}
|
||||
|
||||
type MatrixCliBackupStatus = {
|
||||
serverVersion: string | null;
|
||||
activeVersion: string | null;
|
||||
@@ -155,23 +160,18 @@ function printGuidance(lines: string[]): void {
|
||||
|
||||
function printVerificationStatus(status: MatrixCliVerificationStatus, verbose = false): void {
|
||||
const backup = resolveBackupStatus(status);
|
||||
if (status.verified) {
|
||||
console.log("Verified: yes");
|
||||
console.log(`User: ${status.userId ?? "unknown"}`);
|
||||
console.log(`Device: ${status.deviceId ?? "unknown"}`);
|
||||
} else {
|
||||
console.log("Verified: no");
|
||||
console.log(`User: ${status.userId ?? "unknown"}`);
|
||||
console.log(`Device: ${status.deviceId ?? "unknown"}`);
|
||||
}
|
||||
console.log(`Verified: ${status.verified ? "yes" : "no"}`);
|
||||
printBackupSummary(backup);
|
||||
if (verbose) {
|
||||
console.log("Diagnostics:");
|
||||
console.log(`User: ${status.userId ?? "unknown"}`);
|
||||
console.log(`Device: ${status.deviceId ?? "unknown"}`);
|
||||
printBackupStatus(backup);
|
||||
}
|
||||
console.log(`Recovery key stored: ${status.recoveryKeyStored ? "yes" : "no"}`);
|
||||
if (verbose) {
|
||||
console.log(`Recovery key stored: ${status.recoveryKeyStored ? "yes" : "no"}`);
|
||||
printTimestamp("Recovery key created at", status.recoveryKeyCreatedAt);
|
||||
console.log(`Pending verifications: ${status.pendingVerifications}`);
|
||||
} else {
|
||||
console.log(`Recovery key stored: ${status.recoveryKeyStored ? "yes" : "no"}`);
|
||||
}
|
||||
printGuidance(buildVerificationGuidance(status));
|
||||
}
|
||||
@@ -198,6 +198,7 @@ export function registerMatrixJsCli(params: { program: Command }): void {
|
||||
includeRecoveryKey?: boolean;
|
||||
json?: boolean;
|
||||
}) => {
|
||||
configureCliLogMode(options.verbose === true);
|
||||
try {
|
||||
const status = await getMatrixVerificationStatus({
|
||||
accountId: options.account,
|
||||
@@ -231,6 +232,7 @@ export function registerMatrixJsCli(params: { program: Command }): void {
|
||||
.option("--verbose", "Show detailed diagnostics")
|
||||
.option("--json", "Output as JSON")
|
||||
.action(async (options: { account?: string; verbose?: boolean; json?: boolean }) => {
|
||||
configureCliLogMode(options.verbose === true);
|
||||
try {
|
||||
const status = await getMatrixRoomKeyBackupStatus({ accountId: options.account });
|
||||
if (options.json) {
|
||||
@@ -268,6 +270,7 @@ export function registerMatrixJsCli(params: { program: Command }): void {
|
||||
verbose?: boolean;
|
||||
json?: boolean;
|
||||
}) => {
|
||||
configureCliLogMode(options.verbose === true);
|
||||
try {
|
||||
const result = await restoreMatrixRoomKeyBackup({
|
||||
accountId: options.account,
|
||||
@@ -327,6 +330,7 @@ export function registerMatrixJsCli(params: { program: Command }): void {
|
||||
verbose?: boolean;
|
||||
json?: boolean;
|
||||
}) => {
|
||||
configureCliLogMode(options.verbose === true);
|
||||
try {
|
||||
const result = await bootstrapMatrixVerification({
|
||||
accountId: options.account,
|
||||
@@ -389,6 +393,7 @@ export function registerMatrixJsCli(params: { program: Command }): void {
|
||||
.option("--json", "Output as JSON")
|
||||
.action(
|
||||
async (key: string, options: { account?: string; verbose?: boolean; json?: boolean }) => {
|
||||
configureCliLogMode(options.verbose === true);
|
||||
try {
|
||||
const result = await verifyMatrixRecoveryKey(key, { accountId: options.account });
|
||||
if (options.json) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ConsoleLogger, LogService } from "../sdk/logger.js";
|
||||
|
||||
let matrixSdkLoggingConfigured = false;
|
||||
let matrixSdkLogMode: "default" | "quiet" = "default";
|
||||
const matrixSdkBaseLogger = new ConsoleLogger();
|
||||
|
||||
function shouldSuppressMatrixHttpNotFound(module: string, messageOrObject: unknown[]): boolean {
|
||||
@@ -16,10 +17,31 @@ function shouldSuppressMatrixHttpNotFound(module: string, messageOrObject: unkno
|
||||
}
|
||||
|
||||
export function ensureMatrixSdkLoggingConfigured(): void {
|
||||
if (matrixSdkLoggingConfigured) {
|
||||
if (!matrixSdkLoggingConfigured) {
|
||||
matrixSdkLoggingConfigured = true;
|
||||
}
|
||||
applyMatrixSdkLogger();
|
||||
}
|
||||
|
||||
export function setMatrixSdkLogMode(mode: "default" | "quiet"): void {
|
||||
matrixSdkLogMode = mode;
|
||||
if (!matrixSdkLoggingConfigured) {
|
||||
return;
|
||||
}
|
||||
applyMatrixSdkLogger();
|
||||
}
|
||||
|
||||
function applyMatrixSdkLogger(): void {
|
||||
if (matrixSdkLogMode === "quiet") {
|
||||
LogService.setLogger({
|
||||
trace: () => {},
|
||||
debug: () => {},
|
||||
info: () => {},
|
||||
warn: () => {},
|
||||
error: () => {},
|
||||
});
|
||||
return;
|
||||
}
|
||||
matrixSdkLoggingConfigured = true;
|
||||
|
||||
LogService.setLogger({
|
||||
trace: (module, ...messageOrObject) => matrixSdkBaseLogger.trace(module, ...messageOrObject),
|
||||
|
||||
Reference in New Issue
Block a user