diff --git a/extensions/matrix/src/matrix/config-update.test.ts b/extensions/matrix/src/matrix/config-update.test.ts index 463c2e7a46b..8fb23fced25 100644 --- a/extensions/matrix/src/matrix/config-update.test.ts +++ b/extensions/matrix/src/matrix/config-update.test.ts @@ -103,6 +103,44 @@ describe("updateMatrixAccountConfig", () => { expect(updated.channels?.["matrix"]?.accounts?.default?.proxy).toBeUndefined(); }); + it("stores and clears Matrix invite auto-join settings", () => { + const cfg = { + channels: { + matrix: { + accounts: { + default: { + autoJoin: "allowlist", + autoJoinAllowlist: ["#ops:example.org"], + }, + }, + }, + }, + } as CoreConfig; + + const allowlistUpdated = updateMatrixAccountConfig(cfg, "default", { + autoJoin: "allowlist", + autoJoinAllowlist: ["!ops-room:example.org", "#ops:example.org"], + }); + expect(allowlistUpdated.channels?.matrix?.accounts?.default).toMatchObject({ + autoJoin: "allowlist", + autoJoinAllowlist: ["!ops-room:example.org", "#ops:example.org"], + }); + + const offUpdated = updateMatrixAccountConfig(cfg, "default", { + autoJoin: "off", + autoJoinAllowlist: null, + }); + expect(offUpdated.channels?.matrix?.accounts?.default?.autoJoin).toBe("off"); + expect(offUpdated.channels?.matrix?.accounts?.default?.autoJoinAllowlist).toBeUndefined(); + + const alwaysUpdated = updateMatrixAccountConfig(cfg, "default", { + autoJoin: "always", + autoJoinAllowlist: null, + }); + expect(alwaysUpdated.channels?.matrix?.accounts?.default?.autoJoin).toBe("always"); + expect(alwaysUpdated.channels?.matrix?.accounts?.default?.autoJoinAllowlist).toBeUndefined(); + }); + it("normalizes account id and defaults account enabled=true", () => { const updated = updateMatrixAccountConfig({} as CoreConfig, "Main Bot", { name: "Main Bot", diff --git a/extensions/matrix/src/onboarding.test-harness.ts b/extensions/matrix/src/onboarding.test-harness.ts index 0275d8a77b0..bc689d9c68f 100644 --- a/extensions/matrix/src/onboarding.test-harness.ts +++ b/extensions/matrix/src/onboarding.test-harness.ts @@ -138,7 +138,7 @@ export async function runMatrixAddAccountAllowlistConfigure(params: { "Matrix allowFrom (full @user:server; display name only if unique)": params.allowFromInput, "Matrix rooms allowlist (comma-separated)": params.roomsAllowlistInput, "Matrix invite auto-join allowlist (comma-separated)": - params.autoJoinAllowlistInput ?? "!ops-room:example.org", + params.autoJoinAllowlistInput ?? "#ops-invites:example.org", }, confirm: { "Enable end-to-end encryption (E2EE)?": false, diff --git a/extensions/matrix/src/onboarding.ts b/extensions/matrix/src/onboarding.ts index 3d57ac751ca..4905ddab6e9 100644 --- a/extensions/matrix/src/onboarding.ts +++ b/extensions/matrix/src/onboarding.ts @@ -35,10 +35,10 @@ import { type WizardPrompter, } from "./runtime-api.js"; import { moveSingleMatrixAccountConfigToNamedAccount } from "./setup-config.js"; -import type { CoreConfig } from "./types.js"; +import type { CoreConfig, MatrixConfig } from "./types.js"; const channel = "matrix" as const; -type MatrixInviteAutoJoinPolicy = "allowlist" | "always" | "off"; +type MatrixInviteAutoJoinPolicy = NonNullable; const matrixInviteAutoJoinOptions: Array<{ value: MatrixInviteAutoJoinPolicy;