diff --git a/frontend/src/app/main/data/workspace/mcp.cljs b/frontend/src/app/main/data/workspace/mcp.cljs index 07f766ab61..8ca0af2a60 100644 --- a/frontend/src/app/main/data/workspace/mcp.cljs +++ b/frontend/src/app/main/data/workspace/mcp.cljs @@ -372,7 +372,8 @@ (ptk/type? ::auth/logged-out %))) (rx/map #(when (ptk/type? ::du/set-profile %) (:id (deref %)))) - (rx/pipe (rxo/distinct-contiguous)) + ;; by value: a reloaded profile can carry its id in a new uuid instance + (rx/pipe (rxo/distinct-contiguous =)) (rx/switch-map (fn [profile-id] (if profile-id diff --git a/frontend/test/frontend_tests/data/workspace_mcp_test.cljs b/frontend/test/frontend_tests/data/workspace_mcp_test.cljs index 3906fb7f0c..51e54a34eb 100644 --- a/frontend/test/frontend_tests/data/workspace_mcp_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_mcp_test.cljs @@ -46,6 +46,29 @@ (rx/dispose! subscription) (rx/end! stream)))))))) +(t/deftest ^:async test-initialize-ignores-reloaded-profile + (let [stream (rx/subject) + events (atom []) + id (uuid/next) + ;; equal id in a distinct instance, as a decode after the uuid cache is cleared + reloaded (uuid/uuid (str id))] + (t/is (not (identical? id reloaded))) + (await + (mock/with-mocks* + {cf/flags #{:mcp} + preg/wait-for-runtime (fn [] (js/Promise.resolve true))} + (let [subscription (rx/subs! #(swap! events conj (ptk/type %)) + (ptk/watch (mcp/initialize) {} stream))] + (try + (rx/push! stream (du/set-profile {:id id})) + (await (a/wait-for #(= 1 (count @events)))) + (rx/push! stream (du/set-profile {:id reloaded})) + (await (a/settle)) + (t/is (= [:app.main.data.workspace.mcp/init] @events)) + (finally + (rx/dispose! subscription) + (rx/end! stream)))))))) + (t/deftest test-update-mcp-status (t/testing "enables MCP in profile props and mcp state" (let [state {:profile {:props {:mcp-enabled false}} :mcp {}}