

























@@ -192,13 +192,21 @@ function expectFields(value: unknown, expected: Record<string, unknown>): void {
192192}
193193}
194194195+function mockCall(mock: { mock: { calls: unknown[][] } }, index = 0) {
196+return mock.mock.calls.at(index);
197+}
198+199+function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0, argIndex = 0) {
200+return mockCall(mock, index)?.at(argIndex);
201+}
202+195203function expectPresencePersistCall(
196204mock: ReturnType<typeof vi.fn>,
197205deviceId: string,
198206reason: string,
199207): void {
200208expect(mock).toHaveBeenCalledTimes(1);
201-const [actualDeviceId, metadata] = mock.mock.calls[0] ?? [];
209+const [actualDeviceId, metadata] = mockCall(mock) ?? [];
202210expect(actualDeviceId).toBe(deviceId);
203211expectFields(metadata, { lastSeenReason: reason });
204212const lastSeenAtMs = (metadata as { lastSeenAtMs?: unknown } | undefined)?.lastSeenAtMs;
@@ -610,7 +618,7 @@ describe("voice transcript events", () => {
610618});
611619612620expect(agentCommandMock).toHaveBeenCalledTimes(1);
613-const [opts] = agentCommandMock.mock.calls[0] ?? [];
621+const opts = mockCallArg(agentCommandMock);
614622expectFields(opts, {
615623message: "check provenance",
616624deliver: false,
@@ -625,7 +633,7 @@ describe("voice transcript events", () => {
625633expect(typeof optsRecord.runId).toBe("string");
626634expect(optsRecord.runId).not.toBe(optsRecord.sessionId);
627635expect(addChatRun).toHaveBeenCalledTimes(1);
628-const [runId, runMetadata] = addChatRun.mock.calls[0] ?? [];
636+const [runId, runMetadata] = mockCall(addChatRun) ?? [];
629637expect(runId).toBe(optsRecord.runId);
630638const clientRunId = (runMetadata as { clientRunId?: unknown } | undefined)?.clientRunId;
631639expect(typeof clientRunId).toBe("string");
@@ -649,7 +657,7 @@ describe("voice transcript events", () => {
649657650658expect(agentCommandMock).toHaveBeenCalledTimes(1);
651659expect(warn).toHaveBeenCalledTimes(1);
652-expect(String(warn.mock.calls[0]?.[0])).toContain("voice session-store update failed");
660+expect(String(mockCallArg(warn))).toContain("voice session-store update failed");
653661});
654662655663it("preserves existing session metadata when touching the store for voice transcripts", async () => {
@@ -928,7 +936,7 @@ describe("agent request events", () => {
928936});
929937930938expect(agentCommandMock).toHaveBeenCalledTimes(1);
931-const [opts] = agentCommandMock.mock.calls[0] ?? [];
939+const opts = mockCallArg(agentCommandMock);
932940expectFields(opts, {
933941message: "summarize this",
934942sessionKey: "agent:main:main",
@@ -937,9 +945,7 @@ describe("agent request events", () => {
937945to: undefined,
938946});
939947expect(warn).toHaveBeenCalledTimes(1);
940-expect(String(warn.mock.calls[0]?.[0])).toContain(
941-"agent delivery disabled node=node-route-miss",
942-);
948+expect(String(mockCallArg(warn))).toContain("agent delivery disabled node=node-route-miss");
943949});
944950945951it("reuses the current session route when delivery target is omitted", async () => {
@@ -963,15 +969,16 @@ describe("agent request events", () => {
963969});
964970965971expect(agentCommandMock).toHaveBeenCalledTimes(1);
966-const [opts] = agentCommandMock.mock.calls[0] ?? [];
972+const opts = mockCallArg(agentCommandMock);
967973expectFields(opts, {
968974message: "route on session",
969975sessionKey: "agent:main:main",
970976deliver: true,
971977channel: "telegram",
972978to: "123",
973979});
974-expect(opts.runId).toBe(opts.sessionId);
980+const optsRecord = opts as Record<string, unknown>;
981+expect(optsRecord.runId).toBe(optsRecord.sessionId);
975982});
976983977984it("passes supportsInlineImages false for text-only node-session models", async () => {
@@ -1009,7 +1016,7 @@ describe("agent request events", () => {
10091016});
1010101710111018expect(parseMessageWithAttachmentsMock).toHaveBeenCalledTimes(1);
1012-const parseCall = parseMessageWithAttachmentsMock.mock.calls[0];
1019+const parseCall = mockCall(parseMessageWithAttachmentsMock);
10131020expect(parseCall?.[0]).toBe("describe");
10141021expect(Array.isArray(parseCall?.[1])).toBe(true);
10151022expectFields(parseCall?.[2], { supportsInlineImages: false });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。