Repository navigation
Description
Part of #3322 (Tauri extension points for the desktop app).
Summary
Add the first pieces of the Rust extension API to nodespace_app_lib:
EXTENSION_API_VERSION;AppExtensions<R>, withnone()andplugin(P);- the runtime-generic
assemble(builder, extensions), which registers extension Tauri plugins.
run() doesn't use them yet (#3306 wires them in), so the app doesn't change. Everything is covered by tauri::test::MockRuntime fixture tests driven through assemble.
Context
Plugins carry everything (ADR-082 (proposed) §3.2 and §3.3). Extension commands, managed state, setup and run-event handling arrive as Tauri plugins, not as entries in core's invoke list:
- A
Builderholds one invoke handler (tauri 2.11.2app.rs1650). - Plugin commands are
plugin:<name>|<cmd>and are always ACL-checked (webview/mod.rs1823). - The app crate grants them in its own capability; core's capabilities never name them.
Plugin setup runs early. It runs inside Builder::build, before core's setup. It must not assume the GrpcClient, the shutdown token or a running daemon; that work belongs in #3307's daemon-ready task.
Duplicate names replace silently. A second plugin with an existing name replaces the first (plugin.rs 880-885).
- Core registers
single-instance(desktop only),openeranddialog(lib.rs343-353). - ADR-082 §2.1 treats a duplicate frontend id as a programming error and keeps the first registration. This PR does the same for plugins.
Why assemble covers only the extension half. See the #3322 parent: at least 17 core commands take the Wry-typed tauri::AppHandle, and core's setup starts a real daemon.
Testing a plugin command through IPC in MockRuntime.
tauri::test::mock_contexthas an empty ACL.- A test grants the one command on the context with
Context::runtime_authority_mut()(tauri/src/lib.rs480) andRuntimeAuthority::__allow_command(cmd, ExecutionContext::Local)(ipc/authority.rs137). __allow_commandis public but doc-hidden.
Scope
New packages/desktop-app/app-lib/src/extensions/mod.rs
Register it as pub mod extensions; in lib.rs, and re-export pub use extensions::{assemble, AppExtensions, EXTENSION_API_VERSION};.
pub const EXTENSION_API_VERSION: (u32, u32) = (1, 0);
- Its doc says this is the version of the extension API, under ADR-082's compatibility policy: a breaking change bumps major, an additive change bumps minor.
- The TypeScript host API carries the same value; Enforce EXTENSION_API_VERSION: Rust matches TypeScript, fixture changes bump it #3321 enforces that.
pub struct AppExtensions<R: tauri::Runtime = tauri::Wry>, with private fields (plugins: Vec<Box<dyn tauri::plugin::Plugin<R>>>):
pub fn none() -> Self, plus aDefaultimpl equal tonone(), with noR: Defaultbound;pub fn plugin<P: tauri::plugin::Plugin<R> + 'static>(self, plugin: P) -> Self. Plugins are kept in call order.
pub fn assemble<R: tauri::Runtime>(builder: tauri::Builder<R>, extensions: AppExtensions<R>) -> tauri::Builder<R>
- It registers each extension plugin with
Builder::plugin_boxed, in order. - It skips a plugin whose
name()is inCORE_PLUGIN_NAMES, or was already registered by an earlier extension plugin, and logs it withtracing::error!. - It registers nothing else yet; Add daemon-ready tasks and a channel-rebuilt hook to AppExtensions #3307 and Let an app built on core supply its update source through AppExtensions #3320 add hook state.
- Its rustdoc covers:
- the caller registers core's own plugins first, with single-instance first;
- plugin setup runs before core's setup;
- plugin commands are
plugin:<name>|<cmd>, and the app crate's capability must grant them; - the duplicate-name rule;
run()applies core's own commands and setup (Route the desktop app through run(extensions, context) with no extensions in core #3306);- why
assembleis runtime-generic: for tests.
pub(crate) const CORE_PLUGIN_NAMES: &[&str] = &["single-instance", "opener", "dialog"];
Re-exports (optional here, or in #3307): pub use tonic::transport::Channel; and pub use tokio_util::sync::CancellationToken;, so an extension crate names the exact versions core uses.
All docs use generic wording ("extension", "app crate") and name no product.
New packages/desktop-app/app-lib/src/extensions/fixture_tests.rs
Register it as #[cfg(test)] mod fixture_tests;. It holds the fixture extension; later sub-issues extend it, and #3321 watches it. It contains:
- a
fixtureplugin:tauri::plugin::Builder::<R>::new("fixture"), with.invoke_handler(tauri::generate_handler![fixture_ping])and a.setupthat managesFixtureState; #[tauri::command] fn fixture_ping(state: tauri::State<'_, FixtureState>) -> String.
Out of scope
run(extensions, context)andmain.rs(Route the desktop app through run(extensions, context) with no extensions in core #3306).- Daemon-ready tasks and channel-rebuilt hooks (Add daemon-ready tasks and a channel-rebuilt hook to AppExtensions #3307).
- The update source (Let an app built on core supply its update source through AppExtensions #3320).
- The daemon profile (Let an app built on core supply its DaemonProfile via AppExtensions::daemon_profile #3347).
- The window capability (Have the app library add core's window capability at startup #3308).
Steps
- Run the CLAUDE.md startup sequence. Self-assign at pickup; the worktree is
issue-<N>-app-extensions. - Add the module, the types,
assembleand the re-exports. - Write the fixture tests below:
- build with
assemble(tauri::test::mock_builder(), ext).build(ctx), wherectx = tauri::test::mock_context(tauri::test::noop_assets()); - for the IPC tests, open a
mainwebview withtauri::WebviewWindowBuilder::new(&app, "main", Default::default()); - call
tauri::test::get_ipc_responsewithinvoke_key: tauri::test::INVOKE_KEYand the URLtauri://localhost.
- build with
- Run
bun run quality:fix, thenbun run test:changed.
Acceptance criteria
-
nodespace_app_lib::{AppExtensions, assemble, EXTENSION_API_VERSION}are public and documented, andEXTENSION_API_VERSION == (1, 0). - A fixture plugin registered through
assembleruns its setup, and its managed state is readable. -
plugin:fixture|fixture_pinganswers through IPC once granted, and is denied without a grant. - An extension plugin named
opener,dialogorsingle-instanceis not registered, and its setup never runs. - An extension plugin reusing an earlier extension plugin's name is not registered either.
-
CORE_PLUGIN_NAMESequals thename()of the three plugins core registers, checked against the real plugin constructors. -
AppExtensions::none()registers nothing, and the build succeeds. -
bun run scripts/check-pro-boundary.tspasses.BASELINESare lowered to the exact new counts wherever this PR removes markers, and no count rises. - No product names or GitHub issue numbers in the new code or docs.
Tests and verification
New tests in extensions/fixture_tests.rs:
extension_plugin_setup_runs_and_its_state_is_managedextension_plugin_command_answers_through_ipc_once_grantedextension_plugin_command_is_denied_without_a_grantextension_plugin_named_like_a_core_plugin_is_not_registeredsecond_extension_plugin_with_the_same_name_is_not_registeredcore_plugin_names_match_the_plugins_core_registers: compares, throughtauri::plugin::Plugin::name, against:tauri_plugin_single_instance::init::<MockRuntime, _>(|_, _, _| {});tauri_plugin_opener::init::<MockRuntime>();tauri_plugin_dialog::init::<MockRuntime>().
none_registers_nothing
Mutation-check each new test: break the code path it covers, confirm the test fails, then restore.
cargo test --lib -p nodespace-app-lib -- extensions:: --test-threads=2
cargo clippy -p nodespace-app-lib --all-targets -- -D warnings -D clippy::unused-async
NODESPACE_PRO_SUPABASE_URL=https://example.invalid NODESPACE_PRO_ANON_KEY=dummy cargo check -p nodespace-app
bun run test:changed
Dependencies
Risks and rollback
- A doc-hidden Tauri API in a test.
__allow_commandmay change in a later Tauri release. If it goes away, callfixture_pingdirectly withapp.state(), and keep the "denied without a grant" test. - Skipping a colliding plugin hides a programming error at run time. The error log and the extension app's own smoke test surface it.
- Rollback: revert. Nothing uses the module until Route the desktop app through run(extensions, context) with no extensions in core #3306.
Plan key: C2.1 (pro-boundary DAG).
🤖 Generated with Claude Code
Activity
mstomar125 commentedon Sep 30, 2026
Completed in #3385 (merged). Auto-close did not fire; closing manually.