diff --git a/src-tauri/capabilities/main-window-controls.json b/src-tauri/capabilities/main-window-controls.json new file mode 100644 index 0000000..dbbff86 --- /dev/null +++ b/src-tauri/capabilities/main-window-controls.json @@ -0,0 +1,12 @@ +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "main-window-controls", + "description": "Window controls for the main window, which is decorationless and therefore draws its own title bar. core:window:default grants only read-only queries, so without these the minimize, maximize and close buttons are rejected by the ACL and the window cannot be closed except through the tray.", + "windows": ["main"], + "permissions": [ + "core:window:allow-minimize", + "core:window:allow-toggle-maximize", + "core:window:allow-close", + "core:window:allow-start-dragging" + ] +} diff --git a/src-tauri/capabilities/pet-window-drag.json b/src-tauri/capabilities/pet-window-drag.json new file mode 100644 index 0000000..5fe3e96 --- /dev/null +++ b/src-tauri/capabilities/pet-window-drag.json @@ -0,0 +1,7 @@ +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "pet-window-drag", + "description": "The desktop pet is decorationless and is moved by dragging its body. Scoped to dragging alone: the pet must not be able to close or resize itself, which is why this is separate from the main window capability.", + "windows": ["desktop-pet"], + "permissions": ["core:window:allow-start-dragging"] +} diff --git a/src-tauri/tests/capabilities.rs b/src-tauri/tests/capabilities.rs new file mode 100644 index 0000000..cef83d4 --- /dev/null +++ b/src-tauri/tests/capabilities.rs @@ -0,0 +1,77 @@ +//! Guards the capability set against the recurring "silent no-op" defect. +//! +//! A Tauri command that the ACL rejects fails at the IPC boundary, and every +//! rejection the UI does not explicitly catch looks exactly like an unwired +//! button. This class has now bitten twice: the desktop pet window had no +//! capability entry at all (F-03), and the main window's title bar controls were +//! rejected because `core:window:default` grants only read-only queries. +//! +//! These tests read the shipped capability files, so a permission removed while +//! the UI still calls it fails here rather than in someone's hands. + +use serde::Deserialize; + +#[derive(Debug, Deserialize)] +struct Capability { + identifier: String, + windows: Vec, + permissions: Vec, +} + +fn capability(source: &str) -> Capability { + serde_json::from_str(source).expect("capability file must be valid JSON") +} + +const DEFAULT: &str = include_str!("../capabilities/default.json"); +const MAIN_CONTROLS: &str = include_str!("../capabilities/main-window-controls.json"); +const PET_DRAG: &str = include_str!("../capabilities/pet-window-drag.json"); + +#[test] +fn the_main_window_may_drive_its_own_title_bar() { + let capability = capability(MAIN_CONTROLS); + + assert_eq!(capability.identifier, "main-window-controls"); + assert!(capability.windows.iter().any(|label| label == "main")); + + // Each entry corresponds to a call in `WindowChrome` in src/App.tsx. The + // window is `decorations: false`, so without `allow-close` there is no way + // to close it other than the tray. + for permission in [ + "core:window:allow-minimize", + "core:window:allow-toggle-maximize", + "core:window:allow-close", + "core:window:allow-start-dragging", + ] { + assert!( + capability.permissions.iter().any(|held| held == permission), + "{permission} is called by the title bar but not granted" + ); + } +} + +#[test] +fn the_pet_window_may_drag_itself_and_nothing_more() { + let capability = capability(PET_DRAG); + + assert_eq!(capability.windows, vec!["desktop-pet".to_owned()]); + assert_eq!( + capability.permissions, + vec!["core:window:allow-start-dragging".to_owned()], + "the pet is moved by dragging its body; it must not gain close or resize" + ); +} + +#[test] +fn every_declared_window_carries_the_base_capability() { + let capability = capability(DEFAULT); + + // Missing a label here is what left the pet window unable to receive events + // or use IPC at all. + for label in ["main", "quick-chat", "status-bubble", "desktop-pet"] { + assert!( + capability.windows.iter().any(|held| held == label), + "window {label} has no base capability" + ); + } + assert_eq!(capability.permissions, vec!["core:default".to_owned()]); +} diff --git a/src/App.tsx b/src/App.tsx index 86dbc8f..4230742 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -151,6 +151,7 @@ export function App() { onToggleTheme={() => setTheme((current) => (current === "dark" ? "light" : "dark")) } + onError={setError} />