Skip to content

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

Closed

Description

@mstomar125

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>, with none() and plugin(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 Builder holds one invoke handler (tauri 2.11.2 app.rs 1650).
  • Plugin commands are plugin:<name>|<cmd> and are always ACL-checked (webview/mod.rs 1823).
  • 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), opener and dialog (lib.rs 343-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_context has an empty ACL.
  • A test grants the one command on the context with Context::runtime_authority_mut() (tauri/src/lib.rs 480) and RuntimeAuthority::__allow_command(cmd, ExecutionContext::Local) (ipc/authority.rs 137).
  • __allow_command is 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);

pub struct AppExtensions<R: tauri::Runtime = tauri::Wry>, with private fields (plugins: Vec<Box<dyn tauri::plugin::Plugin<R>>>):

  • pub fn none() -> Self, plus a Default impl equal to none(), with no R: Default bound;
  • 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>

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 fixture plugin: tauri::plugin::Builder::<R>::new("fixture"), with .invoke_handler(tauri::generate_handler![fixture_ping]) and a .setup that manages FixtureState;
  • #[tauri::command] fn fixture_ping(state: tauri::State<'_, FixtureState>) -> String.

Out of scope

Steps

  1. Run the CLAUDE.md startup sequence. Self-assign at pickup; the worktree is issue-<N>-app-extensions.
  2. Add the module, the types, assemble and the re-exports.
  3. Write the fixture tests below:
    • build with assemble(tauri::test::mock_builder(), ext).build(ctx), where ctx = tauri::test::mock_context(tauri::test::noop_assets());
    • for the IPC tests, open a main webview with tauri::WebviewWindowBuilder::new(&app, "main", Default::default());
    • call tauri::test::get_ipc_response with invoke_key: tauri::test::INVOKE_KEY and the URL tauri://localhost.
  4. Run bun run quality:fix, then bun run test:changed.

Acceptance criteria

  • nodespace_app_lib::{AppExtensions, assemble, EXTENSION_API_VERSION} are public and documented, and EXTENSION_API_VERSION == (1, 0).
  • A fixture plugin registered through assemble runs its setup, and its managed state is readable.
  • plugin:fixture|fixture_ping answers through IPC once granted, and is denied without a grant.
  • An extension plugin named opener, dialog or single-instance is not registered, and its setup never runs.
  • An extension plugin reusing an earlier extension plugin's name is not registered either.
  • CORE_PLUGIN_NAMES equals the name() 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.ts passes. BASELINES are 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_managed
  • extension_plugin_command_answers_through_ipc_once_granted
  • extension_plugin_command_is_denied_without_a_grant
  • extension_plugin_named_like_a_core_plugin_is_not_registered
  • second_extension_plugin_with_the_same_name_is_not_registered
  • core_plugin_names_match_the_plugins_core_registers: compares, through tauri::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_command may change in a later Tauri release. If it goes away, call fixture_ping directly with app.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

  1. self-assigned this
    on Sep 30, 2026
  2. added
    pro-boundary
    on Sep 30, 2026
  3. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Completed in #3385 (merged). Auto-close did not fire; closing manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions