feat(plugins): wire real db_get/db_put/dispatch_event host imports (VS-14) #22

Merged
David merged 2 commits from feat/wasm-host-imports-vs-14 into main 2026-05-17 14:34:15 +02:00
Owner

Summary

The wasm meshcore host imports themselves (host_db_get, host_db_put, host_dispatch_event, host_log, host_get_version) were already fully implemented in meshcentral-plugins. The gap: dispatch_plugin handed each plugin a NoopBackend that swallowed every call. Plugins could compile against the ABI but the server never saw any I/O.

Changes

  • New PluginHostBackend in user_session.rs holds a clone of AppState + the plugin name.
  • db_get / db_put: namespace to plugin/<name>/<key> so plugins can't trample each other or the server's own docs; persist via meshcentral-db.
  • dispatch_event: writes to the event log and broadcasts an event:{action:"plugin"} frame to every control session for cross-tab live sync.
  • Sync-to-async bridge via tokio::task::block_in_place + Handle::current().block_on; try_current guard returns a clean error in non-runtime contexts.
  • fetch_url deferred (issue marked it optional; requires a permissions: ["net"] manifest gate which is a separate follow-up).

Test plan

  • cargo check -p meshcentral-web clean.
  • cargo test -p meshcentral-web --lib plugin (8/8 still passing).
  • Reviewer: load a test plugin that exercises host_db_put / host_db_get and observe the namespaced row in meshcentral.db.json.

Closes VS-14.

## Summary The wasm meshcore host imports themselves (`host_db_get`, `host_db_put`, `host_dispatch_event`, `host_log`, `host_get_version`) were already fully implemented in `meshcentral-plugins`. The gap: `dispatch_plugin` handed each plugin a `NoopBackend` that swallowed every call. Plugins could compile against the ABI but the server never saw any I/O. ## Changes - New `PluginHostBackend` in `user_session.rs` holds a clone of `AppState` + the plugin name. - `db_get` / `db_put`: namespace to `plugin/<name>/<key>` so plugins can't trample each other or the server's own docs; persist via `meshcentral-db`. - `dispatch_event`: writes to the event log and broadcasts an `event:{action:"plugin"}` frame to every control session for cross-tab live sync. - Sync-to-async bridge via `tokio::task::block_in_place` + `Handle::current().block_on`; `try_current` guard returns a clean error in non-runtime contexts. - `fetch_url` deferred (issue marked it optional; requires a `permissions: ["net"]` manifest gate which is a separate follow-up). ## Test plan - [x] `cargo check -p meshcentral-web` clean. - [x] `cargo test -p meshcentral-web --lib plugin` (8/8 still passing). - [ ] Reviewer: load a test plugin that exercises `host_db_put` / `host_db_get` and observe the namespaced row in `meshcentral.db.json`. Closes VS-14.
feat(plugins): wire real db_get/db_put/dispatch_event host imports (VS-14)
All checks were successful
Check / fmt + clippy + build + tests (pull_request) Successful in 1m37s
d5fe6d8ce7
The plugin sandbox already exposed full host imports (`host_db_get`, `host_db_put`, `host_dispatch_event`, `host_log`, `host_get_version`) under `crates/meshcentral-plugins/src/host_imports.rs`; the gap was that `dispatch_plugin` handed it a `NoopBackend` that returned `Ok(None)` / `Ok(())` for everything. Plugins could call into them but the server never saw the calls.

Adds `PluginHostBackend` (per-plugin, holds a clone of `AppState` and the plugin name):

- `db_get(key)`: namespaces to `plugin/<name>/<key>` and reads from the configured sqlite database.
- `db_put(doc)`: requires `_id`, namespaces it, persists via `meshcentral-db`.
- `dispatch_event(payload)`: writes to the server-wide event log and broadcasts a `{action:"event", event:{action:"plugin", plugin, payload}}` frame to every control session for cross-tab live-sync.
- `server_version()`: returns `meshcentral_plugins::host_imports::HOST_IMPORT_VERSION` so guests can probe.

Backend methods are sync (wasmtime calls them from a sync context); the async DB / event-log calls are bridged via `tokio::task::block_in_place` + `Handle::current().block_on`, with a `try_current()` guard that returns a clean error if a future test wraps this in `current_thread`. `fetch_url` is intentionally deferred (the issue marks it as optional + capability-gated; landing it requires the per-plugin manifest `permissions: ["net"]` check that VS-6 added).

#VS-14 State Done
Merge branch 'main' into feat/wasm-host-imports-vs-14
Some checks failed
Check / fmt + clippy + build + tests (pull_request) Failing after 3s
Create release / Create release from merged PR (pull_request) Has been skipped
a6f61ddf05
David merged commit edc2d842a3 into main 2026-05-17 14:34:15 +02:00
David deleted branch feat/wasm-host-imports-vs-14 2026-05-17 14:34:15 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/vervain-server!22
No description provided.