S045 (WIP): hidden harness, repaint/zoom/placement fixes; box 10 YouTube click open

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-13 03:42:37 -06:00
commit 959a950ae4
12 changed files with 238 additions and 30 deletions

View file

@ -79,6 +79,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
| `tools/smoke.sh tests/smoke/privacy-mode.txt` (+ `SMOKE_ARGS=--incognito … privacy-incognito.txt`) | privacy mode: `pages/fingerprint.html` read off/on, `fp-off.json`/`fp-on.json` + shots (offline); `privacy-net.txt` (needs `tests/smoke/net/server.py`) frame cookies, per-site pause, Accept-Language; `SMOKE_TIMEOUT=700 … coveryourtracks.txt` EFF's test off/on (internet, direct). Selftest `save <name> <js>` writes a JS string result to `<name>.json`; `SMOKE_ARGS` passes browser arguments | now (S024) |
| `python tools/icons.py` | rebuilds the icon font subset and `src/ui/icons.rs` from `tools/icons.txt` (needs fontTools and Arch's ttf-material-symbols-variable) | now (S015) |
| `tools/engine-test/run.sh servo\|chromium\|webkit` + `analyze.py` | engine comparison: one browser visible on DP-1, throwaway profile, sites from `sites.txt`, per-second RAM (PSS), CPU, GPU of the whole process tree into `docs/engine/runs/<engine>/samples.csv`; `webkit_shell.py` is the WebKitGTK 6.0 shell (needs `webkitgtk-6.0`); report `docs/engine/engine-comparison.md`. Never run two at once or alongside cargo | now |
| `tools/hidden.sh <script> [outdir] [-- driver.sh]` | WebKit build hidden: Xvfb → nested niri (`spikes/webkit-egui/run/nested.sh`), throwaway home, software GL, `NACRE_SCRIPT`; the driver gets `click`/`scroll` (wl-input), `grab` (grim), `key`/`type` (wtype). Scripts in `tests/hidden/` (`basic.txt` offline; `web.txt` + `web-driver.sh` needs internet). Read the PNGs | now (S045) |
| appimagetool, wine + Inno Setup, VM "Windows 10" | packaging and Windows checks | see the user's global CLAUDE.md "Building" |
Don't assume a tool exists: check first. When your plan creates a tool, add its row here.

View file

@ -38,3 +38,11 @@ egui's page rect }, EguiArea }`, today's egui Material You chrome drawn unchange
## Handoff (→ PROGRESS.md)
Where each `Event` comes from; what is stubbed; how to run Nacre hidden until S046 lands.
## WIP state / resume at (2026-11-13)
Boxes 1–9 done (commit 6c748ba + fixes). Box 10: run `HIDDEN_TIMEOUT=400 tools/hidden.sh tests/hidden/web.txt "" -- tests/hidden/web-driver.sh`
(outdir default target/hidden/web-<time>): Wikipedia, new tab, tabs pass; YouTube renders but the real click on the player
(410,450 → page 402,354) dispatches to `<html>` and the video stays paused (`clicks.json`). Resume there: check
`document.elementFromPoint(402,354)` and the player's layout/hit test (privacy/cosmetic scripts off as a variant), then
finish box 10 and box 11 (INDEX line, tracker done).

View file

@ -45,3 +45,4 @@
- D-039 — 2026-11-13 — Media on WebKit: Nacre's page-script media probe (`inject.rs` `media.*`, mediaSession hook) stays the one source for the new tab card, Discord and MPRIS; WebKit's `is-playing-audio` and `set_is_muted` replace the mute script. If WebKitGTK publishes its own MPRIS player it is not left as a second player (turned off or Nacre's skipped, whichever the plan finds possible; one player only). — one engine-neutral source already feeds three features — S051, S013
- D-040 — 2026-11-13 — WebKit tuning defaults (D-032 data, `docs/engine/tune/`): page cache off, memory pressure limit 500 MB per web process, cache model `DocumentViewer`, hardware acceleration policy default (on demand; `never` broke JS checks), related views only for pop-ups. Env overrides for tests (`NACRE_WK_PAGE_CACHE`, `NACRE_WK_MEM_LIMIT`, `NACRE_WK_CACHE_MODEL`, `NACRE_WK_HW`). — lowest PSS/VRAM in the tune runs without failed sites — S052
- D-041 — 2026-11-13 — S044 boxes 3–5 (Nacre `ViewId`, engine-neutral `Event` payload types, selftest on them) move to S045 and are defined directly on WebKit; S044 closes with the privacy/policy move. — converting 56 Servo payload uses and 14 `WebViewId` sites now would only add Servo adapters that S045/S048 delete — orchestrator, 2026-11-13 — S044, S045
- D-042 — 2026-11-13 — S045 GTK host: the WebKit build ports page controls instead of stubbing them (script dialogs, `<select>`, colour, file, HTTP auth, permissions, context menu from WebKit's hit test, notifications); Bluetooth chooser and protocol-handler prompts are removed (WebKit has neither); picture in picture shows "isn't available yet" until S047; one `UserContentManager` per view so page messages carry their `ViewId` (bridge posts to `window.webkit.messageHandlers.nacre`); cookies stay in WebKit's memory until S051 (`Keeping::RunOnly`); downloads come from the response policy (non-displayable main-frame MIME) plus `looks_like_download`, the Servo download probe is gone; WebKit data/cache under `<profile data>/webkit` and `<cache>/webkit`; views sit in a `Gtk.Overlay` placed by margins (a `Gtk.Fixed` size request grew the window); prefers-color-scheme follows GTK's dark preference set by Nacre (its own changes ignored by the system-scheme watcher); with no desktop font DPI (`gtk-xft-dpi` -1) Nacre sets 96 dpi, else WebKit gives every view after the first a NaN zoom (blank page).

View file

@ -356,6 +356,15 @@ Later: S010 list: user checks the Discord icon with their own client (the Discor
- Verified: release build green, `cargo test` 74 green (was 70), smokes launch, basics, input, net-adblock, net-privacy exit 0 (hidden, Servo).
- Not done here: boxes 3–5 (ViewId, neutral payload types, selftest) moved to S045 (D-041).
## S045 — GTK 4 host, WebKitGTK views, Servo out (2026-11-13, WIP: box 10 open)
- Done: `src/engine/` (ViewId, neutral Event payloads, NetworkSession/WebContext/Settings per profile, one WebView per tab, signals → Event), `src/egui_area.rs` (spike + clipboard, cursor, HiDPI, focus), GTK `App` (Rc<RefCell>, idle pump, 100 ms tick), GTK capture-phase shortcuts, stop/reload/zoom/back-forward, real load progress; Servo, winit, gilrs, gst rpath out (`cargo tree -i servo` fails).
- Verified: release build + `cargo test` 73 green; hidden runs (`tools/hidden.sh`, new): `tests/hidden/basic.txt` (new tab, chrome dark/light, tabs open/switch/close, offline) and `web.txt` (Wikipedia renders under the chrome, YouTube renders) — shots read.
- Shots vs Servo `target/smoke/chrome5`: chrome identical (tabs, toolbar, bookmarks bar, card corners, fonts); differences: the address field keeps focus (ring) after opening a tab; page text 1 px higher; no media button (old run's state); output 1280x800 vs 820.
- Fixed on the way: repaints asked for during an egui render were lost (UI froze); a `Gtk.Fixed` size request grew the window; views after the first got a NaN zoom without a desktop font DPI (blank pages); shots need a persistent WidgetPaintable.
- Not done (box 10): YouTube does not start after a real wl-input click on the player: the click reaches the page at the right point (402,354) but its target is `<html>` (hit test finds no element) — next step: elementFromPoint there, compare with the Servo-free spike (which played).
- Stubbed for S047/S048: picture in picture (toast), page `rclick`/`pagescroll`/`pagetype` in selftest go through page JS, request policy `net::policy::decide` and ad-block request blocking not wired (cosmetic/page scripts only), cookie persistence (S051), `Shortcut` per-app window class, console messages from pages.
- Later: system dark detection may be polluted by Nacre's own prefer-dark setting; Wikipedia stays light with Nacre dark (check prefers-color-scheme).
## Later
- Turnstile widget paints as a black half-disc (Servo painting of its iframe/shadow DOM, S006 site doctor).
- Google sign-in past the email step: press Next with a real account, by the user (S006).

View file

@ -47,6 +47,11 @@ pub fn next_id() -> u64 {
NEXT_ID.fetch_add(1, Ordering::Relaxed)
}
thread_local! {
/// Nacre is changing GTK's dark preference itself (not a system change).
static SETTING_SCHEME: Cell<bool> = const { Cell::new(false) };
}
thread_local! {
static APP: RefCell<Weak<RefCell<App>>> = RefCell::new(Weak::new());
static PUMP_QUEUED: Cell<bool> = const { Cell::new(false) };
@ -79,7 +84,7 @@ pub fn pump() {
// Screenshots render the window (the egui area too, which draws through the app), so outside the borrow.
for (window, path) in shots {
if let Err(error) = crate::window::save_shot(&window, &path) {
log::error!("screenshot {}: {error}", path.display());
eprintln!("screenshot {}: {error}", path.display());
}
}
}
@ -450,9 +455,7 @@ impl App {
let engine = self.engine.clone().expect("engine runs");
let webview = engine.create_view(ViewId(tab_id), None);
let zoom = self.shared.settings.borrow().zoom_for(&util::host_of(&url));
if (zoom - 1.0).abs() > 0.001 {
webview.set_page_zoom(zoom);
}
webview.set_page_zoom(zoom);
webview.load(&url);
Web { webview }
}
@ -470,9 +473,15 @@ impl App {
/// WebKitGTK takes prefers-color-scheme from GTK's dark preference (one value for every page).
fn apply_web_scheme(&self) {
let dark = self.web_dark();
// Pages follow GTK's dark preference (prefers-color-scheme). Setting it changes GTK's colour scheme too, so
// the system-scheme watcher (first_setup) ignores what Nacre sets itself.
if let Some(settings) = gtk::Settings::default() {
#[allow(deprecated)]
settings.set_gtk_application_prefer_dark_theme(dark);
if settings.is_gtk_application_prefer_dark_theme() != dark {
SETTING_SCHEME.set(true);
settings.set_gtk_application_prefer_dark_theme(dark);
SETTING_SCHEME.set(false);
}
}
if let Some(engine) = &self.engine {
engine.set_dark_background(dark);
@ -508,7 +517,24 @@ impl App {
}
fn take_shots(&mut self) -> Vec<(gtk::ApplicationWindow, PathBuf)> {
self.windows.values_mut().filter_map(|w| w.shot_request.take().map(|p| (w.window.clone(), p))).collect()
// Shoot only after two frames drawn since the request, so the shot shows what the commands before it did.
let mut shots = Vec::new();
for w in self.windows.values_mut() {
if w.shot_request.is_none() {
continue;
}
match w.shot_frame {
None => w.shot_frame = Some(w.frames_drawn + 2),
Some(frame) if w.frames_drawn >= frame => {
w.shot_frame = None;
shots.extend(w.shot_request.take().map(|p| (w.window.clone(), p)));
continue;
},
Some(_) => {},
}
w.redraw();
}
shots
}
// ── finding things ────────────────────────────────────────────────
@ -1409,6 +1435,13 @@ impl App {
/// The first windows: restored session, an app window, or a new tab.
pub fn open_initial(&mut self) {
*self.shared.system_dark.borrow_mut() = theme::system_dark(gtk_dark());
// Without a font DPI from the desktop (gtk-xft-dpi -1, as in a bare session), WebKit gave every view after
// the first a NaN zoom level: blank pages, innerWidth 0. 96 dpi is GTK's own default.
if let Some(settings) = gtk::Settings::default()
&& settings.gtk_xft_dpi() <= 0
{
settings.set_gtk_xft_dpi(96 * 1024);
}
rustls_provider();
match crate::instance::Server::start(&self.shared.paths, self.jobs_tx.clone()) {
Ok(server) => self.instance = Some(server),
@ -1484,6 +1517,9 @@ impl App {
if let Some(gtk_settings) = gtk::Settings::default() {
let me = self.me.clone();
gtk_settings.connect_gtk_interface_color_scheme_notify(move |_| {
if SETTING_SCHEME.get() {
return;
}
if let Some(app) = me.upgrade() {
with_app(&app, |app| {
*app.shared.system_dark.borrow_mut() = theme::system_dark(gtk_dark());

View file

@ -35,7 +35,9 @@ mod imp {
/// CPU time of each recent render (egui layout + paint), ms.
pub render_ms: RefCell<std::collections::VecDeque<f32>>,
pub renders: Cell<u64>,
pub repaint_pending: Cell<bool>,
/// Inside `render`: a repaint asked for now is lost by GTK, so it is redone right after.
pub rendering: Cell<bool>,
pub repaint_again: Cell<bool>,
pub preedit: Cell<bool>,
pub im: RefCell<Option<gtk::IMMulticontext>>,
/// The last button press (device, button, x, y, time), for a window move from Nacre's title bar.
@ -90,8 +92,24 @@ mod imp {
impl GLAreaImpl for EguiArea {
fn render(&self, _context: &gdk::GLContext) -> glib::Propagation {
self.rendering.set(true);
let result = self.render_frame();
self.rendering.set(false);
if self.repaint_again.replace(false) {
let weak = self.obj().downgrade();
glib::idle_add_local_once(move || {
if let Some(a) = weak.upgrade() {
a.repaint();
}
});
}
result
}
}
impl EguiArea {
fn render_frame(&self) -> glib::Propagation {
let t0 = Instant::now();
self.repaint_pending.set(false);
let obj = self.obj();
let scale = obj.scale_factor() as f32;
let zoom = self.ctx.zoom_factor();
@ -177,9 +195,7 @@ mod imp {
self.renders.set(self.renders.get() + 1);
glib::Propagation::Stop
}
}
impl EguiArea {
fn app_busy(&self) -> bool {
self.busy.borrow().as_ref().is_some_and(|f| f())
}
@ -302,7 +318,9 @@ impl EguiArea {
}
pub fn repaint(&self) {
if !self.imp().repaint_pending.replace(true) {
if self.imp().rendering.get() {
self.imp().repaint_again.set(true);
} else {
self.queue_render();
}
}

View file

@ -180,8 +180,8 @@ impl Engine {
pub fn create_view(self: &Rc<Self>, id: ViewId, related: Option<&View>) -> View {
let ucm = webkit::UserContentManager::new();
let mut builder = webkit::WebView::builder().settings(&self.settings).user_content_manager(&ucm);
builder = match related {
Some(r) => builder.related_view(&r.web),
builder = match related.map(|r| &r.web) {
Some(r) => builder.related_view(r),
None => builder.network_session(&self.session).web_context(&self.context),
};
let web = builder.build();

View file

@ -1,5 +1,6 @@
//! A browser window: a `gtk::ApplicationWindow` holding `Gtk.Overlay { Gtk.Fixed { Gtk.Stack of the tabs' web views
//! at egui's page rect }, EguiArea }` (D-033, D-035), and its tabs. egui draws all of Nacre's chrome in the overlay;
//! A browser window: a `gtk::ApplicationWindow` holding `Gtk.Overlay { Gtk.Stack of the tabs' web views placed at
//! egui's page rect by its margins, EguiArea }` (D-033, D-035), and its tabs. (Margins, not a `Gtk.Fixed` with a
//! size request: a size request taller than the window during a layout change grew the window's minimum size.) egui draws all of Nacre's chrome in the overlay;
//! WebKit draws the page and gets the page's input directly from GTK.
use std::time::Instant;
@ -29,9 +30,9 @@ pub struct BrowserWindow {
pub window: gtk::ApplicationWindow,
/// The egui overlay: every piece of Nacre's interface.
pub area: EguiArea,
fixed: gtk::Fixed,
/// The tabs' web views; the active one is the visible child.
stack: gtk::Stack,
/// Every tab's view, all allocated at the page rect; only the active one is child-visible (mapped).
stack: gtk::Overlay,
/// Where the stack sits now (logical pixels), so it moves only when the page rect changes.
placed: Option<egui::Rect>,
pub kind: Kind,
@ -50,6 +51,8 @@ pub struct BrowserWindow {
pub focused: bool,
/// Save the window to this file after the next frame (self-test screenshots).
pub shot_request: Option<std::path::PathBuf>,
/// The frame count the shot waits for.
pub shot_frame: Option<u64>,
/// How long the last frames took to draw, in ms (self-test status).
pub frame_times: std::collections::VecDeque<f32>,
/// Frames drawn since the window opened (self-test status).
@ -61,21 +64,22 @@ impl BrowserWindow {
let window = gtk::ApplicationWindow::builder().application(app).title(title).default_width(size.0.max(320) as i32).default_height(size.1.max(240) as i32).build();
window.set_decorated(decorated);
window.set_size_request(320, 240);
let stack = gtk::Stack::new();
let stack = gtk::Overlay::new();
stack.set_visible(false);
let fixed = gtk::Fixed::new();
fixed.put(&stack, 0.0, 0.0);
stack.set_hexpand(true);
stack.set_vexpand(true);
let overlay = gtk::Overlay::new();
overlay.set_child(Some(&fixed));
overlay.set_child(Some(&stack));
let area = EguiArea::new(id.0, ui, busy);
area.ctx().set_fonts(crate::ui::fonts());
overlay.add_overlay(&area);
window.set_child(Some(&overlay));
// For screenshots (save_shot): a paintable that tracks what the window's content draws.
unsafe { window.set_data("nacre-shot", gtk::WidgetPaintable::new(Some(&overlay))) };
BrowserWindow {
id,
window,
area,
fixed,
stack,
placed: None,
kind,
@ -90,6 +94,7 @@ impl BrowserWindow {
pip_size: [0, 0],
focused: true,
shot_request: None,
shot_frame: None,
frame_times: Default::default(),
frames_drawn: 0,
}
@ -130,7 +135,8 @@ impl BrowserWindow {
if let Some(web) = &tab.web {
let widget = web.webview.widget();
if widget.parent().is_none() {
self.stack.add_child(&widget);
widget.set_child_visible(false);
self.stack.add_overlay(&widget);
}
}
}
@ -140,13 +146,20 @@ impl BrowserWindow {
match (shown.and_then(|t| { t.frozen = false; t.last_shown = Instant::now(); t.web.as_ref() }), rect) {
(Some(web), Some(rect)) => {
let widget = web.webview.widget();
if self.stack.visible_child().as_ref() != Some(&widget) {
self.stack.set_visible_child(&widget);
if !widget.is_child_visible() {
let mut child = self.stack.first_child();
while let Some(c) = child {
c.set_child_visible(c == widget);
child = c.next_sibling();
}
}
if self.placed != Some(rect) {
self.placed = Some(rect);
self.fixed.move_(&self.stack, rect.min.x.round() as f64, rect.min.y.round() as f64);
self.stack.set_size_request(rect.width().round() as i32, rect.height().round() as i32);
let (w, h) = self.window.child().map(|c| (c.width() as f32, c.height() as f32)).unwrap_or((rect.max.x, rect.max.y));
self.stack.set_margin_start(rect.min.x.round().max(0.0) as i32);
self.stack.set_margin_top(rect.min.y.round().max(0.0) as i32);
self.stack.set_margin_end((w - rect.max.x).round().max(0.0) as i32);
self.stack.set_margin_bottom((h - rect.max.y).round().max(0.0) as i32);
}
self.stack.set_visible(true);
if self.page_focused && !web.webview.focused() && !self.area.has_focus() {
@ -161,7 +174,7 @@ impl BrowserWindow {
pub fn detach(&self, view: &View) {
let widget = view.widget();
if widget.parent().as_ref() == Some(self.stack.upcast_ref()) {
self.stack.remove(&widget);
self.stack.remove_overlay(&widget);
}
}
@ -208,8 +221,9 @@ impl BrowserWindow {
/// Save what the window shows (interface and page) as a PNG.
pub fn save_shot(window: &gtk::ApplicationWindow, path: &std::path::Path) -> Result<(), String> {
let (w, h) = (window.width(), window.height());
let paintable = gtk::WidgetPaintable::new(Some(window));
// A paintable made just now has no frame of the widget yet; the window keeps one that follows its content.
let paintable: gtk::WidgetPaintable = unsafe { window.data::<gtk::WidgetPaintable>("nacre-shot").map(|p| p.as_ref().clone()) }.ok_or("no paintable")?;
let (w, h) = (window.child().map(|c| c.width()).unwrap_or(0), window.child().map(|c| c.height()).unwrap_or(0));
let snapshot = gtk::Snapshot::new();
paintable.snapshot(&snapshot, w as f64, h as f64);
let node = snapshot.to_node().ok_or("nothing drawn")?;

30
tests/hidden/basic.txt Normal file
View file

@ -0,0 +1,30 @@
# S045 hidden check: chrome dark/light like tests/smoke/chrome.txt, tabs open/switch/close. Offline.
wait 3
shot start
set /theme/mode "dark"
page nacre://newtab
wait 1
shot newtab-dark
newtab @PAGES@/hello.html
waitload 30
newtab @PAGES@/color.html
waitload 30
cmd pin
cmd select 3
set /ui/bookmarks_bar "always"
wait 1
shot chrome-dark
status tabs3
cmd select 0
wait 1
shot select0
assert document.title.length > 0
cmd select 2
cmd close_tab
cmd select 2
wait 1
status tabs2
set /theme/mode "light"
wait 1
shot chrome-light
quit

View file

@ -0,0 +1,7 @@
# Driver for tests/hidden/web.txt (sourced by tools/hidden.sh): click the YouTube player when asked.
for i in $(seq 240); do grep -q "click-video" "$OUT/selftest.log" 2>/dev/null && break; sleep 0.5; done
grab before-click
# the middle of the player (1280x800 nested output, page card from y=96)
click 410 450
sleep 3
grab after-click

33
tests/hidden/web.txt Normal file
View file

@ -0,0 +1,33 @@
# S045 hidden check (needs internet): Wikipedia under the chrome, YouTube plays after a real click (driver
# tests/hidden/web-driver.sh clicks with wl-input when the log says "click-video"), tabs open/switch/close.
wait 3
set /theme/mode "dark"
open https://en.wikipedia.org/wiki/Web_browser
waitload 60
wait 3
shot wiki-dark
assert document.querySelector('#firstHeading').textContent.includes('Web browser')
set /theme/mode "light"
wait 2
shot wiki-light
newtab https://www.youtube.com/watch?v=jNQXAC9IVRw
waitload 60
wait 8
shot yt-loaded
save yt-before JSON.stringify((()=>{const v=document.querySelector('video');return v&&{t:v.currentTime,p:v.paused,rs:v.readyState}})())
js window.__ev = []; for (const t of ['pointerdown', 'pointerup', 'click']) addEventListener(t, e => window.__ev.push(t + ':' + e.clientX + ',' + e.clientY + ':' + (e.target.className || e.target.tagName).toString().slice(0, 30)), true); true
log click-video
wait 4
waitfor 60 (()=>{const v=document.querySelector('video');return !!v && v.currentTime > 2})()
save yt-after JSON.stringify((()=>{const v=document.querySelector('video');return v&&{t:v.currentTime,p:v.paused,rs:v.readyState}})())
save clicks JSON.stringify([window.__ev, (()=>{const v=document.querySelector('video');return v&&[v.error&&v.error.code,v.networkState,v.src.slice(0,30)]})()])
shot yt-playing
status tabs
assert location.href.includes('jNQXAC9IVRw')
cmd select 0
wait 1
assert location.host.endsWith('wikipedia.org')
cmd close_tab
wait 1
status closed
quit

51
tools/hidden.sh Executable file
View file

@ -0,0 +1,51 @@
#!/bin/bash
# Hidden run of the WebKit Nacre (S045): Xvfb -> nested niri (spikes/webkit-egui/run/nested.sh) -> target/release/nacre
# with a throwaway home, software GL, and a NACRE_SCRIPT selftest script (see src/selftest.rs).
#
# tools/hidden.sh <script> [outdir] [-- driver.sh]
#
# outdir (default target/hidden/<name>-<time>) gets nacre.log, selftest.log, the script's shots and status files, and
# home/. @PAGES@ / @PAGESDIR@ in the script are replaced as in tools/smoke.sh. An optional driver script runs next to
# Nacre with the nested session's environment and these helpers, for real input and compositor screenshots:
# click X Y [right] wl-input pointer click (logical px of the nested output) scroll X Y N
# grab NAME grim screenshot of the nested output to $OUT/NAME.png key ... / type TEXT (wtype)
# Never connects to Tor or proxies. Exits non-zero if Nacre panicked, crashed or the script didn't finish.
set -u
root=$(cd "$(dirname "$0")/.." && pwd)
script=$1; shift
name=$(basename "$script" .txt)
out=${1:-$root/target/hidden/$name-$(date +%Y%m%d-%H%M%S)}; [ $# -gt 0 ] && shift
driver=""; [ "${1:-}" = "--" ] && driver=$2
mkdir -p "$out"; out=$(cd "$out" && pwd)
export SPIKE_RUN=$out/session
mkdir -p "$SPIKE_RUN"
sed -e "s|@PAGES@|file://$root/tests/smoke/pages|g" -e "s|@PAGESDIR@|$root/tests/smoke/pages|g" "$script" >"$out/script.txt"
"$root/spikes/webkit-egui/run/nested.sh" start >"$out/nested.log" 2>&1
trap '"$root/spikes/webkit-egui/run/nested.sh" stop' EXIT
source "$SPIKE_RUN/env"
ln -sfn "$HOME" "$out/home"
export LIBGL_ALWAYS_SOFTWARE=1 WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 GSK_RENDERER=gl GTK_A11Y=none NO_AT_BRIDGE=1 GDK_DEBUG=no-portals
export RUST_BACKTRACE=1 NACRE_SCRIPT=$out/script.txt
dbus-run-session -- "$root/target/release/nacre" >"$out/nacre.log" 2>&1 &
pid=$!
if [ -n "$driver" ]; then
(
export OUT=$out WL_INPUT_FLIP_Y=1
W=$root/spikes/webkit-egui/target/release/wl-input
click() { "$W" winit click "$@"; }
scroll() { "$W" winit scroll "$@"; }
grab() { grim "$OUT/$1.png"; }
key() { wtype "$@"; }
type() { wtype "$1"; }
source "$driver"
) >"$out/driver.log" 2>&1 &
fi
timeout "${HIDDEN_TIMEOUT:-300}" tail --pid=$pid -f /dev/null
status=0
if kill -0 $pid 2>/dev/null; then echo "timeout"; kill $pid; status=1; fi
wait $pid 2>/dev/null; code=$?
grep -q "panicked" "$out/nacre.log" && { echo "panic"; status=1; }
[ $code -ne 0 ] && [ $status -eq 0 ] && { echo "exit code $code"; status=1; }
grep -q "ASSERT FAILED" "$out/selftest.log" 2>/dev/null && { echo "assert failed"; status=1; }
echo "out: $out"
exit $status