import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import type { OpenClawConfig } from "./runtime-api.js"; import { resolveMatrixOutboundSessionRoute } from "./session-route.js";
const tempDirs = new Set<string>(); const currentDmSessionKey = "agent:main:matrix:channel:!dm:example.org";
type MatrixChannelConfig = NonNullable<NonNullable<OpenClawConfig["channels"]>["matrix"]>;
afterEach(() => { for (const tempDir of tempDirs) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
tempDirs.clear();
});
describe("resolveMatrixOutboundSessionRoute", () => {
it("reuses the current DM room session for same-user sends when Matrix DMs are per-room", () => { const route = resolveUserRouteForCurrentSession({
storedSession: createStoredDirectDmSession(),
accountId: "ops",
});
expectCurrentDmRoomRoute(route);
});
it("falls back to user-scoped routing when the current session is for another DM peer", () => { const route = resolveUserRouteForCurrentSession({
storedSession: createStoredDirectDmSession({ from: "matrix:@bob:example.org" }),
accountId: "ops",
});
expectFallbackUserRoute(route);
});
it("falls back to user-scoped routing when the current session belongs to another Matrix account", () => { const route = resolveUserRouteForCurrentSession({
storedSession: createStoredDirectDmSession(),
accountId: "support",
});
expectFallbackUserRoute(route);
});
it("reuses the canonical DM room after user-target outbound metadata overwrites latest to fields", () => { const route = resolveUserRouteForCurrentSession({
storedSession: createStoredDirectDmSession({
from: "matrix:@bob:example.org",
to: "room:@bob:example.org",
nativeChannelId: "!dm:example.org",
nativeDirectUserId: "@alice:example.org",
lastTo: "room:@bob:example.org",
lastAccountId: "ops",
}),
accountId: "ops",
});
expectCurrentDmRoomRoute(route);
});
it("does not reuse the canonical DM room for a different Matrix user after latest metadata drift", () => { const route = resolveUserRouteForCurrentSession({
storedSession: createStoredDirectDmSession({
from: "matrix:@bob:example.org",
to: "room:@bob:example.org",
nativeChannelId: "!dm:example.org",
nativeDirectUserId: "@alice:example.org",
lastTo: "room:@bob:example.org",
lastAccountId: "ops",
}),
accountId: "ops",
target: "@bob:example.org",
});
it("does not reuse a room after the session metadata was overwritten by a non-DM Matrix send", () => { const route = resolveUserRouteForCurrentSession({
storedSession: createStoredChannelSession(),
accountId: "ops",
});
expectFallbackUserRoute(route);
});
it("uses the effective default Matrix account when accountId is omitted", () => { const route = resolveUserRouteForCurrentSession({
storedSession: createStoredDirectDmSession(),
matrix: defaultAccountPerRoomDmMatrixConfig,
});
expectCurrentDmRoomRoute(route);
});
it("reuses the current DM room when stored account metadata is missing", () => { const route = resolveUserRouteForCurrentSession({
storedSession: createStoredDirectDmSession({ accountId: null }),
matrix: defaultAccountPerRoomDmMatrixConfig,
});
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.