Repository navigation
fix(connections): migrate Salesforce to Agent Tools #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
142 changes: 142 additions & 0 deletions
142
src/features/extensions/lib/reconcileExtensions.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import type { ExtensionEntry } from "../types"; | ||
| import { reconcileExtensions } from "./reconcileExtensions"; | ||
|
|
||
| const { listExtensions, toggleExtension, removeExtension, backupGooseConfig } = | ||
| vi.hoisted(() => ({ | ||
| listExtensions: vi.fn(), | ||
| toggleExtension: vi.fn(), | ||
| removeExtension: vi.fn(), | ||
| backupGooseConfig: vi.fn(), | ||
| })); | ||
| vi.mock("@/features/extensions/api/extensions", () => ({ | ||
| listExtensions, | ||
| toggleExtension, | ||
| removeExtension, | ||
| })); | ||
| vi.mock("@/features/migration/api/migration", () => ({ backupGooseConfig })); | ||
|
|
||
| const legacy: ExtensionEntry = { | ||
| type: "stdio", | ||
| config_key: "salesforce-sq", | ||
| name: "Salesforce (Square)", | ||
| description: "", | ||
| cmd: "uvx", | ||
| args: ["mcp_salesforce_sq@0.2.4"], | ||
| bundled: true, | ||
| enabled: true, | ||
| }; | ||
|
|
||
| describe("startup extension reconciliation", () => { | ||
| beforeEach(() => { | ||
| vi.resetAllMocks(); | ||
| backupGooseConfig.mockResolvedValue({ | ||
| backedUp: true, | ||
| backupPath: "/config.yaml.backup", | ||
| }); | ||
| removeExtension.mockResolvedValue(undefined); | ||
| toggleExtension.mockResolvedValue(undefined); | ||
| }); | ||
|
|
||
| it.each([ | ||
| true, | ||
| false, | ||
| ])("retires the bundled stdio Salesforce MCP when enabled=%s, including after onboarding", async (enabled) => { | ||
| listExtensions.mockResolvedValue([{ ...legacy, enabled }]); | ||
| await reconcileExtensions(); | ||
| expect(backupGooseConfig).toHaveBeenCalledOnce(); | ||
| expect(removeExtension).toHaveBeenCalledWith("salesforce-sq"); | ||
| expect(listExtensions).toHaveBeenCalledTimes(2); | ||
| expect(backupGooseConfig.mock.invocationCallOrder[0]).toBeLessThan( | ||
| listExtensions.mock.invocationCallOrder[1], | ||
| ); | ||
| }); | ||
|
|
||
| it("recognizes uvx paths and normalized package names", async () => { | ||
| listExtensions.mockResolvedValue([ | ||
| { ...legacy, cmd: "/usr/local/bin/uvx", args: ["mcp-salesforce-sq"] }, | ||
| ]); | ||
| await reconcileExtensions(); | ||
| expect(removeExtension).toHaveBeenCalledWith("salesforce-sq"); | ||
| }); | ||
|
|
||
| it("preserves user-owned, remote, credential-configured, and unrelated servers", async () => { | ||
| listExtensions.mockResolvedValue([ | ||
| { ...legacy, bundled: false }, | ||
| { ...legacy, bundled: undefined }, | ||
| { ...legacy, type: "streamable_http", uri: "https://example.com/mcp" }, | ||
| { ...legacy, envs: { SALESFORCE_TOKEN: "configured" } }, | ||
| { ...legacy, env_keys: ["SALESFORCE_TOKEN"] }, | ||
| { ...legacy, cmd: "custom-wrapper" }, | ||
| { ...legacy, args: ["mcp_salesforce_sq_custom"] }, | ||
| { ...legacy, args: ["mcp_salesforce_sq@git+https://example.com/custom"] }, | ||
| { ...legacy, args: ["mcp_salesforce_sq", "--custom"] }, | ||
| ]); | ||
| await reconcileExtensions(); | ||
| expect(backupGooseConfig).not.toHaveBeenCalled(); | ||
| expect(removeExtension).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| { current: [{ ...legacy, envs: { SALESFORCE_TOKEN: "configured" } }] }, | ||
| { current: [{ ...legacy, env_keys: ["SALESFORCE_TOKEN"] }] }, | ||
| { current: [{ ...legacy, args: ["mcp_salesforce_sq", "--custom"] }] }, | ||
| { current: [{ ...legacy, name: "My Salesforce" }] }, | ||
| { current: [{ ...legacy, config_key: "another-salesforce" }] }, | ||
| { current: [] }, | ||
| ])("preserves an entry customized or removed during backup: $current", async ({ | ||
| current, | ||
| }) => { | ||
| listExtensions.mockResolvedValueOnce([legacy]).mockResolvedValue(current); | ||
| await reconcileExtensions(); | ||
| expect(backupGooseConfig).toHaveBeenCalledOnce(); | ||
| expect(removeExtension).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("revalidates each candidate after the preceding removal", async () => { | ||
| const second = { ...legacy, config_key: "other-salesforce" }; | ||
| listExtensions | ||
| .mockResolvedValueOnce([legacy, second]) | ||
| .mockResolvedValueOnce([legacy, second]) | ||
| .mockResolvedValueOnce([ | ||
| { ...second, envs: { SALESFORCE_TOKEN: "configured" } }, | ||
| ]); | ||
| await reconcileExtensions(); | ||
| expect(removeExtension).toHaveBeenCalledExactlyOnceWith("salesforce-sq"); | ||
| }); | ||
|
|
||
| it("enables core tools while retiring Salesforce and becomes a no-op on the next boot", async () => { | ||
| listExtensions | ||
| .mockResolvedValueOnce([ | ||
| legacy, | ||
| { | ||
| type: "builtin", | ||
| name: "skills", | ||
| description: "", | ||
| config_key: "skills", | ||
| enabled: false, | ||
| }, | ||
| { | ||
| type: "builtin", | ||
| name: "developer", | ||
| description: "", | ||
| config_key: "developer", | ||
| enabled: true, | ||
| }, | ||
| ]) | ||
| .mockResolvedValueOnce([legacy]) | ||
| .mockResolvedValueOnce([]); | ||
| await reconcileExtensions(); | ||
| await reconcileExtensions(); | ||
| expect(toggleExtension).toHaveBeenCalledExactlyOnceWith("skills", true); | ||
| expect(removeExtension).toHaveBeenCalledOnce(); | ||
| expect(backupGooseConfig).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it("does not remove anything if the backup fails", async () => { | ||
| listExtensions.mockResolvedValue([legacy]); | ||
| backupGooseConfig.mockRejectedValue(new Error("backup failed")); | ||
| await expect(reconcileExtensions()).rejects.toThrow("backup failed"); | ||
| expect(removeExtension).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { | ||
| listExtensions, | ||
| removeExtension, | ||
| toggleExtension, | ||
| } from "@/features/extensions/api/extensions"; | ||
| import { backupGooseConfig } from "@/features/migration/api/migration"; | ||
| import type { ExtensionEntry } from "../types"; | ||
| import { KEEP_ENABLED } from "./keepEnabled"; | ||
|
|
||
| // This bundled stdio server expects an HTTP request for hosted authentication. | ||
| // Keep user-owned servers and configurations that supply their own token. | ||
| function isLegacySalesforceMcp(extension: ExtensionEntry): boolean { | ||
| return ( | ||
| extension.type === "stdio" && | ||
| extension.bundled === true && | ||
| extension.cmd.split(/[\\/]/).at(-1) === "uvx" && | ||
| extension.args.length === 1 && | ||
| /^mcp[-_]salesforce[-_]sq(?:@\d+(?:\.\d+){1,2}(?:[a-zA-Z0-9.+-]*))?$/.test( | ||
| extension.args[0], | ||
| ) && | ||
| !Object.hasOwn(extension.envs ?? {}, "SALESFORCE_TOKEN") && | ||
| !extension.env_keys?.includes("SALESFORCE_TOKEN") | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Reconcile extension policy on every boot, including already-migrated installs. | ||
| * Core tools stay enabled. Retired bundled Salesforce MCPs are backed up and | ||
| * removed so the extension manager cannot load them on demand. | ||
| * Startup callers log failures and continue, allowing a retry on the next boot. | ||
| */ | ||
| export async function reconcileExtensions(): Promise<void> { | ||
| const extensions = await listExtensions(); | ||
| for (const extension of extensions) { | ||
| if (!KEEP_ENABLED.has(extension.config_key) || extension.enabled) continue; | ||
| try { | ||
| await toggleExtension(extension.config_key, true); | ||
| } catch (error) { | ||
| console.warn( | ||
| `Failed to re-enable always-on extension '${extension.config_key}':`, | ||
| error, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| const retired = extensions.filter(isLegacySalesforceMcp); | ||
| if (retired.length === 0) return; | ||
| await backupGooseConfig(); | ||
| for (const extension of retired) { | ||
| const current = (await listExtensions()).find( | ||
| (entry) => entry.config_key === extension.config_key, | ||
| ); | ||
| if ( | ||
| current && | ||
| isLegacySalesforceMcp(current) && | ||
| JSON.stringify(current) === JSON.stringify(extension) | ||
| ) { | ||
| await removeExtension(current.config_key); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.