





















@@ -214,14 +214,25 @@ function expectFields(record: Record<string, unknown>, expected: Record<string,
214214}
215215}
216216217+function firstMockCall(mock: MockCalls, label: string): unknown[] {
218+const call = mock.mock.calls.at(0);
219+if (!call) {
220+throw new Error(`expected ${label} call`);
221+}
222+return call;
223+}
224+225+function firstMockArg(mock: MockCalls, label: string) {
226+return firstMockCall(mock, label)[0];
227+}
228+217229function expectSingleCallFirstArg(
218230mock: MockCalls,
219231expected: Record<string, unknown>,
220232label = "mock first argument",
221233): Record<string, unknown> {
222234expect(mock.mock.calls).toHaveLength(1);
223-const [firstArg] = mock.mock.calls[0] ?? [];
224-const record = requireRecord(firstArg, label);
235+const record = requireRecord(firstMockArg(mock, label), label);
225236expectFields(record, expected);
226237return record;
227238}
@@ -373,7 +384,9 @@ async function expectBoundStatusCommandDirectReply(params: {
373384374385expect(dispatchSpy).not.toHaveBeenCalled();
375386expect(statusSpy).toHaveBeenCalledTimes(1);
376-const statusCall = statusSpy.mock.calls[0]?.[0] as { sessionKey?: string };
387+const statusCall = firstMockArg(statusSpy, "resolveDirectStatusReplyForSession") as {
388+sessionKey?: string;
389+};
377390expect(statusCall.sessionKey).toMatch(params.expectedPattern);
378391}
379392@@ -1101,7 +1114,9 @@ describe("Discord native plugin command dispatch", () => {
1101111411021115expect(dispatchSpy).not.toHaveBeenCalled();
11031116expect(statusSpy).toHaveBeenCalledTimes(1);
1104-const statusCall = statusSpy.mock.calls[0]?.[0] as { sessionKey?: string };
1117+const statusCall = firstMockArg(statusSpy, "resolveDirectStatusReplyForSession") as {
1118+sessionKey?: string;
1119+};
11051120expect(statusCall.sessionKey).toBe("agent:qwen:discord:channel:1478836151241412759");
11061121});
11071122@@ -1182,7 +1197,7 @@ describe("Discord native plugin command dispatch", () => {
11821197await (command as { run: (interaction: unknown) => Promise<void> }).run(interaction as unknown);
1183119811841199expect(dispatchSpy).toHaveBeenCalledTimes(1);
1185-const dispatchCall = dispatchSpy.mock.calls[0]?.[0] as {
1200+const dispatchCall = firstMockArg(dispatchSpy, "dispatchReplyWithDispatcher") as {
11861201ctx?: { SessionKey?: string; CommandTargetSessionKey?: string };
11871202};
11881203expect(dispatchCall.ctx?.SessionKey).toMatch(/^agent:codex:acp:binding:discord:default:/);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。