2026-03-13 12:44:44 +00:00
|
|
|
#![cfg_attr(not(unix), allow(dead_code, unused_imports))]
|
|
|
|
|
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
use std::path::PathBuf;
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
use std::sync::Arc;
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
|
|
|
|
|
use anyhow::Context;
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg(unix)]
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
use tokio::io::AsyncWriteExt;
|
|
|
|
|
use tokio::sync::Mutex;
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg(unix)]
|
2026-03-11 13:40:55 +00:00
|
|
|
mod compositor_client;
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg(not(unix))]
|
|
|
|
|
mod compositor_client {
|
|
|
|
|
use tokio::sync::mpsc;
|
|
|
|
|
use weft_ipc_types::AppdToCompositor;
|
|
|
|
|
|
|
|
|
|
pub type CompositorSender = mpsc::Sender<AppdToCompositor>;
|
|
|
|
|
}
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
mod ipc;
|
2026-03-11 14:47:23 +00:00
|
|
|
mod mount;
|
2026-03-11 08:17:20 +00:00
|
|
|
mod runtime;
|
2026-03-11 08:01:54 +00:00
|
|
|
mod ws;
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
|
2026-03-11 10:23:46 +00:00
|
|
|
use ipc::{AppInfo, AppStateKind, Request, Response, SessionInfo};
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
|
2026-03-11 08:01:54 +00:00
|
|
|
pub(crate) type Registry = Arc<Mutex<SessionRegistry>>;
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
|
2026-03-11 09:42:40 +00:00
|
|
|
struct SessionEntry {
|
|
|
|
|
app_id: String,
|
|
|
|
|
state: AppStateKind,
|
2026-10-09 07:53:23 +00:00
|
|
|
/// Credential that binds application bridge connections to this session.
|
2026-10-09 07:45:49 +00:00
|
|
|
bridge_token: Option<String>,
|
2026-03-11 09:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
struct SessionRegistry {
|
|
|
|
|
next_id: u64,
|
2026-03-11 09:42:40 +00:00
|
|
|
sessions: std::collections::HashMap<u64, SessionEntry>,
|
2026-03-11 08:17:20 +00:00
|
|
|
broadcast: tokio::sync::broadcast::Sender<Response>,
|
2026-03-11 08:37:09 +00:00
|
|
|
abort_senders: std::collections::HashMap<u64, tokio::sync::oneshot::Sender<()>>,
|
2026-03-11 13:40:55 +00:00
|
|
|
compositor_tx: Option<compositor_client::CompositorSender>,
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
ipc_senders: std::collections::HashMap<u64, tokio::sync::mpsc::Sender<String>>,
|
2026-03-11 08:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for SessionRegistry {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
let (broadcast, _) = tokio::sync::broadcast::channel(16);
|
|
|
|
|
Self {
|
|
|
|
|
next_id: 0,
|
|
|
|
|
sessions: std::collections::HashMap::new(),
|
|
|
|
|
broadcast,
|
2026-03-11 08:37:09 +00:00
|
|
|
abort_senders: std::collections::HashMap::new(),
|
2026-03-11 13:40:55 +00:00
|
|
|
compositor_tx: None,
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
ipc_senders: std::collections::HashMap::new(),
|
2026-03-11 08:17:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SessionRegistry {
|
2026-03-11 09:42:40 +00:00
|
|
|
fn launch(&mut self, app_id: &str) -> u64 {
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
self.next_id += 1;
|
|
|
|
|
let id = self.next_id;
|
2026-03-11 09:42:40 +00:00
|
|
|
self.sessions.insert(
|
|
|
|
|
id,
|
|
|
|
|
SessionEntry {
|
|
|
|
|
app_id: app_id.to_owned(),
|
|
|
|
|
state: AppStateKind::Starting,
|
2026-10-09 07:45:49 +00:00
|
|
|
bridge_token: match runtime::random_token() {
|
|
|
|
|
Ok(token) => Some(token),
|
|
|
|
|
Err(e) => {
|
|
|
|
|
tracing::error!(session_id = id, error = %e, "no bridge token; app messages disabled");
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-03-11 09:42:40 +00:00
|
|
|
},
|
|
|
|
|
);
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 07:45:49 +00:00
|
|
|
pub(crate) fn bridge_token(&self, session_id: u64) -> Option<String> {
|
|
|
|
|
self.sessions.get(&session_id)?.bridge_token.clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Whether `token` authorizes an application bridge for a live session.
|
|
|
|
|
pub(crate) fn authorize_bridge(&self, session_id: u64, token: &str) -> bool {
|
|
|
|
|
self.sessions.get(&session_id).is_some_and(|entry| {
|
|
|
|
|
!matches!(entry.state, AppStateKind::Stopped)
|
|
|
|
|
&& entry
|
|
|
|
|
.bridge_token
|
|
|
|
|
.as_deref()
|
|
|
|
|
.is_some_and(|expected| ws::tokens_match(expected, token))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
fn terminate(&mut self, session_id: u64) -> bool {
|
2026-03-11 08:37:09 +00:00
|
|
|
let found = self.sessions.remove(&session_id).is_some();
|
|
|
|
|
self.abort_senders.remove(&session_id);
|
|
|
|
|
found
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn register_abort(&mut self, session_id: u64) -> tokio::sync::oneshot::Receiver<()> {
|
|
|
|
|
let (tx, rx) = tokio::sync::oneshot::channel();
|
|
|
|
|
self.abort_senders.insert(session_id, tx);
|
|
|
|
|
rx
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:42:40 +00:00
|
|
|
fn running_sessions(&self) -> Vec<SessionInfo> {
|
|
|
|
|
self.sessions
|
|
|
|
|
.iter()
|
2026-03-11 11:53:07 +00:00
|
|
|
.filter(|(_, e)| !matches!(e.state, AppStateKind::Stopped))
|
2026-03-11 09:42:40 +00:00
|
|
|
.map(|(&session_id, e)| SessionInfo {
|
|
|
|
|
session_id,
|
|
|
|
|
app_id: e.app_id.clone(),
|
|
|
|
|
})
|
|
|
|
|
.collect()
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:12:38 +00:00
|
|
|
fn running_app_ids(&self) -> Vec<String> {
|
|
|
|
|
self.sessions
|
|
|
|
|
.values()
|
|
|
|
|
.filter(|e| !matches!(e.state, AppStateKind::Stopped))
|
|
|
|
|
.map(|e| e.app_id.clone())
|
|
|
|
|
.collect()
|
|
|
|
|
}
|
|
|
|
|
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
fn state(&self, session_id: u64) -> AppStateKind {
|
|
|
|
|
self.sessions
|
|
|
|
|
.get(&session_id)
|
2026-03-11 09:42:40 +00:00
|
|
|
.map(|e| e.state.clone())
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
.unwrap_or(AppStateKind::NotFound)
|
|
|
|
|
}
|
2026-03-11 08:17:20 +00:00
|
|
|
|
|
|
|
|
pub(crate) fn set_state(&mut self, session_id: u64, state: AppStateKind) {
|
|
|
|
|
if let Some(entry) = self.sessions.get_mut(&session_id) {
|
2026-03-11 09:42:40 +00:00
|
|
|
entry.state = state;
|
2026-03-11 08:17:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:38:35 +00:00
|
|
|
pub(crate) fn remove_abort_sender(&mut self, session_id: u64) {
|
|
|
|
|
self.abort_senders.remove(&session_id);
|
|
|
|
|
}
|
|
|
|
|
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
pub(crate) fn register_ipc_sender(
|
|
|
|
|
&mut self,
|
|
|
|
|
session_id: u64,
|
|
|
|
|
tx: tokio::sync::mpsc::Sender<String>,
|
|
|
|
|
) {
|
|
|
|
|
self.ipc_senders.insert(session_id, tx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn ipc_sender_for(
|
|
|
|
|
&self,
|
|
|
|
|
session_id: u64,
|
|
|
|
|
) -> Option<tokio::sync::mpsc::Sender<String>> {
|
|
|
|
|
self.ipc_senders.get(&session_id).cloned()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn remove_ipc_sender(&mut self, session_id: u64) {
|
|
|
|
|
self.ipc_senders.remove(&session_id);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:17:20 +00:00
|
|
|
pub(crate) fn subscribe(&self) -> tokio::sync::broadcast::Receiver<Response> {
|
|
|
|
|
self.broadcast.subscribe()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn broadcast(&self) -> &tokio::sync::broadcast::Sender<Response> {
|
|
|
|
|
&self.broadcast
|
|
|
|
|
}
|
2026-03-11 10:28:29 +00:00
|
|
|
|
|
|
|
|
pub(crate) fn shutdown_all(&mut self) {
|
|
|
|
|
self.abort_senders.clear();
|
|
|
|
|
}
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
|
tracing_subscriber::fmt()
|
|
|
|
|
.with_env_filter(
|
|
|
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
|
|
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
|
|
|
|
|
)
|
|
|
|
|
.init();
|
|
|
|
|
|
|
|
|
|
run().await
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg(unix)]
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
async fn run() -> anyhow::Result<()> {
|
|
|
|
|
let socket_path = appd_socket_path()?;
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
|
|
|
|
|
if let Some(parent) = socket_path.parent() {
|
|
|
|
|
std::fs::create_dir_all(parent).with_context(|| format!("create {}", parent.display()))?;
|
|
|
|
|
}
|
|
|
|
|
let _ = std::fs::remove_file(&socket_path);
|
|
|
|
|
|
|
|
|
|
let listener = tokio::net::UnixListener::bind(&socket_path)
|
|
|
|
|
.with_context(|| format!("bind {}", socket_path.display()))?;
|
|
|
|
|
tracing::info!(path = %socket_path.display(), "IPC socket listening");
|
|
|
|
|
|
|
|
|
|
let registry: Registry = Arc::new(Mutex::new(SessionRegistry::default()));
|
2026-03-11 13:40:55 +00:00
|
|
|
if let Some(path) = compositor_client::socket_path() {
|
|
|
|
|
let tx = compositor_client::spawn(path);
|
|
|
|
|
registry.lock().await.compositor_tx = Some(tx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:01:54 +00:00
|
|
|
let ws_port = ws_port();
|
|
|
|
|
let ws_addr: std::net::SocketAddr = format!("127.0.0.1:{ws_port}").parse()?;
|
|
|
|
|
let ws_listener = tokio::net::TcpListener::bind(ws_addr)
|
|
|
|
|
.await
|
|
|
|
|
.with_context(|| format!("bind WebSocket {ws_addr}"))?;
|
2026-03-11 10:00:13 +00:00
|
|
|
let ws_bound_port = ws_listener.local_addr()?.port();
|
|
|
|
|
tracing::info!(port = ws_bound_port, "WebSocket listener ready");
|
2026-03-11 10:36:47 +00:00
|
|
|
if let Err(e) = write_ws_port(ws_bound_port) {
|
|
|
|
|
tracing::warn!(error = %e, "could not write appd.wsport; servo-shell port discovery will fall back to default");
|
|
|
|
|
}
|
2026-10-09 07:45:49 +00:00
|
|
|
let ws_auth = Arc::new(ws::WsAuth {
|
|
|
|
|
system_token: runtime::random_token().context("create system token")?,
|
|
|
|
|
});
|
|
|
|
|
write_system_token(&ws_auth.system_token).context("write appd.systoken")?;
|
2026-03-11 08:01:54 +00:00
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
|
|
|
|
let _ = sd_notify::notify(false, &[sd_notify::NotifyState::Ready]);
|
|
|
|
|
}
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
|
2026-03-11 17:12:38 +00:00
|
|
|
if let Some(app_ids) = load_session() {
|
|
|
|
|
tracing::info!(count = app_ids.len(), "restoring previous session");
|
|
|
|
|
for app_id in app_ids {
|
|
|
|
|
let _ = dispatch(
|
|
|
|
|
crate::ipc::Request::LaunchApp {
|
|
|
|
|
app_id,
|
|
|
|
|
surface_id: 0,
|
|
|
|
|
},
|
|
|
|
|
®istry,
|
|
|
|
|
)
|
|
|
|
|
.await;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 10:06:01 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
let mut sigterm = {
|
|
|
|
|
use tokio::signal::unix::{SignalKind, signal};
|
|
|
|
|
signal(SignalKind::terminate()).context("SIGTERM handler")?
|
|
|
|
|
};
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
|
|
|
|
|
loop {
|
2026-03-11 10:06:01 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
let term = sigterm.recv();
|
|
|
|
|
#[cfg(not(unix))]
|
|
|
|
|
let term = std::future::pending::<Option<()>>();
|
|
|
|
|
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
tokio::select! {
|
|
|
|
|
result = listener.accept() => {
|
|
|
|
|
let (stream, _) = result.context("accept")?;
|
|
|
|
|
let reg = Arc::clone(®istry);
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
if let Err(e) = handle_connection(stream, reg).await {
|
2026-03-11 08:01:54 +00:00
|
|
|
tracing::warn!(error = %e, "unix connection error");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
result = ws_listener.accept() => {
|
|
|
|
|
let (stream, _) = result.context("ws accept")?;
|
|
|
|
|
let reg = Arc::clone(®istry);
|
2026-03-11 08:17:20 +00:00
|
|
|
let rx = registry.lock().await.subscribe();
|
2026-10-09 07:45:49 +00:00
|
|
|
let auth = Arc::clone(&ws_auth);
|
2026-03-11 08:01:54 +00:00
|
|
|
tokio::spawn(async move {
|
2026-10-09 07:45:49 +00:00
|
|
|
if let Err(e) = ws::handle_ws_connection(stream, reg, rx, auth).await {
|
2026-03-11 08:01:54 +00:00
|
|
|
tracing::warn!(error = %e, "ws connection error");
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-03-11 10:06:01 +00:00
|
|
|
_ = tokio::signal::ctrl_c() => {
|
|
|
|
|
tracing::info!("SIGINT received; shutting down");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_ = term => {
|
|
|
|
|
tracing::info!("SIGTERM received; shutting down");
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:12:38 +00:00
|
|
|
save_session(registry.lock().await.running_app_ids()).await;
|
2026-03-11 10:28:29 +00:00
|
|
|
registry.lock().await.shutdown_all();
|
|
|
|
|
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
let _ = std::fs::remove_file(&socket_path);
|
2026-10-09 07:53:23 +00:00
|
|
|
// A newer appd may already have replaced the file; only this instance's
|
|
|
|
|
// own token is removed.
|
|
|
|
|
if let Ok(path) = system_token_path()
|
|
|
|
|
&& std::fs::read_to_string(&path).is_ok_and(|t| t == ws_auth.system_token)
|
|
|
|
|
{
|
2026-10-09 07:45:49 +00:00
|
|
|
let _ = std::fs::remove_file(path);
|
|
|
|
|
}
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
Ok(())
|
2026-03-11 17:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg(not(unix))]
|
|
|
|
|
async fn run() -> anyhow::Result<()> {
|
|
|
|
|
anyhow::bail!("weft-appd requires a Unix platform")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(not(any(unix, test)), allow(dead_code))]
|
2026-03-11 17:12:38 +00:00
|
|
|
fn session_file_path() -> Option<std::path::PathBuf> {
|
|
|
|
|
let runtime_dir = std::env::var("XDG_RUNTIME_DIR").ok()?;
|
|
|
|
|
Some(PathBuf::from(runtime_dir).join("weft/last-session.json"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg_attr(not(any(unix, test)), allow(dead_code))]
|
2026-03-11 17:12:38 +00:00
|
|
|
async fn save_session(app_ids: Vec<String>) {
|
|
|
|
|
let Some(path) = session_file_path() else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
2026-03-11 17:16:37 +00:00
|
|
|
if let Some(parent) = path.parent() {
|
|
|
|
|
let _ = std::fs::create_dir_all(parent);
|
|
|
|
|
}
|
2026-03-11 17:12:38 +00:00
|
|
|
if let Ok(json) = serde_json::to_string(&app_ids) {
|
|
|
|
|
let _ = std::fs::write(&path, json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_session() -> Option<Vec<String>> {
|
|
|
|
|
let path = session_file_path()?;
|
|
|
|
|
let json = std::fs::read_to_string(&path).ok()?;
|
|
|
|
|
let _ = std::fs::remove_file(&path);
|
|
|
|
|
serde_json::from_str(&json).ok()
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:01:54 +00:00
|
|
|
fn ws_port() -> u16 {
|
|
|
|
|
std::env::var("WEFT_APPD_WS_PORT")
|
|
|
|
|
.ok()
|
|
|
|
|
.and_then(|s| s.parse().ok())
|
|
|
|
|
.unwrap_or(7410)
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 07:45:49 +00:00
|
|
|
/// Writes the system-role WebSocket credential to a file only the user can read.
|
|
|
|
|
#[cfg_attr(not(unix), allow(dead_code))]
|
|
|
|
|
fn write_system_token(token: &str) -> std::io::Result<()> {
|
|
|
|
|
use std::io::Write;
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
use std::os::unix::fs::OpenOptionsExt;
|
|
|
|
|
let path = system_token_path()?;
|
|
|
|
|
let staging = path.with_extension(format!("systoken.{}", std::process::id()));
|
|
|
|
|
// A leftover staging file could carry other permissions; the file is
|
|
|
|
|
// always created afresh so the mode below applies.
|
|
|
|
|
let _ = std::fs::remove_file(&staging);
|
|
|
|
|
let mut options = std::fs::OpenOptions::new();
|
|
|
|
|
options.write(true).create_new(true);
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
options.mode(0o600);
|
|
|
|
|
let written = options.open(&staging).and_then(|mut file| {
|
|
|
|
|
file.write_all(token.as_bytes())?;
|
|
|
|
|
file.sync_all()
|
|
|
|
|
});
|
|
|
|
|
let result = written.and_then(|()| std::fs::rename(&staging, &path));
|
|
|
|
|
if result.is_err() {
|
|
|
|
|
let _ = std::fs::remove_file(&staging);
|
|
|
|
|
}
|
|
|
|
|
result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn system_token_path() -> std::io::Result<PathBuf> {
|
|
|
|
|
let dir = PathBuf::from(
|
|
|
|
|
std::env::var("XDG_RUNTIME_DIR")
|
|
|
|
|
.map_err(|_| std::io::Error::other("XDG_RUNTIME_DIR not set"))?,
|
|
|
|
|
)
|
|
|
|
|
.join("weft");
|
|
|
|
|
std::fs::create_dir_all(&dir)?;
|
|
|
|
|
Ok(dir.join("appd.systoken"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg_attr(not(any(unix, test)), allow(dead_code))]
|
2026-03-11 08:01:54 +00:00
|
|
|
fn write_ws_port(port: u16) -> anyhow::Result<()> {
|
|
|
|
|
let runtime_dir = std::env::var("XDG_RUNTIME_DIR").context("XDG_RUNTIME_DIR not set")?;
|
|
|
|
|
let path = PathBuf::from(runtime_dir).join("weft/appd.wsport");
|
|
|
|
|
if let Some(parent) = path.parent() {
|
2026-03-11 10:36:47 +00:00
|
|
|
std::fs::create_dir_all(parent).with_context(|| format!("create {}", parent.display()))?;
|
2026-03-11 08:01:54 +00:00
|
|
|
}
|
2026-03-11 10:36:47 +00:00
|
|
|
std::fs::write(&path, port.to_string()).with_context(|| format!("write {}", path.display()))?;
|
2026-03-11 08:01:54 +00:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg(unix)]
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
async fn handle_connection(
|
|
|
|
|
stream: tokio::net::UnixStream,
|
|
|
|
|
registry: Registry,
|
|
|
|
|
) -> anyhow::Result<()> {
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
2026-03-13 09:38:01 +00:00
|
|
|
let cred = stream.peer_cred().context("SO_PEERCRED")?;
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
let our_uid = unsafe { libc::getuid() };
|
|
|
|
|
if cred.uid() != our_uid {
|
2026-03-13 09:38:01 +00:00
|
|
|
anyhow::bail!(
|
|
|
|
|
"peer UID {} != process UID {}; connection rejected",
|
|
|
|
|
cred.uid(),
|
|
|
|
|
our_uid
|
|
|
|
|
);
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
let (reader, writer) = tokio::io::split(stream);
|
|
|
|
|
let mut reader = tokio::io::BufReader::new(reader);
|
|
|
|
|
let mut writer = tokio::io::BufWriter::new(writer);
|
|
|
|
|
|
|
|
|
|
while let Some(req) = ipc::read_frame(&mut reader).await? {
|
|
|
|
|
tracing::debug!(?req, "request");
|
|
|
|
|
let resp = dispatch(req, ®istry).await;
|
|
|
|
|
ipc::write_frame(&mut writer, &resp).await?;
|
|
|
|
|
writer.flush().await?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
pub(crate) fn session_ipc_socket_path(session_id: u64) -> Option<PathBuf> {
|
|
|
|
|
let runtime_dir = std::env::var("XDG_RUNTIME_DIR").ok()?;
|
|
|
|
|
let dir = PathBuf::from(runtime_dir).join("weft");
|
|
|
|
|
std::fs::create_dir_all(&dir).ok()?;
|
|
|
|
|
Some(dir.join(format!("ipc-{session_id}.sock")))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:01:54 +00:00
|
|
|
pub(crate) async fn dispatch(req: Request, registry: &Registry) -> Response {
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
match req {
|
|
|
|
|
Request::LaunchApp {
|
|
|
|
|
app_id,
|
|
|
|
|
surface_id: _,
|
|
|
|
|
} => {
|
|
|
|
|
let session_id = registry.lock().await.launch(&app_id);
|
|
|
|
|
tracing::info!(session_id, %app_id, "launched");
|
2026-03-11 08:37:09 +00:00
|
|
|
let abort_rx = registry.lock().await.register_abort(session_id);
|
2026-03-11 13:40:55 +00:00
|
|
|
let compositor_tx = registry.lock().await.compositor_tx.clone();
|
2026-03-13 11:52:39 +00:00
|
|
|
|
|
|
|
|
if std::env::var("WEFT_RUNTIME_BIN").is_err() {
|
|
|
|
|
let _ = registry.lock().await.broadcast().send(Response::LaunchAck {
|
|
|
|
|
session_id,
|
|
|
|
|
app_id: app_id.clone(),
|
|
|
|
|
});
|
|
|
|
|
{
|
|
|
|
|
let mut reg = registry.lock().await;
|
|
|
|
|
reg.set_state(session_id, AppStateKind::Stopped);
|
|
|
|
|
reg.remove_abort_sender(session_id);
|
|
|
|
|
}
|
|
|
|
|
let _ = registry.lock().await.broadcast().send(Response::AppState {
|
|
|
|
|
session_id,
|
|
|
|
|
state: AppStateKind::Stopped,
|
|
|
|
|
});
|
|
|
|
|
return Response::LaunchAck { session_id, app_id };
|
|
|
|
|
}
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
let ipc_socket = session_ipc_socket_path(session_id);
|
|
|
|
|
let broadcast = registry.lock().await.broadcast().clone();
|
2026-03-13 09:58:40 +00:00
|
|
|
if let Some(ref sock_path) = ipc_socket
|
|
|
|
|
&& let Some(tx) =
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
runtime::spawn_ipc_relay(session_id, sock_path.clone(), broadcast).await
|
2026-03-13 09:58:40 +00:00
|
|
|
{
|
|
|
|
|
registry.lock().await.register_ipc_sender(session_id, tx);
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
}
|
2026-03-11 08:17:20 +00:00
|
|
|
let reg = Arc::clone(registry);
|
|
|
|
|
let aid = app_id.clone();
|
|
|
|
|
tokio::spawn(async move {
|
2026-03-11 13:40:55 +00:00
|
|
|
if let Err(e) =
|
2026-03-11 14:10:11 +00:00
|
|
|
runtime::supervise(session_id, &aid, reg, abort_rx, compositor_tx, ipc_socket)
|
|
|
|
|
.await
|
2026-03-11 13:40:55 +00:00
|
|
|
{
|
2026-03-11 08:17:20 +00:00
|
|
|
tracing::warn!(session_id, error = %e, "runtime supervisor error");
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-03-11 17:27:56 +00:00
|
|
|
let _ = registry.lock().await.broadcast().send(Response::LaunchAck {
|
|
|
|
|
session_id,
|
|
|
|
|
app_id: app_id.clone(),
|
|
|
|
|
});
|
2026-03-11 09:46:28 +00:00
|
|
|
Response::LaunchAck { session_id, app_id }
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
Request::TerminateApp { session_id } => {
|
|
|
|
|
let found = registry.lock().await.terminate(session_id);
|
|
|
|
|
if found {
|
|
|
|
|
tracing::info!(session_id, "terminated");
|
|
|
|
|
Response::AppState {
|
|
|
|
|
session_id,
|
|
|
|
|
state: AppStateKind::Stopped,
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Response::Error {
|
|
|
|
|
code: 1,
|
|
|
|
|
message: format!("session {session_id} not found"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Request::QueryRunning => {
|
2026-03-11 09:42:40 +00:00
|
|
|
let sessions = registry.lock().await.running_sessions();
|
|
|
|
|
Response::RunningApps { sessions }
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
Request::QueryAppState { session_id } => {
|
|
|
|
|
let state = registry.lock().await.state(session_id);
|
|
|
|
|
Response::AppState { session_id, state }
|
|
|
|
|
}
|
2026-03-11 10:23:46 +00:00
|
|
|
Request::QueryInstalledApps => {
|
|
|
|
|
let apps = scan_installed_apps();
|
|
|
|
|
Response::InstalledApps { apps }
|
|
|
|
|
}
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
Request::IpcForward {
|
|
|
|
|
session_id,
|
|
|
|
|
payload,
|
|
|
|
|
} => {
|
2026-03-13 09:58:40 +00:00
|
|
|
if let Some(tx) = registry.lock().await.ipc_sender_for(session_id)
|
|
|
|
|
&& tx.send(payload).await.is_err()
|
|
|
|
|
{
|
|
|
|
|
tracing::warn!(session_id, "IPC relay sender closed");
|
|
|
|
|
registry.lock().await.remove_ipc_sender(session_id);
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
}
|
|
|
|
|
Response::AppState {
|
|
|
|
|
session_id,
|
|
|
|
|
state: ipc::AppStateKind::Running,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Request::PanelGesture {
|
|
|
|
|
gesture_type,
|
|
|
|
|
fingers,
|
|
|
|
|
dx,
|
|
|
|
|
dy,
|
|
|
|
|
} => {
|
|
|
|
|
let msg = Response::NavigationGesture {
|
|
|
|
|
gesture_type,
|
|
|
|
|
fingers,
|
|
|
|
|
dx,
|
|
|
|
|
dy,
|
|
|
|
|
};
|
|
|
|
|
let _ = registry.lock().await.broadcast().send(msg.clone());
|
|
|
|
|
msg
|
|
|
|
|
}
|
2026-03-11 10:23:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:20:51 +00:00
|
|
|
pub(crate) fn app_store_roots() -> Vec<std::path::PathBuf> {
|
2026-03-11 10:23:46 +00:00
|
|
|
if let Ok(explicit) = std::env::var("WEFT_APP_STORE") {
|
|
|
|
|
return vec![std::path::PathBuf::from(explicit)];
|
|
|
|
|
}
|
|
|
|
|
let mut roots = Vec::new();
|
|
|
|
|
if let Ok(home) = std::env::var("HOME") {
|
|
|
|
|
roots.push(
|
|
|
|
|
std::path::PathBuf::from(home)
|
|
|
|
|
.join(".local")
|
|
|
|
|
.join("share")
|
|
|
|
|
.join("weft")
|
|
|
|
|
.join("apps"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
roots.push(std::path::PathBuf::from("/usr/share/weft/apps"));
|
|
|
|
|
roots
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize)]
|
|
|
|
|
struct WappPackage {
|
|
|
|
|
id: String,
|
|
|
|
|
name: String,
|
2026-03-11 12:15:09 +00:00
|
|
|
version: String,
|
2026-03-11 10:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize)]
|
|
|
|
|
struct WappManifest {
|
|
|
|
|
package: WappPackage,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn scan_installed_apps() -> Vec<AppInfo> {
|
|
|
|
|
let mut seen = std::collections::HashSet::new();
|
|
|
|
|
let mut apps = Vec::new();
|
|
|
|
|
for root in app_store_roots() {
|
|
|
|
|
let Ok(entries) = std::fs::read_dir(&root) else {
|
|
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
for entry in entries.flatten() {
|
|
|
|
|
let manifest_path = entry.path().join("wapp.toml");
|
|
|
|
|
let Ok(contents) = std::fs::read_to_string(&manifest_path) else {
|
|
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
let Ok(m) = toml::from_str::<WappManifest>(&contents) else {
|
|
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
if seen.insert(m.package.id.clone()) {
|
|
|
|
|
apps.push(AppInfo {
|
|
|
|
|
app_id: m.package.id,
|
|
|
|
|
name: m.package.name,
|
2026-03-11 12:15:09 +00:00
|
|
|
version: m.package.version,
|
2026-03-11 10:23:46 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
}
|
2026-03-11 10:23:46 +00:00
|
|
|
apps
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg_attr(not(any(unix, test)), allow(dead_code))]
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
fn appd_socket_path() -> anyhow::Result<PathBuf> {
|
|
|
|
|
if let Ok(p) = std::env::var("WEFT_APPD_SOCKET") {
|
|
|
|
|
return Ok(PathBuf::from(p));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let runtime_dir = std::env::var("XDG_RUNTIME_DIR").context("XDG_RUNTIME_DIR not set")?;
|
|
|
|
|
|
|
|
|
|
Ok(PathBuf::from(runtime_dir).join("weft/appd.sock"))
|
|
|
|
|
}
|
2026-03-11 07:32:02 +00:00
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
use ipc::AppStateKind;
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
static ENV_LOCK: std::sync::OnceLock<tokio::sync::Mutex<()>> = std::sync::OnceLock::new();
|
|
|
|
|
|
|
|
|
|
fn env_lock() -> &'static tokio::sync::Mutex<()> {
|
|
|
|
|
ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 07:40:20 +00:00
|
|
|
fn make_registry() -> Registry {
|
|
|
|
|
Arc::new(Mutex::new(SessionRegistry::default()))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
#[tokio::test]
|
|
|
|
|
async fn ws_port_defaults_to_7410() {
|
|
|
|
|
let _env = env_lock().lock().await;
|
2026-03-11 11:46:15 +00:00
|
|
|
let prior = std::env::var("WEFT_APPD_WS_PORT").ok();
|
|
|
|
|
unsafe { std::env::remove_var("WEFT_APPD_WS_PORT") };
|
|
|
|
|
let port = ws_port();
|
|
|
|
|
unsafe {
|
2026-03-13 09:58:40 +00:00
|
|
|
if let Some(v) = prior {
|
|
|
|
|
std::env::set_var("WEFT_APPD_WS_PORT", v)
|
2026-03-11 11:46:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(port, 7410);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
#[tokio::test]
|
|
|
|
|
async fn ws_port_uses_env_override() {
|
|
|
|
|
let _env = env_lock().lock().await;
|
2026-03-11 11:46:15 +00:00
|
|
|
let prior = std::env::var("WEFT_APPD_WS_PORT").ok();
|
|
|
|
|
unsafe { std::env::set_var("WEFT_APPD_WS_PORT", "9000") };
|
|
|
|
|
let port = ws_port();
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_APPD_WS_PORT", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_APPD_WS_PORT"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(port, 9000);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 11:40:05 +00:00
|
|
|
#[test]
|
|
|
|
|
fn appd_socket_path_uses_override_env() {
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().blocking_lock();
|
2026-03-11 11:40:05 +00:00
|
|
|
let prior = std::env::var("WEFT_APPD_SOCKET").ok();
|
|
|
|
|
unsafe { std::env::set_var("WEFT_APPD_SOCKET", "/tmp/custom.sock") };
|
|
|
|
|
let path = appd_socket_path().unwrap();
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_APPD_SOCKET", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_APPD_SOCKET"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(path, PathBuf::from("/tmp/custom.sock"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn appd_socket_path_errors_without_xdg_and_no_override() {
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().blocking_lock();
|
2026-03-11 11:40:05 +00:00
|
|
|
let prior_sock = std::env::var("WEFT_APPD_SOCKET").ok();
|
|
|
|
|
let prior_xdg = std::env::var("XDG_RUNTIME_DIR").ok();
|
|
|
|
|
unsafe {
|
|
|
|
|
std::env::remove_var("WEFT_APPD_SOCKET");
|
|
|
|
|
std::env::remove_var("XDG_RUNTIME_DIR");
|
|
|
|
|
}
|
|
|
|
|
let result = appd_socket_path();
|
|
|
|
|
unsafe {
|
2026-03-13 09:58:40 +00:00
|
|
|
if let Some(v) = prior_sock {
|
|
|
|
|
std::env::set_var("WEFT_APPD_SOCKET", v)
|
2026-03-11 11:40:05 +00:00
|
|
|
}
|
2026-03-13 09:58:40 +00:00
|
|
|
if let Some(v) = prior_xdg {
|
|
|
|
|
std::env::set_var("XDG_RUNTIME_DIR", v)
|
2026-03-11 11:40:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 07:40:20 +00:00
|
|
|
#[tokio::test]
|
|
|
|
|
async fn dispatch_launch_returns_ack() {
|
|
|
|
|
let reg = make_registry();
|
2026-03-11 17:28:59 +00:00
|
|
|
let mut rx = reg.lock().await.subscribe();
|
2026-03-11 07:40:20 +00:00
|
|
|
let resp = dispatch(
|
|
|
|
|
Request::LaunchApp {
|
|
|
|
|
app_id: "com.test.app".into(),
|
|
|
|
|
surface_id: 0,
|
|
|
|
|
},
|
|
|
|
|
®,
|
|
|
|
|
)
|
|
|
|
|
.await;
|
|
|
|
|
match resp {
|
2026-03-11 09:46:28 +00:00
|
|
|
Response::LaunchAck {
|
|
|
|
|
session_id,
|
|
|
|
|
ref app_id,
|
|
|
|
|
} => {
|
|
|
|
|
assert!(session_id > 0);
|
|
|
|
|
assert_eq!(app_id, "com.test.app");
|
|
|
|
|
}
|
2026-03-11 07:40:20 +00:00
|
|
|
_ => panic!("expected LaunchAck"),
|
|
|
|
|
}
|
2026-03-11 17:28:59 +00:00
|
|
|
assert!(
|
|
|
|
|
matches!(rx.try_recv(), Ok(Response::LaunchAck { .. })),
|
|
|
|
|
"LaunchAck must also be broadcast"
|
|
|
|
|
);
|
2026-03-11 07:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn dispatch_terminate_known_returns_stopped() {
|
|
|
|
|
let reg = make_registry();
|
|
|
|
|
let ack = dispatch(
|
|
|
|
|
Request::LaunchApp {
|
|
|
|
|
app_id: "app".into(),
|
|
|
|
|
surface_id: 0,
|
|
|
|
|
},
|
|
|
|
|
®,
|
|
|
|
|
)
|
|
|
|
|
.await;
|
|
|
|
|
let session_id = match ack {
|
2026-03-11 09:46:28 +00:00
|
|
|
Response::LaunchAck { session_id, .. } => session_id,
|
2026-03-11 07:40:20 +00:00
|
|
|
_ => panic!("expected LaunchAck"),
|
|
|
|
|
};
|
|
|
|
|
let resp = dispatch(Request::TerminateApp { session_id }, ®).await;
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
resp,
|
|
|
|
|
Response::AppState {
|
|
|
|
|
state: AppStateKind::Stopped,
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn dispatch_terminate_unknown_returns_error() {
|
|
|
|
|
let reg = make_registry();
|
|
|
|
|
let resp = dispatch(Request::TerminateApp { session_id: 999 }, ®).await;
|
|
|
|
|
assert!(matches!(resp, Response::Error { .. }));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
#[tokio::test(flavor = "current_thread")]
|
2026-03-11 17:47:29 +00:00
|
|
|
async fn session_stops_when_runtime_bin_absent() {
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().lock().await;
|
|
|
|
|
let prior = std::env::var("WEFT_RUNTIME_BIN").ok();
|
2026-03-11 17:47:29 +00:00
|
|
|
unsafe { std::env::remove_var("WEFT_RUNTIME_BIN") };
|
|
|
|
|
let reg = make_registry();
|
|
|
|
|
let ack = dispatch(
|
|
|
|
|
Request::LaunchApp {
|
|
|
|
|
app_id: "com.test.nobinary".into(),
|
|
|
|
|
surface_id: 0,
|
|
|
|
|
},
|
|
|
|
|
®,
|
|
|
|
|
)
|
|
|
|
|
.await;
|
|
|
|
|
let session_id = match ack {
|
|
|
|
|
Response::LaunchAck { session_id, .. } => session_id,
|
|
|
|
|
_ => panic!("expected LaunchAck"),
|
|
|
|
|
};
|
2026-03-13 11:52:39 +00:00
|
|
|
let mut stopped = false;
|
|
|
|
|
for _ in 0..50 {
|
|
|
|
|
tokio::task::yield_now().await;
|
|
|
|
|
if matches!(reg.lock().await.state(session_id), AppStateKind::Stopped) {
|
|
|
|
|
stopped = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tokio::time::sleep(std::time::Duration::from_millis(5)).await;
|
|
|
|
|
}
|
2026-03-11 17:47:29 +00:00
|
|
|
let state = reg.lock().await.state(session_id);
|
2026-03-13 11:52:39 +00:00
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_RUNTIME_BIN", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_RUNTIME_BIN"),
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-11 17:47:29 +00:00
|
|
|
assert!(
|
2026-03-13 11:52:39 +00:00
|
|
|
stopped && matches!(state, AppStateKind::Stopped),
|
2026-03-11 17:47:29 +00:00
|
|
|
"session should be Stopped when WEFT_RUNTIME_BIN is absent"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 11:53:07 +00:00
|
|
|
#[tokio::test]
|
|
|
|
|
async fn running_sessions_excludes_stopped() {
|
|
|
|
|
let reg = make_registry();
|
|
|
|
|
let session_id = reg.lock().await.launch("com.test.app");
|
|
|
|
|
reg.lock()
|
|
|
|
|
.await
|
|
|
|
|
.set_state(session_id, AppStateKind::Stopped);
|
|
|
|
|
let sessions = reg.lock().await.running_sessions();
|
|
|
|
|
assert!(sessions.is_empty());
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 07:40:20 +00:00
|
|
|
#[tokio::test]
|
|
|
|
|
async fn dispatch_query_running_lists_active_sessions() {
|
|
|
|
|
let reg = make_registry();
|
2026-03-13 11:52:39 +00:00
|
|
|
reg.lock().await.launch("a");
|
|
|
|
|
reg.lock().await.launch("b");
|
2026-03-11 07:40:20 +00:00
|
|
|
let resp = dispatch(Request::QueryRunning, ®).await;
|
|
|
|
|
match resp {
|
2026-03-11 09:42:40 +00:00
|
|
|
Response::RunningApps { sessions } => {
|
|
|
|
|
assert_eq!(sessions.len(), 2);
|
|
|
|
|
let mut ids: Vec<&str> = sessions.iter().map(|s| s.app_id.as_str()).collect();
|
|
|
|
|
ids.sort();
|
|
|
|
|
assert_eq!(ids, vec!["a", "b"]);
|
|
|
|
|
}
|
2026-03-11 07:40:20 +00:00
|
|
|
_ => panic!("expected RunningApps"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn dispatch_query_app_state_returns_starting() {
|
|
|
|
|
let reg = make_registry();
|
2026-03-13 11:52:39 +00:00
|
|
|
let session_id = reg.lock().await.launch("app");
|
2026-03-11 07:40:20 +00:00
|
|
|
let resp = dispatch(Request::QueryAppState { session_id }, ®).await;
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
resp,
|
|
|
|
|
Response::AppState {
|
|
|
|
|
state: AppStateKind::Starting,
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 10:48:22 +00:00
|
|
|
#[tokio::test]
|
|
|
|
|
async fn dispatch_query_app_state_unknown_returns_not_found() {
|
|
|
|
|
let reg = make_registry();
|
|
|
|
|
let resp = dispatch(Request::QueryAppState { session_id: 9999 }, ®).await;
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
resp,
|
|
|
|
|
Response::AppState {
|
|
|
|
|
state: AppStateKind::NotFound,
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 07:32:02 +00:00
|
|
|
#[test]
|
|
|
|
|
fn registry_launch_increments_id() {
|
|
|
|
|
let mut reg = SessionRegistry::default();
|
|
|
|
|
let id1 = reg.launch("com.example.a");
|
|
|
|
|
let id2 = reg.launch("com.example.b");
|
|
|
|
|
assert!(id2 > id1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn registry_terminate_known_session() {
|
|
|
|
|
let mut reg = SessionRegistry::default();
|
|
|
|
|
let id = reg.launch("com.example.app");
|
|
|
|
|
assert!(reg.terminate(id));
|
|
|
|
|
assert!(matches!(reg.state(id), AppStateKind::NotFound));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn registry_terminate_unknown_returns_false() {
|
|
|
|
|
let mut reg = SessionRegistry::default();
|
|
|
|
|
assert!(!reg.terminate(999));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-03-11 09:42:40 +00:00
|
|
|
fn registry_running_sessions_reflects_live_sessions() {
|
2026-03-11 07:32:02 +00:00
|
|
|
let mut reg = SessionRegistry::default();
|
2026-03-11 09:42:40 +00:00
|
|
|
let id1 = reg.launch("com.example.a");
|
|
|
|
|
let id2 = reg.launch("com.example.b");
|
|
|
|
|
let mut sessions = reg.running_sessions();
|
|
|
|
|
sessions.sort_by_key(|s| s.session_id);
|
|
|
|
|
assert_eq!(sessions.len(), 2);
|
|
|
|
|
assert_eq!(sessions[0].session_id, id1);
|
|
|
|
|
assert_eq!(sessions[0].app_id, "com.example.a");
|
|
|
|
|
assert_eq!(sessions[1].session_id, id2);
|
|
|
|
|
assert_eq!(sessions[1].app_id, "com.example.b");
|
2026-03-11 07:32:02 +00:00
|
|
|
reg.terminate(id1);
|
2026-03-11 09:42:40 +00:00
|
|
|
assert_eq!(reg.running_sessions().len(), 1);
|
|
|
|
|
assert_eq!(reg.running_sessions()[0].session_id, id2);
|
2026-03-11 07:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn registry_state_not_found_for_unknown() {
|
|
|
|
|
let reg = SessionRegistry::default();
|
|
|
|
|
assert!(matches!(reg.state(42), AppStateKind::NotFound));
|
|
|
|
|
}
|
2026-03-11 08:24:34 +00:00
|
|
|
|
2026-03-11 10:32:26 +00:00
|
|
|
#[tokio::test]
|
|
|
|
|
async fn dispatch_query_installed_returns_installed_apps() {
|
|
|
|
|
let reg = make_registry();
|
|
|
|
|
let resp = dispatch(Request::QueryInstalledApps, ®).await;
|
|
|
|
|
assert!(matches!(resp, Response::InstalledApps { .. }));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 10:23:46 +00:00
|
|
|
#[test]
|
|
|
|
|
fn scan_installed_apps_finds_valid_packages() {
|
|
|
|
|
use std::fs;
|
2026-03-13 11:52:39 +00:00
|
|
|
|
|
|
|
|
let _env = env_lock().blocking_lock();
|
2026-03-11 10:23:46 +00:00
|
|
|
let store = std::env::temp_dir().join(format!("weft_appd_scan_{}", std::process::id()));
|
|
|
|
|
let app_dir = store.join("com.example.scanner");
|
|
|
|
|
fs::create_dir_all(&app_dir).unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
app_dir.join("wapp.toml"),
|
|
|
|
|
"[package]\nid = \"com.example.scanner\"\nname = \"Scanner\"\nversion = \"1.0.0\"\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let prior = std::env::var("WEFT_APP_STORE").ok();
|
|
|
|
|
unsafe { std::env::set_var("WEFT_APP_STORE", &store) };
|
|
|
|
|
|
|
|
|
|
let apps = scan_installed_apps();
|
|
|
|
|
assert_eq!(apps.len(), 1);
|
|
|
|
|
assert_eq!(apps[0].app_id, "com.example.scanner");
|
|
|
|
|
assert_eq!(apps[0].name, "Scanner");
|
2026-03-11 12:15:09 +00:00
|
|
|
assert_eq!(apps[0].version, "1.0.0");
|
2026-03-11 10:23:46 +00:00
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_APP_STORE", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_APP_STORE"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let _ = fs::remove_dir_all(&store);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:24:34 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn supervisor_transitions_through_ready_to_stopped() {
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().lock().await;
|
2026-03-11 08:24:34 +00:00
|
|
|
let script =
|
|
|
|
|
std::env::temp_dir().join(format!("weft_test_runtime_{}.sh", std::process::id()));
|
fix(appd): report sessions running only after the UI host is ready
weft-appd marked a session Running and broadcast APP_READY as soon as the
runtime printed READY, then started weft-app-shell with its output
discarded and never watched it. A session with no UI, a UI host that
failed to start, or one that crashed was still reported running. Early
failure paths skipped parts of the cleanup: the image mount was not
unmounted, the compositor association was not released, and the abort
sender leaked on spawn failure. Readiness was any stdout line equal to
READY, which a Wasm guest (inherited stdout) or a page (window.alert
writes to the app shell's stdout) could print.
Now a session becomes Running only after the runtime and then the app
shell report readiness, each within 30 s; WEFT_APP_SHELL_BIN is required
and checked before anything starts. After that, the runtime exiting, the
app shell exiting or a terminate request ends the session. Every exit
path goes through one teardown that kills both children, releases the
compositor association, unmounts the image, stops the file portal and
broadcasts Stopped.
Readiness uses a per-session random token passed to both children in
WEFT_READY_TOKEN. weft-runtime and weft-app-shell print READY <token>,
and appd accepts only a line ending with it; guests receive only the
variables the runtime names and pages cannot read the host environment.
Child output is read in bounded, lossily decoded lines, so invalid UTF-8
or long lines no longer stop the readers. Compositor notifications use
try_send so a disconnected compositor cannot stall teardown, and all
children are killed if the supervisor is dropped.
The IPC relay is not yet owned by the session, and children are killed
without a graceful period.
Validation:
- cargo test -p weft-appd (43 passed); new tests cover: not ready until
the app shell is ready, runtime exit before that, no app shell
configured (runtime never starts), app shell exit ending a running
session with the runtime process gone, and READY lines without the
token; they fail against the previous supervisor
- end to end with weft-compositor (nested), weft-appd, weft-runtime
(wasmtime-runtime) and weft-app-shell: the Counter demo reaches
APP_READY and is on screen; a page that prints a READY line through
alert and never loads is stopped after 30 s without APP_READY;
terminate leaves no child processes
- clippy -D warnings and fmt --check for weft-appd and weft-runtime
2026-10-09 01:41:09 +00:00
|
|
|
std::fs::write(
|
|
|
|
|
&script,
|
|
|
|
|
"#!/bin/sh\necho READY $WEFT_READY_TOKEN\nexec sleep 1\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
2026-03-11 08:24:34 +00:00
|
|
|
std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
|
|
|
|
|
|
fix(appd): report sessions running only after the UI host is ready
weft-appd marked a session Running and broadcast APP_READY as soon as the
runtime printed READY, then started weft-app-shell with its output
discarded and never watched it. A session with no UI, a UI host that
failed to start, or one that crashed was still reported running. Early
failure paths skipped parts of the cleanup: the image mount was not
unmounted, the compositor association was not released, and the abort
sender leaked on spawn failure. Readiness was any stdout line equal to
READY, which a Wasm guest (inherited stdout) or a page (window.alert
writes to the app shell's stdout) could print.
Now a session becomes Running only after the runtime and then the app
shell report readiness, each within 30 s; WEFT_APP_SHELL_BIN is required
and checked before anything starts. After that, the runtime exiting, the
app shell exiting or a terminate request ends the session. Every exit
path goes through one teardown that kills both children, releases the
compositor association, unmounts the image, stops the file portal and
broadcasts Stopped.
Readiness uses a per-session random token passed to both children in
WEFT_READY_TOKEN. weft-runtime and weft-app-shell print READY <token>,
and appd accepts only a line ending with it; guests receive only the
variables the runtime names and pages cannot read the host environment.
Child output is read in bounded, lossily decoded lines, so invalid UTF-8
or long lines no longer stop the readers. Compositor notifications use
try_send so a disconnected compositor cannot stall teardown, and all
children are killed if the supervisor is dropped.
The IPC relay is not yet owned by the session, and children are killed
without a graceful period.
Validation:
- cargo test -p weft-appd (43 passed); new tests cover: not ready until
the app shell is ready, runtime exit before that, no app shell
configured (runtime never starts), app shell exit ending a running
session with the runtime process gone, and READY lines without the
token; they fail against the previous supervisor
- end to end with weft-compositor (nested), weft-appd, weft-runtime
(wasmtime-runtime) and weft-app-shell: the Counter demo reaches
APP_READY and is on screen; a page that prints a READY line through
alert and never loads is stopped after 30 s without APP_READY;
terminate leaves no child processes
- clippy -D warnings and fmt --check for weft-appd and weft-runtime
2026-10-09 01:41:09 +00:00
|
|
|
let shell = std::env::temp_dir().join(format!("weft_test_shell_{}.sh", std::process::id()));
|
|
|
|
|
std::fs::write(
|
|
|
|
|
&shell,
|
|
|
|
|
"#!/bin/sh\necho READY $WEFT_READY_TOKEN\nexec sleep 1\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::fs::set_permissions(&shell, std::fs::Permissions::from_mode(0o755)).unwrap();
|
|
|
|
|
|
2026-03-11 08:24:34 +00:00
|
|
|
let prior = std::env::var("WEFT_RUNTIME_BIN").ok();
|
fix(appd): report sessions running only after the UI host is ready
weft-appd marked a session Running and broadcast APP_READY as soon as the
runtime printed READY, then started weft-app-shell with its output
discarded and never watched it. A session with no UI, a UI host that
failed to start, or one that crashed was still reported running. Early
failure paths skipped parts of the cleanup: the image mount was not
unmounted, the compositor association was not released, and the abort
sender leaked on spawn failure. Readiness was any stdout line equal to
READY, which a Wasm guest (inherited stdout) or a page (window.alert
writes to the app shell's stdout) could print.
Now a session becomes Running only after the runtime and then the app
shell report readiness, each within 30 s; WEFT_APP_SHELL_BIN is required
and checked before anything starts. After that, the runtime exiting, the
app shell exiting or a terminate request ends the session. Every exit
path goes through one teardown that kills both children, releases the
compositor association, unmounts the image, stops the file portal and
broadcasts Stopped.
Readiness uses a per-session random token passed to both children in
WEFT_READY_TOKEN. weft-runtime and weft-app-shell print READY <token>,
and appd accepts only a line ending with it; guests receive only the
variables the runtime names and pages cannot read the host environment.
Child output is read in bounded, lossily decoded lines, so invalid UTF-8
or long lines no longer stop the readers. Compositor notifications use
try_send so a disconnected compositor cannot stall teardown, and all
children are killed if the supervisor is dropped.
The IPC relay is not yet owned by the session, and children are killed
without a graceful period.
Validation:
- cargo test -p weft-appd (43 passed); new tests cover: not ready until
the app shell is ready, runtime exit before that, no app shell
configured (runtime never starts), app shell exit ending a running
session with the runtime process gone, and READY lines without the
token; they fail against the previous supervisor
- end to end with weft-compositor (nested), weft-appd, weft-runtime
(wasmtime-runtime) and weft-app-shell: the Counter demo reaches
APP_READY and is on screen; a page that prints a READY line through
alert and never loads is stopped after 30 s without APP_READY;
terminate leaves no child processes
- clippy -D warnings and fmt --check for weft-appd and weft-runtime
2026-10-09 01:41:09 +00:00
|
|
|
let prior_shell = std::env::var("WEFT_APP_SHELL_BIN").ok();
|
2026-03-12 19:16:58 +00:00
|
|
|
let prior_cgroup = std::env::var("WEFT_DISABLE_CGROUP").ok();
|
2026-03-11 08:24:34 +00:00
|
|
|
// SAFETY: single-threaded test (flavor = "current_thread"); no concurrent env access.
|
2026-03-12 19:16:58 +00:00
|
|
|
unsafe {
|
|
|
|
|
std::env::set_var("WEFT_RUNTIME_BIN", &script);
|
fix(appd): report sessions running only after the UI host is ready
weft-appd marked a session Running and broadcast APP_READY as soon as the
runtime printed READY, then started weft-app-shell with its output
discarded and never watched it. A session with no UI, a UI host that
failed to start, or one that crashed was still reported running. Early
failure paths skipped parts of the cleanup: the image mount was not
unmounted, the compositor association was not released, and the abort
sender leaked on spawn failure. Readiness was any stdout line equal to
READY, which a Wasm guest (inherited stdout) or a page (window.alert
writes to the app shell's stdout) could print.
Now a session becomes Running only after the runtime and then the app
shell report readiness, each within 30 s; WEFT_APP_SHELL_BIN is required
and checked before anything starts. After that, the runtime exiting, the
app shell exiting or a terminate request ends the session. Every exit
path goes through one teardown that kills both children, releases the
compositor association, unmounts the image, stops the file portal and
broadcasts Stopped.
Readiness uses a per-session random token passed to both children in
WEFT_READY_TOKEN. weft-runtime and weft-app-shell print READY <token>,
and appd accepts only a line ending with it; guests receive only the
variables the runtime names and pages cannot read the host environment.
Child output is read in bounded, lossily decoded lines, so invalid UTF-8
or long lines no longer stop the readers. Compositor notifications use
try_send so a disconnected compositor cannot stall teardown, and all
children are killed if the supervisor is dropped.
The IPC relay is not yet owned by the session, and children are killed
without a graceful period.
Validation:
- cargo test -p weft-appd (43 passed); new tests cover: not ready until
the app shell is ready, runtime exit before that, no app shell
configured (runtime never starts), app shell exit ending a running
session with the runtime process gone, and READY lines without the
token; they fail against the previous supervisor
- end to end with weft-compositor (nested), weft-appd, weft-runtime
(wasmtime-runtime) and weft-app-shell: the Counter demo reaches
APP_READY and is on screen; a page that prints a READY line through
alert and never loads is stopped after 30 s without APP_READY;
terminate leaves no child processes
- clippy -D warnings and fmt --check for weft-appd and weft-runtime
2026-10-09 01:41:09 +00:00
|
|
|
std::env::set_var("WEFT_APP_SHELL_BIN", &shell);
|
2026-03-12 19:16:58 +00:00
|
|
|
std::env::set_var("WEFT_DISABLE_CGROUP", "1");
|
|
|
|
|
}
|
2026-03-11 08:24:34 +00:00
|
|
|
|
|
|
|
|
let registry: Registry = Arc::new(Mutex::new(SessionRegistry::default()));
|
|
|
|
|
let mut rx = registry.lock().await.subscribe();
|
|
|
|
|
let session_id = registry.lock().await.launch("test.app");
|
2026-03-11 08:37:09 +00:00
|
|
|
let abort_rx = registry.lock().await.register_abort(session_id);
|
2026-03-11 08:24:34 +00:00
|
|
|
|
2026-03-11 13:40:55 +00:00
|
|
|
runtime::supervise(
|
|
|
|
|
session_id,
|
|
|
|
|
"test.app",
|
|
|
|
|
Arc::clone(®istry),
|
|
|
|
|
abort_rx,
|
|
|
|
|
None,
|
2026-03-11 14:10:11 +00:00
|
|
|
None,
|
2026-03-11 13:40:55 +00:00
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
2026-03-11 08:24:34 +00:00
|
|
|
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
registry.lock().await.state(session_id),
|
|
|
|
|
AppStateKind::Stopped
|
|
|
|
|
));
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
let notification =
|
|
|
|
|
tokio::time::timeout(std::time::Duration::from_millis(200), rx.recv()).await;
|
2026-03-11 08:24:34 +00:00
|
|
|
assert!(matches!(
|
|
|
|
|
notification,
|
2026-03-13 11:52:39 +00:00
|
|
|
Ok(Ok(Response::AppReady { session_id: sid, .. })) if sid == session_id
|
2026-03-11 08:24:34 +00:00
|
|
|
));
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
let stopped = tokio::time::timeout(std::time::Duration::from_millis(200), rx.recv()).await;
|
2026-03-11 10:38:33 +00:00
|
|
|
assert!(matches!(
|
|
|
|
|
stopped,
|
2026-03-13 11:52:39 +00:00
|
|
|
Ok(Ok(Response::AppState { session_id: sid, state: AppStateKind::Stopped })) if sid == session_id
|
2026-03-11 10:38:33 +00:00
|
|
|
));
|
|
|
|
|
|
2026-03-11 08:24:34 +00:00
|
|
|
let _ = std::fs::remove_file(&script);
|
fix(appd): report sessions running only after the UI host is ready
weft-appd marked a session Running and broadcast APP_READY as soon as the
runtime printed READY, then started weft-app-shell with its output
discarded and never watched it. A session with no UI, a UI host that
failed to start, or one that crashed was still reported running. Early
failure paths skipped parts of the cleanup: the image mount was not
unmounted, the compositor association was not released, and the abort
sender leaked on spawn failure. Readiness was any stdout line equal to
READY, which a Wasm guest (inherited stdout) or a page (window.alert
writes to the app shell's stdout) could print.
Now a session becomes Running only after the runtime and then the app
shell report readiness, each within 30 s; WEFT_APP_SHELL_BIN is required
and checked before anything starts. After that, the runtime exiting, the
app shell exiting or a terminate request ends the session. Every exit
path goes through one teardown that kills both children, releases the
compositor association, unmounts the image, stops the file portal and
broadcasts Stopped.
Readiness uses a per-session random token passed to both children in
WEFT_READY_TOKEN. weft-runtime and weft-app-shell print READY <token>,
and appd accepts only a line ending with it; guests receive only the
variables the runtime names and pages cannot read the host environment.
Child output is read in bounded, lossily decoded lines, so invalid UTF-8
or long lines no longer stop the readers. Compositor notifications use
try_send so a disconnected compositor cannot stall teardown, and all
children are killed if the supervisor is dropped.
The IPC relay is not yet owned by the session, and children are killed
without a graceful period.
Validation:
- cargo test -p weft-appd (43 passed); new tests cover: not ready until
the app shell is ready, runtime exit before that, no app shell
configured (runtime never starts), app shell exit ending a running
session with the runtime process gone, and READY lines without the
token; they fail against the previous supervisor
- end to end with weft-compositor (nested), weft-appd, weft-runtime
(wasmtime-runtime) and weft-app-shell: the Counter demo reaches
APP_READY and is on screen; a page that prints a READY line through
alert and never loads is stopped after 30 s without APP_READY;
terminate leaves no child processes
- clippy -D warnings and fmt --check for weft-appd and weft-runtime
2026-10-09 01:41:09 +00:00
|
|
|
let _ = std::fs::remove_file(&shell);
|
2026-03-11 08:24:34 +00:00
|
|
|
// SAFETY: single-threaded test; restoring env to prior state.
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_RUNTIME_BIN", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_RUNTIME_BIN"),
|
|
|
|
|
}
|
fix(appd): report sessions running only after the UI host is ready
weft-appd marked a session Running and broadcast APP_READY as soon as the
runtime printed READY, then started weft-app-shell with its output
discarded and never watched it. A session with no UI, a UI host that
failed to start, or one that crashed was still reported running. Early
failure paths skipped parts of the cleanup: the image mount was not
unmounted, the compositor association was not released, and the abort
sender leaked on spawn failure. Readiness was any stdout line equal to
READY, which a Wasm guest (inherited stdout) or a page (window.alert
writes to the app shell's stdout) could print.
Now a session becomes Running only after the runtime and then the app
shell report readiness, each within 30 s; WEFT_APP_SHELL_BIN is required
and checked before anything starts. After that, the runtime exiting, the
app shell exiting or a terminate request ends the session. Every exit
path goes through one teardown that kills both children, releases the
compositor association, unmounts the image, stops the file portal and
broadcasts Stopped.
Readiness uses a per-session random token passed to both children in
WEFT_READY_TOKEN. weft-runtime and weft-app-shell print READY <token>,
and appd accepts only a line ending with it; guests receive only the
variables the runtime names and pages cannot read the host environment.
Child output is read in bounded, lossily decoded lines, so invalid UTF-8
or long lines no longer stop the readers. Compositor notifications use
try_send so a disconnected compositor cannot stall teardown, and all
children are killed if the supervisor is dropped.
The IPC relay is not yet owned by the session, and children are killed
without a graceful period.
Validation:
- cargo test -p weft-appd (43 passed); new tests cover: not ready until
the app shell is ready, runtime exit before that, no app shell
configured (runtime never starts), app shell exit ending a running
session with the runtime process gone, and READY lines without the
token; they fail against the previous supervisor
- end to end with weft-compositor (nested), weft-appd, weft-runtime
(wasmtime-runtime) and weft-app-shell: the Counter demo reaches
APP_READY and is on screen; a page that prints a READY line through
alert and never loads is stopped after 30 s without APP_READY;
terminate leaves no child processes
- clippy -D warnings and fmt --check for weft-appd and weft-runtime
2026-10-09 01:41:09 +00:00
|
|
|
match prior_shell {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_APP_SHELL_BIN", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_APP_SHELL_BIN"),
|
|
|
|
|
}
|
2026-03-12 19:16:58 +00:00
|
|
|
match prior_cgroup {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_DISABLE_CGROUP", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_DISABLE_CGROUP"),
|
|
|
|
|
}
|
2026-03-11 08:24:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-03-11 11:24:03 +00:00
|
|
|
|
2026-03-11 11:30:21 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn supervisor_abort_during_startup_broadcasts_stopped() {
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().lock().await;
|
2026-03-11 11:30:21 +00:00
|
|
|
let script =
|
|
|
|
|
std::env::temp_dir().join(format!("weft_test_sleep_{}.sh", std::process::id()));
|
|
|
|
|
std::fs::write(&script, "#!/bin/sh\nsleep 60\n").unwrap();
|
|
|
|
|
std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
|
|
|
|
|
|
|
|
|
|
let prior = std::env::var("WEFT_RUNTIME_BIN").ok();
|
|
|
|
|
unsafe { std::env::set_var("WEFT_RUNTIME_BIN", &script) };
|
|
|
|
|
|
|
|
|
|
let registry: Registry = Arc::new(Mutex::new(SessionRegistry::default()));
|
|
|
|
|
let mut rx = registry.lock().await.subscribe();
|
|
|
|
|
let session_id = registry.lock().await.launch("test.abort.startup");
|
|
|
|
|
let abort_rx = registry.lock().await.register_abort(session_id);
|
|
|
|
|
|
|
|
|
|
registry.lock().await.terminate(session_id);
|
|
|
|
|
|
|
|
|
|
runtime::supervise(
|
|
|
|
|
session_id,
|
|
|
|
|
"test.abort.startup",
|
|
|
|
|
Arc::clone(®istry),
|
|
|
|
|
abort_rx,
|
2026-03-11 13:40:55 +00:00
|
|
|
None,
|
2026-03-11 14:10:11 +00:00
|
|
|
None,
|
2026-03-11 11:30:21 +00:00
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
registry.lock().await.state(session_id),
|
|
|
|
|
AppStateKind::NotFound
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let broadcast = rx.try_recv();
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
broadcast,
|
|
|
|
|
Ok(Response::AppState { session_id: sid, state: AppStateKind::Stopped }) if sid == session_id
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let _ = std::fs::remove_file(&script);
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_RUNTIME_BIN", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_RUNTIME_BIN"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 11:24:03 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn supervisor_spawn_failure_broadcasts_stopped() {
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().lock().await;
|
2026-03-11 11:24:03 +00:00
|
|
|
let prior = std::env::var("WEFT_RUNTIME_BIN").ok();
|
|
|
|
|
unsafe {
|
|
|
|
|
std::env::set_var(
|
|
|
|
|
"WEFT_RUNTIME_BIN",
|
|
|
|
|
"/nonexistent/path/to/weft-runtime-does-not-exist",
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let registry: Registry = Arc::new(Mutex::new(SessionRegistry::default()));
|
|
|
|
|
let mut rx = registry.lock().await.subscribe();
|
|
|
|
|
let session_id = registry.lock().await.launch("test.spawn.fail");
|
|
|
|
|
let abort_rx = registry.lock().await.register_abort(session_id);
|
|
|
|
|
|
|
|
|
|
runtime::supervise(
|
|
|
|
|
session_id,
|
|
|
|
|
"test.spawn.fail",
|
|
|
|
|
Arc::clone(®istry),
|
|
|
|
|
abort_rx,
|
2026-03-11 13:40:55 +00:00
|
|
|
None,
|
2026-03-11 14:10:11 +00:00
|
|
|
None,
|
2026-03-11 11:24:03 +00:00
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
registry.lock().await.state(session_id),
|
|
|
|
|
AppStateKind::Stopped
|
|
|
|
|
));
|
|
|
|
|
|
2026-03-13 11:52:39 +00:00
|
|
|
let broadcast =
|
|
|
|
|
tokio::time::timeout(std::time::Duration::from_millis(200), rx.recv()).await;
|
2026-03-11 11:24:03 +00:00
|
|
|
assert!(matches!(
|
|
|
|
|
broadcast,
|
2026-03-13 11:52:39 +00:00
|
|
|
Ok(Ok(Response::AppState { session_id: sid, state: AppStateKind::Stopped })) if sid == session_id
|
2026-03-11 11:24:03 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_RUNTIME_BIN", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_RUNTIME_BIN"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-11 17:16:37 +00:00
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn session_save_load_roundtrip() {
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().lock().await;
|
2026-03-11 17:16:37 +00:00
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_session_test_{}", std::process::id()));
|
|
|
|
|
std::fs::create_dir_all(&tmp).unwrap();
|
|
|
|
|
let prior = std::env::var("XDG_RUNTIME_DIR").ok();
|
|
|
|
|
unsafe { std::env::set_var("XDG_RUNTIME_DIR", &tmp) };
|
|
|
|
|
|
|
|
|
|
let app_ids = vec!["com.example.foo".to_string(), "com.example.bar".to_string()];
|
|
|
|
|
save_session(app_ids.clone()).await;
|
|
|
|
|
|
|
|
|
|
let loaded = load_session();
|
|
|
|
|
assert!(loaded.is_some());
|
|
|
|
|
let mut loaded = loaded.unwrap();
|
|
|
|
|
loaded.sort();
|
|
|
|
|
let mut expected = app_ids.clone();
|
|
|
|
|
expected.sort();
|
|
|
|
|
assert_eq!(loaded, expected);
|
|
|
|
|
|
|
|
|
|
assert!(load_session().is_none());
|
|
|
|
|
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("XDG_RUNTIME_DIR", v),
|
|
|
|
|
None => std::env::remove_var("XDG_RUNTIME_DIR"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn session_save_empty_load_returns_empty_vec() {
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().lock().await;
|
2026-03-11 17:16:37 +00:00
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_session_empty_{}", std::process::id()));
|
|
|
|
|
std::fs::create_dir_all(&tmp).unwrap();
|
|
|
|
|
let prior = std::env::var("XDG_RUNTIME_DIR").ok();
|
|
|
|
|
unsafe { std::env::set_var("XDG_RUNTIME_DIR", &tmp) };
|
|
|
|
|
|
|
|
|
|
save_session(vec![]).await;
|
|
|
|
|
let loaded = load_session();
|
|
|
|
|
assert!(matches!(loaded, Some(v) if v.is_empty()));
|
|
|
|
|
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("XDG_RUNTIME_DIR", v),
|
|
|
|
|
None => std::env::remove_var("XDG_RUNTIME_DIR"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn load_session_no_file_returns_none() {
|
2026-03-13 11:52:39 +00:00
|
|
|
let _env = env_lock().blocking_lock();
|
2026-03-11 17:16:37 +00:00
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_session_missing_{}", std::process::id()));
|
|
|
|
|
let prior = std::env::var("XDG_RUNTIME_DIR").ok();
|
|
|
|
|
unsafe { std::env::set_var("XDG_RUNTIME_DIR", &tmp) };
|
|
|
|
|
|
|
|
|
|
assert!(load_session().is_none());
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("XDG_RUNTIME_DIR", v),
|
|
|
|
|
None => std::env::remove_var("XDG_RUNTIME_DIR"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
fix(appd): report sessions running only after the UI host is ready
weft-appd marked a session Running and broadcast APP_READY as soon as the
runtime printed READY, then started weft-app-shell with its output
discarded and never watched it. A session with no UI, a UI host that
failed to start, or one that crashed was still reported running. Early
failure paths skipped parts of the cleanup: the image mount was not
unmounted, the compositor association was not released, and the abort
sender leaked on spawn failure. Readiness was any stdout line equal to
READY, which a Wasm guest (inherited stdout) or a page (window.alert
writes to the app shell's stdout) could print.
Now a session becomes Running only after the runtime and then the app
shell report readiness, each within 30 s; WEFT_APP_SHELL_BIN is required
and checked before anything starts. After that, the runtime exiting, the
app shell exiting or a terminate request ends the session. Every exit
path goes through one teardown that kills both children, releases the
compositor association, unmounts the image, stops the file portal and
broadcasts Stopped.
Readiness uses a per-session random token passed to both children in
WEFT_READY_TOKEN. weft-runtime and weft-app-shell print READY <token>,
and appd accepts only a line ending with it; guests receive only the
variables the runtime names and pages cannot read the host environment.
Child output is read in bounded, lossily decoded lines, so invalid UTF-8
or long lines no longer stop the readers. Compositor notifications use
try_send so a disconnected compositor cannot stall teardown, and all
children are killed if the supervisor is dropped.
The IPC relay is not yet owned by the session, and children are killed
without a graceful period.
Validation:
- cargo test -p weft-appd (43 passed); new tests cover: not ready until
the app shell is ready, runtime exit before that, no app shell
configured (runtime never starts), app shell exit ending a running
session with the runtime process gone, and READY lines without the
token; they fail against the previous supervisor
- end to end with weft-compositor (nested), weft-appd, weft-runtime
(wasmtime-runtime) and weft-app-shell: the Counter demo reaches
APP_READY and is on screen; a page that prints a READY line through
alert and never loads is stopped after 30 s without APP_READY;
terminate leaves no child processes
- clippy -D warnings and fmt --check for weft-appd and weft-runtime
2026-10-09 01:41:09 +00:00
|
|
|
|
|
|
|
|
/// Outcome of one supervised session with scripted runtime and app shell.
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
struct SessionRun {
|
|
|
|
|
notifications: Vec<Response>,
|
|
|
|
|
state: AppStateKind,
|
|
|
|
|
elapsed: std::time::Duration,
|
|
|
|
|
runtime_pid: Option<i32>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Runs `supervise` with shell scripts standing in for weft-runtime and
|
|
|
|
|
/// weft-app-shell. The runtime script's PID is recorded so a test can check
|
|
|
|
|
/// that the session did not leave it running.
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
async fn run_scripted_session(runtime_body: &str, shell_body: Option<&str>) -> SessionRun {
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
|
|
|
|
|
let dir = std::env::temp_dir().join(format!(
|
|
|
|
|
"weft_session_{}_{}",
|
|
|
|
|
std::process::id(),
|
|
|
|
|
SESSION_RUN.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
|
|
|
|
|
));
|
|
|
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
|
|
|
let pid_file = dir.join("runtime.pid");
|
|
|
|
|
let write = |name: &str, body: &str| {
|
|
|
|
|
let path = dir.join(name);
|
|
|
|
|
std::fs::write(&path, format!("#!/bin/sh\n{body}\n")).unwrap();
|
|
|
|
|
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();
|
|
|
|
|
path
|
|
|
|
|
};
|
|
|
|
|
let runtime = write(
|
|
|
|
|
"runtime.sh",
|
|
|
|
|
&format!("echo $$ > {}\n{runtime_body}", pid_file.display()),
|
|
|
|
|
);
|
|
|
|
|
let shell = shell_body.map(|body| write("shell.sh", body));
|
|
|
|
|
|
|
|
|
|
let _restore = RestoreOnDrop {
|
|
|
|
|
prior: SCRIPTED_ENV
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|n| (*n, std::env::var(n).ok()))
|
|
|
|
|
.collect(),
|
|
|
|
|
dir: dir.clone(),
|
|
|
|
|
};
|
|
|
|
|
// SAFETY: callers hold env_lock and use a current_thread runtime.
|
|
|
|
|
unsafe {
|
|
|
|
|
std::env::set_var("WEFT_RUNTIME_BIN", &runtime);
|
|
|
|
|
match &shell {
|
|
|
|
|
Some(path) => std::env::set_var("WEFT_APP_SHELL_BIN", path),
|
|
|
|
|
None => std::env::remove_var("WEFT_APP_SHELL_BIN"),
|
|
|
|
|
}
|
|
|
|
|
std::env::set_var("WEFT_DISABLE_CGROUP", "1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let registry = make_registry();
|
|
|
|
|
let mut rx = registry.lock().await.subscribe();
|
|
|
|
|
let session_id = registry.lock().await.launch("test.app");
|
|
|
|
|
let abort_rx = registry.lock().await.register_abort(session_id);
|
|
|
|
|
let started = std::time::Instant::now();
|
|
|
|
|
tokio::time::timeout(
|
|
|
|
|
std::time::Duration::from_secs(20),
|
|
|
|
|
runtime::supervise(
|
|
|
|
|
session_id,
|
|
|
|
|
"test.app",
|
|
|
|
|
Arc::clone(®istry),
|
|
|
|
|
abort_rx,
|
|
|
|
|
None,
|
|
|
|
|
None,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
.expect("session did not settle")
|
|
|
|
|
.unwrap();
|
|
|
|
|
let elapsed = started.elapsed();
|
|
|
|
|
|
|
|
|
|
let mut notifications = Vec::new();
|
|
|
|
|
while let Ok(n) = rx.try_recv() {
|
|
|
|
|
notifications.push(n);
|
|
|
|
|
}
|
|
|
|
|
let state = registry.lock().await.state(session_id);
|
|
|
|
|
let runtime_pid = std::fs::read_to_string(&pid_file)
|
|
|
|
|
.ok()
|
|
|
|
|
.and_then(|s| s.trim().parse().ok());
|
|
|
|
|
|
|
|
|
|
SessionRun {
|
|
|
|
|
notifications,
|
|
|
|
|
state,
|
|
|
|
|
elapsed,
|
|
|
|
|
runtime_pid,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
static SESSION_RUN: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
const SCRIPTED_ENV: [&str; 3] = [
|
|
|
|
|
"WEFT_RUNTIME_BIN",
|
|
|
|
|
"WEFT_APP_SHELL_BIN",
|
|
|
|
|
"WEFT_DISABLE_CGROUP",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/// Restores the scripted-session environment and removes its scripts,
|
|
|
|
|
/// also when an assertion fails.
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
struct RestoreOnDrop {
|
|
|
|
|
prior: Vec<(&'static str, Option<String>)>,
|
|
|
|
|
dir: std::path::PathBuf,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
impl Drop for RestoreOnDrop {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
// SAFETY: the owning test holds env_lock on a current_thread runtime.
|
|
|
|
|
unsafe {
|
|
|
|
|
for (name, value) in &self.prior {
|
|
|
|
|
match value {
|
|
|
|
|
Some(v) => std::env::set_var(name, v),
|
|
|
|
|
None => std::env::remove_var(name),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let _ = std::fs::remove_dir_all(&self.dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
fn became_ready(run: &SessionRun) -> bool {
|
|
|
|
|
run.notifications
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|n| matches!(n, Response::AppReady { .. }))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
fn process_alive(pid: i32) -> bool {
|
|
|
|
|
std::path::Path::new(&format!("/proc/{pid}")).exists()
|
|
|
|
|
&& !std::fs::read_to_string(format!("/proc/{pid}/stat"))
|
|
|
|
|
.map(|stat| stat.split_whitespace().nth(2) == Some("Z"))
|
|
|
|
|
.unwrap_or(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn session_is_not_ready_until_app_shell_is_ready() {
|
|
|
|
|
let _env = env_lock().lock().await;
|
|
|
|
|
let run = run_scripted_session(
|
|
|
|
|
"echo READY $WEFT_READY_TOKEN\nexec sleep 30",
|
|
|
|
|
Some("sleep 0.3\nexit 1"),
|
|
|
|
|
)
|
|
|
|
|
.await;
|
|
|
|
|
assert!(!became_ready(&run), "{:?}", run.notifications);
|
|
|
|
|
assert!(matches!(run.state, AppStateKind::Stopped));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn session_stops_when_runtime_exits_before_app_shell_is_ready() {
|
|
|
|
|
let _env = env_lock().lock().await;
|
|
|
|
|
let run = run_scripted_session(
|
|
|
|
|
"echo READY $WEFT_READY_TOKEN\nexit 0",
|
|
|
|
|
Some("exec sleep 30"),
|
|
|
|
|
)
|
|
|
|
|
.await;
|
|
|
|
|
assert!(!became_ready(&run), "{:?}", run.notifications);
|
|
|
|
|
assert!(matches!(run.state, AppStateKind::Stopped));
|
|
|
|
|
assert!(run.elapsed < std::time::Duration::from_secs(10));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn session_without_app_shell_never_becomes_ready() {
|
|
|
|
|
let _env = env_lock().lock().await;
|
|
|
|
|
let run = run_scripted_session("echo READY $WEFT_READY_TOKEN\nexec sleep 30", None).await;
|
|
|
|
|
assert!(!became_ready(&run), "{:?}", run.notifications);
|
|
|
|
|
assert!(matches!(run.state, AppStateKind::Stopped));
|
|
|
|
|
assert!(
|
|
|
|
|
run.runtime_pid.is_none(),
|
|
|
|
|
"runtime started without a UI host"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn readiness_requires_the_session_token() {
|
|
|
|
|
let _env = env_lock().lock().await;
|
|
|
|
|
// Application output can contain READY lines; only the token counts.
|
|
|
|
|
let run = run_scripted_session(
|
|
|
|
|
"echo READY $WEFT_READY_TOKEN\nexec sleep 30",
|
|
|
|
|
Some("echo READY\necho READY 0123456789abcdef\nsleep 0.3"),
|
|
|
|
|
)
|
|
|
|
|
.await;
|
|
|
|
|
assert!(!became_ready(&run), "{:?}", run.notifications);
|
|
|
|
|
assert!(matches!(run.state, AppStateKind::Stopped));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
|
|
|
async fn app_shell_exit_ends_running_session_and_runtime() {
|
|
|
|
|
let _env = env_lock().lock().await;
|
|
|
|
|
let run = run_scripted_session(
|
|
|
|
|
"echo READY $WEFT_READY_TOKEN\nexec sleep 30",
|
|
|
|
|
Some("echo READY $WEFT_READY_TOKEN\nexec sleep 0.3"),
|
|
|
|
|
)
|
|
|
|
|
.await;
|
|
|
|
|
assert!(became_ready(&run), "{:?}", run.notifications);
|
|
|
|
|
assert!(matches!(run.state, AppStateKind::Stopped));
|
|
|
|
|
assert!(run.elapsed < std::time::Duration::from_secs(10));
|
|
|
|
|
let pid = run.runtime_pid.expect("runtime started");
|
|
|
|
|
assert!(!process_alive(pid), "runtime {pid} left running");
|
|
|
|
|
}
|
2026-03-11 07:32:02 +00:00
|
|
|
}
|