Matrix: keep default account device fields scoped

This commit is contained in:
Gustavo Madeira Santana 2026-03-08 21:54:01 -04:00
parent 4ef8b360f7
commit ee4be1f989
No known key found for this signature in database
2 changed files with 15 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import type { PluginRuntime, RuntimeEnv } from "openclaw/plugin-sdk/matrix";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { matrixPlugin } from "./channel.js";
import { resolveMatrixConfigForAccount } from "./matrix/client/config.js";
import { setMatrixRuntime } from "./runtime.js";
import type { CoreConfig } from "./types.js";
@ -192,6 +193,8 @@ describe("matrix directory", () => {
matrix: {
homeserver: "https://default.example.org",
accessToken: "default-token",
deviceId: "DEFAULTDEVICE",
avatarUrl: "mxc://server/avatar",
encryption: true,
threadReplies: "inbound",
groups: {
@ -212,9 +215,13 @@ describe("matrix directory", () => {
}) as CoreConfig;
expect(updated.channels?.["matrix"]?.accessToken).toBeUndefined();
expect(updated.channels?.["matrix"]?.deviceId).toBeUndefined();
expect(updated.channels?.["matrix"]?.avatarUrl).toBeUndefined();
expect(updated.channels?.["matrix"]?.accounts?.default).toMatchObject({
accessToken: "default-token",
homeserver: "https://default.example.org",
deviceId: "DEFAULTDEVICE",
avatarUrl: "mxc://server/avatar",
encryption: true,
threadReplies: "inbound",
groups: {
@ -227,6 +234,12 @@ describe("matrix directory", () => {
userId: "@ops:example.org",
accessToken: "ops-token",
});
expect(resolveMatrixConfigForAccount(updated, "ops", {})).toMatchObject({
homeserver: "https://matrix.example.org",
userId: "@ops:example.org",
accessToken: "ops-token",
deviceId: undefined,
});
});
it("writes default matrix account credentials under channels.matrix.accounts.default", () => {

View File

@ -336,6 +336,8 @@ const COMMON_SINGLE_ACCOUNT_KEYS_TO_MOVE = new Set([
const SINGLE_ACCOUNT_KEYS_TO_MOVE_BY_CHANNEL: Record<string, ReadonlySet<string>> = {
matrix: new Set([
"deviceId",
"avatarUrl",
"initialSyncLimit",
"encryption",
"allowlistOnly",