



























@@ -172,6 +172,16 @@ function createDispatchSpy() {
172172return vi.fn<DispatchDiscordCommandInteraction>().mockResolvedValue({ accepted: true });
173173}
174174175+type MockWithCalls = { mock: { calls: unknown[][] } };
176+177+function firstMockArg(mock: MockWithCalls, label: string) {
178+const call = mock.mock.calls.at(0);
179+if (!call) {
180+throw new Error(`expected ${label} call`);
181+}
182+return call[0];
183+}
184+175185function createModelPickerFallbackButton(
176186context: ModelPickerContext,
177187dispatchCommandInteraction: DispatchDiscordCommandInteraction = createDispatchSpy(),
@@ -230,7 +240,9 @@ function expectDispatchedModelSelection(params: {
230240model: string;
231241runtime?: string;
232242}) {
233-const dispatchCall = params.dispatchSpy.mock.calls[0]?.[0];
243+const dispatchCall = firstMockArg(params.dispatchSpy, "dispatchCommandInteraction") as
244+| Parameters<DispatchDiscordCommandInteraction>[0]
245+| undefined;
234246expect(dispatchCall?.prompt).toBe(
235247params.runtime
236248 ? `/model ${params.model} --runtime ${params.runtime}`
@@ -485,7 +497,7 @@ describe("Discord model picker interactions", () => {
485497expect(withTimeoutSpy).toHaveBeenCalledTimes(1);
486498await vi.waitFor(() => expect(dispatchSpy).toHaveBeenCalledTimes(1));
487499expect(submitInteraction.followUp).toHaveBeenCalledTimes(1);
488-const followUpPayload = submitInteraction.followUp.mock.calls[0]?.[0] as {
500+const followUpPayload = firstMockArg(submitInteraction.followUp, "interaction.followUp") as {
489501components?: Array<{ components?: Array<{ content?: string }> }>;
490502};
491503const followUpText = JSON.stringify(followUpPayload);
@@ -521,10 +533,7 @@ describe("Discord model picker interactions", () => {
521533await button.run(interaction as unknown as PickerButtonInteraction, data);
522534523535expect(interaction.editReply).toHaveBeenCalledTimes(1);
524-const updatePayload = interaction.editReply.mock.calls[0]?.[0];
525-if (!updatePayload) {
526-throw new Error("recents button did not emit an update payload");
527-}
536+const updatePayload = firstMockArg(interaction.editReply, "interaction.editReply");
528537const updateText = JSON.stringify(updatePayload);
529538expect(updateText).toContain("gpt-4o");
530539expect(updateText).toContain("claude-sonnet-4-5");
@@ -655,9 +664,9 @@ describe("Discord model picker interactions", () => {
655664 dispatchSpy,
656665model: "lmstudio/unsloth/gemma-4-26b-a4b-it@iq4_xs",
657666});
658-expect(JSON.stringify(submitInteraction.followUp.mock.calls[0]?.[0])).toContain(
659-"✅ Model set to lmstudio/unsloth/gemma-4-26b-a4b-it@iq4_xs.",
660-);
667+expect(
668+JSON.stringify(firstMockArg(submitInteraction.followUp, "interaction.followUp")),
669+).toContain("✅ Model set to lmstudio/unsloth/gemma-4-26b-a4b-it@iq4_xs.");
661670});
662671663672it("does not write a fallback override when hidden /model dispatch is rejected", async () => {
@@ -699,9 +708,9 @@ describe("Discord model picker interactions", () => {
699708const store = loadSessionStore(storePath, { skipCache: true });
700709expect(store["agent:worker:subagent:bound"]?.providerOverride).toBeUndefined();
701710expect(store["agent:worker:subagent:bound"]?.modelOverride).toBeUndefined();
702-expect(JSON.stringify(submitInteraction.followUp.mock.calls[0]?.[0])).toContain(
703-"❌ Failed to apply openai/gpt-4o.",
704-);
711+expect(
712+JSON.stringify(firstMockArg(submitInteraction.followUp, "interaction.followUp")),
713+).toContain("❌ Failed to apply openai/gpt-4o.");
705714});
706715707716it("loads model picker data from the effective bound route", async () => {
@@ -777,7 +786,7 @@ describe("Discord model picker interactions", () => {
777786});
778787779788expect(loadSpy).toHaveBeenCalledWith(cfg, "main");
780-const payload = JSON.stringify(interaction.reply.mock.calls[0]?.[0]);
789+const payload = JSON.stringify(firstMockArg(interaction.reply, "interaction.reply"));
781790expect(payload).toContain("openai-codex");
782791expect(payload).toContain("gpt-5.5-codex");
783792expect(payload).not.toContain("Provider not found");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。