Skip to content

Have the app library add core's window capability at startup #3308

Closed as not planned

Description

@mstomar125

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

Summary

Move core's window capability out of the app crate and into the library.

Today it is src-tauri/capabilities/default.json. It grants window main:

  • core:default;
  • core:window:allow-destroy and core:window:allow-close;
  • opener:default and dialog:default.

After this PR, the library adds it at startup with Manager::add_capability. Every app crate built on core then gets it without copying the file (ADR-082 (proposed) §3.7, item 5). A core test fails if the capability names a plugin that core's app crate doesn't depend on directly.

Context

  • Where capabilities come from today. tauri_build::build() reads capabilities/** from the crate that calls it, and generate_context!() embeds them. Without this change, an app crate outside core would have to copy core's file and keep it in sync.
  • Manager::add_capability. It comes with the dynamic-acl feature, which Tauri enables by default (tauri/src/lib.rs 813).
    • It resolves permissions against the app's ACL manifests.
    • It panics on a permission whose plugin isn't in them (ipc/authority.rs 174-179).
    • Those manifests come from tauri_build, which reads only direct dependencies' permission files. That is why Split the desktop Tauri crate into an app-lib library and a thin app crate #3303 kept tauri-plugin-opener and tauri-plugin-dialog as direct dependencies of src-tauri.
  • Timing. Tauri creates the config windows and then runs the app's setup, synchronously on the main thread (app.rs 2513-2524). The event loop handles IPC messages only after setup returns. So a capability added at the top of core's setup is in place before any frontend call.
  • Testing. generate_context!() produces a runtime-generic Context<R>, so a test in the app crate can build the real config and ACL on MockRuntime.

Scope

  • Move the file: git mv src-tauri/capabilities/default.json app-lib/src/window-capability.json.
    • Drop the $schema line, or point it at ../../src-tauri/gen/schemas/desktop-schema.json.
    • Keep the identifier, windows and permissions unchanged.
    • Remove src-tauri/capabilities/, which is now empty.
  • New function, in app-lib/src/extensions/ or a new app-lib/src/capability.rs:
    pub fn add_core_window_capability<R: tauri::Runtime, M: tauri::Manager<R>>(
        manager: &M,
    ) -> tauri::Result<()>
    It calls manager.add_capability(include_str!("window-capability.json")). Its rustdoc covers:
    • what the capability grants;
    • that the app crate must depend directly on each plugin crate the capability names;
    • that it panics otherwise.
  • run()'s setup: call it first, before the menu is built, with ?.
  • src-tauri/Cargo.toml: add [dev-dependencies] tauri = { version = "2", features = ["test"] } and serde_json, for the tests below.

Out of scope

  • Capabilities for extension plugins. The app crate grants those itself.
  • Any permission change.

Steps

  1. Run the CLAUDE.md startup sequence. Self-assign at pickup; the worktree is issue-<N>-library-window-capability.
  2. Move the file, add the function, and call it from setup.
  3. Add the tests.
  4. Smoke-test in dev and in a release bundle. A release build reports an ACL failure only as "not allowed by ACL".
  5. Run bun run quality:fix, then bun run test:changed.

Acceptance criteria

  • src-tauri/capabilities/ is gone, and the library adds an identical capability at startup.
  • window_capability_names_only_plugins_the_app_crate_depends_on passes, and fails if a permission such as clipboard-manager:default is added.
  • window_capability_resolves_against_the_app_crates_acl passes, and fails for an unknown permission. The test builds mock_builder(), with a setup that calls add_core_window_capability, using tauri::generate_context!() in src-tauri.
  • A source-text test shows add_core_window_capability( is the first call in run()'s setup, before app.set_menu.
  • The dev smoke test (bun run dev:tauri) and a release bundle (bun run --cwd packages/desktop-app tauri:build, on a quiet machine) both show:
    • nodes load and live updates arrive (core:event);
    • Import Folder opens a dialog (dialog:default);
    • an external link opens in the browser (opener:default);
    • window close and Cmd+Q exit (core:window:allow-destroy and allow-close).
  • 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.

Tests and verification

In src-tauri/src/main.rs, add #[cfg(test)] mod tests (it runs under test-app-units' --bins):

  • window_capability_names_only_plugins_the_app_crate_depends_on:
    • parse the JSON through include_str!("../../app-lib/src/window-capability.json");
    • map each non-core permission prefix x to tauri-plugin-x;
    • assert each one is a key under [dependencies] in include_str!("../Cargo.toml").
  • window_capability_resolves_against_the_app_crates_acl

In app-lib/src/lib.rs, add the source-text test above.

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

  • IPC before setup returns. If a webview could send IPC before setup finishes, early calls would be denied. The smoke test covers startup, and the Context above explains why this doesn't happen.
  • Fallback, if a device shows otherwise: keep the file in src-tauri/capabilities/ as well, and record an amendment to ADR-082.
  • Rollback: revert. The file returns to src-tauri/capabilities/.

Plan key: C2.7 (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 Oct 1, 2026

    @mstomar125
    ContributorAuthor

    Superseded by #3414 (umbrella against the final ADR-081–085)

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