From 09c5d39d8c3cf44b1bdfd0c6432c46495e546578 Mon Sep 17 00:00:00 2001 From: thisTom Date: Tue, 22 Sep 2026 17:37:23 +0800 Subject: [PATCH] fix(mcode): refresh provider state after removal (#7578) Co-authored-by: thisTom <19346741+thisTom@users.noreply.github.com> --- src/App.tsx | 4 +++ tests/integration/App.test.tsx | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index c66e65649..33706344f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -777,6 +777,10 @@ function App() { await queryClient.invalidateQueries({ queryKey: hermesKeys.liveProviderIds, }); + } else if (activeApp === "mcode") { + await queryClient.invalidateQueries({ + queryKey: ["providers", "mcode"], + }); } toast.success( activeApp === "pi" diff --git a/tests/integration/App.test.tsx b/tests/integration/App.test.tsx index eeabd53af..b111b41d1 100644 --- a/tests/integration/App.test.tsx +++ b/tests/integration/App.test.tsx @@ -390,6 +390,61 @@ describe("App integration with MSW", () => { ); }); + it("refreshes MiniMax Code provider membership after removing it from live config", async () => { + localStorage.setItem("cc-switch-last-app", "mcode"); + let liveConfigManaged = true; + let providerRequests = 0; + server.use( + http.post("http://tauri.local/get_providers", async ({ request }) => { + const { app } = (await request.json()) as { app: string }; + if (app !== "mcode") return; + providerRequests += 1; + return HttpResponse.json({ + custom: { + id: "custom", + name: "Custom MiniMax Code", + settingsConfig: {}, + meta: { liveConfigManaged }, + }, + }); + }), + http.post( + "http://tauri.local/remove_provider_from_live_config", + async ({ request }) => { + expect(await request.json()).toEqual({ id: "custom", app: "mcode" }); + liveConfigManaged = false; + return HttpResponse.json(true); + }, + ), + ); + + const { default: App } = await import("@/App"); + renderApp(App); + + await waitFor(() => + expect(screen.getByTestId("provider-list")).toHaveTextContent( + '"liveConfigManaged":true', + ), + ); + const requestsBeforeRemoval = providerRequests; + fireEvent.click(screen.getByText("remove")); + fireEvent.click(screen.getByText("confirm-delete")); + + await waitFor(() => + expect(screen.queryByTestId("confirm-dialog")).not.toBeInTheDocument(), + ); + expect(liveConfigManaged).toBe(false); + await waitFor(() => + expect(screen.getByTestId("provider-list")).toHaveTextContent( + '"liveConfigManaged":false', + ), + ); + expect(providerRequests).toBeGreaterThan(requestsBeforeRemoval); + expect(screen.getByTestId("provider-list")).toHaveTextContent( + "Custom MiniMax Code", + ); + }); + it("warns without blocking when removing Pi's global default provider", async () => { localStorage.setItem("cc-switch-last-app", "pi"); setProviders("pi", {