Skip to content
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

refactor plugin controller to use v2 #13

Merged
merged 11 commits into from
Jun 1, 2021
Merged

Conversation

shanejonas
Copy link
Contributor

@shanejonas shanejonas commented May 21, 2021

  • add tests around plugin controller + worker controller + rpc handler

You can see an example of it implemented (and try it out) here:

https://github.com/MetaMask/metamask-snaps-beta/blob/develop-temp-05-20-2021/app/scripts/metamask-controller.js#L312-L348

- add tests around plugin controller + worker controller + rpc handler
@shanejonas shanejonas force-pushed the refactor-plugin-controller-v2 branch from aa22f43 to c89e588 Compare May 21, 2021 18:06
@shanejonas shanejonas requested a review from rekmarks May 25, 2021 22:24
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good so far! The biggest issue left is this memstore. I'm OK with doing this in two parts if you'd prefer, removing that in a follow-up PR. But it'll be in a weird hybrid state until then.

I'll need to read up a bit more on how this worker controller works - I don't understand that part very well yet.

packages/controllers/src/plugins/PluginController.ts Outdated Show resolved Hide resolved
packages/controllers/src/plugins/PluginController.ts Outdated Show resolved Hide resolved
@shanejonas shanejonas requested a review from Gudahtt May 28, 2021 00:21
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tests!

This looks good to me overall. All of my questions / requests are inline.

packages/controllers/src/plugins/PluginController.ts Outdated Show resolved Hide resolved
packages/controllers/src/plugins/PluginController.ts Outdated Show resolved Hide resolved
packages/controllers/src/plugins/PluginController.ts Outdated Show resolved Hide resolved
packages/controllers/src/plugins/PluginController.ts Outdated Show resolved Hide resolved
packages/controllers/src/plugins/PluginController.test.ts Outdated Show resolved Hide resolved
Comment on lines +101 to +105
terminateWorkerOf: TerminateWorkerOf;
command: Command;
terminateAll: TerminateAll;
createPluginWorker: CreatePluginWorker;
startPlugin: StartPlugin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that we'll eventually extract these into that generic execution environment service we discussed?

packages/controllers/src/plugins/PluginController.ts Outdated Show resolved Hide resolved
@shanejonas shanejonas requested a review from rekmarks May 31, 2021 22:40
const plugin = plugins[pluginName];
const newPlugin = { ...plugin, [property]: value };
const newPlugins = { ...plugins, [pluginName]: newPlugin };
this.updateState({
plugins: newPlugins,
this.update((state: any) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: probably worth commenting here about why we needed to use any - to avoid the incompatibility between Immer's WritableState type and recursive types like Json.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the other cases as well - anytime there's an update I suppose 🤔

const plugin = pluginsState[pluginName];
const { initialPermissions } = plugin;

// Don't prompt if there are no permissions requested:
if (Object.keys(initialPermissions).length === 0) {
return [];
}
if (initialPermissions === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is an otherwise unrelated bug fix?

plugins: newPlugins,
pluginStates: newPluginStates,
});
this._removeAllPermissionsFor(pluginNames);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the order of this has changed now - it's after the state update rather than before. This seems fine though. I don't know of a reason this would matter.

metadata: {
inlinePluginIsRunning: {
persist: false,
anonymous: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably make this true here? This isn't exactly personally identifiable. Though I'd imagine this is not here long-term, since it's only for testing.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shanejonas shanejonas merged commit 857e209 into main Jun 1, 2021
@shanejonas shanejonas deleted the refactor-plugin-controller-v2 branch June 1, 2021 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants