Skip to content

Add AppExtensions with Tauri-plugin support and a runtime-generic assemble() - #3385

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3304-app-extensions
Sep 30, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3304-app-extensions

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3304

Summary

Adds the first pieces of the Rust extension API to nodespace_app_lib, in a new extensions module:

  • EXTENSION_API_VERSION: (u32, u32) = (1, 0).
  • AppExtensions<R = tauri::Wry> with private fields, none(), plugin(P) (kept in call order) and a Default equal to none() with no R: Default bound.
  • assemble(builder, extensions), generic over the runtime, which registers each extension plugin with Builder::plugin_boxed in order.
  • pub(crate) CORE_PLUGIN_NAMES = ["single-instance", "opener", "dialog"].

assemble skips, and logs with tracing::error!, an extension plugin whose name is in CORE_PLUGIN_NAMES or was already registered by an earlier extension plugin. Tauri's plugin store would otherwise let the later plugin silently replace the earlier one, so the first registration wins. Skipped means never handed to the builder, so its setup never runs.

run() does not call any of this yet, so the app is unchanged. The re-exports are in lib.rs: pub use extensions::{assemble, AppExtensions, EXTENSION_API_VERSION};.

Tests

extensions/fixture_tests.rs holds a fixture plugin (fixture, command fixture_ping, managed FixtureState), all driven through assemble on tauri::test::MockRuntime. The IPC tests grant the command with Context::runtime_authority_mut().__allow_command(..), as the issue describes.

The seven tests the issue lists:

  • extension_plugin_setup_runs_and_its_state_is_managed
  • extension_plugin_command_answers_through_ipc_once_granted
  • extension_plugin_command_is_denied_without_a_grant (also asserts the refusal is the capability check's, not a missing plugin)
  • extension_plugin_named_like_a_core_plugin_is_not_registered (loops over all three core names; a probe registered under the name before assemble stands in for core's plugin, and the test checks that its setup still ran and the extension plugin's did not)
  • second_extension_plugin_with_the_same_name_is_not_registered
  • core_plugin_names_match_the_plugins_core_registers (compares against the real single_instance, opener and dialog constructors' name())
  • none_registers_nothing (covers none() and Default)

Two more I added: extension_api_version_is_one_zero, and extension_plugins_are_registered_in_the_order_they_were_added, since call order is part of the specified contract.

Mutation results

Each mutation was applied on its own, the suite run, and the change reverted:

Mutation Tests that failed
version const set to (1, 1) extension_api_version_is_one_zero
assemble registers nothing granted IPC, denied, setup/state, order, second-same-name
core-name skip disabled (the extension plugin replaces core's) ..named_like_a_core_plugin..
duplicate-name skip disabled second_extension_plugin_with_the_same_name..
plugins registered in reverse order order, second-same-name
dialog dropped from CORE_PLUGIN_NAMES core_plugin_names_match..
opener misspelled in CORE_PLUGIN_NAMES core_plugin_names_match..
assemble always adds a fixture plugin none_registers_nothing
Default adds a fixture plugin none_registers_nothing
test helper grants every command ..denied_without_a_grant

Verification

  • cargo test --lib -p nodespace-app-lib -- extensions:: --test-threads=2: 9 passed.
  • cargo fmt -p nodespace-app-lib clean. cargo clippy -p nodespace-app-lib --all-targets -- -D warnings -D clippy::unused-async clean.
  • NODESPACE_PRO_SUPABASE_URL=https://example.invalid NODESPACE_PRO_ANON_KEY=dummy cargo check -p nodespace-app passes.
  • bun run test:changed passed (scripts tier and the Rust workspace under nextest), re-run after the review fixes.
  • No new rustdoc warnings from the module.

Pro/core boundary ratchet

bun run scripts/check-pro-boundary.ts passes on this branch rebased onto main with the check. This PR adds and removes no markers (0 hits on its added lines and no pro-named files), so every count equals main's and none rises. The only count below its baseline is cloudSyncHooks (0 against 4), which an earlier merge on main caused; this PR does not touch it, so no baseline is edited here.

Deviations from the issue

  • The optional re-exports (tonic::transport::Channel, tokio_util::sync::CancellationToken) are left for the daemon-ready-task change, where DaemonReady first needs them.
  • core_plugin_names_match_the_plugins_core_registers is #[cfg(desktop)], mirroring the guard on the single-instance plugin in run() (the desktop alias comes from this crate's build.rs).
  • CORE_PLUGIN_NAMES is checked against the plugin constructors as the issue specifies. It is not yet tied to the registrations in run(), which do not go through assemble.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code review (medium), initial review

Review Type: Initial Review

Scope: extensions/mod.rs (new), extensions/fixture_tests.rs (new), 4 lines in lib.rs. I checked the rustdoc claims against the vendored tauri 2.11.2 source and did not run any builds (the author's test and mutation results are taken as given and only spot-checked by reasoning).

Requirements Check (issue 3304)

  • AppExtensions, assemble and EXTENSION_API_VERSION are public, re-exported from lib.rs and documented. The value is (1, 0) and extension_api_version_is_one_zero covers it.
  • A fixture plugin registered through assemble runs its setup and its managed state is readable (extension_plugin_setup_runs_and_its_state_is_managed).
  • plugin:fixture|fixture_ping answers through real IPC once granted and is refused without a grant (the two IPC tests).
  • An extension plugin named single-instance, opener or dialog is not registered and its setup never runs. The test loops over all three names.
  • An extension plugin that reuses an earlier extension plugin's name is not registered, and the first registration stays.
  • CORE_PLUGIN_NAMES is compared with Plugin::name() of the real single_instance, opener and dialog constructors. Comparison is sorted set equality, so the "in the order it does" wording in the const's doc is not enforced (see Nit 1).
  • AppExtensions::none() and Default register nothing and the build succeeds. The assertion is bounded, see Nit 2.
  • Ratchet: judged reasonable, see below.
  • No product names and no issue numbers in the new code or docs. I grepped both files for nodespace, #<digits>, issue and adr: no matches. git diff --check is clean.

Ratchet criterion. scripts/check-pro-boundary.ts is not on main, so it cannot run here. I took MARKERS from the issue-3299-pro-boundary-ratchet branch and applied every marker regex to the 360 added lines: 0 hits. The new files also have no pro basename segment. The PR removes no markers, so BASELINES has nothing to lower, and adds none, so no count rises. Once that script lands, the merge gate will run it against this diff. Substituting the measurement is the right call and I reproduced it.

Deviations.

  1. Deferring the optional Channel and CancellationToken re-exports is fine. The issue marks them optional, and adding an unused public surface now would be speculative.
  2. #[cfg(desktop)] on the plugin-names test is correct and safe. run() uses the same guard, and the desktop alias comes from app-lib/build.rs:42. The existing cfg_alias_tests::desktop_cfg_alias_is_set (app-lib/src/tests.rs:355) fails if the alias ever disappears, so the guarded test cannot silently compile out on a desktop target.
  3. CORE_PLUGIN_NAMES is checked against constructors, not against run()'s registrations. This is acceptable for this PR because run() does not go through assemble yet. It leaves a drift risk that should be tracked in the change that wires run() (see Improvement 1).

The 2 extra tests are worth keeping. extension_plugins_are_registered_in_the_order_they_were_added covers a real contract: single-instance must be registered first, and PluginStore is an insertion-ordered Vec that initialize_all walks in order. extension_api_version_is_one_zero is a literal-equals-literal check, but it is an acceptance criterion and a deliberate tripwire for a version bump.

Verification of the rustdoc claims against tauri 2.11.2

All claims in assemble's rustdoc are true. None is wrong.

  • Plugin setup runs inside Builder::build, before core's setup. Builder::build ends with app.manager.initialize_plugins(handle)? (app.rs:2432, which calls PluginStore::initialize_all, manager/mod.rs:488). The app's own .setup closure is not run by build at all. setup() (app.rs:2513-2526) is called from the RuntimeRunEvent::Ready arm (app.rs:1416) once the event loop starts. So the claim holds, and the gap is wider than "before": build returns before core's setup begins. As a consequence, no test here can observe the plugin-before-app-setup ordering. It is a doc-only claim, which is acceptable.
  • Plugin commands are plugin:<name>|<cmd> and always ACL-checked. webview/mod.rs:1811-1851 splits the plugin: prefix and rejects when (plugin_command.is_some() || has_app_acl_manifest || !is_local) && cmd != FETCH_CHANNEL_DATA_COMMAND && invoke.acl.is_none(). The only exempt plugin command is tauri's internal plugin:__TAURI_CHANNEL__|fetch, which is irrelevant to extensions. The ACL check runs before extend_api looks up the plugin, so an ungranted call is refused with the ACL message whether or not the plugin is registered. That is why the denied test needs its extra registration assertion, and it has one.
  • Duplicate names silently replace. PluginStore::register (plugin.rs:880-885) drops every existing entry with the same name and pushes the new one. Builder::plugin_boxed (app.rs:1851-1854) discards the returned bool, so nothing is logged. A replacement also moves the plugin to the end of the list, which does not matter here.
  • Skipping means the setup never runs. A plugin is initialized only through initialize_all over the store contents at build. A plugin never passed to plugin_boxed never enters the store, so its setup cannot run.
  • Single-instance first. The repo's own comment in run() and the tauri-plugin-single-instance 2.4.3 README both say the plugin must be registered first because plugins run in the order they were added.
  • Test-only APIs. RuntimeAuthority::__allow_command (ipc/authority.rs:136-146) and Context::runtime_authority_mut (lib.rs:478-482) are #[doc(hidden)] pub with no feature gate. The grant inserts windows: ["*"] with ExecutionContext::Local, which is what the test needs.
  • Log visibility. run() defaults to EnvFilter::new("nodespace_app=info"). tracing-subscriber matches directive targets with starts_with (filter/env/directive.rs:246), so nodespace_app_lib::extensions errors are visible by default, the same as the existing tracing::warn! calls in lib.rs.

Three docs are forward-looking rather than wrong (Nit 3).

Test quality

  • extension_plugin_command_is_denied_without_a_grant does prove an ACL refusal, not some other error. In debug builds the refusal text is fixture.fixture_ping not allowed. Plugin not found (authority.rs:432). In release builds it is Command plugin:fixture|fixture_ping not allowed by ACL. Both contain not allowed. A wrong invoke key would panic in get_ipc_response's recv().expect(..), not return Err, so it cannot pass for the wrong reason. A missing plugin yields plugin fixture not found, which does not match. The try_state::<FixtureState>().is_some() guard closes the last gap. The Plugin not found tail is a tauri quirk meaning there is no ACL manifest for that key, so do not assert on it.
  • The URL choice is sound on all CI OSes. cfg!(any(windows, target_os = "android")) mirrors tauri_protocol_url (manager/mod.rs:340), and is_local_url compares scheme and domain to that URL. A wrong origin would make the granted test fail loudly (a Remote origin does not match a Local grant). The denied test would still pass, but the granted test guards it.
  • The remove_plugin-based assertions are sound but redundant. mock_builder() registers no plugins, so remove_plugin(name) == true means an extension plugin got in. Anything in the store has its setup run during build, so the ran flag already proves the same thing. They do no harm.
  • none_registers_nothing is meaningful but bounded. The plugin store is pub(crate) in tauri and cannot be enumerated, so the test can only catch a stray fixture plugin or a stray plugin under a core name. That covers the plausible regressions (the author's two mutations show it) but not a stray plugin under an arbitrary name.
  • Construction has no side effects on Windows or Linux. tauri_plugin_single_instance::init::<MockRuntime, _>(..) only builds the plugin. The lock is taken in setup, which is never run there.
  • Coverage of the mutation table is consistent with what the tests assert (each row I traced fails the stated test).

Code Review Findings

[Improvement] 1. Core plugin names can drift from what run() registers (packages/desktop-app/app-lib/src/extensions/mod.rs:35, packages/desktop-app/app-lib/src/lib.rs:349-358).
Principle: one source of truth for an invariant that guards against silent replacement.
CORE_PLUGIN_NAMES is a hand-kept list, and its test compares it with the constructors, not with run(). If someone adds a fourth plugin to run() (or renames one), nothing fails, and an extension plugin can then silently replace it, which is the exact hazard the const exists to prevent. This is not a blocker because run() does not use assemble yet, and the author documented it. Suggest that the change that wires run() in derives both from one place (for example, run() registers core's plugins through one function, and a test asserts the names it registers equal the const), or lists this as an acceptance criterion there.

[Improvement] 2. The core-name collision test does not model the hazard (fixture_tests.rs:140-155).
Principle: test the failure the guard is for, not only the guard's mechanism.
The test builds on mock_builder(), where no core plugin exists, so it shows only that the extension plugin is not registered. It never shows that core's plugin survives. It does catch removal of the skip (the extension's setup would run), so it is not vacuous. A stronger version registers a probe plugin under a core name on the builder before calling assemble, then asserts that the core probe's setup ran and the extension probe's did not. That fails if the skip were replaced by a replace-on-collision behavior. Small change, same helpers.

[Nit] 1. The CORE_PLUGIN_NAMES doc claims an order the test does not enforce (mod.rs:30, fixture_tests.rs:210-215).
The doc says "in the order it does", but the test sorts both sides. Either drop the phrase or compare unsorted (single-instance, opener, dialog is the registration order in run()).

[Nit] 2. Tighten the ACL assertion and comment the doc-hidden helper (fixture_tests.rs:134-137, 62-71).
contains("not allowed") would also match a refusal for a different command. Also asserting that the message contains fixture_ping (true in debug and release) ties it to this command. On build_app_granting, add a one-line why: the mock context has an empty ACL and add_capability needs generated manifests, so the doc-hidden grant is the only route. A Tauri bump that removes it then has a clear pointer to the fallback in the issue's risk section. In none_registers_nothing, a one-line comment that only known names can be probed (the store is not enumerable) sets the right expectation.

[Nit] 3. Three docs state future wiring as present fact (mod.rs:11-13, 74-77, 26-27).
On this branch main.rs calls run(context) and run() does not call assemble, and no TypeScript version constant exists on main. Yet the docs say the core app crate passes AppExtensions::none, that run applies core's plugins around assemble, and that the TypeScript host API carries the same value. The issue asked for this wording and the follow-up changes land next, so it is fine to keep. If those changes slip, rephrase them as the invariant ("must stay equal to the TypeScript host API's value") so the docs do not go stale.

[Nit] 4. #[must_use] on the consuming builders (mod.rs:48, 58, 100).
ext.plugin(p); with the result discarded compiles without a warning and drops the plugin. tauri marks its own Builder::plugin #[must_use], but neither tauri's Builder nor AppExtensions is #[must_use] at the type level. Adding it to none, plugin and assemble costs nothing. Also let mut builder = builder; (mod.rs:101) can be mut builder in the signature.

API design notes (no action needed)

  • Private field and Default. The private plugins field is right, and impl<R: Runtime> Default avoids the R: Default bound that #[derive(Default)] would add. The comment explaining that is helpful.
  • Send bound. Plugin<R> has a Send supertrait (plugin.rs:37), so Box<dyn Plugin<R>> is already Send and P: Plugin<R> + 'static is exactly Builder::plugin's bound. No extra bound is needed. The struct is !Sync, consistent with tauri's builder.
  • Box<dyn Plugin<R>> storage. Boxed storage is the right choice: it feeds plugin_boxed directly and lets assemble read name() for the dedupe and the core-name check, which a closure-based design could not.
  • HashSet<&'static str>. Correct, because Plugin::name returns &'static str.
  • Skip and tracing::error!. Adequate for the accepted risk (the issue calls the hidden-programming-error trade-off out explicitly). The log carries the plugin name and the reason, and it is visible under the default filter. One note for the wiring change: keep assemble after the subscriber init at the top of run(), as run() does today.

Recommendation: APPROVE. There are no blockers. Every acceptance criterion is met, the rustdoc claims check out against tauri 2.11.2, and the tests are non-vacuous. The two improvements are cheap and worth doing here or tracking for the change that wires run(); the nits are optional.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review: APPROVE (posted as a comment, GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125
mstomar125 force-pushed the issue-3304-app-extensions branch from 6a0d6fd to 6cb0987 Compare September 30, 2026 11:03
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary

Addresses the pragmatic code review (medium, initial) above, which recommended APPROVE with no blockers. Pushed as 6cb09875, rebased onto current main.

Addressed (5 of 6 recommendations)

  • Improvement 2: extension_plugin_named_like_a_core_plugin_is_not_registered now registers a probe under each core plugin name before assemble, then asserts the core probe's setup still ran and the extension plugin's did not. It now proves the extension plugin is skipped rather than replacing core's. With the core-name skip disabled the test fails on both assertions.
  • Nit 1: dropped the "in the order it does" wording from CORE_PLUGIN_NAMES, since the test compares sorted sets.
  • Nit 2: the denied-without-a-grant test also asserts the refusal names fixture_ping. Added a comment on why the grant uses a doc-hidden call, and one in none_registers_nothing that only known plugin names can be probed.
  • Nit 3 (part): removed the module-doc sentence saying core's app crate passes none(), which is not true yet. The remaining forward-looking rustdoc lines (run applies core's own commands and setup, and the TypeScript host API carries the same version) are wording the issue explicitly specifies, so they stay.
  • Nit 4: #[must_use] on none, plugin and assemble, and mut builder in the assemble signature.

Skipped (1)

  • Improvement 1, tie run()'s plugin registrations and CORE_PLUGIN_NAMES to one source. run() does not go through assemble yet, so there is nothing to tie until it does. This belongs to the change that wires run() through assemble, where a single shared source for those registrations should be an acceptance criterion. I am flagging it to the coordinator for that issue. Revisit if run() gains another plugin before then.

Verification after the fixes

  • 9 extension tests pass, clippy clean with -D warnings -D clippy::unused-async, cargo fmt clean, the Pro-mode cargo check -p nodespace-app passes.
  • All 11 mutations re-run; each fails exactly the tests it should (including the rewritten core-name test and the denied test).
  • bun run scripts/check-pro-boundary.ts (now on main) passes with no count above its baseline; this PR adds and removes no markers.
  • bun run test:changed passed (scripts tier and Rust workspace under nextest).

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The production-code changes are attributes and a signature mut, plus comment and doc trims, with no logic change. The one behavioral edit is the core-name test, which is the reviewer's own suggestion, test-only, and mutation-verified on both assertions. Nothing new was added that a reviewer has not already seen the design of.

mstomar125 and others added 2 commits September 30, 2026 13:08
…emble()

Adds the first pieces of the extension API to nodespace_app_lib:
EXTENSION_API_VERSION, AppExtensions<R> with none() and plugin(P), and
assemble(builder, extensions), which registers extension Tauri plugins in
the order they were added.

A plugin whose name belongs to a plugin core registers (single-instance,
opener, dialog), or that reuses the name of an earlier extension plugin, is
skipped and logged, since Tauri would otherwise let it silently replace the
earlier plugin. assemble is generic over the runtime so the fixture tests
drive it on tauri::test::MockRuntime, including a plugin command answered
through IPC once granted and refused without a grant.

run() does not use these yet, so the app is unchanged.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…n docs and must_use

- The core-name test now registers a probe under each core plugin name before
  assemble and asserts that its setup still ran and the extension plugin's did
  not, so it shows the extension plugin is skipped rather than replacing core's.
- The denied-without-a-grant test also asserts the refusal names the command.
- Comment why the grant uses a doc-hidden call, and that the no-extension test
  can only probe known names.
- Mark none, plugin and assemble #[must_use]; take the builder as `mut` in the
  assemble signature.
- Drop the unenforced "in the order it does" wording from the core plugin list
  and the module-doc sentence about core's app crate.

Skipped: tying run()'s plugin registrations to CORE_PLUGIN_NAMES, which needs
run() to go through assemble and belongs with that wiring.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

Add AppExtensions with Tauri-plugin support and a runtime-generic assemble()

1 participant