Skip to content

friglet-tray: use the control_socket config key like the daemon (SNB-681) - #58

Closed
setavenger wants to merge 6 commits into
integrationfrom
snb-681-tray-control-socket-key
Closed

setavenger wants to merge 6 commits into
integrationfrom
snb-681-tray-control-socket-key

Conversation

@setavenger

Copy link
Copy Markdown
Owner

Stacked on #54; review only the commits after it.

Fixes SNB-681 (Bug). +66 / −1 lines, of which 38 are the new test.

What and why

The daemon listens on FRIGLET_CONTROL_SOCKET, else the config file's control_socket, else the platform default. Its figment env layer is merged over the TOML file (friglet/src/config.rs:230-238,338-341). The tray used friglet_ipc::default_socket_path(), which only knows the env variable and the default. So with control_socket set in config.toml, the tray never reached the daemon:

  • With the daemon not running, it entered first-run setup mode (nothing answered at the default path).
  • Or it spawned a daemon, waited 30 s for a socket that came up somewhere else, killed it, and supervision kept restarting it.

The new setup::control_socket_path(config_path, env) resolves the path in the daemon's order. It reads the default config file, the same file a zero-argument daemon loads, and run() uses it for AppState's socket path.

No FRIGLET_CONTROL_SOCKET is passed to a spawned daemon. It reads the same config file and inherits the tray's environment, so it already binds the path the tray probes; the run below shows this with the real daemon. Not passing it also means the env value cannot reach GetConfig, and from there the settings save cannot write control_socket into the user's config.toml.

Behaviour change (intended) and what stays

  • Changed: with control_socket in the config file and no env override, the tray now uses the key.
  • Unchanged: env set (it still wins); no key, no config file, or a config file that does not parse (the platform default, as before; such a daemon would not start anyway).
  • Not handled (unchanged from before): the socket path is resolved once at tray startup. Hand-editing control_socket while the tray runs needs a tray restart, as an env change does today.

Verification

  • New unit test setup::tests::control_socket_follows_the_daemons_order covers:

    • no file: the default;
    • the key: the key's path;
    • env plus key: env;
    • file without the key: the default;
    • unparsable file: the default.

    The old resolution (default_socket_path()) returns the default in the "key" case, so the key assertion fails against it.

  • Runtime, real binaries under Xvfb with dbus-run-session, temp HOME/XDG_CONFIG_HOME, no FRIGLET_CONTROL_SOCKET in the tray's environment, control_socket set only in config.toml:

    • Attach (fake daemon listening on the configured path):

    • Spawn (FRIGLET_DAEMON_BIN pointing at the real friglet debug build, full signet config):

      • before: the daemon logs control socket listening path=<configured path>, but the tray had not connected after 12 s; it would kill the daemon after 30 s;
      • after: the same daemon log line, then spawned daemon and connected 0.25 s after the spawn.

      All spawned daemons were killed afterwards.

  • cargo check --workspace --all-targets --all-features: 0 warnings.

  • cargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings: clean.

  • cargo fmt -p friglet -p friglet-ipc -p friglet-tray -- --check: clean.

  • cargo test --workspace: 252 passed, 1 ignored, 0 failed (friglet-tray: bind the test fakes' sockets before spawning (SNB-679) #54's 251 plus the new test).

  • No friglet-ipc changes were needed.

setavenger and others added 6 commits October 3, 2026 08:46
Three lifecycle e2e tests wrote a shell script to a temp dir and then ran
it as the "daemon binary". The test harness runs tests on parallel
threads of one process, so another test's spawn could fork while the
script was still open for writing; the forked child holds that write
handle until it execs, and running the script in that window fails with
"Text file busy" (ETXTBSY, os error 26).

The scripts are now committed as executable fixtures under
friglet-tray/tests/fixtures/ and located via CARGO_MANIFEST_DIR, so
nothing is written while the tests run. The long-running fixture uses
`exec sleep 30`, so killing the spawned child no longer leaves a stray
sleep behind for 30 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…NB-667)

Nothing here changes what the tray does:

- Tauri commands set_config and set_scan_key: registered, but the UI
  has saved settings through apply_settings since 8bf4c40 and never
  invokes them. The SetConfig / SetScanKey protocol requests stay
  (wire compatibility with separately installed daemons).
- lifecycle: decide/Action (used only by its own test), attach_or_spawn
  (no callers) and QuitAction/quit_action (an enum around one bool;
  perform_quit now tests the bool).
- show_settings_window / show_wallet_window were copies differing only
  in the tab: one show_window_tab(app, tab). The
  FRIGLET_TRAY_SHOW_ON_START parse is a pure function of the value, so
  its test no longer sets the process environment (the unsafe set_var's
  safety comment was false: tests run in parallel).
- get_config and send_with_note share one daemon_request helper
  (connect, request, map errors); the poller and the poll_once test
  helper share record_poll.
- ErrorBook::event returned "should be logged", which its only caller
  ignored; it returns nothing now. Doc links point at the constants
  that exist (STALL_GRACE_SECS, UNREACHABLE_GRACE_SECS).
- fake-daemon example: uses friglet_ipc's NETWORKS and one scan-key
  check instead of copies.
- UI: CSS rules already covered by `[hidden] { display: none
  !important; }`, a `.hint code` rule that matches nothing, and an
  unused id="recent-errors".
- tauri.conf.json: the bundle.linux.deb.depends block. The Tauri CLI
  adds libwebkit2gtk-4.1-0 and the appindicator package itself (with
  tauri's tray-icon feature on) and does not de-duplicate, so the .deb
  listed both packages twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- lib.rs tests: spawn_fake_daemon / spawn_fake_daemon_owned were a
  second fake next to spawn_stoppable_fake_daemon, differing only in
  canned GetStatus fields no test reads. Their four users never send
  Shutdown or check the pid, so they now use the one fake.
- lifecycle_e2e: attaches_when_daemon_already_running is covered by
  attach_carries_daemons_self_reported_ownership, which attaches the
  same way (the locator panics if consulted) and also checks the
  carried ownership.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fake daemons in the lib tests and the lifecycle e2e tests bound
their socket inside the task they spawned, so every test slept a fixed
100 ms after starting one and hoped the bind had happened by then. The
helpers now bind (friglet_ipc::listen) before spawning the accept loop
and return with the socket up, and the eleven sleeps are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…681)

The daemon listens on FRIGLET_CONTROL_SOCKET, else the config file's
control_socket, else the platform default (its env layer is merged over
the file). The tray only looked at the env variable and the default, so
with control_socket set in config.toml it never reached the daemon: it
went into first-run setup mode when nothing answered at the default
path, or spawned a daemon, waited 30 s for a socket that came up
elsewhere, killed it and kept restarting it.

setup::control_socket_path resolves the path in the daemon's order from
the default config file, and the tray uses it at startup. A daemon the
tray spawns already reads the same config file and inherits the tray's
environment, so nothing is passed to it, and nothing new is written to
the user's config.toml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…env (SNB-681)

Only the first lookup in control_socket_path goes through the injected
env; the final fallback, friglet_ipc::default_socket_path, reads the
real FRIGLET_CONTROL_SOCKET again. Say so in the doc comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@setavenger

Copy link
Copy Markdown
Owner Author

Merged into integration through #71 on 2026-10-11 (the user live-tested the combined stack first). GitHub's stacked-PR merge rebased the stack, so this PR's commits landed with new IDs and GitHub can't mark it merged itself. The code is identical: integration now has the same tree as the tested branch friglet-deslop-live-test (08bf11d), which contains this PR's head. Closing as merged via #71.

@setavenger setavenger closed this Oct 11, 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.

1 participant