mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 04:15:48 -06:00
test: tighten matrix route assertions
This commit is contained in:
@@ -145,14 +145,14 @@ function resolveUserRouteForCurrentSession(params: {
|
||||
}
|
||||
|
||||
function expectCurrentDmRoomRoute(route: ReturnType<typeof resolveMatrixOutboundSessionRoute>) {
|
||||
expect(route).toMatchObject({
|
||||
sessionKey: currentDmSessionKey,
|
||||
baseSessionKey: currentDmSessionKey,
|
||||
peer: { kind: "channel", id: "!dm:example.org" },
|
||||
chatType: "direct",
|
||||
from: "matrix:@alice:example.org",
|
||||
to: "room:!dm:example.org",
|
||||
});
|
||||
const currentRoute = expectRoute(route);
|
||||
expect(currentRoute.sessionKey).toBe(currentDmSessionKey);
|
||||
expect(currentRoute.baseSessionKey).toBe(currentDmSessionKey);
|
||||
expect(currentRoute.peer.kind).toBe("channel");
|
||||
expect(currentRoute.peer.id).toBe("!dm:example.org");
|
||||
expect(currentRoute.chatType).toBe("direct");
|
||||
expect(currentRoute.from).toBe("matrix:@alice:example.org");
|
||||
expect(currentRoute.to).toBe("room:!dm:example.org");
|
||||
}
|
||||
|
||||
function expectFallbackUserRoute(
|
||||
@@ -162,14 +162,21 @@ function expectFallbackUserRoute(
|
||||
},
|
||||
) {
|
||||
const userId = params?.userId ?? "@alice:example.org";
|
||||
expect(route).toMatchObject({
|
||||
sessionKey: "agent:main:main",
|
||||
baseSessionKey: "agent:main:main",
|
||||
peer: { kind: "direct", id: userId },
|
||||
chatType: "direct",
|
||||
from: `matrix:${userId}`,
|
||||
to: `room:${userId}`,
|
||||
});
|
||||
const fallbackRoute = expectRoute(route);
|
||||
expect(fallbackRoute.sessionKey).toBe("agent:main:main");
|
||||
expect(fallbackRoute.baseSessionKey).toBe("agent:main:main");
|
||||
expect(fallbackRoute.peer.kind).toBe("direct");
|
||||
expect(fallbackRoute.peer.id).toBe(userId);
|
||||
expect(fallbackRoute.chatType).toBe("direct");
|
||||
expect(fallbackRoute.from).toBe(`matrix:${userId}`);
|
||||
expect(fallbackRoute.to).toBe(`room:${userId}`);
|
||||
}
|
||||
|
||||
function expectRoute(route: ReturnType<typeof resolveMatrixOutboundSessionRoute>) {
|
||||
if (!route) {
|
||||
throw new Error("Expected Matrix route");
|
||||
}
|
||||
return route;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
@@ -275,11 +282,12 @@ describe("resolveMatrixOutboundSessionRoute", () => {
|
||||
currentSessionKey: "agent:main:matrix:channel:!ops:example.org:thread:$RootEvent:Example.Org",
|
||||
});
|
||||
|
||||
expect(route).toMatchObject({
|
||||
sessionKey: "agent:main:matrix:channel:!ops:example.org:thread:$RootEvent:Example.Org",
|
||||
baseSessionKey: "agent:main:matrix:channel:!ops:example.org",
|
||||
threadId: "$RootEvent:Example.Org",
|
||||
});
|
||||
const channelRoute = expectRoute(route);
|
||||
expect(channelRoute.sessionKey).toBe(
|
||||
"agent:main:matrix:channel:!ops:example.org:thread:$RootEvent:Example.Org",
|
||||
);
|
||||
expect(channelRoute.baseSessionKey).toBe("agent:main:matrix:channel:!ops:example.org");
|
||||
expect(channelRoute.threadId).toBe("$RootEvent:Example.Org");
|
||||
});
|
||||
|
||||
it("resolves per-room DM metadata from the base key when currentSessionKey has a thread suffix", () => {
|
||||
@@ -306,12 +314,11 @@ describe("resolveMatrixOutboundSessionRoute", () => {
|
||||
currentSessionKey: `${route?.baseSessionKey}:thread:$DmRoot:Example.Org`,
|
||||
});
|
||||
|
||||
expect(threadedRoute).toMatchObject({
|
||||
sessionKey: `${route?.baseSessionKey}:thread:$DmRoot:Example.Org`,
|
||||
baseSessionKey: route?.baseSessionKey,
|
||||
to: "room:!dm:example.org",
|
||||
threadId: "$DmRoot:Example.Org",
|
||||
});
|
||||
const dmThreadRoute = expectRoute(threadedRoute);
|
||||
expect(dmThreadRoute.sessionKey).toBe(`${route?.baseSessionKey}:thread:$DmRoot:Example.Org`);
|
||||
expect(dmThreadRoute.baseSessionKey).toBe(route?.baseSessionKey);
|
||||
expect(dmThreadRoute.to).toBe("room:!dm:example.org");
|
||||
expect(dmThreadRoute.threadId).toBe("$DmRoot:Example.Org");
|
||||
});
|
||||
|
||||
it('does not recover currentSessionKey threads for shared dmScope "main" DMs', () => {
|
||||
@@ -327,10 +334,9 @@ describe("resolveMatrixOutboundSessionRoute", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(route).toMatchObject({
|
||||
sessionKey: "agent:main:main",
|
||||
baseSessionKey: "agent:main:main",
|
||||
});
|
||||
expect(route?.threadId).toBeUndefined();
|
||||
const dmRoute = expectRoute(route);
|
||||
expect(dmRoute.sessionKey).toBe("agent:main:main");
|
||||
expect(dmRoute.baseSessionKey).toBe("agent:main:main");
|
||||
expect(dmRoute.threadId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user