Matrix: reuse crypto availability status

This commit is contained in:
Gustavo Madeira Santana
2026-04-10 12:12:01 -04:00
parent d9d0e0c16e
commit dfe29e36bb
5 changed files with 17 additions and 6 deletions

View File

@@ -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.",

View File

@@ -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")}`,

View File

@@ -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.",

View File

@@ -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,

View File

@@ -19,6 +19,7 @@ type MatrixLegacyCryptoPlan = {
};
type MatrixLegacyCryptoDetection = {
inspectorAvailable: boolean;
plans: MatrixLegacyCryptoPlan[];
warnings: string[];
};