From dfe29e36bb41ba42401efcd95927cca3bea77ea7 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Fri, 10 Apr 2026 12:12:01 -0400 Subject: [PATCH] Matrix: reuse crypto availability status --- extensions/matrix/src/legacy-crypto.test.ts | 2 ++ extensions/matrix/src/legacy-crypto.ts | 14 +++++++++++--- extensions/matrix/src/migration-snapshot.test.ts | 2 ++ extensions/matrix/src/migration-snapshot.ts | 4 +--- src/plugin-sdk/matrix-runtime-heavy.ts | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/extensions/matrix/src/legacy-crypto.test.ts b/extensions/matrix/src/legacy-crypto.test.ts index c85aea4f7e0..e161bdec104 100644 --- a/extensions/matrix/src/legacy-crypto.test.ts +++ b/extensions/matrix/src/legacy-crypto.test.ts @@ -92,6 +92,7 @@ describe("matrix legacy encrypted-state migration", () => { const { cfg, rootDir } = writeDefaultLegacyCryptoFixture(home); const detection = detectLegacyMatrixCrypto({ cfg, env: process.env }); + expect(detection.inspectorAvailable).toBe(true); expect(detection.warnings).toEqual([]); expect(detection.plans).toHaveLength(1); @@ -210,6 +211,7 @@ describe("matrix legacy encrypted-state migration", () => { const { cfg } = writeDefaultLegacyCryptoFixture(home); const detection = detectLegacyMatrixCrypto({ cfg, env: process.env }); + expect(detection.inspectorAvailable).toBe(false); expect(detection.plans).toHaveLength(1); expect(detection.warnings).toContain( "Legacy Matrix encrypted state was detected, but the Matrix crypto inspector is unavailable.", diff --git a/extensions/matrix/src/legacy-crypto.ts b/extensions/matrix/src/legacy-crypto.ts index 7914807346a..da578c4f9c2 100644 --- a/extensions/matrix/src/legacy-crypto.ts +++ b/extensions/matrix/src/legacy-crypto.ts @@ -57,6 +57,7 @@ type MatrixLegacyCryptoPlan = { }; type MatrixLegacyCryptoDetection = { + inspectorAvailable: boolean; plans: MatrixLegacyCryptoPlan[]; warnings: string[]; }; @@ -324,13 +325,20 @@ export function detectLegacyMatrixCrypto(params: { cfg: params.cfg, env: params.env ?? process.env, }); - if (detection.plans.length > 0 && !isMatrixLegacyCryptoInspectorAvailable()) { + const inspectorAvailable = + detection.plans.length === 0 || isMatrixLegacyCryptoInspectorAvailable(); + if (!inspectorAvailable && detection.plans.length > 0) { return { + inspectorAvailable, plans: detection.plans, warnings: [...detection.warnings, MATRIX_LEGACY_CRYPTO_INSPECTOR_UNAVAILABLE_MESSAGE], }; } - return detection; + return { + inspectorAvailable, + plans: detection.plans, + warnings: detection.warnings, + }; } export async function autoPrepareLegacyMatrixCrypto(params: { @@ -359,7 +367,7 @@ export async function autoPrepareLegacyMatrixCrypto(params: { warnings, }; } - if (!params.deps?.inspectLegacyStore && !isMatrixLegacyCryptoInspectorAvailable()) { + if (!params.deps?.inspectLegacyStore && !detection.inspectorAvailable) { if (warnings.length > 0) { params.log?.warn?.( `matrix: legacy encrypted-state warnings:\n${warnings.map((entry) => `- ${entry}`).join("\n")}`, diff --git a/extensions/matrix/src/migration-snapshot.test.ts b/extensions/matrix/src/migration-snapshot.test.ts index 882bf2834c8..172de40fe64 100644 --- a/extensions/matrix/src/migration-snapshot.test.ts +++ b/extensions/matrix/src/migration-snapshot.test.ts @@ -124,6 +124,7 @@ describe("matrix migration snapshots", () => { cfg, env: process.env, }); + expect(detection.inspectorAvailable).toBe(true); expect(detection.plans).toHaveLength(1); expect(detection.warnings).toEqual([]); expect( @@ -167,6 +168,7 @@ describe("matrix migration snapshots", () => { cfg, env: process.env, }); + expect(detection.inspectorAvailable).toBe(false); expect(detection.plans).toHaveLength(1); expect(detection.warnings).toContain( "Legacy Matrix encrypted state was detected, but the Matrix crypto inspector is unavailable.", diff --git a/extensions/matrix/src/migration-snapshot.ts b/extensions/matrix/src/migration-snapshot.ts index 6fcfcb634d9..c5a518cf825 100644 --- a/extensions/matrix/src/migration-snapshot.ts +++ b/extensions/matrix/src/migration-snapshot.ts @@ -1,5 +1,4 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime"; -import { isMatrixLegacyCryptoInspectorAvailable } from "./legacy-crypto-inspector-availability.js"; import { detectLegacyMatrixCrypto } from "./legacy-crypto.js"; import { detectLegacyMatrixState } from "./legacy-state.js"; import { @@ -24,8 +23,7 @@ export function resolveMatrixMigrationStatus(params: { const legacyState = detectLegacyMatrixState({ cfg: params.cfg, env }); const legacyCrypto = detectLegacyMatrixCrypto({ cfg: params.cfg, env }); const actionableLegacyState = legacyState !== null && !("warning" in legacyState); - const actionableLegacyCrypto = - legacyCrypto.plans.length > 0 && isMatrixLegacyCryptoInspectorAvailable(); + const actionableLegacyCrypto = legacyCrypto.plans.length > 0 && legacyCrypto.inspectorAvailable; return { legacyState, legacyCrypto, diff --git a/src/plugin-sdk/matrix-runtime-heavy.ts b/src/plugin-sdk/matrix-runtime-heavy.ts index 21849426d22..e353cbe9af4 100644 --- a/src/plugin-sdk/matrix-runtime-heavy.ts +++ b/src/plugin-sdk/matrix-runtime-heavy.ts @@ -19,6 +19,7 @@ type MatrixLegacyCryptoPlan = { }; type MatrixLegacyCryptoDetection = { + inspectorAvailable: boolean; plans: MatrixLegacyCryptoPlan[]; warnings: string[]; };