Skip to content

Route the desktop app through run(extensions, context) with no extensions in core - #3393

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3306-run-with-extensions
Sep 30, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3306-run-with-extensions

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3306

Part of #3322 (Tauri extension points for the desktop app), under the Pro/core boundary epic #3298.

What changed

nodespace_app_lib::run is now run(extensions: AppExtensions, context: tauri::Context<tauri::Wry>) and does everything main.rs and run did between them, in this order:

  1. redirects stdio to log files in a Windows release build (moved from main.rs, same #[cfg(all(windows, not(debug_assertions)))] gate);
  2. builds the multi-thread tokio runtime and calls tauri::async_runtime::set with it;
  3. runs the app build inside runtime.block_on, so the main thread stays inside the runtime while the event loop runs;
  4. registers core's plugins, single-instance first;
  5. calls assemble(builder, extensions);
  6. applies core's setup, menu handler and commands (untouched), builds with context and runs the loop.

main.rs keeps the windows_subsystem attribute and its DO NOT REMOVE comment, and is one call: run(AppExtensions::none(), tauri::generate_context!()). tokio is dropped from nodespace-app's Cargo.toml (nothing else in the crate used it), which removes one line from Cargo.lock.

The rustdoc on run is the app-crate contract in generic wording: call it from a plain fn main (not inside a tokio runtime), and the app crate must call tauri_build::build() and generate_context!(), keep windows_subsystem, call nodespace_app_build::drop_unstaged_bundle_entries() first, depend directly on every plugin crate the window capability names, and use core's Tauri and tonic versions.

The coordinator's acceptance criterion: one source for core's plugins

Core's plugin registrations and the names assemble protects now come from one function, extensions::core_plugins, in registration order (single-instance first, then opener, then dialog).

  • register_core_plugins(builder) registers that list; run calls it and registers no plugin itself.
  • core_plugin_names() reads the names off the same list, and assemble uses it. The hand-kept CORE_PLUGIN_NAMES constant is gone, so a plugin added to core is protected from a same-named extension plugin the moment it is added, with no second list to update.
  • run_registers_core_plugins_only_through_the_shared_list fails if anyone adds a .plugin( call to run directly.

Deviations from the issue text

  1. run_app helper instead of one big block_on(async move { ... }). The app build (tracing, shutdown token, builder chain, the ~400-line setup closure, the command list) moves unchanged into a private run_app, and run calls runtime.block_on(async move { run_app(extensions, context) }). The order and semantics are what the issue specifies. Wrapping the chain in the async block would re-indent about 600 lines, hide the real change in the diff, and risk rustfmt silently giving up on the nested closure. run_app sits between run and handle_run_event, so the source-text suites and the new tests still read it as part of run.
  2. "assemble after the dialog plugin" is now "register_core_plugins before assemble". The dialog plugin registration lives in core_plugins, not in run, because of the criterion above. The test pins register_core_plugins( before let builder = assemble(builder, extensions); before .setup(.
  3. generate_context!() is evaluated as an argument to run, so before the runtime is built rather than inside block_on. It only builds a Context value and does not touch the async runtime.
  4. The test core_plugin_names_match_the_plugins_core_registers hand-mirrored the plugin list, which is the second source this PR removes. It is replaced by core_plugin_names_are_unique and single_instance_plugin_is_the_first_core_plugin.

Every anchor the existing source-text suites search for (== quit_id {, app.manage(shutdown_token_for_setup.clone()); ... Window <-> database pin registry, the graceful_shutdown and persist_window_geometry slices) is byte-identical and those suites pass unchanged, as do relaunch_tests and shutdown_tests.

For the reviewer: the only Windows-only code is the stdio redirect hunk. It moved from main.rs to run verbatim; the call lost its nodespace_app_lib:: prefix because it is now inside that crate, and the comment's reference to "the attribute above" now says the app crate's main.rs. A macOS check cannot compile it, so please read it.

Ratchet delta

scripts/check-pro-boundary.ts: no marker count changes (before and after are identical on every marker), no baseline is edited and none is raised. No added line contains a marker word. The check passes in the push check.

Tests and mutation checks

New source-text tests in run_wiring_tests (lib.rs) and changed tests in extensions/fixture_tests.rs. Each was mutation-checked individually: break the path, confirm the test fails (as a test failure, not a compile error), restore.

Test Mutation Result
run_assembles_extensions_after_core_plugins_and_before_setup register core plugins after assemble fails
same assemble moved after .setup( fails
run_registers_core_plugins_only_through_the_shared_list a direct plugin registration added to run fails
run_sets_the_async_runtime_before_building_the_app async_runtime::set moved after the builder is created fails
same the app built outside runtime.block_on fails
run_redirects_stdio_before_the_runtime_starts redirect moved after the runtime build fails
same the cfg gate loosened (drops not(debug_assertions)) fails
run_builds_with_the_callers_context .build(context) no longer present fails
same the context macro name appears in run fails
core_plugin_names_are_unique a core plugin listed twice fails
single_instance_plugin_is_the_first_core_plugin opener inserted before single-instance fails
extension_plugin_named_like_a_core_plugin_is_not_registered (now driven by core_plugin_names) assemble reserves no names fails
same core_plugin_names returns an empty list (guards against a vacuous pass) fails

Verification run:

  • cargo clippy -p nodespace-app-lib -p nodespace-app --all-targets -- -D warnings -D clippy::unused-async: clean.
  • cargo fmt --check: clean.
  • cargo test --lib --bins -p nodespace-app-lib -p nodespace-app: 252 passed, 0 failed.
  • NODESPACE_PRO_SUPABASE_URL=https://example.invalid NODESPACE_PRO_ANON_KEY=dummy cargo check -p nodespace-app: passes.
  • bun run test:changed (rust and scripts tiers): passed.

Not done: the free-app smoke test

The issue's manual smoke test (launch, default database, create and edit a node, File/Edit/View menus, Quit from the menu, Cmd+Q and tray Quit, close-window flush, second launch hands off, update check) was not run, for two reasons.

  • A dev-build launch bootstraps a persistent KeepAlive launchd agent (app.nodespace.daemon.dev) whose daemon opens the real ~/.nodespace database. Launchd does not inherit an isolated NODESPACE_HOME, so it cannot be run against an isolated database from a shared dev Mac.
  • The menu, Cmd+Q and tray Quit checks need someone clicking in the GUI.

It needs one real-device pass with bun run dev:tauri. What it exercises that no test here does: real Wry startup order, the single-instance handoff (the plugin now comes from core_plugins), and the quit and flush paths.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Code Review Summary

Review Type: Initial Review (medium effort: high-confidence findings only)

Verdict: APPROVE (no blockers; the smoke-test criterion still needs a real-device pass, see the requirements check and Improvement 3).

The change does what #3306 asks, and the startup semantics are preserved. I compared the old main.rs and run() (git show origin/main:...) with the new run / run_app split and read the pinned Tauri sources (tauri 2.11.2, tauri-plugin-single-instance 2.4.3) in the local cargo registry.

  • Order is unchanged. The old order was stdio redirect, runtime build, async_runtime::set, then block_on(run(generate_context!())). Inside run it was tracing init, shutdown token, single-instance, opener, dialog, .setup( and on. The new order is the same, with assemble inserted between dialog and .setup(, as the issue says. Nothing is dropped, and the .setup(...) closure, on_menu_event and invoke_handler hunks are untouched in the diff.
  • run_app inside block_on is equivalent. runtime.block_on(async move { run_app(..) }) polls on the calling thread, so the main thread stays inside the runtime while app.run loops, as before. The run_app split is a sound deviation from the issue's "wrap in one async block", because it avoids re-indenting about 600 lines. The use tauri::{menu::*, Manager} move is correct: only run_app needs it.
  • generate_context!() now runs as an argument, before the redirect and the runtime. This is unavoidable given the signature the issue mandates. The macro only builds a Context value and does not touch the async runtime, so it is sound. (Rustdoc nit below.)
  • Tracing is initialised before assemble. The collision guard's tracing::error! therefore reaches a subscriber. This matters and is correct.
  • plugin_boxed is exactly plugin. In tauri 2.11.2 Builder::plugin is self.plugin_boxed(Box::new(plugin)), so registration is identical: same order, same single-instance-first behaviour.
  • Constructing a plugin has no side effects today. tauri_plugin_single_instance::init only builds a plugin::Builder::new("single-instance").setup(..) on macOS, Linux and Windows. The socket, D-Bus and mutex work all happens inside the setup hook. So building throwaway instances in assemble is harmless now. Plugin::name() returns a fixed &'static str field, so it is reliable.
  • Windows hunk is a correct move. daemon_setup is a crate-root module (pub mod daemon_setup, gated for macos, linux and windows) and redirect_gui_stdio_to_log_files is #[cfg(windows)]. The path daemon_setup::... resolves from lib.rs. The workspace has no per-package debug-assertions override, so not(debug_assertions) evaluates the same in the library as it did in the binary.
  • Nothing else in src-tauri uses tokio. Nothing under src-tauri (main.rs, build.rs, Cargo.toml) mentions it, and the Cargo.lock delta is exactly the one removed line.
  • Comments are clean. The added lines contain no #NNNN issue references, and the new code and comments have no Pro, tenant, sync or Supabase wording.

Requirements Check (issue #3306)

  • ✅ run(extensions, context) is the only entry point (run_app is private), and its rustdoc covers the app-crate contract: plain fn main, tauri_build plus generate_context!, windows_subsystem, drop_unstaged_bundle_entries() (the fn exists in app-build/src/bundle_entries.rs:50), direct plugin-crate deps, and Tauri and tonic versions. The rustdoc matches ADR-082 §3.7 items 1-4 and 6. Item 5 (capability ownership) is Have the app library add core's window capability at startup #3308 and is correctly omitted.
  • ✅ main.rs keeps the attribute and its DO NOT REMOVE comment, and is a single run(AppExtensions::none(), tauri::generate_context!()) call.
  • ✅ (deviation is sound) The assemble ordering test is register_core_plugins( before let builder = assemble(builder, extensions); before .setup( (lib.rs:1531). The issue said "after the dialog plugin"; dialog now lives inside core_plugins, which is what the coordinator's criterion requires.
  • ✅ Runtime set before builder created, pinned (lib.rs:1561).
  • ✅ The existing suites' anchors are still present and unmoved: == quit_id {, app.manage(shutdown_token_for_setup.clone()); through Window <-> database pin registry, fn persist_window_geometry and pub(crate) fn graceful_shutdown. I did not re-run them; I take the PR's 252 passed on trust.
  • ✅ .build(context) present and generate_context! absent from run, with the needle built by concat! (lib.rs:1595).
  • ✅ Pro-mode compile check: reported passing in the PR body (I did not re-run it).
  • ✅ Ratchet: the PR reports no marker count changes. I did not re-run check-pro-boundary.ts (read-only review), but I found no marker words in the added lines.
  • ✅ No issue numbers in code comments.
  • ✅ Coordinator criterion (one shared source for core's plugins and reserved names): met. See below.
  • ❌ Free-app manual smoke test: not done. The PR's reasoning is sound (a dev-build launch bootstraps the app.nodespace.daemon.dev KeepAlive launchd agent, which opens the real ~/.nodespace and does not inherit an isolated NODESPACE_HOME, and the menu/Cmd+Q/tray checks need a human at the GUI). But the issue lists it as an acceptance criterion, so it stays open until someone does the real-device pass or explicitly waives it. Note the PR says "Closes Route the desktop app through run(extensions, context) with no extensions in core #3306". See Improvement 3.

Coordinator criterion (points 2 and 3). core_plugins() is the single list. register_core_plugins registers it and core_plugin_names (used by assemble) reads its names, so a plugin added to the list is protected immediately, and the old CORE_PLUGIN_NAMES constant is gone (no remaining references in the repo). run_registers_core_plugins_only_through_the_shared_list fails on any .plugin (including .plugin_boxed and app.handle().plugin() between pub fn run( and fn handle_run_event. Residual gaps, which I judge acceptable: a registration made in a helper function called from run_app (rather than in its text), or an app crate registering its own plugin, is invisible to a source-text test. It is not circumventable by the normal path of adding a plugin to run.

Findings

Critical Issues

None.

Suggested Improvements

  1. [Improvement] The Windows-only cfg gate is not pinned, and no PR check compiles it.
    📁 packages/desktop-app/app-lib/src/lib.rs:365-366, test at lib.rs:1583-1592
    run_redirects_stdio_before_the_runtime_starts pins the call text and its position before the runtime build, but not the #[cfg(all(windows, not(debug_assertions)))] line above it. Only release.yml builds Windows, so this hunk is not compiled before release. Dropping or loosening not(debug_assertions) in a later edit compiles fine on macOS and Linux and would send a developer's live terminal output to a log file during tauri dev on Windows. That is exactly what the moved comment says the gate prevents. Suggest asserting the two-line substring #[cfg(all(windows, not(debug_assertions)))]\n daemon_setup::redirect_gui_stdio_to_log_files(); (or pinning the attribute line and its adjacency to the call). Principle: pin what CI cannot compile.

  2. [Improvement] Document the "constructing a core plugin is side-effect free" invariant that the one-list design now relies on.
    📁 packages/desktop-app/app-lib/src/extensions/mod.rs:41-82 and :151
    assemble builds every core plugin and drops them just to read names, and register_core_plugins builds them again. That is fine today (verified for all three plugins: their init() only builds a plugin with a setup hook). But a future core plugin whose init() does real work (opens a file, starts a thread, claims a resource) would run it twice, and once per assemble call in tests, with no hint why. Add one sentence to core_plugins' rustdoc: constructors must have no effects, because all effects belong in the plugin's setup hook. Principle: make the invariant explicit where the next maintainer will add a plugin.

  3. [Improvement] Track the open smoke-test criterion.
    📁 PR body ("Not done: the free-app smoke test")
    The reasoning for skipping it is correct and I would not run it on a shared Mac either. Based on the diff, the only things that could fail at real startup and not in the tests are ones the change does not actually alter: Wry event-loop startup, the single-instance handoff (same plugin, same plugin_boxed path, verified), and the quit/flush paths (the setup closure and run-event handler are byte-identical). Risk is low, but the criterion is unchecked. Either do the one bun run dev:tauri pass on a device where the daemon can be isolated, or state the waiver in the issue, and consider "Refs" rather than "Closes" until then.

Nitpicks

  • Nit: packages/desktop-app/app-lib/src/extensions/mod.rs:129-131: the public assemble rustdoc tells the caller to use [register_core_plugins], which is pub(crate). External app crates cannot call it, and cargo doc would emit rustdoc::private_intra_doc_links (not enforced in CI today). Reword to "run registers core's own plugins first, single-instance before any other, as that plugin requires". The same applies to core_plugins' "the builder run starts from" at mod.rs:31-32, which is really run_app.
  • Nit: packages/desktop-app/app-lib/src/lib.rs:353-364: the moved comment still says stdio is redirected "before anything else runs", but generate_context!() and AppExtensions::none() are now evaluated in main before run is entered. Nothing is lost in practice (the macro only builds a Context), but soften the wording, and the wrap is now uneven (one short-wrapped line joined onto a long one). In the rustdoc, "Nothing that spawns a task or touches Tauri's async runtime may run before it" is right; consider adding "including the evaluation of its arguments" (a future app crate's extensions() runs before run), and that tauri::async_runtime::set panics if the runtime is already initialised.
  • Nit: packages/desktop-app/app-lib/src/lib.rs:1561-1580: run_sets_the_async_runtime_before_building_the_app asserts runtime.block_on( exists after the set, but not that it wraps run_app. Pinning runtime.block_on(async move { run_app(extensions, context) }) would make "the builder is created inside the runtime" a checked property, not a textual-order coincidence.
  • Nit: packages/desktop-app/app-lib/src/extensions/fixture_tests.rs:222-241: nothing asserts that core_plugin_names contains opener and dialog, the two plugins capabilities/default.json grants (opener:default, dialog:default). Deleting one from core_plugins would pass every test. This is not a regression (the removed hand-mirrored test had the same blind spot); it is a cheap addition.

What is good

  • The single-source design meets the coordinator's criterion by construction, not by a second list that a test has to keep in sync.
  • The tests are mostly non-vacuous and mutation-checked, per the table in the PR body. core_plugin_names returning an empty list is explicitly guarded against in extension_plugin_named_like_a_core_plugin_is_not_registered.
  • The source-text suites stay honest: the slice is bounded by pub fn run( and fn handle_run_event, both of which occur before the test module's own literals.

@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

Copy link
Copy Markdown
Contributor Author

Address-review summary (round 1)

Review: the pragmatic review above, verdict APPROVE with no blockers. Fixes are in e8e9f0c.

Addressed (6 of 8 items)

  • [Improvement] Pin the Windows cfg gate. run_redirects_stdio_before_the_runtime_starts now searches for #[cfg(all(windows, not(debug_assertions)))] together with the call, since no PR check compiles that hunk. Mutation: loosening the gate to #[cfg(windows)] makes the test fail.
  • [Improvement] Constructor invariant. core_plugins' rustdoc now says building the list must have no effects (it is built once to read names and again to register), and that anything with an effect belongs in the plugin's setup hook.
  • [Nit] Crate-private doc link. assemble's public rustdoc no longer links register_core_plugins; it says run registers core's plugins first. core_plugins' rustdoc no longer says "the builder run starts from".
  • [Nit] Comment and rustdoc accuracy. The redirect comment says the redirect happens "before the runtime and the app are built" (not "before anything else runs"), and is re-wrapped. run's rustdoc now says the caller's arguments count as "before it", because Tauri panics when run sets its runtime after one was already initialised (checked against tauri 2.11.2: set panics with "runtime already initialized").
  • [Nit] Pin the block_on wrapper. run_sets_the_async_runtime_before_building_the_app also asserts runtime.block_on(async move { run_app(extensions, context) }). Mutation: calling run_app outside block_on makes the test fail.

Skipped, with reasoning

  • [Nit] Assert that core_plugin_names contains opener and dialog. That would add a second hand-kept list of plugin names, which is what this PR removes. The check that a window capability names only registered plugins belongs with the capability move (ADR-082 §3.7 item 5, the capability issue), where the capability file lives. Revisit if a core plugin is ever dropped by accident.
  • [Improvement 3] "Refs" instead of "Closes", and the smoke test. The PR keeps Closes #3306 as the coordinator instructed. The manual free-app smoke test is still not done (reasons in the PR body) and needs a real-device bun run dev:tauri pass or an explicit waiver from the coordinator; nothing in this round changes that.

Verification after the fixes

  • Mutation checks for the strengthened tests: the redirect-gate mutant and the block_on mutant are killed, and the redirect-order mutant is still killed.
  • Process note: my first attempt at this re-run reverted my own uncommitted edits (the harness restores files with git checkout), so two mutants appeared to survive against the old tests. I discarded that result, committed the fixes and re-ran; the numbers above are from that clean re-run.
  • cargo test --lib -p nodespace-app-lib: 252 passed. cargo clippy ... -D warnings -D clippy::unused-async clean. cargo fmt --check clean. Ratchet: no marker changed, BASELINES untouched.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: This round changed comments, rustdoc and two test assertions. No production logic changed (the non-test code diff is comments and doc text only), and each new assertion was mutation-checked.

mstomar125 and others added 2 commits September 30, 2026 14:13
…ins from one list

run() now takes AppExtensions and the app crate's Tauri context, and does what
main.rs and run() did between them: redirect stdio in a Windows release build,
build the tokio runtime and hand it to Tauri, register core's plugins, apply
the extension with assemble(), then add core's setup, menu handler and
commands. main.rs is a single call with AppExtensions::none().

Core's plugins are one list, extensions::core_plugins. run registers them
through it and assemble reads the names an extension plugin may not reuse off
it, replacing the hand-kept CORE_PLUGIN_NAMES constant.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ocument the plugin constructor invariant

- run_redirects_stdio_before_the_runtime_starts now includes the
  cfg(all(windows, not(debug_assertions))) attribute in its needle, since no
  PR check compiles the Windows-only call.
- run_sets_the_async_runtime_before_building_the_app also pins that the app is
  built inside runtime.block_on.
- core_plugins' rustdoc states that building the list must have no effects:
  it is built once to read names and again to register.
- assemble's rustdoc no longer links to a crate-private function.
- The redirect comment and run's rustdoc no longer claim more than they can:
  the caller's arguments are evaluated before run, and Tauri panics if its
  runtime is already initialised when run sets its own.

Skipped: asserting that opener and dialog are listed. That would add a second
hand-kept list of plugin names, and the check that a window capability names
only registered plugins belongs with the capability move.

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.

Route the desktop app through run(extensions, context) with no extensions in core

1 participant