Skip to content

Let an app crate name its daemon and ship core's window capability in the library - #3613

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3414-tauri-extension-points
Oct 5, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3414-tauri-extension-points

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Part of #3414 (its "Tauri (ADR-082 §4)" acceptance items).

An app crate built on core can now name the daemon it installs and starts with AppExtensions::daemon_profile(profile). Core's window capability now ships in the library, which adds it at startup with Manager::add_capability, so every app crate built on core gets it without a capability file of its own. With AppExtensions::none(), core keeps its own profile (DaemonProfile::community()) and its own update source, and the free app behaves exactly as before.

AppExtensions::update_source was already on main, so this PR leaves it alone.

Extension API

EXTENSION_API_VERSION goes from 2.0 to 2.1, in Rust (app-lib/src/extensions/mod.rs) and TypeScript (src/lib/plugins/ui-extensions.ts) together. Under ADR-082 §8 this is a minor bump, because it only adds things:

  • AppExtensions::daemon_profile(DaemonProfile) -> Self, with DaemonProfile re-exported from extensions and the crate root;
  • nodespace_app_lib::window_capability: CAPABILITY, add(manager) and plugin_crates(). plugin_crates() lets an app crate check its own manifest against the plugins core's capability grants.

The TypeScript surface doesn't change. The surface snapshot was re-recorded only because it stores the version; its diff is the one minor line. extension-api-version-agreement.test.ts passes.

What changed

Daemon profile (daemon_profile.rs, extensions/mod.rs, lib.rs, daemon_setup.rs). This is ported from parked draft #3416, which was built against the drafts. Following ADR-082 §4.5, the profile carries only binary_name and service_env, with no product field.

  • AppExtensions::daemon_profile(profile) stores the profile, and the last call wins. Its rustdoc says what each field controls, which shared service identity no profile can change (ADR-084 §4), and that the named daemon must honour the registration contract in ADR-084 §4.2.
  • Reserved keys are refused. A service_env key that repeats one of the two variables core's launcher writes itself (NODESPACED_SOCKET, NODESPACE_UI_BINARY) panics, naming the key. launchd would otherwise accept the duplicate key and silently replace core's value. CORE_SERVICE_ENV is the one list of those variables. write_plist now writes its two <key>s from the same constants, and the plist test asserts that the list equals what the plist writes. The rendered plist is byte-for-byte unchanged.
  • run installs the profile with daemon_profile::install(extensions.take_daemon_profile()), right after the Windows stdio redirect and before the runtime, the builder or any setup exist. That puts it ahead of every reader, the first of which is core's stale-daemon kill in setup. install panics if something read or set the profile first, because that is an ordering bug. With no profile supplied, it installs profile_for_this_build(). assemble ignores the profile, so tests on MockRuntime never touch the process-wide one.

Window capability (window_capability.rs, window-capability.json, lib.rs, src-tauri)

  • git mv src-tauri/capabilities/default.json app-lib/src/window-capability.json. The window and permissions are unchanged. The identifier becomes core-window (review round 1), so it can't be confused with an app crate's own capability, which Tauri's scaffold names default. The $schema line is dropped because its relative path no longer pointed anywhere. src-tauri/capabilities/ is gone.
  • window_capability::add(app)? is the first statement of core's setup. Tauri creates the config windows and then runs setup inside the event loop's Ready callback (tauri 2.11 app.rs, fn setup), so no IPC call can reach the app before the capability is in place.
  • Tauri resolves a runtime capability against the ACL that tauri_build assembled from the app crate's direct dependencies, and Resolved::resolve(..).unwrap() panics on a plugin it doesn't know. A missing dependency therefore builds cleanly and panics only when the app starts. The new tests catch that first (see below).
  • run's "What an app crate must do" list now points at window_capability::plugin_crates. It also says to leave build.removeUnusedCommands off, because that setting strips plugin commands that no capability file grants.
  • src-tauri/src/main.rs expands tauri::generate_context!() once, in a runtime-generic fn context<R: tauri::Runtime>() -> tauri::Context<R>. main calls it on Wry and the tests call it on MockRuntime. On macOS the macro embeds the Info.plist under a fixed symbol, so a second expansion in the test module failed to link (_EMBED_INFO_PLIST is already defined). Clippy doesn't catch that because it never links, but the test run did.
  • src-tauri/Cargo.toml gets dev-dependencies for those tests: tauri with test, serde_json and toml 0.8, all already in the lockfile. Its comment on the plugin dependencies now says why they are there.

Tests

Every Rust run went through the machine slot, as test:changed's Rust tier does. No daemon was spawned, no model was loaded, and nothing ran against the GPU.

  • cargo clippy -p nodespace-app-lib -p nodespace-app --all-targets -- -D warnings -D clippy::unused-async: clean.
  • cargo fmt -p nodespace-app-lib -p nodespace-app -- --check: clean.
  • cargo-nextest nextest run -p nodespace-app-lib --lib: 324 of 324 passed.
  • cargo-nextest nextest run -p nodespace-app-lib --test it -E 'test(/^extension_daemon_profile_test::/)': 2 of 2 passed. This is the only it module run, because the others spawn nodespaced.
  • cargo-nextest nextest run -p nodespace-app --bins: 4 of 4 passed (the new window_capability_tests).
  • cargo test --lib --bins -p nodespace-app -p nodespace-app-lib -p nodespace-app-test-support -- --test-threads=2, which is the gate's test-app-units invocation: 4, 324 and 0 passed.
  • bun run --cwd packages/desktop-app test src/tests/extension-api src/tests/plugins/ui-extensions.test.ts src/tests/build/nodespace-extensions-plugin.test.ts: 6 files, 149 tests passed, including extension-api-version-agreement and the surface snapshot.
  • bun run scripts/check-pro-boundary.ts: exit 0. The push check passed.

New tests:

Test What it shows
daemon_profile::tests::install_into_stores_a_supplied_profile, …falls_back_to_the_build_default_when_nothing_is_supplied, …refuses_a_cell_that_is_already_set the set-once install on a local cell; None means the build default
…an_installed_profile_is_what_every_read_sees, …installing_after_a_read_panics (each re-runs itself alone in a child process) the real process-wide cell: an install is what active() and the Windows image name read; a late install panics, naming the ordering bug
…core_service_env_names_the_socket_and_the_ui_binary, …a_reserved_service_env_key_is_found_wherever_it_sits, …a_key_that_only_resembles_a_reserved_one_is_allowed the reserved list, matched exactly
daemon_setup::macos_plist_keepalive_tests::community_plist_environment_holds_only_the_core_variables (renamed) the plist's own variables equal CORE_SERVICE_ENV
extensions::fixture_tests::daemon_profile::{none_carries_no_daemon_profile, a_named_daemon_profile_is_carried_to_run_and_the_last_call_wins, a_service_env_key_core_sets_itself_is_refused, assemble_builds_with_a_daemon_profile_and_does_not_install_it} the AppExtensions method on MockRuntime
extensions::fixture_tests::extension_api_version_is_two_one the Rust constant
run_wiring_tests::run_installs_the_extension_daemon_profile_before_building_the_app the install comes before the runtime, the builder and .setup(, exactly once
run_wiring_tests::setup_adds_the_window_capability_before_anything_else window_capability::add(app)?; is setup's first statement, exactly once
window_capability::tests::the_capability_grants_the_main_window_what_the_frontend_needs identifier core-window; window and permissions unchanged by the move; plugin_crates() pinned, and its message says a new plugin is a major bump
window_capability::tests::plugin_crates_names_the_crate_of_each_granted_plugin_once core: skipped, scoped (object) permissions read, duplicates dropped
tests/it/extension_daemon_profile_test::{an_app_crate_names_its_own_daemon_profile, an_app_crate_cannot_replace_the_socket_core_registers} the public API from outside the library
nodespace-app window_capability_tests::the_app_crate_depends_directly_on_every_plugin_the_window_capability_grants the acceptance test: every crate in plugin_crates() is a key of the app crate's [dependencies]
…the_window_capability_resolves_against_this_crates_acl add succeeds against the ACL tauri_build built for this crate (its real context, on MockRuntime)
…the_window_capability_grants_the_main_window_and_no_other over IPC: plugin:app|version from main is refused before add and answered after it; a window labelled other stays refused
…the_tauri_config_leaves_unused_plugin_commands_in tauri.conf.json doesn't turn on build.removeUnusedCommands, under either spelling Tauri reads

Not done here: a GUI smoke run (dev:tauri or a release bundle), because this session has no interactive display. The IPC test above checks the same grant through Tauri's real ACL path. A smoke run before release would confirm the dialog, the opener and window close on a device.

Mutation check

22 mutations, each applied, run against its tests, then reverted. 22 of 22 caught.

# Mutation Failing tests
M1 install_into ignores the supplied profile install_into_stores_a_supplied_profile, an_installed_profile_is_what_every_read_sees
M2 install ignores an already-set profile installing_after_a_read_panics
M3 install writes a private cell an_installed_profile_is_what_every_read_sees
M4 reserved list misses NODESPACE_UI_BINARY 4: the list, the finder, the plist test, the refusal
M5 reserved keys match by case-insensitive prefix a_key_that_only_resembles_a_reserved_one_is_allowed
M6 daemon_profile() refusal disabled a_service_env_key_core_sets_itself_is_refused, an_app_crate_cannot_replace_the_socket_core_registers
M7 daemon_profile() drops the profile a_named_daemon_profile_is_carried_to_run_and_the_last_call_wins
M8 take clones instead of taking same
M9 assemble installs the profile assemble_builds_with_a_daemon_profile_and_does_not_install_it
M10 none() carries a profile none_carries_no_daemon_profile
M11 run never installs run_installs_the_extension_daemon_profile_before_building_the_app
M12 run installs after the runtime is built same
W1 capability adds clipboard-manager:default 4: the pin test, the deps test, ACL resolution, the IPC grant
W2 app crate drops tauri-plugin-dialog the deps test, ACL resolution, the IPC grant
W3 capability names window settings the pin test, the IPC grant
W4 plugin_crates keeps core: the pin test, the fixture test, the deps test
W5 plugin_crates ignores scoped permissions the fixture test
W6 add() grants nothing the IPC grant
W7 setup adds the capability after set_menu setup_adds_the_window_capability_before_anything_else
W8 removeUnusedCommands: true the_tauri_config_leaves_unused_plugin_commands_in
W8b remove-unused-commands: true (the kebab alias, added in review round 1) same
V1 Rust constant 2.2 while TypeScript stays 2.1 extension-api-version-agreement (TS), extension_api_version_is_two_one

Acceptance mapping (#3414, Tauri section)

  • AppExtensions::daemon_profile and AppExtensions::update_source let an app built on core supply its DaemonProfile and UpdateSource, and core uses its own defaults with AppExtensions::none(). daemon_profile is new here; update_source was already on main. none_carries_no_daemon_profile and install_into_falls_back_to_the_build_default_when_nothing_is_supplied cover the profile default. The existing none_manages_the_builtin_update_source covers the update-source default.
  • The app library adds core's window capability at startup with Manager::add_capability (window_capability::add, first in setup). A core test fails if that capability names a plugin core's app crate doesn't depend on directly: the_app_crate_depends_directly_on_every_plugin_the_window_capability_grants checks the manifest, and the_window_capability_resolves_against_this_crates_acl checks the real ACL. Mutations W1 and W2 show both fail.

Out of scope here, and left for later PRs: typed subtypes and edge fields, frontend nodeTypes and treeItemActions, the redesign of the versioning snapshot gate, and docs.

Pro boundary

bun run scripts/check-pro-boundary.ts exits 0. New code and comments name extension points for what they do.

Documentation

No docs change in this PR. architecture/extension-points.md is a separate #3414 item.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Automated pragmatic-code-review (medium depth)

Review Type: Initial Review

Scope: the two "Tauri (ADR-082 §4)" acceptance items of #3414 only. Checked against accepted ADR-082 §4, §4.5, §4.6, §8 and §9, ADR-084 §4, and Tauri 2.11.2 / tauri-codegen 2.6.2 / tauri-build 2.6.2 / tauri-utils 2.9.2 source. Review was done by reading the code; nothing was built or run except scripts/check-pro-boundary.ts, which exits 0.

Requirements Check

  • ✅ AppExtensions::daemon_profile and AppExtensions::update_source let an app built on core supply its DaemonProfile and UpdateSource, and core uses its own defaults with AppExtensions::none().
    • DaemonProfile has exactly binary_name and service_env, as in ADR-082 §4.5. Nothing from the shared service identity is in the profile, and the rustdoc says why (ADR-084 §4).
    • The method signature matches ADR-082 §4.2.
    • none() carries no profile, and install(None) falls back to profile_for_this_build() (DaemonProfile::community()). That covers the §9 requirement that none() yields core's profile. update_source was already on main and is covered by none_manages_the_builtin_update_source.
    • The install is ordered correctly and is race-free in every way that matters:
      • run installs on the main thread before the tokio runtime, the builder, plugin setup or core setup exist.
      • active() is pub(crate), so no app crate can read the profile directly.
      • Any core read that came first makes install panic with a message that names the ordering bug, rather than silently using another daemon.
    • The reserved-key refusal is sound:
      • It matches keys exactly, as launchd does.
      • CORE_SERVICE_ENV is now the source of the plist's two <key>s and is asserted equal to them.
      • service_env is rendered only into the macOS plist, so that list is complete for every place the profile's environment is written.
  • ✅ The app library adds core's window capability at startup with Manager::add_capability, and a core test fails if that capability names a plugin core's app crate does not depend on directly.
    • window_capability::add(app)? is the first statement of core's setup. In Tauri 2.11.2 App::run, setup runs inside the RuntimeRunEvent::Ready handler on the main thread (app.rs:1415, fn setup at app.rs:2513), right after the config windows are created.
    • On all three platforms the webview delivers IPC through main-thread callbacks. On Windows I checked that wry 0.55.1 issues Navigate as the last step of init_webview, and nothing after it pumps messages before user setup. So no frontend call can be checked against the ACL before the grant is in place.
    • add_capability needs the dynamic-acl feature, which is on by default. It also keeps the ACL manifests in release builds (runtime_authority!, ipc/authority.rs:77-100), so the release binary resolves the capability the same way the tests do.
    • The acceptance test genuinely fails on a missing direct dependency. the_app_crate_depends_directly_on_every_plugin_the_window_capability_grants checks the manifest. the_window_capability_resolves_against_this_crates_acl checks the real tauri_build ACL through crate::context() on MockRuntime. There Resolved::resolve(..).unwrap() panics on an unknown plugin (ipc/authority.rs:174-179), and the test catches that panic.
    • plugin_crates_in handles core: permissions, scoped object permissions, unprefixed app permissions and duplicates correctly.

Code Review Findings

No blockers.

The main.rs change is sound for the release binary:

  • tauri-codegen 2.6.2 already wraps its output in fn inner<R: Runtime, A: Assets<R>> (context.rs:472-491), so expanding generate_context!() inside fn context<R>() is a supported shape.
  • _EMBED_INFO_PLIST is a nested item. It is emitted once however many runtimes instantiate context, so there is no duplicate symbol.
  • The plist block is emitted only for macOS dev builds anyway (context.rs:302). The release binary instantiates only context::<Wry>().
  • The tauri test feature comes in only as a dev-dependency. It doesn't reach tauri build, and tauri_build's manifest check reads only normal and build dependencies (tauri-build manifest.rs:83-96).

The EXTENSION_API_VERSION 2.0 → 2.1 bump is correct under ADR-082 §8. A new AppExtensions method is explicitly minor, window_capability and the root re-export of DaemonProfile only add items, and nothing that worked against 2.0 breaks on 2.1. Rust, TypeScript and the snapshot's version field move together, and the agreement test covers them.

🟢 Suggestion: say that the capability's plugin set is part of the app-crate contract

📁 packages/desktop-app/app-lib/src/window_capability.rs:1-24, 84-107 (module doc and the pin test)
Principle: make implicit contracts explicit (ADR-082 §8 versions "the app-crate contract").
After this PR, adding a plugin permission to window-capability.json makes every app crate built on core panic at startup until it adds that plugin crate as a direct dependency. The pin test will fail on such an edit, but nothing tells the person editing it that this is an extension-API change.
Recommendation: add one sentence to the module doc, or to the pin test's doc comment. It should say that changing the set of plugins the capability grants changes what every app crate must depend on, so it bumps EXTENSION_API_VERSION and gets called out under "Extension API" (ADR-082 §8).

🟢 Suggestion: give NODESPACE_UI_BINARY one shared constant (follow-up is fine)

📁 packages/desktop-app/app-lib/src/daemon_profile.rs:20-21; literals remain at daemon_setup.rs:1733 (systemd unit), daemon_setup.rs:2196 (Windows spawn) and packages/daemon/src/tray.rs:450 (the reader)
Principle: DRY for a cross-process contract.
The new UI_BINARY_ENV_VAR is pub(crate) in app-lib and is used only by the plist. The other writers, and the daemon that reads the variable, still spell it out. SOCKET_ENV_VAR already lives in nodespace_proto::socket so that both sides share it. ADR-082 §4.5 also expects the parts of the registration contract to be exported as library items.
Recommendation: move it next to SOCKET_ENV_VAR in nodespace_proto::socket and use it at all four sites. This is out of scope for the Tauri items, so a follow-up issue is fine.

🟢 Nit: the daemon_profile rustdoc lists only five of the six contract items

📁 packages/desktop-app/app-lib/src/extensions/mod.rs:308-312
The summary of ADR-084 §4.2 leaves out item 6: show core's tray (nodespace_daemon::tray) when passed --tray. This rustdoc is what an app-crate author will read as the contract, so either list all six items or just point to ADR-084 §4.2.

🟢 Nit: the removeUnusedCommands guard misses the kebab-case alias

📁 packages/desktop-app/src-tauri/src/window_capability_tests.rs:126-139
tauri-utils also accepts remove-unused-commands (config.rs:3446, #[serde(alias = "remove-unused-commands")]). Asserting that neither key is true closes the gap cheaply.

🟢 Nit: the capability identifier "default"

📁 packages/desktop-app/app-lib/src/window-capability.json:2
"default" is the identifier Tauri's scaffold gives an app crate's own capabilities/default.json. Runtime grants merge without any identifier uniqueness check (ipc/authority.rs:155-226), so nothing breaks. But debug-build ACL refusal messages cite capabilities by identifier, and two defaults make them ambiguous. A descriptive identifier such as core-window would be clearer, and we have no compatibility concern before there are users. The PR keeps the identifier unchanged on purpose, so this is optional.

Positives worth keeping

  • Expanding generate_context!() once means the tests check exactly the context main ships, not a second test = true context.
  • install_into is split out so the set-once logic is tested on a local OnceLock, and the process-wide behaviour is tested in a re-executed child process, so the shared test process is never polluted.
  • The refusal is checked both inside the crate and from outside it (tests/it/extension_daemon_profile_test.rs), which also shows that the root re-export works for an app crate.
  • Pro boundary: check-pro-boundary.ts exits 0. The new code names its extension points for what they do, and the comments contain no issue numbers.

Recommendation

APPROVE. Both Tauri acceptance items are met, and the implementation follows ADR-082 §4.5, §4.6 and §8. The suggestions above are optional; the first two are the most useful.

@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-review verdicts). Full findings in the review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review: round 1

Review round 1 (report) came back APPROVE, with five optional findings and no blockers. Changes are in 81fb7f21.

Addressed (4)

  • Document the capability's plugin set as part of the app-crate contract. window_capability's module doc now says the plugins it grants are part of the versioned app-crate contract (ADR-082 §8). Granting a permission of a new plugin makes every app crate built on an earlier core panic at startup until it adds that dependency, so it is a major EXTENSION_API_VERSION change. That is the same class as "adding a required BaseServices field". The pin test's assertion message says the same, so whoever changes the list sees it.
  • Capability identifier "default". It is now core-window, kept apart from the default an app crate's own capability files usually carry. Runtime grants merge either way, but debug ACL output is no longer ambiguous. The pin test is updated.
  • Contract summary. The daemon_profile rustdoc now lists all six items of ADR-084 §4.2, including "shows core's tray when passed --tray".
  • removeUnusedCommands kebab-case alias. the_tauri_config_leaves_unused_plugin_commands_in checks both removeUnusedCommands and remove-unused-commands, the serde(alias) that tauri-utils 2.9.2 reads. Mutation-checked: setting either spelling to true fails the test.

Skipped (1)

  • One shared constant for NODESPACE_UI_BINARY. The literals that remain are:

    • daemon_setup.rs's systemd unit, which is Linux-only;
    • its Windows spawn, which is Windows-only;
    • packages/daemon/src/tray.rs.

    This Mac can't compile the first two, so an edit there would land without a local build. Moving the constant into nodespace_proto::socket would also mean touching the daemon crate, which is beyond this PR's scope. The launchd plist, the only place a profile's service_env is written, already uses the shared constants, and its test ties them to CORE_SERVICE_ENV. It makes a fine follow-up, done alongside the systemd and Windows NODESPACED_SOCKET literals.

Checks after the change: run under the machine slot, with no daemon and no model loaded.

  • cargo fmt --check: clean.
  • cargo clippy -p nodespace-app-lib -p nodespace-app --all-targets -- -D warnings -D clippy::unused-async: clean.
  • nextest -p nodespace-app-lib --lib: 324 of 324 passed.
  • nextest -p nodespace-app --bins: 4 of 4 passed.
  • Both alias mutations caught.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The round changes doc comments, one capability identifier string (with its pin test), and one test that now checks a second key. No logic changes, and every change is tested and mutation-checked where it is testable. The review approved the design and logic, and those are untouched.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits October 5, 2026 13:58
… the library

AppExtensions::daemon_profile(profile) names the daemon an app built on
core installs and starts. run installs it into the process-wide profile
before the runtime and the app exist; AppExtensions::none() installs the
build's default. A service_env key that repeats one of the variables
core's launcher writes itself (CORE_SERVICE_ENV) is refused, and
write_plist now writes those keys from the same constants. DaemonProfile
is re-exported from extensions and the crate root.

Core's window capability moves from src-tauri/capabilities/default.json
to app-lib/src/window-capability.json. window_capability::add adds it
with Manager::add_capability as the first statement of core's setup, and
window_capability::plugin_crates lists the plugin crates an app crate
must depend on directly. The app crate's tests check its manifest and
resolve the capability against its real ACL on MockRuntime; main builds
its context through one runtime-generic context() so generate_context!
expands once per binary.

EXTENSION_API_VERSION goes to 2.1 in Rust and TypeScript, and the
surface snapshot records the new version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- window_capability's module doc says the plugins it grants are part of
  the versioned app-crate contract, and that granting a new one is a
  major EXTENSION_API_VERSION change; the pin test's message says so too.
- The capability's identifier is core-window, apart from the default
  identifier an app crate's own capability files usually carry.
- daemon_profile's rustdoc lists the whole ADR-084 §4.2 contract,
  including core's tray on --tray.
- The config test also refuses removeUnusedCommands under its kebab-case
  alias, which Tauri reads too.

Co-Authored-By: Claude Opus 5.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.

1 participant