refactor!: Standardise SnapController action/event names and types#3907
refactor!: Standardise SnapController action/event names and types#3907Mrtenz wants to merge 12 commits intocontroller-refactorsfrom
SnapController action/event names and types#3907Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## controller-refactors #3907 +/- ##
=====================================================
Coverage 98.55% 98.55%
=====================================================
Files 425 425
Lines 12358 12360 +2
Branches 1935 1935
=====================================================
+ Hits 12180 12182 +2
Misses 178 178 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| @@ -0,0 +1,773 @@ | |||
| #!yarn tsx | |||
There was a problem hiding this comment.
Not ideal to be duplicating this file between repos
There was a problem hiding this comment.
Agreed, we can consider extracting it into a publishable package at some point.
| @@ -0,0 +1,773 @@ | |||
| #!yarn tsx | |||
There was a problem hiding this comment.
Can you explain the diff between this version and the one in core? Are we intending to sync back these changes?
There was a problem hiding this comment.
The only difference is support for nested directories. The core script assumes all controllers are in the top-level src directory, which is not the case for Snaps controllers. We can sync this with core if we decide to create a package for the script.
There was a problem hiding this comment.
Definitely don't want them to diverge.
| const allSnaps = this.#messenger.call('SnapController:getAllSnaps'); | ||
| const filteredSnaps = getRunnableSnaps(allSnaps); |
There was a problem hiding this comment.
Since we are making a breaking change here we could consider swapping to use SnapController: getRunnableSnaps
There was a problem hiding this comment.
Can do it in the follow up PR for MultichainRouter.
| #getSnapsWithPermission(permissionName: string) { | ||
| const allSnaps = this.messenger.call('SnapController:getAll'); | ||
| const allSnaps = this.messenger.call('SnapController:getAllSnaps'); | ||
| const filteredSnaps = getRunnableSnaps(allSnaps); |
There was a problem hiding this comment.
Same as MultichainRouter
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
packages/snaps-controllers/src/snaps/SnapController-method-action-types.ts
Show resolved
Hide resolved
| export const MESSENGER_EXPOSED_METHODS = [ | ||
| 'init', | ||
| 'updateRegistry', | ||
| 'startSnap', |
There was a problem hiding this comment.
| 'startSnap', |
TBH probably does not need to be publicly accessible
| 'incrementActiveReferences', | ||
| 'decrementActiveReferences', |
There was a problem hiding this comment.
I wonder if we should just remove this 😄
| 'getSnapExpect', | ||
| 'getTruncatedSnap', | ||
| 'getTruncatedSnapExpect', |
There was a problem hiding this comment.
Unsure if these need to be publicly accessible
|
|
||
| messenger.delegate({ | ||
| actions: [ | ||
| 'PermissionController:hasPermission', |
| const originalTerminateFunction = service.terminateJob.bind(service); | ||
|
|
||
| let promise: Promise<unknown>; | ||
| let promise: Promise<unknown> = Promise.resolve(); |
There was a problem hiding this comment.
Without this, TypeScript complains about promise not being assigned.

This renames all
SnapControlleraction and event names and types to follow theController...Actionpattern used in most other controllers. I've also added thegenerate-method-actionsscript used inMetaMask/coreto automatically generate these types.I found numerous unrelated type errors in test files that I fixed in this pull request as well, since it was a bit difficult to determine if a type error was caused by this refactor or not, in some cases.
Breaking changes
SnapControlleraction types were renamed fromDoSomethingtoSnapControllerDoSomethingAction.GetSnapis nowSnapControllerGetSnapAction.getSnapinstead ofget.HandleSnapRequestis nowSnapControllerHandleRequestAction.GetSnapStateis nowSnapControllerGetSnapStateAction.HasSnapis nowSnapControllerHasSnapAction.hasSnapinstead ofhas.UpdateSnapStateis nowSnapControllerUpdateSnapStateAction.ClearSnapStateis nowSnapControllerClearSnapStateAction.UpdateRegistryis nowSnapControllerUpdateRegistryAction.EnableSnapis nowSnapControllerEnableSnapAction.enableSnapinstead ofenable.DisableSnapis nowSnapControllerDisableSnapAction.disableSnapinstead ofdisable.RemoveSnapis nowSnapControllerRemoveSnapAction.removeSnapinstead ofremove.GetPermittedSnapsis nowSnapControllerGetPermittedSnapsAction.getPermittedSnapsinstead ofgetPermitted.GetAllSnapsis nowSnapControllerGetAllSnapsAction.getAllSnapsinstead ofgetAll.GetRunnableSnapsis nowSnapControllerGetRunnableSnapsAction.StopAllSnapsis nowSnapControllerStopAllSnapsAction.IncrementActiveReferencesis nowSnapControllerIncrementActiveReferencesAction.DecrementActiveReferencesis nowSnapControllerDecrementActiveReferencesAction.InstallSnapsis nowSnapControllerInstallSnapsAction.installSnapsinstead ofinstall.DisconnectOriginis nowSnapControllerRemoveSnapFromSubjectAction.RevokeDynamicPermissionsis nowSnapControllerRevokeDynamicSnapPermissionsAction.GetSnapFileis nowSnapControllerGetSnapFileAction.IsMinimumPlatformVersionis nowSnapControllerIsMinimumPlatformVersionAction.SetClientActiveis nowSnapControllerSetClientActiveAction.SnapControllerevent types were renamed fromOnSomethingtoSnapControllerOnSomethingEvent.SnapStateChangewas removed in favour ofSnapControllerStateChangeEvent.SnapBlockedis nowSnapControllerSnapBlockedEvent.SnapInstallStartedis nowSnapControllerSnapInstallStartedEvent.SnapInstallFailedis nowSnapControllerSnapInstallFailedEvent.SnapInstalledis nowSnapControllerSnapInstalledEvent.SnapUninstalledis nowSnapControllerSnapUninstalledEvent.SnapUnblockedis now `SnapControllerSnapUnblockedEvent.SnapUpdatedis nowSnapControllerSnapUpdatedEvent.SnapRolledbackis nowSnapControllerSnapRolledbackEvent.SnapTerminatedis nowSnapControllerSnapTerminatedEvent.SnapEnabledis nowSnapControllerSnapEnabledEvent.SnapDisabledis nowSnapControllerSnapDisabledEvent.Note
Medium Risk
Medium risk due to breaking renames of
SnapControllermessenger action/event types and action string IDs (e.g.,get→getSnap,getAll→getAllSnaps), which can cause widespread compile/runtime call-site breakage if any consumers aren’t updated.Overview
BREAKING: Renames
SnapControllermessenger action/event types to theSnapController...Action/SnapController...Eventpattern and updates several action IDs/method names (notablySnapController:get→SnapController:getSnapandSnapController:getAll→SnapController:getAllSnaps).Adds an auto-generated
SnapController-method-action-types.tsand introduces a repo/workspacegenerate-method-action-typesscript, wiring it into rootlint(with--check) and addingyargsas a dev dependency.Updates affected controllers/tests (
CronjobController,SnapInsightsController,SnapInterfaceController,MultichainRouter) to use the newSnapControlleraction types/IDs, plus minor test util renames and removal of now-unnecessary lint-disable comments in execution services.Written by Cursor Bugbot for commit 3b51590. This will update automatically on new commits. Configure here.