





















@@ -13,6 +13,32 @@ type SessionModule = typeof import("./session.js");
13131414let recordInboundSession: SessionModule["recordInboundSession"];
151516+function requireFirstCallArg(mock: ReturnType<typeof vi.fn>): {
17+sessionKey?: string;
18+ctx?: MsgContext;
19+createIfMissing?: boolean;
20+deliveryContext?: {
21+channel?: string;
22+to?: string;
23+};
24+} {
25+const arg = mock.mock.calls[0]?.[0] as
26+| {
27+sessionKey?: string;
28+ctx?: MsgContext;
29+createIfMissing?: boolean;
30+deliveryContext?: {
31+channel?: string;
32+to?: string;
33+};
34+}
35+| undefined;
36+if (!arg) {
37+throw new Error("Expected mock call argument");
38+}
39+return arg;
40+}
41+1642describe("recordInboundSession", () => {
1743const ctx: MsgContext = {
1844Provider: "demo-channel",
@@ -43,16 +69,11 @@ describe("recordInboundSession", () => {
4369onRecordError: vi.fn(),
4470});
457146-expect(updateLastRouteMock).toHaveBeenCalledWith(
47-expect.objectContaining({
48-sessionKey: "agent:main:main",
49-ctx: undefined,
50-deliveryContext: expect.objectContaining({
51-channel: "demo-channel",
52-to: "demo-channel:1234",
53-}),
54-}),
55-);
72+const route = requireFirstCallArg(updateLastRouteMock);
73+expect(route.sessionKey).toBe("agent:main:main");
74+expect(route.ctx).toBeUndefined();
75+expect(route.deliveryContext?.channel).toBe("demo-channel");
76+expect(route.deliveryContext?.to).toBe("demo-channel:1234");
5677});
57785879it("passes ctx when updating the same session key", async () => {
@@ -68,16 +89,11 @@ describe("recordInboundSession", () => {
6889onRecordError: vi.fn(),
6990});
709171-expect(updateLastRouteMock).toHaveBeenCalledWith(
72-expect.objectContaining({
73-sessionKey: "agent:main:demo-channel:1234:thread:42",
74- ctx,
75-deliveryContext: expect.objectContaining({
76-channel: "demo-channel",
77-to: "demo-channel:1234",
78-}),
79-}),
80-);
92+const route = requireFirstCallArg(updateLastRouteMock);
93+expect(route.sessionKey).toBe("agent:main:demo-channel:1234:thread:42");
94+expect(route.ctx).toBe(ctx);
95+expect(route.deliveryContext?.channel).toBe("demo-channel");
96+expect(route.deliveryContext?.to).toBe("demo-channel:1234");
8197});
82988399it("normalizes mixed-case session keys before recording and route updates", async () => {
@@ -93,17 +109,12 @@ describe("recordInboundSession", () => {
93109onRecordError: vi.fn(),
94110});
9511196-expect(recordSessionMetaFromInboundMock).toHaveBeenCalledWith(
97-expect.objectContaining({
98-sessionKey: "agent:main:demo-channel:1234:thread:42",
99-}),
100-);
101-expect(updateLastRouteMock).toHaveBeenCalledWith(
102-expect.objectContaining({
103-sessionKey: "agent:main:demo-channel:1234:thread:42",
104- ctx,
105-}),
112+expect(requireFirstCallArg(recordSessionMetaFromInboundMock).sessionKey).toBe(
113+"agent:main:demo-channel:1234:thread:42",
106114);
115+const route = requireFirstCallArg(updateLastRouteMock);
116+expect(route.sessionKey).toBe("agent:main:demo-channel:1234:thread:42");
117+expect(route.ctx).toBe(ctx);
107118});
108119109120it("skips last-route updates when main DM owner pin mismatches sender", async () => {
@@ -147,16 +158,9 @@ describe("recordInboundSession", () => {
147158onRecordError: vi.fn(),
148159});
149160150-expect(recordSessionMetaFromInboundMock).toHaveBeenCalledWith(
151-expect.objectContaining({
152-createIfMissing: false,
153-}),
154-);
155-expect(updateLastRouteMock).toHaveBeenCalledWith(
156-expect.objectContaining({
157-sessionKey: "agent:main:main",
158-createIfMissing: false,
159-}),
160-);
161+expect(requireFirstCallArg(recordSessionMetaFromInboundMock).createIfMissing).toBe(false);
162+const route = requireFirstCallArg(updateLastRouteMock);
163+expect(route.sessionKey).toBe("agent:main:main");
164+expect(route.createIfMissing).toBe(false);
161165});
162166});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。