
















@@ -44,7 +44,9 @@ type MockInteraction = {
4444reply: ReturnType<typeof vi.fn>;
4545followUp: ReturnType<typeof vi.fn>;
4646update: ReturnType<typeof vi.fn>;
47+editReply: ReturnType<typeof vi.fn>;
4748acknowledge: ReturnType<typeof vi.fn>;
49+acknowledged: boolean;
4850client: object;
4951};
5052@@ -96,7 +98,7 @@ function createModelPickerContext(): ModelPickerContext {
96989799function createInteraction(params?: { userId?: string; values?: string[] }): MockInteraction {
98100const userId = params?.userId ?? "owner";
99-return {
101+const interaction = {
100102user: {
101103id: userId,
102104username: "tester",
@@ -115,9 +117,16 @@ function createInteraction(params?: { userId?: string; values?: string[] }): Moc
115117reply: vi.fn().mockResolvedValue({ ok: true }),
116118followUp: vi.fn().mockResolvedValue({ ok: true }),
117119update: vi.fn().mockResolvedValue({ ok: true }),
118-acknowledge: vi.fn().mockResolvedValue({ ok: true }),
120+editReply: vi.fn().mockResolvedValue({ ok: true }),
121+acknowledge: vi.fn(),
122+acknowledged: false,
119123client: {},
120124};
125+interaction.acknowledge.mockImplementation(async () => {
126+interaction.acknowledged = true;
127+return { ok: true };
128+});
129+return interaction;
121130}
122131123132function createDefaultModelPickerData(): ModelsProviderData {
@@ -323,6 +332,28 @@ describe("Discord model picker interactions", () => {
323332expect(loadSpy).not.toHaveBeenCalled();
324333});
325334335+it("defers owner picker interactions before loading model data", async () => {
336+const context = createModelPickerContext();
337+const pickerData = createDefaultModelPickerData();
338+const loadSpy = vi
339+.spyOn(modelPickerModule, "loadDiscordModelPickerData")
340+.mockImplementation(async () => {
341+expect(interaction.acknowledge).toHaveBeenCalledTimes(1);
342+return pickerData;
343+});
344+const select = createModelPickerFallbackSelect(context);
345+const interaction = createInteraction({ userId: "owner", values: ["gpt-4o"] });
346+347+await select.run(
348+interaction as unknown as PickerSelectInteraction,
349+createModelsViewSelectData(),
350+);
351+352+expect(loadSpy).toHaveBeenCalledTimes(1);
353+expect(interaction.editReply).toHaveBeenCalledTimes(1);
354+expect(interaction.update).not.toHaveBeenCalled();
355+});
356+326357it("requires submit click before routing selected model through /model pipeline", async () => {
327358const context = createModelPickerContext();
328359const pickerData = createDefaultModelPickerData();
@@ -338,7 +369,7 @@ describe("Discord model picker interactions", () => {
338369dispatchCommandInteraction: dispatchSpy,
339370});
340371341-expect(selectInteraction.update).toHaveBeenCalledTimes(1);
372+expect(selectInteraction.editReply).toHaveBeenCalledTimes(1);
342373expect(dispatchSpy).not.toHaveBeenCalled();
343374344375const submitInteraction = await runSubmitButton({
@@ -347,7 +378,7 @@ describe("Discord model picker interactions", () => {
347378dispatchCommandInteraction: dispatchSpy,
348379});
349380350-expect(submitInteraction.update).toHaveBeenCalledTimes(1);
381+expect(submitInteraction.editReply).toHaveBeenCalledTimes(1);
351382expect(dispatchSpy).toHaveBeenCalledTimes(1);
352383expectDispatchedModelSelection({
353384 dispatchSpy,
@@ -547,8 +578,8 @@ describe("Discord model picker interactions", () => {
547578548579await button.run(interaction as unknown as PickerButtonInteraction, data);
549580550-expect(interaction.update).toHaveBeenCalledTimes(1);
551-const updatePayload = interaction.update.mock.calls[0]?.[0];
581+expect(interaction.editReply).toHaveBeenCalledTimes(1);
582+const updatePayload = interaction.editReply.mock.calls[0]?.[0];
552583if (!updatePayload) {
553584throw new Error("recents button did not emit an update payload");
554585}
@@ -585,7 +616,7 @@ describe("Discord model picker interactions", () => {
585616dispatchCommandInteraction: dispatchSpy,
586617});
587618588-expect(submitInteraction.update).toHaveBeenCalledTimes(1);
619+expect(submitInteraction.editReply).toHaveBeenCalledTimes(1);
589620expect(dispatchSpy).toHaveBeenCalledTimes(1);
590621expectDispatchedModelSelection({ dispatchSpy, model: "openai/gpt-4o" });
591622});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。