Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openclaw/extensions/matrix/src/matrix/   (KI Agentensystem Version 22©)  Datei vom 26.3.2026 mit Größe 7 kB image not shown  

Quelle  config-update.test.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import { describe, expect, it } from "vitest";
import type { CoreConfig } from "../types.js";
import { resolveMatrixConfigFieldPath, updateMatrixAccountConfig } from "./config-update.js";

describe("updateMatrixAccountConfig", () => {
  it("resolves account-aware Matrix config field paths", () => {
    expect(resolveMatrixConfigFieldPath({} as CoreConfig, "default", "dm.policy")).toBe(
      "channels.matrix.dm.policy",
    );

    const cfg = {
      channels: {
        matrix: {
          accounts: {
            ops: {},
          },
        },
      },
    } as CoreConfig;

    expect(resolveMatrixConfigFieldPath(cfg, "ops", ".dm.allowFrom")).toBe(
      "channels.matrix.accounts.ops.dm.allowFrom",
    );
  });

  it("supports explicit null clears and boolean false values", () => {
    const cfg = {
      channels: {
        matrix: {
          accounts: {
            default: {
              homeserver: "https://matrix.example.org",
              userId: "@bot:example.org",
              accessToken: "old-token", // pragma: allowlist secret
              password: "old-password", // pragma: allowlist secret
              encryption: true,
            },
          },
        },
      },
    } as CoreConfig;

    const updated = updateMatrixAccountConfig(cfg, "default", {
      accessToken: "new-token",
      password: null,
      userId: null,
      encryption: false,
    });

    expect(updated.channels?.["matrix"]?.accounts?.default).toMatchObject({
      accessToken: "new-token",
      encryption: false,
    });
    expect(updated.channels?.["matrix"]?.accounts?.default?.password).toBeUndefined();
    expect(updated.channels?.["matrix"]?.accounts?.default?.userId).toBeUndefined();
  });

  it("preserves SecretRef auth inputs when updating config", () => {
    const updated = updateMatrixAccountConfig({} as CoreConfig, "default", {
      accessToken: { source: "env", provider: "default", id: "MATRIX_ACCESS_TOKEN" },
      password: { source: "env", provider: "default", id: "MATRIX_PASSWORD" },
    });

    expect(updated.channels?.matrix?.accessToken).toEqual({
      source: "env",
      provider: "default",
      id: "MATRIX_ACCESS_TOKEN",
    });
    expect(updated.channels?.matrix?.password).toEqual({
      source: "env",
      provider: "default",
      id: "MATRIX_PASSWORD",
    });
  });

  it("stores and clears Matrix allowBots, allowPrivateNetwork, and proxy settings", () => {
    const cfg = {
      channels: {
        matrix: {
          accounts: {
            default: {
              allowBots: true,
              network: {
                dangerouslyAllowPrivateNetwork: true,
              },
              proxy: "http://127.0.0.1:7890",
            },
          },
        },
      },
    } as CoreConfig;

    const updated = updateMatrixAccountConfig(cfg, "default", {
      allowBots: "mentions",
      allowPrivateNetwork: null,
      proxy: null,
    });

    expect(updated.channels?.["matrix"]?.accounts?.default).toMatchObject({
      allowBots: "mentions",
    });
    expect(updated.channels?.["matrix"]?.accounts?.default?.network).toBeUndefined();
    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",
      homeserver: "https://matrix.example.org",
    });

    expect(updated.channels?.["matrix"]?.accounts?.["main-bot"]).toMatchObject({
      name: "Main Bot",
      homeserver: "https://matrix.example.org",
      enabled: true,
    });
  });

  it("updates nested access config for named accounts without touching top-level defaults", () => {
    const cfg = {
      channels: {
        matrix: {
          dm: {
            policy: "pairing",
          },
          groups: {
            "!default:example.org": { enabled: true },
          },
          accounts: {
            ops: {
              homeserver: "https://matrix.ops.example.org",
              accessToken: "ops-token",
              dm: {
                enabled: true,
                policy: "pairing",
              },
            },
          },
        },
      },
    } as CoreConfig;

    const updated = updateMatrixAccountConfig(cfg, "ops", {
      dm: {
        policy: "allowlist",
        allowFrom: ["@alice:example.org"],
      },
      groupPolicy: "allowlist",
      groups: {
        "!ops-room:example.org": { enabled: true },
      },
      rooms: null,
    });

    expect(updated.channels?.["matrix"]?.dm?.policy).toBe("pairing");
    expect(updated.channels?.["matrix"]?.groups).toEqual({
      "!default:example.org": { enabled: true },
    });
    expect(updated.channels?.["matrix"]?.accounts?.ops).toMatchObject({
      dm: {
        enabled: true,
        policy: "allowlist",
        allowFrom: ["@alice:example.org"],
      },
      groupPolicy: "allowlist",
      groups: {
        "!ops-room:example.org": { enabled: true },
      },
    });
    expect(updated.channels?.["matrix"]?.accounts?.ops?.rooms).toBeUndefined();
  });

  it("reuses and canonicalizes non-normalized account entries when updating", () => {
    const cfg = {
      channels: {
        matrix: {
          accounts: {
            Ops: {
              homeserver: "https://matrix.ops.example.org",
              accessToken: "ops-token",
            },
          },
        },
      },
    } as CoreConfig;

    const updated = updateMatrixAccountConfig(cfg, "ops", {
      deviceName: "Ops Bot",
    });

    expect(updated.channels?.["matrix"]?.accounts?.Ops).toBeUndefined();
    expect(updated.channels?.["matrix"]?.accounts?.ops).toMatchObject({
      homeserver: "https://matrix.ops.example.org",
      accessToken: "ops-token",
      deviceName: "Ops Bot",
      enabled: true,
    });
  });
});

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.