From 6a092f950de857b8c7890fbcb210c43e65c12cc7 Mon Sep 17 00:00:00 2001 From: astar76 Date: Thu, 12 Nov 2026 11:18:39 -0600 Subject: [PATCH 01/10] S008: R1-20 per-site memory and permissions enforced (images, sound), restart smoke Co-Authored-By: Claude Sonnet 5.5 --- Plans/02 Verify/S008-verify-stores.md | 1 + src/actions.rs | 6 +++ src/app.rs | 24 +++++++---- src/hub.rs | 34 ++++++++++++++- src/selftest.rs | 28 ++++++++++++ src/store/permissions.rs | 24 ++++++++++- src/ui/pages/misc.rs | 6 ++- src/ui/pages/settings.rs | 4 ++ tests/smoke/pages/site.html | 11 +++++ tests/smoke/site-memory-restart.txt | 36 ++++++++++++++++ tests/smoke/site-memory.txt | 62 +++++++++++++++++++++++++++ 11 files changed, 223 insertions(+), 13 deletions(-) create mode 100644 tests/smoke/pages/site.html create mode 100644 tests/smoke/site-memory-restart.txt create mode 100644 tests/smoke/site-memory.txt diff --git a/Plans/02 Verify/S008-verify-stores.md b/Plans/02 Verify/S008-verify-stores.md index 73cedc0..cc60983 100644 --- a/Plans/02 Verify/S008-verify-stores.md +++ b/Plans/02 Verify/S008-verify-stores.md @@ -17,6 +17,7 @@ Verify passwords/vault and autofill, permissions prompts, history/bookmarks/down - [ ] History, bookmarks (add, folder, bookmarks bar, import/export HTML), downloads page lists entries - [ ] User scripts/styles apply on matching pages; install a site as an app and launch it - [ ] Importer: build a fake old-Nacre profile from `~/Documents/Apps/Nacre` config format in a temp dir (never the user's real profile) and import it +- [x] R1-20 per-site memory and enforcement: set per-site zoom, ad blocker on/off, privacy-mode flag (flag persistence only; internals are D-011) and other per-site choices; set per-site permissions (camera, mic, location, notifications, pop-ups, autoplay, …); quit, relaunch with `SMOKE_HOME=/home`, check values are in the stores and apply again on reopening the site; check each permission is enforced (blocked/allowed/asked per its stored value), not only stored; fix what is not - [ ] Change a sample of settings via `set` and via clicks; check `settings.json` and the effect; mark FEATURES rows - [ ] PROGRESS entry, INDEX line, commit `S008: …` and push diff --git a/src/actions.rs b/src/actions.rs index 4cf3222..684557f 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -2422,6 +2422,12 @@ impl App { /// The UI edits settings in place; this notices and applies what changed. pub fn apply_settings_if_changed(&mut self) { + let revision = self.shared.permissions.borrow().revision(); + if revision != self.permissions_seen { + self.permissions_seen = revision; + self.shared.permissions.borrow_mut().flush(); + self.refresh_hub_config(); + } let current = self.shared.settings.borrow().clone(); if current == self.applied { return; diff --git a/src/app.rs b/src/app.rs index 1abc2c1..9d3e3f6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -182,6 +182,8 @@ pub struct App { pub gilrs: Option, pub gamepads: HashMap, pub applied: Settings, + /// `Permissions::revision` the hub and the file were last updated for. + pub permissions_seen: u64, pub exiting: bool, last_tick: Instant, last_save: Instant, @@ -307,6 +309,7 @@ impl App { gilrs: None, gamepads: HashMap::new(), applied: settings, + permissions_seen: 0, exiting: false, last_tick: Instant::now(), last_save: Instant::now(), @@ -392,7 +395,7 @@ impl App { pub fn refresh_hub_config(&self) { let settings = self.shared.settings.borrow(); - *self.hub.config.borrow_mut() = HubConfig::from_settings(&settings, &self.shared.user_agent.borrow(), self.shared.http_allowed.borrow().clone()); + *self.hub.config.borrow_mut() = HubConfig::from_settings(&settings, &self.shared.permissions.borrow(), &self.shared.user_agent.borrow(), self.shared.http_allowed.borrow().clone()); } /// (Re)build the scripts every page gets. Applies on each page's next load. @@ -540,13 +543,16 @@ impl App { } } self.check_app_scope(window, id, &url); - if host_changed { - let zoom = self.shared.settings.borrow().zoom_for(&util::host_of(&url)); - if let Some(tab) = self.tab_mut(id) { - tab.zoom = zoom; - if let Some(web) = &tab.web { - web.webview.set_page_zoom(zoom); - } + // A zoom change is saved for the site at once, so the site's value is always the right one. Not only + // when the host changed: a new tab already holds its address when the first event arrives. + let zoom = self.shared.settings.borrow().zoom_for(&util::host_of(&url)); + if let Some(tab) = self.tab_mut(id) { + let differs = (tab.zoom - zoom).abs() > 0.001; + tab.zoom = zoom; + if (host_changed || differs) + && let Some(web) = &tab.web + { + web.webview.set_page_zoom(zoom); } } self.redraw(window); @@ -810,7 +816,7 @@ impl App { } // Mute state survives navigation. let shared = self.shared.clone(); - let muted = self.tab_mut(id).map(|t| t.muted || shared.settings.borrow().site_muted(&util::host_of_str(&t.url))).unwrap_or(false); + let muted = self.tab_mut(id).map(|t| t.muted || shared.settings.borrow().site_muted(&util::host_of_str(&t.url)) || shared.permissions.borrow().answer(&shared.settings.borrow(), &util::host_of_str(&t.url), crate::store::permissions::Kind::Sound) == crate::store::permissions::Answer::Block).unwrap_or(false); if muted && let Some(tab) = self.tab_mut(id) { tab.muted = true; if let Some(web) = &tab.web { diff --git a/src/hub.rs b/src/hub.rs index 9cc1e91..ace6fc6 100644 --- a/src/hub.rs +++ b/src/hub.rs @@ -15,6 +15,7 @@ use url::Url; use crate::adblock::{AdBlocker, Verdict}; use crate::inject::{self, PageMessage}; +use crate::store::permissions::{Answer, Decision, Kind, Permissions}; use crate::store::settings::Settings; use crate::util; @@ -73,13 +74,21 @@ pub struct HubConfig { pub https_exceptions: Vec, pub strip_params: bool, pub google_signin: bool, + /// Images permission: blocked unless a site says otherwise, and the sites that differ (host, blocked). + pub images_block_default: bool, + pub images_sites: Vec<(String, bool)>, pub user_agent: String, /// Tabs where the user chose "open over http anyway" this session (host). pub http_allowed: Vec, } impl HubConfig { - pub fn from_settings(settings: &Settings, user_agent: &str, http_allowed: Vec) -> HubConfig { + /// Whether pictures are blocked on pages of this host. + pub fn images_blocked(&self, host: &str) -> bool { + self.images_sites.iter().find(|(h, _)| h == host).map(|(_, block)| *block).unwrap_or(self.images_block_default) + } + + pub fn from_settings(settings: &Settings, permissions: &Permissions, user_agent: &str, http_allowed: Vec) -> HubConfig { HubConfig { adblock_enabled: settings.adblock.enabled, adblock_allow: settings.adblock.allow.clone(), @@ -87,6 +96,8 @@ impl HubConfig { https_exceptions: settings.privacy.https_exceptions.clone(), strip_params: settings.privacy.strip_params, google_signin: settings.privacy.google_signin, + images_block_default: permissions.answer(settings, "", Kind::Images) == Answer::Block, + images_sites: permissions.all().into_iter().filter(|(_, kind, _)| *kind == Kind::Images).map(|(host, _, decision)| (host, decision == Decision::Block)).collect(), user_agent: user_agent.to_owned(), http_allowed, } @@ -245,9 +256,14 @@ impl Hub { return; } - // Sub-resources: the ad blocker. + // Sub-resources: the Images permission, then the ad blocker. let page_url = page.as_ref().map(Url::as_str).unwrap_or(""); let page_host = util::host_of_str(page_url); + if kind == "image" && matches!(url.scheme(), "http" | "https") && !page_host.is_empty() && config.images_blocked(&page_host) { + drop(config); + load.intercept(WebResourceResponse::new(url).status_code(StatusCode::NO_CONTENT)).cancel(); + return; + } let paused = !config.adblock_enabled || config.adblock_allow.iter().any(|h| util::host_matches(&page_host, h)); drop(config); if !paused && matches!(url.scheme(), "http" | "https" | "ws" | "wss") { @@ -403,6 +419,20 @@ impl servo::GamepadDelegate for Gamepads { mod tests { use super::*; + #[test] + fn images_follow_the_site_answer_then_the_default() { + let mut settings = Settings::default(); + let mut permissions = Permissions::load(std::path::PathBuf::from("/nonexistent/permissions.json"), true); + assert!(!HubConfig::from_settings(&settings, &permissions, "", Vec::new()).images_blocked("a.example")); + permissions.set("a.example", Kind::Images, Some(Decision::Block)); + let config = HubConfig::from_settings(&settings, &permissions, "", Vec::new()); + assert!(config.images_blocked("a.example") && !config.images_blocked("b.example")); + settings.privacy.permission_defaults.insert("images".into(), crate::store::settings::PermissionDefault::Block); + permissions.set("b.example", Kind::Images, Some(Decision::Allow)); + let config = HubConfig::from_settings(&settings, &permissions, "", Vec::new()); + assert!(config.images_blocked("a.example") && config.images_blocked("c.example") && !config.images_blocked("b.example")); + } + #[test] fn strips_tracking() { let u = Url::parse("https://a.example/p?id=3&utm_source=x&fbclid=y").unwrap(); diff --git a/src/selftest.rs b/src/selftest.rs index 0ec2e71..d714731 100644 --- a/src/selftest.rs +++ b/src/selftest.rs @@ -10,6 +10,8 @@ //! resize resize the window (logical pixels) //! status save tabs, downloads, VPN, ad blocker and so on as .json //! set change a setting, e.g. `set /privacy/https_only true` +//! perm allow|block|default store a site's answer for a permission (kinds: store::permissions::Kind keys) +//! prompt allow|deny [remember] answer the active tab's first permission prompt //! flyout main, downloads, shield, vpn, media, siteinfo, profiles, apps, qr, tabmenu, back, //! bookmark (edit the current page's bookmark), none //! type put text in the address bar with its suggestions open @@ -271,6 +273,27 @@ impl App { } self.apply_settings_if_changed(); }, + "perm" => { + let parts: Vec<&str> = rest.split_whitespace().collect(); + let kind = parts.get(1).and_then(|k| crate::store::permissions::Kind::ALL.iter().find(|x| x.key() == *k)); + let decision = match parts.get(2).copied() { + Some("allow") => Some(Some(crate::store::permissions::Decision::Allow)), + Some("block") => Some(Some(crate::store::permissions::Decision::Block)), + Some("default") => Some(None), + _ => None, + }; + match (parts.first(), kind, decision) { + (Some(host), Some(kind), Some(decision)) => self.shared.permissions.borrow_mut().set(host, *kind, decision), + _ => self.selftest_log(&format!("perm: bad line {rest}")), + } + self.refresh_hub_config(); + }, + "prompt" => { + let remember = rest.contains("remember"); + let answer = if rest.starts_with("allow") { crate::actions::PromptAnswer::Allow { remember } } else { crate::actions::PromptAnswer::Deny { remember } }; + let tab = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.id).unwrap_or(0); + self.run_in(window, Command::Prompt { tab, answer }); + }, "flyout" => { let url = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.url.clone()).unwrap_or_default(); let tab = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.id).unwrap_or(0); @@ -676,6 +699,11 @@ impl App { "route": self.shared.bridge.as_ref().map(|b| format!("{:?}", b.route())), "bridge_bytes": self.shared.bridge.as_ref().map(|b| b.bytes.load(std::sync::atomic::Ordering::Relaxed)), "adblock": {"ready": self.shared.adblock.ready(), "rules": self.shared.adblock.rule_count(), "status": self.shared.adblock_status.borrow().clone(), "total": settings.adblock.total}, + "permissions": self.shared.permissions.borrow().all().iter().fold(serde_json::Map::new(), |mut m, (host, kind, decision)| { + m.entry(host.clone()).or_insert_with(|| serde_json::json!({})).as_object_mut().expect("object").insert(kind.key().to_owned(), serde_json::json!(format!("{decision:?}").to_lowercase())); + m + }), + "site_state": {"zoom_sites": settings.web.zoom_sites, "adblock_allow": settings.adblock.allow, "keep_active": settings.perf.keep_active, "muted_sites": settings.media.muted_sites, "https_exceptions": settings.privacy.https_exceptions}, "history": self.shared.history.borrow().len(), "bookmarks": self.shared.bookmarks.borrow().all().len(), "logins": self.shared.vault.borrow().contents.logins.len(), diff --git a/src/store/permissions.rs b/src/store/permissions.rs index 41eee72..19098ee 100644 --- a/src/store/permissions.rs +++ b/src/store/permissions.rs @@ -120,6 +120,18 @@ impl Kind { } } + /// Why Nacre can't enforce this one: Servo 0.7 has no per-site switch for it. Those rows show as unavailable. + pub fn engine_limit(self) -> Option<&'static str> { + match self { + Kind::Location => Some("Servo 0.7 never asks for the location: navigator.geolocation does nothing"), + Kind::Camera | Kind::Microphone | Kind::DeviceInfo => Some("Servo 0.7 has no navigator.mediaDevices, so no page can ask"), + Kind::Storage => Some("Servo 0.7 has no navigator.storage.persist(), so no page can ask"), + Kind::Javascript => Some("Servo 0.7 can't turn JavaScript off for one site"), + Kind::Clipboard => Some("Servo 0.7 doesn't ask before a page reads the clipboard"), + _ => None, + } + } + /// The answer when the user has set nothing: sensitive things ask, harmless ones are allowed. pub fn builtin_default(self) -> PermissionDefault { match self { @@ -150,12 +162,14 @@ pub struct Permissions { sites: BTreeMap>, dirty: bool, read_only: bool, + /// Counts every change, so the app notices edits made by menus and pages. + revision: u64, } impl Permissions { pub fn load(path: PathBuf, read_only: bool) -> Permissions { let sites = if read_only { BTreeMap::new() } else { util::load_json(&path) }; - Permissions { path, sites, dirty: false, read_only } + Permissions { path, sites, dirty: false, read_only, revision: 0 } } /// The decision stored for exactly this site, if any. @@ -198,6 +212,11 @@ impl Permissions { }, } self.dirty = true; + self.revision += 1; + } + + pub fn revision(&self) -> u64 { + self.revision } /// Every stored decision: (host, kind, decision). @@ -212,6 +231,7 @@ impl Permissions { pub fn clear_host(&mut self, host: &str) { if self.sites.remove(host).is_some() { self.dirty = true; + self.revision += 1; } } @@ -219,6 +239,7 @@ impl Permissions { if !self.sites.is_empty() { self.sites.clear(); self.dirty = true; + self.revision += 1; } } @@ -248,5 +269,6 @@ mod tests { assert_eq!(p.answer(&s, "a.example", Kind::Camera), Answer::Allow); p.set("a.example", Kind::Camera, None); assert!(p.all().is_empty()); + assert_eq!(p.revision(), 2); } } diff --git a/src/ui/pages/misc.rs b/src/ui/pages/misc.rs index 42f3f7a..4f55f07 100644 --- a/src/ui/pages/misc.rs +++ b/src/ui/pages/misc.rs @@ -3,7 +3,7 @@ use egui::{RichText, Sense, Stroke, Ui, vec2}; -use super::super::widgets::{ButtonKind, button, card, empty_state, icon, icon_button, icon_row, icon_link_row, list_item, page_column, page_header, row, search_pill, section, segmented, status_state, switch, switch_row}; +use super::super::widgets::{ButtonKind, button, card, empty_state, icon, icon_button, icon_row, icon_link_row, list_item, page_column, page_header, row, search_pill, section, segmented, status_state, switch, switch_row, unavailable_row}; use super::super::{Frame, paint}; use crate::actions::Command; use crate::store::permissions::{Decision, Kind}; @@ -73,6 +73,10 @@ pub fn site_settings(ui: &mut Ui, f: &mut Frame, host: &str) { section(ui, "Permissions"); card(ui, |ui| { for kind in Kind::ALL { + if let Some(reason) = kind.engine_limit() { + unavailable_row(ui, kind.label(), reason); + continue; + } let current = f.shared.permissions.borrow().site_decision(host, *kind); let mut value: u8 = match current { None => 0, diff --git a/src/ui/pages/settings.rs b/src/ui/pages/settings.rs index 1987730..1dc97dd 100644 --- a/src/ui/pages/settings.rs +++ b/src/ui/pages/settings.rs @@ -1293,6 +1293,10 @@ fn permissions(ui: &mut Ui, f: &mut Frame, s: &mut Settings) { section(ui, "Defaults"); card(ui, |ui| { for kind in crate::store::permissions::Kind::ALL { + if let Some(reason) = kind.engine_limit() { + unavailable_row(ui, kind.label(), reason); + continue; + } let mut value = s.privacy.permission_defaults.get(kind.key()).copied().unwrap_or_else(|| kind.builtin_default()); let before = value; row(ui, kind.label(), "", |ui| segmented(ui, &mut value, PermissionDefault::ALL)); diff --git a/tests/smoke/pages/site.html b/tests/smoke/pages/site.html new file mode 100644 index 0000000..55ee25e --- /dev/null +++ b/tests/smoke/pages/site.html @@ -0,0 +1,11 @@ + + +Site permissions probe + + diff --git a/tests/smoke/site-memory-restart.txt b/tests/smoke/site-memory-restart.txt new file mode 100644 index 0000000..02c8f9c --- /dev/null +++ b/tests/smoke/site-memory-restart.txt @@ -0,0 +1,36 @@ +# Per-site memory and permissions (S008, R1-20), part 2: run on part 1's home (SMOKE_HOME=/home). +# Everything set in part 1 is still stored, and applies again when the site is opened. +wait 3 +status stored +expect /permissions/127.0.0.1/notifications block +expect /permissions/127.0.0.1/popups block +expect /permissions/127.0.0.1/images block +expect /permissions/127.0.0.1/sound block +expect /site_state/adblock_allow/0 "127.0.0.1" +expect /site_state/keep_active/0 "127.0.0.1" +expect /site_state/muted_sites/0 "127.0.0.1" +expect /site_state/https_exceptions/0 "127.0.0.1" +expect /site_state/zoom_sites/127.0.0.1 > 1 +# Open the site fresh: zoom, mute, images and permissions apply again; a blocked pop-up stays blocked. +newtab http://127.0.0.1:8768/site.html +waitfor 20 window.res && window.res.img !== undefined +assert res.img === 'blocked' +wait 2 +status opened +expect /active/zoom > 1 +expect /active/muted true +js notif() +waitfor 10 res.notif === 'denied' +js pop() +wait 2 +status checked +expect /tab_count 2 +# Reset the images answer: the picture loads again, and the change is stored. +perm 127.0.0.1 images default +cmd reload +waitload +waitfor 20 window.res && window.res.img !== undefined +assert res.img === 'loaded' +shot images-back +status done +quit diff --git a/tests/smoke/site-memory.txt b/tests/smoke/site-memory.txt new file mode 100644 index 0000000..5b1cd5b --- /dev/null +++ b/tests/smoke/site-memory.txt @@ -0,0 +1,62 @@ +# Per-site memory and permissions (S008, R1-20), part 1: set values, then quit. +# Part 2 (site-memory-restart.txt) runs on the same home and checks they came back and still apply. Offline. +# python3 -m http.server 8768 --bind 127.0.0.1 --directory tests/smoke/pages & +# tools/smoke.sh tests/smoke/site-memory.txt (hidden) +# SMOKE_HOME=/home tools/smoke.sh tests/smoke/site-memory-restart.txt +wait 3 +open http://127.0.0.1:8768/site.html +waitfor 20 window.res && window.res.img !== undefined +assert res.img === 'loaded' +# Notifications: asks first; deny + remember; the next ask is refused without a prompt. +js notif() +wait 3 +status ask +expect /active/prompts 1 +prompt deny remember +waitfor 10 res.notif === 'denied' +js notif() +waitfor 10 res.notif === 'denied' +status notif +expect /active/prompts 0 +expect /permissions/127.0.0.1/notifications block +# Pop-ups: a new tab by default, none once blocked. +js pop() +wait 2 +status popup-default +expect /tab_count 2 +cmd close_tab +cmd select 0 +perm 127.0.0.1 popups block +js pop() +wait 2 +status popup +expect /tab_count 1 +# Images blocked for the site: the picture doesn't load after a reload. +perm 127.0.0.1 images block +cmd reload +waitload +waitfor 20 window.res && window.res.img !== undefined +assert res.img === 'blocked' +shot images-blocked +# Sound blocked: the tab is muted on load. +perm 127.0.0.1 sound block +cmd reload +waitload +wait 2 +status sound +expect /active/muted true +# Other per-site choices: zoom, ad blocker off, keep active, mute, HTTPS exception. +cmd zoom 1 +cmd zoom 1 +set /adblock/allow ["127.0.0.1"] +set /perf/keep_active ["127.0.0.1"] +set /media/muted_sites ["127.0.0.1"] +set /privacy/https_exceptions ["127.0.0.1"] +wait 1 +status set +expect /active/zoom > 1 +expect /site_state/adblock_allow/0 "127.0.0.1" +expect /permissions/127.0.0.1/images block +expect /permissions/127.0.0.1/popups block +status done +quit From 1a1c386e43315ef54486582537d8b0ba5a5728d0 Mon Sep 17 00:00:00 2001 From: astar76 Date: Thu, 12 Nov 2026 11:19:54 -0600 Subject: [PATCH 02/10] S008: every nacre:// page smoke and blank-shot checker Co-Authored-By: Claude Sonnet 5.5 --- Plans/02 Verify/S008-verify-stores.md | 2 +- tests/smoke/stores-pages.txt | 58 +++++++++++++++++++++++++++ tools/check-shots.py | 22 ++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/smoke/stores-pages.txt create mode 100755 tools/check-shots.py diff --git a/Plans/02 Verify/S008-verify-stores.md b/Plans/02 Verify/S008-verify-stores.md index cc60983..76fb715 100644 --- a/Plans/02 Verify/S008-verify-stores.md +++ b/Plans/02 Verify/S008-verify-stores.md @@ -11,7 +11,7 @@ Verify passwords/vault and autofill, permissions prompts, history/bookmarks/down - `src/ui/pages/mod.rs` (list of pages) ## Steps -- [ ] Script: open every nacre:// page and take a shot; check none panics or renders empty +- [x] Script: open every nacre:// page and take a shot; check none panics or renders empty - [ ] Vault: create, lock/unlock, save a login from a local form page, autofill it, export/import; check the vault file is encrypted - [ ] Permissions: a local page asking for notifications/geolocation/camera; allow/deny/remember; check `permissions` store - [ ] History, bookmarks (add, folder, bookmarks bar, import/export HTML), downloads page lists entries diff --git a/tests/smoke/stores-pages.txt b/tests/smoke/stores-pages.txt new file mode 100644 index 0000000..dade89c --- /dev/null +++ b/tests/smoke/stores-pages.txt @@ -0,0 +1,58 @@ +# Stores pass (S008): every nacre:// page opens, nothing panics, nothing renders blank (tools/check-shots.py). +# Settings sections are covered by settings.txt. Offline. Hidden: tools/smoke.sh tests/smoke/stores-pages.txt +# then: python3 tools/check-shots.py +wait 3 +resize 1280 900 +page nacre://newtab +wait 1 +shot page-newtab +page nacre://settings +wait 1 +shot page-settings +page nacre://history +wait 1 +shot page-history +page nacre://bookmarks +wait 1 +shot page-bookmarks +page nacre://downloads +wait 1 +shot page-downloads +page nacre://passwords +wait 1 +shot page-passwords +page nacre://apps +wait 1 +shot page-apps +page nacre://site-settings +wait 1 +shot page-site-settings +page nacre://site-settings/example.com +wait 1 +shot page-site-settings-host +page nacre://clear-data +wait 1 +shot page-clear-data +page nacre://about +wait 1 +shot page-about +page nacre://welcome +wait 1 +shot page-welcome +page nacre://task-manager +wait 1 +shot page-task-manager +page nacre://devtools +wait 1 +shot page-devtools +page nacre://gallery +wait 1 +shot page-gallery +page nacre://source/@PAGES@/hello.html +wait 1 +shot page-source +open https://no-such-host.invalid/ +wait 4 +shot page-error +status done +quit diff --git a/tools/check-shots.py b/tools/check-shots.py new file mode 100755 index 0000000..7db6d15 --- /dev/null +++ b/tools/check-shots.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +"""Fail if a smoke screenshot looks blank: usage `tools/check-shots.py [prefix]` (checks *.png). +A shot is blank when its window area has fewer than 8 distinct colours or one colour covers over 99.5 % of it.""" +import sys +from collections import Counter +from pathlib import Path + +from PIL import Image + +out = Path(sys.argv[1]) +prefix = sys.argv[2] if len(sys.argv) > 2 else "" +bad = 0 +shots = sorted(out.glob(prefix + "*.png")) +for shot in shots: + image = Image.open(shot).convert("RGB") + colours = Counter(image.getdata()) + top = colours.most_common(1)[0][1] / (image.width * image.height) + blank = len(colours) < 8 or top > 0.995 + print(f"{'BLANK' if blank else 'ok '} {shot.name}: {len(colours)} colours, {top:.1%} one colour") + bad += blank +print(f"{len(shots)} shots, {bad} blank") +sys.exit(1 if bad or not shots else 0) From b54d1a828ebeaace2fc7043bc19ed065ef08f3af Mon Sep 17 00:00:00 2001 From: astar76 Date: Thu, 12 Nov 2026 11:31:19 -0600 Subject: [PATCH 03/10] S008: vault smoke (save, autofill, master lock, csv), permission prompt answers Co-Authored-By: Claude Sonnet 5.5 --- Plans/02 Verify/S008-verify-stores.md | 4 +- src/selftest.rs | 28 ++++++++++++ tests/smoke/pages/login.html | 9 ++++ tests/smoke/pages/vault-import.csv | 4 ++ tests/smoke/site-memory-restart.txt | 32 ++++++++++++++ tests/smoke/stores-vault-check.sh | 15 +++++++ tests/smoke/stores-vault.txt | 64 +++++++++++++++++++++++++++ 7 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 tests/smoke/pages/login.html create mode 100644 tests/smoke/pages/vault-import.csv create mode 100755 tests/smoke/stores-vault-check.sh create mode 100644 tests/smoke/stores-vault.txt diff --git a/Plans/02 Verify/S008-verify-stores.md b/Plans/02 Verify/S008-verify-stores.md index 76fb715..e563ed3 100644 --- a/Plans/02 Verify/S008-verify-stores.md +++ b/Plans/02 Verify/S008-verify-stores.md @@ -12,8 +12,8 @@ Verify passwords/vault and autofill, permissions prompts, history/bookmarks/down ## Steps - [x] Script: open every nacre:// page and take a shot; check none panics or renders empty -- [ ] Vault: create, lock/unlock, save a login from a local form page, autofill it, export/import; check the vault file is encrypted -- [ ] Permissions: a local page asking for notifications/geolocation/camera; allow/deny/remember; check `permissions` store +- [x] Vault: create, lock/unlock, save a login from a local form page, autofill it, export/import; check the vault file is encrypted +- [x] Permissions: a local page asking for notifications/geolocation/camera; allow/deny/remember; check `permissions` store - [ ] History, bookmarks (add, folder, bookmarks bar, import/export HTML), downloads page lists entries - [ ] User scripts/styles apply on matching pages; install a site as an app and launch it - [ ] Importer: build a fake old-Nacre profile from `~/Documents/Apps/Nacre` config format in a temp dir (never the user's real profile) and import it diff --git a/src/selftest.rs b/src/selftest.rs index d714731..4d48cac 100644 --- a/src/selftest.rs +++ b/src/selftest.rs @@ -12,6 +12,7 @@ //! set change a setting, e.g. `set /privacy/https_only true` //! perm allow|block|default store a site's answer for a permission (kinds: store::permissions::Kind keys) //! prompt allow|deny [remember] answer the active tab's first permission prompt +//! vault master | lock | unlock | remove_master | export | import the password vault //! flyout main, downloads, shield, vpn, media, siteinfo, profiles, apps, qr, tabmenu, back, //! bookmark (edit the current page's bookmark), none //! type put text in the address bar with its suggestions open @@ -288,6 +289,32 @@ impl App { } self.refresh_hub_config(); }, + "vault" => { + let (what, arg) = rest.split_once(char::is_whitespace).map(|(w, a)| (w, a.trim())).unwrap_or((rest, "")); + let result = { + let mut vault = self.shared.vault.borrow_mut(); + match what { + "master" => vault.set_master(arg).map(|_| String::new()), + "lock" => { + vault.lock(); + Ok(String::new()) + }, + "unlock" => vault.unlock(arg).map(|_| String::new()), + "remove_master" => vault.remove_master().map(|_| String::new()), + "export" => vault.export_csv().and_then(|csv| std::fs::write(arg, csv).map_err(|e| crate::store::vault::VaultError::Io(e.to_string()))).map(|_| String::new()), + "import" => match std::fs::read_to_string(arg) { + Ok(text) => vault.import_csv(&text).map(|(added, skipped)| format!("imported {added}, skipped {skipped}")), + Err(error) => Err(crate::store::vault::VaultError::Io(error.to_string())), + }, + _ => Ok(format!("unknown vault command {what}")), + } + }; + match result { + Ok(note) if !note.is_empty() => self.selftest_log(¬e), + Ok(_) => {}, + Err(error) => self.selftest_log(&format!("vault {what}: {error}")), + } + }, "prompt" => { let remember = rest.contains("remember"); let answer = if rest.starts_with("allow") { crate::actions::PromptAnswer::Allow { remember } } else { crate::actions::PromptAnswer::Deny { remember } }; @@ -708,6 +735,7 @@ impl App { "bookmarks": self.shared.bookmarks.borrow().all().len(), "logins": self.shared.vault.borrow().contents.logins.len(), "vault_locked": self.shared.vault.borrow().locked(), + "vault_mode": format!("{:?}", self.shared.vault.borrow().mode()), "apps": self.shared.apps.borrow().items.len(), "dlm": format!("{:?}", self.shared.dlm_status.borrow()), "discord": self.shared.presence_status.borrow().clone(), diff --git a/tests/smoke/pages/login.html b/tests/smoke/pages/login.html new file mode 100644 index 0000000..aeecabc --- /dev/null +++ b/tests/smoke/pages/login.html @@ -0,0 +1,9 @@ + + +Login probe + +
+

+

+

+
diff --git a/tests/smoke/pages/vault-import.csv b/tests/smoke/pages/vault-import.csv new file mode 100644 index 0000000..3f1298c --- /dev/null +++ b/tests/smoke/pages/vault-import.csv @@ -0,0 +1,4 @@ +name,url,username,password,note +shop,https://shop.example/login,bob,Tr0ub4dor&3,first +mail,https://mail.example/,carol,correct horse battery, +bad,not a url,dave,x, diff --git a/tests/smoke/site-memory-restart.txt b/tests/smoke/site-memory-restart.txt index 02c8f9c..4594039 100644 --- a/tests/smoke/site-memory-restart.txt +++ b/tests/smoke/site-memory-restart.txt @@ -25,6 +25,38 @@ js pop() wait 2 status checked expect /tab_count 2 +expect /active/prompts 1 +# That one prompt is the 'pop-up blocked' notice; dismiss it. +prompt deny +# Prompt answers: allow + remember is stored; deny without remember is not (it asks again after a reload). +perm 127.0.0.1 notifications default +cmd reload +waitload +waitfor 20 window.res && window.res.img !== undefined +js notif() +wait 3 +status ask-again +expect /active/prompts 1 +prompt allow remember +waitfor 10 res.notif === 'granted' +status allowed +expect /permissions/127.0.0.1/notifications allow +perm 127.0.0.1 notifications default +cmd reload +waitload +waitfor 20 window.res && window.res.img !== undefined +js notif() +wait 3 +prompt deny +waitfor 10 res.notif === 'denied' +cmd reload +waitload +waitfor 20 window.res && window.res.img !== undefined +js notif() +wait 3 +status asked-third +expect /active/prompts 1 +prompt deny remember # Reset the images answer: the picture loads again, and the change is stored. perm 127.0.0.1 images default cmd reload diff --git a/tests/smoke/stores-vault-check.sh b/tests/smoke/stores-vault-check.sh new file mode 100755 index 0000000..49cc838 --- /dev/null +++ b/tests/smoke/stores-vault-check.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# After tests/smoke/stores-vault.txt: the vault file holds no plain text and the device key is gone (master mode); the +# CSV export has the login. Usage: tests/smoke/stores-vault-check.sh +set -eu +out=${1:?outdir} +data=$out/home/.local/share/nacre-servo/Default +fail=0 +for secret in s3cret-Pa55 alice 127.0.0.1 'Tr0ub4dor' carol; do + if grep -q -- "$secret" "$data/vault.json"; then echo "FAIL: vault.json contains '$secret'"; fail=1; fi +done +if [ -e "$data/vault.key" ]; then echo "FAIL: vault.key still exists in master mode"; fail=1; fi +grep -q 's3cret-Pa55' "$out/home/export.csv" || { echo "FAIL: export.csv lacks the login"; fail=1; } +[ "$(stat -c %a "$data/vault.json")" = 600 ] || { echo "FAIL: vault.json mode is not 600"; fail=1; } +[ $fail = 0 ] && echo "vault files ok" +exit $fail diff --git a/tests/smoke/stores-vault.txt b/tests/smoke/stores-vault.txt new file mode 100644 index 0000000..ed09d60 --- /dev/null +++ b/tests/smoke/stores-vault.txt @@ -0,0 +1,64 @@ +# Stores pass (S008): the password vault. Save a login from a local form, autofill it, master password lock/unlock, +# CSV export and import. Offline. Start the page server first, then run hidden and check the files afterwards: +# python3 -m http.server 8768 --bind 127.0.0.1 --directory tests/smoke/pages & +# tools/smoke.sh tests/smoke/stores-vault.txt then tests/smoke/stores-vault-check.sh +wait 3 +open http://127.0.0.1:8768/login.html +waitload +waitfor 10 document.getElementById('pass') !== null +locate #user +wait 1 +click @ +pagetype alice +locate #pass +wait 1 +click @ +pagetype s3cret-Pa55 +locate #go +wait 1 +click @ +wait 2 +status save-prompt +expect /active/prompts 1 +prompt allow +status saved +expect /logins 1 +# Autofill: with one saved login the form fills itself. +open http://127.0.0.1:8768/login.html +waitload +waitfor 10 document.getElementById('pass').value === 's3cret-Pa55' +assert document.getElementById('user').value === 'alice' +shot autofilled +# Export, master password, lock. +vault export @HOME@/export.csv +vault master hunter2 +status master +expect /vault_mode "Master" +vault lock +status locked +expect /vault_locked true +expect /logins 0 +open http://127.0.0.1:8768/login.html +waitload +wait 2 +assert document.getElementById('pass').value === '' +vault unlock wrong-password +status wrong +expect /vault_locked true +vault unlock hunter2 +status unlocked +expect /vault_locked false +expect /logins 1 +open http://127.0.0.1:8768/login.html +waitload +waitfor 10 document.getElementById('pass').value === 's3cret-Pa55' +# Import: the same file again adds nothing; a Chrome-format file adds two and skips the bad row. +vault import @HOME@/export.csv +vault import @PAGESDIR@/vault-import.csv +status imported +expect /logins 3 +page nacre://passwords +wait 1 +shot passwords-page +status done +quit From 8cd424f8dfdcec8f65f7a7d7fb986b8006ee1c8a Mon Sep 17 00:00:00 2001 From: astar76 Date: Thu, 12 Nov 2026 11:35:21 -0600 Subject: [PATCH 04/10] S008: history, bookmarks, downloads smoke with restart Co-Authored-By: Claude Sonnet 5.5 --- Plans/02 Verify/S008-verify-stores.md | 2 +- src/selftest.rs | 26 +++++++++++++ tests/smoke/pages/chrome-bookmarks.html | 15 ++++++++ tests/smoke/stores-lists-restart.txt | 12 ++++++ tests/smoke/stores-lists.txt | 49 +++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tests/smoke/pages/chrome-bookmarks.html create mode 100644 tests/smoke/stores-lists-restart.txt create mode 100644 tests/smoke/stores-lists.txt diff --git a/Plans/02 Verify/S008-verify-stores.md b/Plans/02 Verify/S008-verify-stores.md index e563ed3..6b6852d 100644 --- a/Plans/02 Verify/S008-verify-stores.md +++ b/Plans/02 Verify/S008-verify-stores.md @@ -14,7 +14,7 @@ Verify passwords/vault and autofill, permissions prompts, history/bookmarks/down - [x] Script: open every nacre:// page and take a shot; check none panics or renders empty - [x] Vault: create, lock/unlock, save a login from a local form page, autofill it, export/import; check the vault file is encrypted - [x] Permissions: a local page asking for notifications/geolocation/camera; allow/deny/remember; check `permissions` store -- [ ] History, bookmarks (add, folder, bookmarks bar, import/export HTML), downloads page lists entries +- [x] History, bookmarks (add, folder, bookmarks bar, import/export HTML), downloads page lists entries - [ ] User scripts/styles apply on matching pages; install a site as an app and launch it - [ ] Importer: build a fake old-Nacre profile from `~/Documents/Apps/Nacre` config format in a temp dir (never the user's real profile) and import it - [x] R1-20 per-site memory and enforcement: set per-site zoom, ad blocker on/off, privacy-mode flag (flag persistence only; internals are D-011) and other per-site choices; set per-site permissions (camera, mic, location, notifications, pop-ups, autoplay, …); quit, relaunch with `SMOKE_HOME=/home`, check values are in the stores and apply again on reopening the site; check each permission is enforced (blocked/allowed/asked per its stored value), not only stored; fix what is not diff --git a/src/selftest.rs b/src/selftest.rs index 4d48cac..e42de02 100644 --- a/src/selftest.rs +++ b/src/selftest.rs @@ -13,6 +13,7 @@ //! perm allow|block|default store a site's answer for a permission (kinds: store::permissions::Kind keys) //! prompt allow|deny [remember] answer the active tab's first permission prompt //! vault master | lock | unlock | remove_master | export | import the password vault +//! bookmarks folder | export | import a folder on the bar; the Netscape HTML file (what the page's buttons do) //! flyout main, downloads, shield, vpn, media, siteinfo, profiles, apps, qr, tabmenu, back, //! bookmark (edit the current page's bookmark), none //! type put text in the address bar with its suggestions open @@ -315,6 +316,26 @@ impl App { Err(error) => self.selftest_log(&format!("vault {what}: {error}")), } }, + "bookmarks" => { + let (what, arg) = rest.split_once(char::is_whitespace).map(|(w, a)| (w, a.trim())).unwrap_or((rest, "")); + let mut bookmarks = self.shared.bookmarks.borrow_mut(); + let note = match what { + "folder" => { + bookmarks.add_folder(crate::store::bookmarks::BAR, arg); + String::new() + }, + "export" => std::fs::write(arg, bookmarks.export_html()).map(|_| String::new()).unwrap_or_else(|e| format!("bookmarks export: {e}")), + "import" => match std::fs::read_to_string(arg) { + Ok(text) => format!("imported {} bookmarks", bookmarks.import_html(&text, "file")), + Err(error) => format!("bookmarks import: {error}"), + }, + _ => format!("unknown bookmarks command {what}"), + }; + drop(bookmarks); + if !note.is_empty() { + self.selftest_log(¬e); + } + }, "prompt" => { let remember = rest.contains("remember"); let answer = if rest.starts_with("allow") { crate::actions::PromptAnswer::Allow { remember } } else { crate::actions::PromptAnswer::Deny { remember } }; @@ -712,6 +733,10 @@ impl App { times.sort_by(f32::total_cmp); serde_json::json!({"count": times.len(), "median_ms": times.get(times.len() / 2), "max_ms": times.last(), "drawn": w.frames_drawn}) }); + let bookmark_folders = { + let b = self.shared.bookmarks.borrow(); + [crate::store::bookmarks::BAR, crate::store::bookmarks::OTHER].iter().filter_map(|id| b.get(*id)).map(|n| n.children.iter().filter(|c| c.is_folder()).count()).sum::() + }; serde_json::json!({ "windows": self.windows.len(), "tab_count": tabs.len(), @@ -733,6 +758,7 @@ impl App { "site_state": {"zoom_sites": settings.web.zoom_sites, "adblock_allow": settings.adblock.allow, "keep_active": settings.perf.keep_active, "muted_sites": settings.media.muted_sites, "https_exceptions": settings.privacy.https_exceptions}, "history": self.shared.history.borrow().len(), "bookmarks": self.shared.bookmarks.borrow().all().len(), + "bookmark_folders": bookmark_folders, "logins": self.shared.vault.borrow().contents.logins.len(), "vault_locked": self.shared.vault.borrow().locked(), "vault_mode": format!("{:?}", self.shared.vault.borrow().mode()), diff --git a/tests/smoke/pages/chrome-bookmarks.html b/tests/smoke/pages/chrome-bookmarks.html new file mode 100644 index 0000000..df2a36c --- /dev/null +++ b/tests/smoke/pages/chrome-bookmarks.html @@ -0,0 +1,15 @@ + + +Bookmarks +

Bookmarks

+

+

Bookmarks bar

+

+

On the bar +

+

Reading

+

+

Article A +
Article B & more +

+

diff --git a/tests/smoke/stores-lists-restart.txt b/tests/smoke/stores-lists-restart.txt new file mode 100644 index 0000000..a87c445 --- /dev/null +++ b/tests/smoke/stores-lists-restart.txt @@ -0,0 +1,12 @@ +# Stores pass (S008), part 2: history, bookmarks and the finished download are still there after a restart. +wait 3 +status back +expect /history > 1 +expect /bookmarks 4 +expect /bookmark_folders 2 +expect /downloads/0/state "Done" +page nacre://bookmarks +wait 1 +shot bookmarks-restored +status done +quit diff --git a/tests/smoke/stores-lists.txt b/tests/smoke/stores-lists.txt new file mode 100644 index 0000000..078fd60 --- /dev/null +++ b/tests/smoke/stores-lists.txt @@ -0,0 +1,49 @@ +# Stores pass (S008): history, bookmarks (add, folder, bar, Netscape HTML export/import), downloads page, and that all +# of it is still there after a restart. Offline. Part 1 (hidden): +# python3 -m http.server 8768 --bind 127.0.0.1 --directory tests/smoke/pages & +# python3 tests/smoke/net/server.py & +# tools/smoke.sh tests/smoke/stores-lists.txt +# Part 2: SMOKE_HOME=/home tools/smoke.sh tests/smoke/stores-lists-restart.txt +wait 3 +resize 1280 900 +open http://127.0.0.1:8768/hello.html +waitload +open http://127.0.0.1:8768/site.html +waitload +status visits +expect /history > 1 +page nacre://history +wait 1 +shot history +# Bookmark the page, make a folder, show the bar. +open http://127.0.0.1:8768/site.html +waitload +cmd bookmark +wait 1 +flyout none +bookmarks folder Work +set /ui/bookmarks_bar "always" +wait 1 +status marked +expect /bookmarks 1 +expect /bookmark_folders 1 +shot bar +# Export, then import a file in another browser's layout: 1 on the bar + 2 in a folder, then again adds nothing. +bookmarks export @HOME@/bookmarks-export.html +bookmarks import @PAGESDIR@/chrome-bookmarks.html +bookmarks import @PAGESDIR@/chrome-bookmarks.html +status imported +expect /bookmarks 4 +page nacre://bookmarks +wait 1 +shot bookmarks +# Downloads: one finished file listed on the page. +cmd download http://127.0.0.1:8766/file.zip +wait 4 +status download +expect /downloads/0/state "Done" +page nacre://downloads +wait 1 +shot downloads +status done +quit From f5659642b9d2d6c154413e6b90e9459b35987495 Mon Sep 17 00:00:00 2001 From: astar76 Date: Thu, 12 Nov 2026 11:37:34 -0600 Subject: [PATCH 05/10] S008: user scripts/styles and site-app smoke Co-Authored-By: Claude Sonnet 5.5 --- Plans/02 Verify/S008-verify-stores.md | 2 +- src/selftest.rs | 4 +++ tests/smoke/pages/probe.user.css | 5 ++++ tests/smoke/pages/probe.user.js | 8 ++++++ tests/smoke/stores-apps.txt | 41 +++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/smoke/pages/probe.user.css create mode 100644 tests/smoke/pages/probe.user.js create mode 100644 tests/smoke/stores-apps.txt diff --git a/Plans/02 Verify/S008-verify-stores.md b/Plans/02 Verify/S008-verify-stores.md index 6b6852d..f7bd284 100644 --- a/Plans/02 Verify/S008-verify-stores.md +++ b/Plans/02 Verify/S008-verify-stores.md @@ -15,7 +15,7 @@ Verify passwords/vault and autofill, permissions prompts, history/bookmarks/down - [x] Vault: create, lock/unlock, save a login from a local form page, autofill it, export/import; check the vault file is encrypted - [x] Permissions: a local page asking for notifications/geolocation/camera; allow/deny/remember; check `permissions` store - [x] History, bookmarks (add, folder, bookmarks bar, import/export HTML), downloads page lists entries -- [ ] User scripts/styles apply on matching pages; install a site as an app and launch it +- [x] User scripts/styles apply on matching pages; install a site as an app and launch it - [ ] Importer: build a fake old-Nacre profile from `~/Documents/Apps/Nacre` config format in a temp dir (never the user's real profile) and import it - [x] R1-20 per-site memory and enforcement: set per-site zoom, ad blocker on/off, privacy-mode flag (flag persistence only; internals are D-011) and other per-site choices; set per-site permissions (camera, mic, location, notifications, pop-ups, autoplay, …); quit, relaunch with `SMOKE_HOME=/home`, check values are in the stores and apply again on reopening the site; check each permission is enforced (blocked/allowed/asked per its stored value), not only stored; fix what is not - [ ] Change a sample of settings via `set` and via clicks; check `settings.json` and the effect; mark FEATURES rows diff --git a/src/selftest.rs b/src/selftest.rs index e42de02..93d63a8 100644 --- a/src/selftest.rs +++ b/src/selftest.rs @@ -24,6 +24,7 @@ //! cmd [arg] back, forward, reload, bookmark, install_app, pip, exitpip, free_memory, //! update_lists, check_updates, close_tab, select , zoom , //! find , download , pause_download|resume_download|cancel_download [id] (newest), +//! install_script (a .user.js / .user.css), open_app [id] (default: the first installed app), //! navigate , mute, pin //! js