fix(mcp): refresh desktop connection list after MCP mutations
This commit is contained in:
1 parent
914a97326c
commit
0be8a38984
8 files changed
+223
-10
No files matched your search
@@ -117,6 +117,49 @@ describe("connectionStore one_time runtime cleanup", () => {
|
||||
expect(store.connections).toEqual([]);
|
||||
});
|
||||
|
||||
it("reloads externally added, copied and deleted connections while preserving existing tree state", async () => {
|
||||
installApiMocks();
|
||||
const { loadConnections } = await import("@/lib/backend/api");
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
const kept = previewConnection({ id: "kept", one_time: false });
|
||||
const temporary = previewConnection({ id: "temporary" });
|
||||
store.connections = [kept, previewConnection({ id: "removed", one_time: false }), temporary];
|
||||
store.connectedIds.add("kept");
|
||||
store.treeNodes = [{ id: "kept", label: kept.name, type: "connection", connectionId: "kept", isExpanded: true, children: [{ id: "kept:app", label: "app", type: "database", connectionId: "kept", database: "app", isExpanded: true }] }];
|
||||
vi.mocked(loadConnections).mockResolvedValue([kept, previewConnection({ id: "added", one_time: false }), previewConnection({ id: "copied", one_time: false })]);
|
||||
|
||||
await store.reloadFromDisk();
|
||||
|
||||
expect(store.connections.map((connection) => connection.id)).toEqual(["kept", "added", "copied", "temporary"]);
|
||||
expect(store.treeNodes.map((node) => node.id)).toEqual(["kept", "added", "copied", "temporary"]);
|
||||
expect(store.treeNodes[0]).toMatchObject({ isExpanded: true, children: expect.arrayContaining([expect.objectContaining({ id: "kept:app", isExpanded: true })]) });
|
||||
expect(store.connectedIds.has("kept")).toBe(true);
|
||||
});
|
||||
|
||||
it("reads a fresh snapshot when an external change arrives during an in-flight reload", async () => {
|
||||
installApiMocks();
|
||||
const { loadConnections } = await import("@/lib/backend/api");
|
||||
let finishFirstRead!: (connections: ConnectionConfig[]) => void;
|
||||
vi.mocked(loadConnections)
|
||||
.mockReturnValueOnce(
|
||||
new Promise((resolve) => {
|
||||
finishFirstRead = resolve;
|
||||
}),
|
||||
)
|
||||
.mockResolvedValueOnce([previewConnection({ id: "new", one_time: false })]);
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
const initialLoad = store.initFromDisk();
|
||||
await vi.waitFor(() => expect(loadConnections).toHaveBeenCalledOnce());
|
||||
const externalReload = store.reloadFromDisk();
|
||||
finishFirstRead([]);
|
||||
await Promise.all([initialLoad, externalReload]);
|
||||
|
||||
expect(loadConnections).toHaveBeenCalledTimes(2);
|
||||
expect(store.getConfig("new")).toBeDefined();
|
||||
});
|
||||
|
||||
it("removeConnection leaves saved connections to the save_connections sync", async () => {
|
||||
installApiMocks();
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
|
||||
@@ -9995,6 +9995,13 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
updateLayoutAndRebuild(reconciledLayout);
|
||||
}
|
||||
|
||||
async function reloadFromDisk() {
|
||||
// An external change may arrive after an in-flight reload read its snapshot.
|
||||
// Wait for it, then read again instead of joining that stale snapshot.
|
||||
await initFromDiskPromise;
|
||||
await initFromDisk();
|
||||
}
|
||||
|
||||
async function initFromDisk() {
|
||||
// Connection normalization and timeout migration depend on persisted global
|
||||
// settings. Startup helpers may initialize connections before App.initApp().
|
||||
@@ -10067,6 +10074,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
replacePinnedTreeNode,
|
||||
removeTreeNode,
|
||||
refreshAllTree,
|
||||
reloadFromDisk,
|
||||
collapseAllTreeNodes,
|
||||
refreshSidebarObjectPagination,
|
||||
refreshTreeNode,
|
||||
|
||||
Reference in new issue
Block a user