Compare commits

...

3 Commits

Author SHA1 Message Date
Gustavo Madeira Santana
a5af238053 Matrix: trim dead client config exports 2026-04-09 01:27:35 -04:00
Gustavo Madeira Santana
043c4b1947 Matrix: remove native approval wrapper 2026-04-09 01:27:33 -04:00
Gustavo Madeira Santana
39d273cbbe Matrix: drop dead helper aliases 2026-04-09 01:27:31 -04:00
6 changed files with 28 additions and 96 deletions

View File

@@ -1,6 +1,6 @@
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
import { describe, expect, it } from "vitest";
import { matrixApprovalCapability, matrixNativeApprovalAdapter } from "./approval-native.js";
import { matrixApprovalCapability } from "./approval-native.js";
function buildConfig(
overrides?: Partial<NonNullable<NonNullable<OpenClawConfig["channels"]>["matrix"]>>,
@@ -46,7 +46,7 @@ describe("matrix native approval adapter", () => {
});
it("describes native matrix approval delivery capabilities", () => {
const capabilities = matrixNativeApprovalAdapter.native?.describeDeliveryCapabilities({
const capabilities = matrixApprovalCapability.native?.describeDeliveryCapabilities({
cfg: buildConfig(),
accountId: "default",
approvalKind: "exec",
@@ -74,7 +74,7 @@ describe("matrix native approval adapter", () => {
});
it("resolves origin targets from matrix turn source", async () => {
const target = await matrixNativeApprovalAdapter.native?.resolveOriginTarget?.({
const target = await matrixApprovalCapability.native?.resolveOriginTarget?.({
cfg: buildConfig(),
accountId: "default",
approvalKind: "exec",
@@ -100,7 +100,7 @@ describe("matrix native approval adapter", () => {
});
it("resolves approver dm targets", async () => {
const targets = await matrixNativeApprovalAdapter.native?.resolveApproverDmTargets?.({
const targets = await matrixApprovalCapability.native?.resolveApproverDmTargets?.({
cfg: buildConfig(),
accountId: "default",
approvalKind: "exec",
@@ -118,7 +118,7 @@ describe("matrix native approval adapter", () => {
});
it("falls back to the session-key origin target for plugin approvals when the store is missing", async () => {
const target = await matrixNativeApprovalAdapter.native?.resolveOriginTarget?.({
const target = await matrixApprovalCapability.native?.resolveOriginTarget?.({
cfg: buildConfig({
dm: { allowFrom: ["@owner:example.org"] },
}),
@@ -144,7 +144,7 @@ describe("matrix native approval adapter", () => {
});
it("suppresses same-channel plugin forwarding when Matrix native delivery is available", () => {
const shouldSuppress = matrixNativeApprovalAdapter.delivery?.shouldSuppressForwardingFallback;
const shouldSuppress = matrixApprovalCapability.delivery?.shouldSuppressForwardingFallback;
if (!shouldSuppress) {
throw new Error("delivery suppression helper unavailable");
}
@@ -178,7 +178,7 @@ describe("matrix native approval adapter", () => {
});
it("preserves room-id case when matching Matrix origin targets", async () => {
const target = await matrixNativeApprovalAdapter.native?.resolveOriginTarget?.({
const target = await matrixApprovalCapability.native?.resolveOriginTarget?.({
cfg: buildConfig(),
accountId: "default",
approvalKind: "exec",
@@ -300,7 +300,7 @@ describe("matrix native approval adapter", () => {
});
it("enables matrix-native plugin approval delivery when DM approvers are configured", () => {
const capabilities = matrixNativeApprovalAdapter.native?.describeDeliveryCapabilities({
const capabilities = matrixApprovalCapability.native?.describeDeliveryCapabilities({
cfg: buildConfig({
dm: { allowFrom: ["@owner:example.org"] },
}),
@@ -328,7 +328,7 @@ describe("matrix native approval adapter", () => {
});
it("keeps matrix-native plugin approval delivery disabled without DM approvers", () => {
const capabilities = matrixNativeApprovalAdapter.native?.describeDeliveryCapabilities({
const capabilities = matrixApprovalCapability.native?.describeDeliveryCapabilities({
cfg: buildConfig(),
accountId: "default",
approvalKind: "plugin",

View File

@@ -334,15 +334,3 @@ export const matrixApprovalCapability = createChannelApprovalCapability({
native: matrixNativeAdapter,
render: matrixNativeApprovalCapability.render,
});
export const matrixNativeApprovalAdapter = {
auth: {
authorizeActorAction: matrixApprovalCapability.authorizeActorAction,
getActionAvailabilityState: matrixApprovalCapability.getActionAvailabilityState,
getExecInitiatingSurfaceState: matrixApprovalCapability.getExecInitiatingSurfaceState,
},
delivery: matrixDeliveryAdapter,
nativeRuntime: matrixApprovalCapability.nativeRuntime,
render: matrixApprovalCapability.render,
native: matrixNativeAdapter,
};

View File

@@ -21,5 +21,3 @@ export async function resolveMatrixApproval(params: {
clientDisplayName: `Matrix approval (${params.senderId?.trim() || "unknown"})`,
});
}
export const resolveMatrixExecApproval = resolveMatrixApproval;

View File

@@ -42,8 +42,6 @@ vi.mock("./client/storage.js", async () => {
const {
backfillMatrixAuthDeviceIdAfterStartup,
getMatrixScopedEnvVarNames,
resolveImplicitMatrixAccountId,
resolveMatrixConfig,
resolveMatrixConfigForAccount,
resolveMatrixAuth,
resolveMatrixAuthContext,
@@ -69,11 +67,18 @@ function requireCredentialsReadModule(): typeof import("./credentials-read.js")
return credentialsReadModule;
}
function resolveDefaultMatrixAuthContext(
cfg: CoreConfig,
env: NodeJS.ProcessEnv = {} as NodeJS.ProcessEnv,
) {
return resolveMatrixAuthContext({ cfg, env });
}
beforeEach(() => {
installMatrixTestRuntime();
});
describe("resolveMatrixConfig", () => {
describe("Matrix auth/config live surfaces", () => {
it("prefers config over env", () => {
const cfg = {
channels: {
@@ -94,7 +99,7 @@ describe("resolveMatrixConfig", () => {
MATRIX_PASSWORD: "env-pass",
MATRIX_DEVICE_NAME: "EnvDevice",
} as NodeJS.ProcessEnv;
const resolved = resolveMatrixConfig(cfg, env);
const resolved = resolveDefaultMatrixAuthContext(cfg, env).resolved;
expect(resolved).toEqual({
homeserver: "https://cfg.example.org",
userId: "@cfg:example.org",
@@ -117,7 +122,7 @@ describe("resolveMatrixConfig", () => {
MATRIX_DEVICE_ID: "ENVDEVICE",
MATRIX_DEVICE_NAME: "EnvDevice",
} as NodeJS.ProcessEnv;
const resolved = resolveMatrixConfig(cfg, env);
const resolved = resolveDefaultMatrixAuthContext(cfg, env).resolved;
expect(resolved.homeserver).toBe("https://env.example.org");
expect(resolved.userId).toBe("@env:example.org");
expect(resolved.accessToken).toBe("env-token");
@@ -146,7 +151,7 @@ describe("resolveMatrixConfig", () => {
MATRIX_ACCESS_TOKEN: "env-token",
} as NodeJS.ProcessEnv;
const resolved = resolveMatrixConfig(cfg, env);
const resolved = resolveDefaultMatrixAuthContext(cfg, env).resolved;
expect(resolved.accessToken).toBe("env-token");
});
@@ -169,7 +174,7 @@ describe("resolveMatrixConfig", () => {
MATRIX_PASSWORD: "env-pass",
} as NodeJS.ProcessEnv;
const resolved = resolveMatrixConfig(cfg, env);
const resolved = resolveDefaultMatrixAuthContext(cfg, env).resolved;
expect(resolved.password).toBe("env-pass");
});
@@ -241,7 +246,7 @@ describe("resolveMatrixConfig", () => {
},
} as CoreConfig;
expect(() => resolveMatrixConfig(cfg, {} as NodeJS.ProcessEnv)).toThrow(
expect(() => resolveDefaultMatrixAuthContext(cfg, {} as NodeJS.ProcessEnv)).toThrow(
/channels\.matrix\.accessToken: unresolved SecretRef "env:default:MATRIX_ACCESS_TOKEN"/i,
);
});
@@ -265,7 +270,7 @@ describe("resolveMatrixConfig", () => {
} as CoreConfig;
expect(() =>
resolveMatrixConfig(cfg, {
resolveDefaultMatrixAuthContext(cfg, {
MATRIX_ACCESS_TOKEN: "env-token",
} as NodeJS.ProcessEnv),
).toThrow(/not allowlisted in secrets\.providers\.matrix-env\.allowlist/i);
@@ -289,7 +294,9 @@ describe("resolveMatrixConfig", () => {
},
} as CoreConfig;
expect(resolveMatrixConfig(cfg, {} as NodeJS.ProcessEnv).accessToken).toBeUndefined();
expect(
resolveDefaultMatrixAuthContext(cfg, {} as NodeJS.ProcessEnv).resolved.accessToken,
).toBeUndefined();
});
it("uses account-scoped env vars for non-default accounts before global env", () => {
@@ -368,7 +375,6 @@ describe("resolveMatrixConfig", () => {
},
} as CoreConfig;
expect(resolveImplicitMatrixAccountId(cfg, {} as NodeJS.ProcessEnv)).toBe("default");
expect(resolveMatrixAuthContext({ cfg, env: {} as NodeJS.ProcessEnv }).accountId).toBe(
"default",
);
@@ -392,7 +398,6 @@ describe("resolveMatrixConfig", () => {
},
} as CoreConfig;
expect(resolveImplicitMatrixAccountId(cfg, {} as NodeJS.ProcessEnv)).toBeNull();
expect(() => resolveMatrixAuthContext({ cfg, env: {} as NodeJS.ProcessEnv })).toThrow(
/channels\.matrix\.defaultAccount.*--account <id>/i,
);
@@ -413,7 +418,6 @@ describe("resolveMatrixConfig", () => {
},
} as CoreConfig;
expect(resolveImplicitMatrixAccountId(cfg, {} as NodeJS.ProcessEnv)).toBe("ops");
expect(resolveMatrixAuthContext({ cfg, env: {} as NodeJS.ProcessEnv }).accountId).toBe("ops");
});
@@ -432,7 +436,6 @@ describe("resolveMatrixConfig", () => {
},
} as CoreConfig;
expect(resolveImplicitMatrixAccountId(cfg, {} as NodeJS.ProcessEnv)).toBe("ops");
expect(resolveMatrixAuthContext({ cfg, env: {} as NodeJS.ProcessEnv }).accountId).toBe("ops");
});
@@ -449,7 +452,6 @@ describe("resolveMatrixConfig", () => {
MATRIX_OPS_ACCESS_TOKEN: "ops-token",
} as NodeJS.ProcessEnv;
expect(resolveImplicitMatrixAccountId(cfg, env)).toBeNull();
expect(() => resolveMatrixAuthContext({ cfg, env })).toThrow(
/channels\.matrix\.defaultAccount.*--account <id>/i,
);
@@ -467,7 +469,6 @@ describe("resolveMatrixConfig", () => {
MATRIX_OPS_ACCESS_TOKEN: "ops-token",
} as NodeJS.ProcessEnv;
expect(resolveImplicitMatrixAccountId(cfg, env)).toBe("ops");
expect(resolveMatrixAuthContext({ cfg, env }).accountId).toBe("ops");
});
@@ -487,7 +488,6 @@ describe("resolveMatrixConfig", () => {
},
} as CoreConfig;
expect(resolveImplicitMatrixAccountId(cfg, {} as NodeJS.ProcessEnv)).toBe("ops");
expect(resolveMatrixAuthContext({ cfg, env: {} as NodeJS.ProcessEnv }).accountId).toBe("ops");
});
@@ -504,7 +504,6 @@ describe("resolveMatrixConfig", () => {
MATRIX_OPS_ACCESS_TOKEN: "ops-token",
} as NodeJS.ProcessEnv;
expect(resolveImplicitMatrixAccountId(cfg, env)).toBe("ops");
expect(resolveMatrixAuthContext({ cfg, env }).accountId).toBe("ops");
});
@@ -520,7 +519,6 @@ describe("resolveMatrixConfig", () => {
MATRIX_OPS_USER_ID: "@ops:example.org",
} as NodeJS.ProcessEnv;
expect(resolveImplicitMatrixAccountId(cfg, env)).toBe("ops");
expect(resolveMatrixAuthContext({ cfg, env }).accountId).toBe("ops");
});
@@ -686,7 +684,7 @@ describe("resolveMatrixConfig", () => {
},
} as CoreConfig;
const resolved = resolveMatrixConfig(cfg, {} as NodeJS.ProcessEnv);
const resolved = resolveDefaultMatrixAuthContext(cfg, {} as NodeJS.ProcessEnv).resolved;
expect(resolved.dispatcherPolicy).toEqual({
mode: "explicit-proxy",

View File

@@ -589,54 +589,6 @@ export async function resolveValidatedMatrixHomeserverUrl(
return normalized;
}
export function resolveMatrixConfig(
cfg: CoreConfig = getMatrixRuntime().config.loadConfig() as CoreConfig,
env: NodeJS.ProcessEnv = process.env,
): MatrixResolvedConfig {
const matrix = resolveMatrixBaseConfig(cfg);
const suppressInactivePasswordSecretRef = hasConfiguredMatrixAccessTokenSource({
cfg,
env,
accountId: DEFAULT_ACCOUNT_ID,
});
const fieldReadOptions = {
env,
config: cfg,
};
const defaultScopedEnv = resolveScopedMatrixEnvConfig(DEFAULT_ACCOUNT_ID, env);
const globalEnv = resolveGlobalMatrixEnvConfig(env);
const resolvedStrings = resolveMatrixAccountStringValues({
accountId: DEFAULT_ACCOUNT_ID,
scopedEnv: defaultScopedEnv,
channel: {
homeserver: readMatrixBaseConfigField(matrix, "homeserver", fieldReadOptions),
userId: readMatrixBaseConfigField(matrix, "userId", fieldReadOptions),
accessToken: readMatrixBaseConfigField(matrix, "accessToken", fieldReadOptions),
password: readMatrixBaseConfigField(matrix, "password", {
...fieldReadOptions,
suppressSecretRef: suppressInactivePasswordSecretRef,
}),
deviceId: readMatrixBaseConfigField(matrix, "deviceId", fieldReadOptions),
deviceName: readMatrixBaseConfigField(matrix, "deviceName", fieldReadOptions),
},
globalEnv,
});
const initialSyncLimit = clampMatrixInitialSyncLimit(matrix.initialSyncLimit);
const encryption = matrix.encryption ?? false;
const allowPrivateNetwork = isPrivateNetworkOptInEnabled(matrix) ? true : undefined;
return {
homeserver: resolvedStrings.homeserver,
userId: resolvedStrings.userId,
accessToken: resolvedStrings.accessToken || undefined,
password: resolvedStrings.password || undefined,
deviceId: resolvedStrings.deviceId || undefined,
deviceName: resolvedStrings.deviceName || undefined,
initialSyncLimit,
encryption,
...buildMatrixNetworkFields({ allowPrivateNetwork, proxy: matrix.proxy }),
};
}
export function resolveMatrixConfigForAccount(
cfg: CoreConfig,
accountId: string,
@@ -712,7 +664,7 @@ export function resolveMatrixConfigForAccount(
};
}
export function resolveImplicitMatrixAccountId(
function resolveImplicitMatrixAccountId(
cfg: CoreConfig,
env: NodeJS.ProcessEnv = process.env,
): string | null {

View File

@@ -92,7 +92,3 @@ export function resolveMatrixAllowListMatch(params: {
];
return resolveAllowlistMatchByCandidates<MatrixAllowListMatchSource>({ allowList, candidates });
}
export function resolveMatrixAllowListMatches(params: { allowList: string[]; userId?: string }) {
return resolveMatrixAllowListMatch(params).allowed;
}