mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 09:42:01 +00:00
🐛 Keep the MCP connection when an account first leaves the workspace (#13192)
The MCP controller restarts its runtime when the profile id changes, and it compared ids by object identity. Leaving the workspace clears the transit uuid cache, and on the first visit it also saves the workspace-visited prop, which reloads the profile. The reloaded id came back as a new uuid instance, so MCP init ran again: it closed the plugin, dropped the WebSocket and left the new plugin disconnected. Compare profile ids by value, and add a regression test that sends the same id as two distinct uuid instances. Closes #13128 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
932544996f
commit
84a7471ea2
@ -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
|
||||
|
||||
@ -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 {}}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user