Skip to main content

Unit tests against the mock host

On wasm32-wasip2 the Rust SDK calls the IDE. On your machine it calls the SDK’s mock host, so cargo test tests your plugin’s logic without the IDE:
MockHost::install() sets up a mock for the current test. It:
  • enforces capabilities like the IDE when you restrict them: MockHost::install().with_capabilities(&["editor.read"]) makes every other gated call return Error::Denied;
  • keeps a versioned editor document: type_in_editor makes the plugin’s next edit stale, so you can test Error::Stale handling;
  • holds project files (set_project_root, add_file, add_dir), settings (set_setting), the UI language (set_locale), VCS state, symbols and more;
  • records what the plugin did: notifications(), status_items(), storage(), subscriptions(), tasks(), fetches(), logs(), diagnostics(), opened locations, terminals, run targets;
  • lets you script answers: answer_next_prompt for pickers and input boxes, on_fetch for HTTP responses, on_process for program output.
The full list is in cargo doc for the SDK (src/mock.rs). The official plugins all have native tests to copy from.

Validate the package

check validates a folder or an .oiplugin exactly as Install Plugin from Disk… would: the manifest, every contribution, SVG sanitising, translation catalogs, and the component. For the component it checks that it imports nothing but the plugin API and WASI, that every function it imports exists in this IDE with the same signature, and that it exports the plugin world. It then prints the plugin’s code size and API version, categories, activation events, contributions and every capability with its risk, and ends with ok. openidea-plugin build runs check after every build. Run it on any package you build with other toolchains (componentize-py, jco componentize, TinyGo).

Try it in the IDE

Link the folder with openidea-plugin link, then after each openidea-plugin build click Reload from disk in the plugin’s details in Settings › Plugins (or run Reload Plugins). See the Quickstart. Settings › Plugins shows for each plugin its status, why it failed if it did, and its call statistics: recent call latency (p95), crashes, editor results that came too late, and how often it was reclaimed while idle.

Logging

  • host::log(level, message) writes to the IDE log, tagged with the plugin id.
  • eprintln! output is logged too, and a panic’s message is shown with the crash.
  • Debug and trace lines are written only when the IDE is started with RUST_LOG=info,ide_plugin=trace.
  • Open the log folder with Help › Show Log in Finder (macOS), Show Log in Explorer (Windows) or Show Log in Files (Linux).
For output the user should see, use an Output channel (host::output_append, API 1.4) or a notification instead.

Troubleshooting

Testing the host (contributors)

When you change the SDK, the WIT files or a plugin inside this repository, rebuild the checked-in components and run the host’s integration tests:
crates/ide-host/tests/plugins.rs loads the checked-in components of the official plugins and of the fixtures in crates/ide-plugin/tests/fixtures/. See Plugin host for more.