Skip to content

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

Closed

Description

@mstomar125

Part of #3322 (Tauri extension points for the desktop app).

Summary

Replace nodespace_app_lib::run(context) (from #3303) with pub fn run(extensions: AppExtensions, context: tauri::Context<tauri::Wry>) (ADR-082 (proposed) §3.2). run() now does everything main.rs and run() do today, in this order:

  1. redirects stdio in Windows release builds;
  2. builds the tokio runtime and hands it to Tauri;
  3. registers core's plugins;
  4. calls assemble(builder, extensions);
  5. applies core's setup, menu handler and commands;
  6. builds with context and runs the loop.

Core's main.rs becomes a single call with AppExtensions::none(). The free app behaves exactly as before.

Context

src-tauri/src/main.rs, after #3303, contains:

  • the windows_subsystem attribute (1-2), which must stay in the binary crate (ADR-082 §3.7, item 2);
  • the Windows release stdio redirect (17-18);
  • the runtime build and tauri::async_runtime::set (20-26);
  • runtime.block_on(async { nodespace_app_lib::run(tauri::generate_context!()) }).

run() in app-lib/src/lib.rs (311-870 at af8ddb6, before #3303 moved it):

  • builds the builder with single-instance first (343-349), then opener and dialog (352-353);
  • then applies .setup, .on_menu_event, .invoke_handler and .build(context).

Today run() runs inside runtime.block_on, so the main thread is inside the tokio runtime while the event loop runs. Keep that.

The source-text suites in lib.rs search for fixed anchors inside run() and must keep passing unchanged:

  • quit_wiring_tests: == quit_id {, and app.manage(shutdown_token_for_setup.clone()); … Window <-> database pin registry;
  • graceful_shutdown_stops_daemon_tests;
  • window_geometry_capture_tests.

Scope

app-lib/src/lib.rs

pub fn run(extensions: AppExtensions, context: tauri::Context<tauri::Wry>), in this order:

  1. #[cfg(all(windows, not(debug_assertions)))] daemon_setup::redirect_gui_stdio_to_log_files();, moved from main.rs with its comment.
  2. Build the multi-thread runtime, then call tauri::async_runtime::set(runtime.handle().clone()).
  3. Wrap everything that follows in runtime.block_on(async move { … }).
  4. Tracing init and the shutdown token (unchanged).
  5. The builder with single-instance first, then opener and dialog (unchanged).
  6. let builder = assemble(builder, extensions);.
  7. .setup(…), .on_menu_event(…) and .invoke_handler(…) (unchanged).
  8. .build(context) and app.run(…) (unchanged).

Rustdoc on run, in generic wording with no product names:

  • run must be called from a plain fn main, not inside a tokio runtime.
  • It lists what an app crate must do (ADR-082 §3.7):
    • call tauri_build::build() in build.rs and generate_context!() in main;
    • keep the windows_subsystem attribute in main.rs;
    • call nodespace_app_build::drop_unstaged_bundle_entries() (Move the bundle-staging build helpers into a nodespace-app-build crate #3305) before tauri_build::build();
    • depend directly on every Tauri plugin crate that core's window capability names;
    • use the same Tauri and tonic versions as core's lockfile.

Keep every text anchor listed above byte-identical.

src-tauri/src/main.rs

Keep lines 1-2 and their DO NOT REMOVE comment. The rest becomes:

fn main() {
    nodespace_app_lib::run(nodespace_app_lib::AppExtensions::none(), tauri::generate_context!())
}

Remove tokio from src-tauri/Cargo.toml if nothing else in the crate uses it.

Out of scope

Steps

  1. Run the CLAUDE.md startup sequence. Self-assign at pickup; the worktree is issue-<N>-run-with-extensions.
  2. Move the runtime and stdio setup into run, and call assemble.
  3. Simplify main.rs.
  4. Add the tests below.
  5. Run bun run quality:fix, then bun run test:changed.
  6. Smoke-test with bun run dev:tauri, against the dev daemon and socket, never a real user database.

Acceptance criteria

  • run(extensions, context) is the only entry point, and its rustdoc covers the app-crate contract.
  • main.rs contains the windows_subsystem attribute and a single run(AppExtensions::none(), tauri::generate_context!()) call.
  • Inside run, assemble(builder, extensions) comes after the dialog plugin and before .setup(. A test pins this.
  • The runtime is set before the builder is created. A test pins this.
  • Every existing lib.rs source-text suite, relaunch_tests and shutdown_tests pass unchanged.
  • Free-app smoke test:
    • the app launches and opens the default database;
    • you can create and edit a node;
    • the File, Edit and View menus work;
    • Quit from the menu, Cmd+Q and tray Quit each close the app and stop the daemon;
    • closing the window flushes and exits;
    • a second launch hands off to the running instance;
    • the update check runs, with no banner when current.
  • The Pro-mode compile check passes.
  • 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 GitHub issue numbers in code comments.

Tests and verification

New source-text tests go in a run_wiring_tests module in lib.rs. Each slices from pub fn run( to fn handle_run_event, so the tests' own literals are never in range:

  • run_assembles_extensions_after_core_plugins_and_before_setup
  • run_sets_the_async_runtime_before_building_the_app
  • run_builds_with_the_callers_context: .build(context) is present, and the generate_context! macro name is absent. Build the searched string with concat!.

Mutation-check each new test: break the code path it covers, confirm the test fails, then restore.

cargo test --lib --bins -p nodespace-app-lib -p nodespace-app -- --test-threads=2
cargo clippy -p nodespace-app-lib -p nodespace-app --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
bun run dev:tauri

Dependencies

Risks and rollback

  • Startup order. The order is: stdio redirect, then the runtime, then async_runtime::set, then the builder. Tauri must see the custom runtime before anything spawns.
  • Windows-only code. A macOS PR check can't compile it, so the reviewer reads the #[cfg(windows)] hunk. It is a move, not an edit.
  • Rollback: revert. Add AppExtensions with Tauri-plugin support and a runtime-generic assemble() #3304 stays harmless on its own.

Plan key: C2.2 (pro-boundary DAG).

🤖 Generated with Claude Code

Activity

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

    @mstomar125
    ContributorAuthor

    Coordinator note from #3304's review: when run() is routed through assemble() here, derive core's own plugin registrations and extensions::CORE_PLUGIN_NAMES from one shared source (so a new core plugin can't be added to run() without the collision guard knowing its name). Treat that as an acceptance criterion.

  4. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Completed in #3393 (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