Skip to content

Let an app crate supply its DaemonProfile through AppExtensions - #3416

Closed
mstomar125 wants to merge 1 commit into
mainfrom
issue-3347-extension-daemon-profile
Closed

mstomar125 wants to merge 1 commit into
mainfrom
issue-3347-extension-daemon-profile

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

An app built on core can now name the daemon it installs and starts with AppExtensions::daemon_profile(profile) (ADR-082 §3.2 and §3.6, proposed). run installs that profile before it builds the app. Core's own app passes AppExtensions::none(), which carries no profile, so it keeps the build's default and nothing changes for the free app.

Closes #3347

Changes

daemon_profile.rs

  • install(supplied: Option<DaemonProfile>) sets the process-wide profile to supplied, or to profile_for_this_build() when nothing is supplied. If the profile was already set, because something read it or installed one first, it panics with a message that names the ordering bug.
  • install_into(cell, supplied) -> Result<(), DaemonProfile> holds the set-once logic over a caller's cell, so the unit tests use a local OnceLock.
  • CORE_SERVICE_ENV = [SOCKET_ENV_VAR, UI_BINARY_ENV_VAR] is the one list of the variables core's launcher writes into the launchd plist itself. DaemonProfile::reserved_service_env_key() finds a service_env key that repeats one of them. The match is exact, the way launchd compares keys.
  • active()'s docs now say that run installs the profile, and that the lazy default only applies to a read before any install, which only tests make.

extensions/mod.rs

  • Private field daemon_profile: Option<DaemonProfile>, set by pub fn daemon_profile(self, profile) -> Self; the last call wins.
  • The rustdoc says what each field controls:
    • binary_name: what is installed, registered, started, killed by image name on Windows, and checked by the startup product check;
    • service_env: launchd only;
    • product.
  • It also says that the label, socket, UI pid file and marker are core's shared identity (ADR-084 decision 2(a)), and that the named daemon must honour ADR-084's registration contract.
  • Reserved keys are refused (the criterion added from Add a DaemonProfile for the app's daemon binary and service env (no behavior change) #3346's review). daemon_profile() panics on a service_env key in CORE_SERVICE_ENV, naming the key. A duplicate plist key is accepted and would silently replace core's value.
  • pub(crate) fn take_daemon_profile(&mut self) hands the profile to run. assemble ignores it.

daemon_setup.rs

  • write_plist now writes core's two <key>s from SOCKET_ENV_VAR and UI_BINARY_ENV_VAR, the constants CORE_SERVICE_ENV is built from.
  • The community-plist test now also asserts that the plist's own variables equal CORE_SERVICE_ENV, so the refusal list and what the plist writes cannot drift apart.
  • The rendered plist is byte-for-byte unchanged.

lib.rs

  • pub use daemon_profile::DaemonProfile; at the library root.
  • run calls daemon_profile::install(extensions.take_daemon_profile()) right after the Windows stdio redirect, before the runtime and the builder exist. That precedes every reader: plugin setup, then core's .setup (kill_stale_daemon_sync → daemon_binary_name()), then ensure_daemon_running. It comes after the redirect, so a Windows release build logs the panic of a late install.

Deviations from the issue

Tests

Test What it shows Mutation
daemon_profile::tests::install_into_stores_a_supplied_profile a supplied profile is stored (local cell) install_into ignoring supplied → fails
…install_into_falls_back_to_the_build_default_when_nothing_is_supplied None stores profile_for_this_build(), so AppExtensions::none() ends at the build default fallback to another profile → fails
…install_into_refuses_a_cell_that_is_already_set Err(profile) and the cell keeps its value silent overwrite → fails
…an_installed_profile_is_what_every_read_sees (own process) install(Some(custom)) sets the real cell: active() and the Windows image name read custom-daemon install writing a private cell → fails
…installing_after_a_read_panics (own process) a read and then an install panics, naming the ordering bug install ignoring the Err → fails
…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, and an exact match on it list missing the UI binary → fails; prefix or case-insensitive match → fails
daemon_setup::macos_plist_keepalive_tests::community_plist_environment_holds_only_the_core_variables the plist's own variables equal CORE_SERVICE_ENV list missing the UI binary → fails; write_plist writing another socket key → fails
extensions::fixture_tests::daemon_profile::none_carries_no_daemon_profile AppExtensions::none() carries no profile none() with Some(..) → fails
…a_named_daemon_profile_is_carried_to_run_and_the_last_call_wins the method stores the profile, the last call wins, and the take empties it method dropping the profile → fails; take leaving it behind → fails
…a_service_env_key_core_sets_itself_is_refused both NODESPACED_SOCKET and NODESPACE_UI_BINARY are refused by name the check disabled → fails
…assemble_builds_with_a_daemon_profile_and_does_not_install_it the fixture plugin plus a profile builds on MockRuntime, and the process profile stays the build default assemble installing → fails
run_wiring_tests::run_installs_the_extension_daemon_profile_before_building_the_app install comes before the runtime, the builder and .setup(, exactly once install removed or moved → fails
tests/it/extension_daemon_profile_test::an_app_crate_names_its_own_daemon_profile from outside the library: nodespace_app_lib::DaemonProfile { binary_name: "custom-daemon", service_env: vec![], product: "custom" } passes through AppExtensions::none().daemon_profile(..) and assemble compile-level (public API)
…an_app_crate_cannot_replace_the_socket_core_registers the refusal reaches an external crate the check disabled → fails

Mutation check: 14 of 14 mutations caught (3347-mutate.py, each mutation reverted afterwards).

Pro-boundary ratchet

bun run scripts/check-pro-boundary.ts passes, and no count rises. This diff adds no marker; --changed lists only pre-existing lines in lib.rs. Marker counts are identical to this branch's base, origin/main a7d2f93d (both runs compared). BASELINES is unchanged:

export const BASELINES = {
  // pro_* Tauri commands, the pro_sync / pro_client modules, pro_env
  proCommands: 261,
  // the proSync store, resolveProSyncVariant, isProSyncActive, pro-sync imports
  proSyncModule: 368,
  // the Pro proto, CloudSyncService, ProClient / ProTier, Pro Worker URLs
  proProtocol: 91,
  // quoted pro:tier-detected, sync:status and sync:error event names
  proEvents: 81,
  // the Pro membership service
  membershipService: 54,
  // Pro build, daemon, socket, launchd and installer branching
  editionBranching: 97,
  // tenant binding, sync_enabled and auth_status state
  cloudBindState: 196,
  // cloud embedding and membership-edge sync hooks
  cloudSyncHooks: 0,
  // Supabase, RLS, pgvector, nodespace-sync and "Pro daemon" wording
  cloudWording: 37,
  // the word tenant (one fixture exempt, see EXEMPTIONS)
  tenantWording: 428,
  // the word Pro, except chip and model names such as "M2 Pro", "DeepSeek V4 Pro"
  proWording: 235,
  // files whose basename has a pro segment
  proNamedFiles: 18,
} satisfies Record<MarkerName, number>;

Checks

🤖 Generated with Claude Code

AppExtensions gains daemon_profile(profile), and run installs the
supplied profile, or the build's default, before it builds the app.

- daemon_profile::install(Option<DaemonProfile>) sets the process-wide
  profile once and panics when it was already set, naming the ordering
  bug. install_into holds the set-once logic over a caller's cell.
- AppExtensions::daemon_profile refuses a service_env key that is one of
  core's own launchd variables (CORE_SERVICE_ENV: NODESPACED_SOCKET,
  NODESPACE_UI_BINARY). write_plist writes those keys from the same
  constants.
- assemble ignores the profile; tests drive it on MockRuntime and never
  write the process-wide cell.
- DaemonProfile is re-exported from the library root.
- Tests: install_into with a local cell, the real install and a late
  install each in a child process of the test binary, the extension
  fixture, a source-order pin on run, and an integration test that
  builds a profile from outside the library.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Superseded by #3613. It ports this draft's AppExtensions::daemon_profile onto current main, following accepted ADR-082 §4.5: the profile carries only binary_name and service_env, with no product field. #3613 also covers the rest of #3414's Tauri section: core's window capability added at startup with Manager::add_capability, and EXTENSION_API_VERSION 2.1 in Rust and TypeScript.

🤖 Generated with Claude Code

@mstomar125 mstomar125 closed this Oct 5, 2026
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.

Let an app built on core supply its DaemonProfile via AppExtensions::daemon_profile

1 participant