From 00ccda7d451656359e1bb71100e04ab24ac4c155 Mon Sep 17 00:00:00 2001 From: "kitokey-sam[bot]" <356216031+kitokey-sam[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 13:26:55 +0100 Subject: [PATCH 1/4] shell: the e2e cut in shards played side by side, each in a session of its own (#862, step 3) After #865, the window's 47 scenarios take ~880 s of a ~19-minute run. headless.sh, for a full run, now hands it to e2e_sharded.sh: the tray's part, main()'s own scenarios (H to R), and the others in three lists balanced by their measured times (e2e_times.txt, longest first into the lightest), each a headless.sh session of its own, side by side. Their text is put back in a whole run's order, every shard's logs are judged together as a whole run's, the screenshots gathered; one verdict, 77 if a shard could not run. KITOKEY_E2E_SHARDS=1 runs it whole, as before. e2e.sh writes where KITOKEY_E2E_OUT says and plays its tray part alone (KITOKEY_E2E_PART=tray) or main()'s own alone (=main). Agent-Session: 92ded11e-58ef-492d-ba56-c820b9011de8 Co-Authored-By: Claude Opus 5.5 --- modules/shell/scripts/e2e.sh | 36 +++++++---- modules/shell/scripts/e2e_logs.py | 5 +- modules/shell/scripts/e2e_sharded.sh | 83 ++++++++++++++++++++++++++ modules/shell/scripts/e2e_shards.py | 89 ++++++++++++++++++++++++++++ modules/shell/scripts/e2e_times.txt | 50 ++++++++++++++++ modules/shell/scripts/e2e_window.py | 9 ++- modules/shell/scripts/headless.sh | 26 +++++--- 7 files changed, 273 insertions(+), 25 deletions(-) create mode 100755 modules/shell/scripts/e2e_sharded.sh create mode 100644 modules/shell/scripts/e2e_shards.py create mode 100644 modules/shell/scripts/e2e_times.txt diff --git a/modules/shell/scripts/e2e.sh b/modules/shell/scripts/e2e.sh index 70ef1c7d..db12c7fa 100755 --- a/modules/shell/scripts/e2e.sh +++ b/modules/shell/scripts/e2e.sh @@ -8,9 +8,13 @@ # the window, three times. set -euo pipefail cd "$(dirname "$0")/.." -mkdir -p .evidence -: > .evidence/e2e.txt -say() { echo "$*" | tee -a .evidence/e2e.txt; } +# Where its text goes: the module's `.evidence`, or a shard's own folder when the run is cut in +# shards side by side (scripts/e2e_sharded.sh, #862); `tray`, a shard that plays the tray's part alone. +out=${KITOKEY_E2E_OUT:-.evidence} +part=${KITOKEY_E2E_PART:-} +mkdir -p "$out" +: > "$out/e2e.txt" +say() { echo "$*" | tee -a "$out/e2e.txt"; } # Each of the tray's scenarios timed, said when the next one begins or the window's part does: where # a run's minutes go (#862). `SECONDS` is bash's own clock, whole seconds. scenario="" scenario_at=0 @@ -22,7 +26,7 @@ scenario() { scenario_done; scenario=$1; scenario_at=$SECONDS; say "$1. $2"; } if ! only=$(python3 -I scripts/e2e_only.py --asked scripts/e2e_window.py 2>&1); then say "$only"; exit 3; fi export KITOKEY_E2E_ONLY="$only" # The run's logs and screenshots, where NapkinStack reads them after it (nstack e2e shell). -evidence=${NSTACK_EVIDENCE:-$PWD/.evidence/e2e} +evidence=${NSTACK_EVIDENCE:-$PWD/$out/e2e} mkdir -p "$evidence" watcher="org.kde.StatusNotifierWatcher /StatusNotifierWatcher org.kde.StatusNotifierWatcher" @@ -35,7 +39,7 @@ fi if [ -z "${KITOKEY_HEADLESS:-}" ] && pgrep -x kitokey >/dev/null; then say "e2e: NOT RUN — a Kitokey is running outside the run: quit it first (its menu, Quitter Kitokey)"; exit 1 fi -cargo build --locked 2>&1 | tail -1 >> .evidence/e2e.txt +cargo build --locked 2>&1 | tail -1 >> "$out/e2e.txt" bin=${CARGO_TARGET_DIR:-$PWD/target}/debug/kitokey work=$(mktemp -d) app="" @@ -141,7 +145,8 @@ failed=0 check() { if "$@"; then say " ok $*"; else say " FAIL $*"; failed=1; fi; } is() { [ "$1" = "$2" ] || { say " got: $1"; return 1; }; } -if [ -z "$only" ]; then +# The tray's part: neither in a window shard (KITOKEY_E2E_ONLY) nor in main()'s own (#862). +if [ -z "$only" ] && [ "$part" != main ]; then # The program that hears, played: it notes what it was given, fails, is slow or stuck when told. cat > "$work/kitokey-transcription" <<'PLAYED' #!/bin/sh @@ -590,11 +595,13 @@ fi scenario_done # The window (cycle 03): Kitokey started with --window by tauri-driver, its page read over # WebDriver (scripts/e2e_window.py). For a few seconds a window appears, twice. -if ! command -v WebKitWebDriver >/dev/null; then +if [ "$part" = tray ]; then + say "the window's scenarios: in the other shards" +elif ! command -v WebKitWebDriver >/dev/null; then say "H. the window: NOT RUN — WebKitGTK's WebDriver is missing (Fedora: webkit2gtk4.1-devel)" failed=1 else - command -v tauri-driver >/dev/null || cargo install tauri-driver --locked --version 2.1.0 2>&1 | tail -1 >> .evidence/e2e.txt + command -v tauri-driver >/dev/null || cargo install tauri-driver --locked --version 2.1.0 2>&1 | tail -1 >> "$out/e2e.txt" mkdir -p "$work/window" # Its pages as they were drawn, kept for an eye against D11's boards — the author's first. # Kept where the user says, untouched; by default in the evidence, this run's alone. @@ -607,14 +614,14 @@ else quiet_module=$(pactl load-module module-null-sink sink_name=kitokey_e2e_quiet) export PULSE_SINK=kitokey_e2e_quiet # A window that stops answering fails the run, never holds it: it takes about 6 minutes. - if ! timeout --kill-after=30 1200 uv run --quiet --with selenium==4.51.0 --with jsonschema==4.23.0 --with rfc3339-validator==0.1.4 python -u scripts/e2e_window.py "$bin" "$work/window" | tee -a .evidence/e2e.txt; then + if ! timeout --kill-after=30 1200 uv run --quiet --with selenium==4.51.0 --with jsonschema==4.23.0 --with rfc3339-validator==0.1.4 python -u scripts/e2e_window.py "$bin" "$work/window" | tee -a "$out/e2e.txt"; then failed=1 fi fi # Its log (ADR-0007): each recording and making under an id, never a path of the run's folder. shell_log=$(cat "$work"/state/kitokey/logs/shell.*.jsonl 2>/dev/null || true) -if [ -z "$only" ]; then +if [ -z "$only" ] && [ "$part" != main ]; then check grep -q '"message":"shell.recording_started"' <<< "$shell_log" check grep -q '"message":"shell.minutes_written"' <<< "$shell_log" fi @@ -622,9 +629,14 @@ check test -z "$(grep -F "$work" <<< "$shell_log")" check test ! -s "$work/errors" # Every warning and error logged is one a scenario provokes, and each one named is logged: the # logs read, not thrown away with the run's folder (D29). -logs_read() { uv run --quiet --with pyyaml==6.0.3 python scripts/e2e_logs.py "$work" "$evidence" MANIFEST.yaml | tee -a .evidence/e2e.txt; return "${PIPESTATUS[0]}"; } +logs_read() { uv run --quiet --with pyyaml==6.0.3 python scripts/e2e_logs.py "$work" "$evidence" MANIFEST.yaml | tee -a "$out/e2e.txt"; return "${PIPESTATUS[0]}"; } check logs_read -[ -s "$work/errors" ] && sed 's/^/ /' "$work/errors" >> .evidence/e2e.txt +[ -s "$work/errors" ] && sed 's/^/ /' "$work/errors" >> "$out/e2e.txt" +if [ -n "$part" ]; then + # A shard, never the module's e2e: its status a partial run's, its last line says which. + [ "$failed" = 0 ] && say "e2e: shard ($part): its checks passed" || say "e2e: shard ($part): FAILED" + exit 3 +fi if [ -n "$only" ]; then # Never read as the module's e2e: its status is a failure either way, its last line says which. [ "$failed" = 0 ] && say "e2e: partial run ($only): its checks passed — not the module's e2e" || say "e2e: partial run ($only): FAILED" diff --git a/modules/shell/scripts/e2e_logs.py b/modules/shell/scripts/e2e_logs.py index 57e4e65f..cb9afc19 100644 --- a/modules/shell/scripts/e2e_logs.py +++ b/modules/shell/scripts/e2e_logs.py @@ -39,8 +39,9 @@ if not hit: unknown.setdefault(entry.get("message", line), line) unseen = [item for item in declared if item["pattern"] not in seen] -# A partial run (KITOKEY_E2E_ONLY) plays some scenarios: what the others provoke is not owed. -partial = bool(os.environ.get("KITOKEY_E2E_ONLY", "").strip()) +# A partial run (KITOKEY_E2E_ONLY), or a shard (KITOKEY_E2E_PART, #862), plays some scenarios: what +# the others provoke is not owed — a sharded run judges every shard's logs together, once. +partial = bool(os.environ.get("KITOKEY_E2E_ONLY", "").strip() or os.environ.get("KITOKEY_E2E_PART", "").strip()) print(f" {lines} log lines kept in {kept}; {len(unknown)} warning or error message(s) not provoked, " f"{len(unseen)} declared and never logged") for line in unknown.values(): diff --git a/modules/shell/scripts/e2e_sharded.sh b/modules/shell/scripts/e2e_sharded.sh new file mode 100755 index 00000000..777c79d8 --- /dev/null +++ b/modules/shell/scripts/e2e_sharded.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# The module's e2e cut in shards played side by side (#862), each in a GNOME session of its own +# made by scripts/headless.sh: the tray's part; main()'s own scenarios, H to R; and the scenarios +# main() calls, in KITOKEY_E2E_SHARDS lists balanced by their measured times (scripts/e2e_times.txt). +# Their text put back in one, in the order a whole run says it; every shard's logs judged together, +# once, as a whole run's are (D29); one verdict. Run by headless.sh for a full run. +set -uo pipefail +here=$(cd "$(dirname "$0")" && pwd) +cd "$here/.." +out=.evidence +evidence=${NSTACK_EVIDENCE:-$PWD/$out/e2e} +mkdir -p "$out" "$evidence" +: > "$out/e2e.txt" +say() { echo "$*" | tee -a "$out/e2e.txt"; } +began=$SECONDS + +# Built once, before the shards share it: each one's own build then finds it done. +cargo build --locked 2>&1 | tail -1 >> "$out/e2e.txt" +mapfile -t lists < <(python3 -I scripts/e2e_shards.py lists "${KITOKEY_E2E_SHARDS:-3}" scripts/e2e_window.py scripts/e2e_times.txt) +# Beside the sessions headless.sh makes, never under /tmp: the shards' screenshots and logs. +shards=$(mktemp -d "${XDG_CACHE_HOME:-$HOME/.cache}/kitokey-shards-XXXXXX") +trap 'rm -rf "$shards"' EXIT +say "e2e: in $((${#lists[@]} + 2)) shards side by side (#862): the tray's part, main()'s own scenarios, and the others in ${#lists[@]}" + +# Each shard's environment: its folder for its text and evidence, and what it plays. +play() { # number, then the shard's own variables + local number=$1 + shift + mkdir -p "$shards/$number" + env "$@" KITOKEY_E2E_SHARDS=1 KITOKEY_E2E_OUT="$shards/$number" NSTACK_EVIDENCE="$shards/$number/e2e" \ + bash scripts/headless.sh > "$shards/$number/output.txt" 2>&1 & + pids+=("$!") +} +pids=() +play 0 KITOKEY_E2E_PART=tray KITOKEY_E2E_ONLY= +play 1 KITOKEY_E2E_PART=main KITOKEY_E2E_ONLY= +for number in "${!lists[@]}"; do + play $((number + 2)) KITOKEY_E2E_PART= KITOKEY_E2E_ONLY="${lists[$number]}" +done +statuses=() +for pid in "${pids[@]}"; do + status=0 + wait "$pid" || status=$? + statuses+=("$status") +done + +# The shards' text, in a whole run's order. +texts=() +for number in "${!pids[@]}"; do texts+=("$shards/$number/e2e.txt"); done +python3 -I scripts/e2e_shards.py merge scripts/e2e_window.py "${texts[@]}" | tee -a "$out/e2e.txt" + +# Each shard's verdict: a shard ran whole when its last line says its checks passed. Not run on one +# — no GNOME, no WebDriver — is not run on all; any other end fails the run. +failed=0 +not_run=0 +for number in "${!pids[@]}"; do + last=$(tail -n 1 "$shards/$number/e2e.txt" 2>/dev/null || true) + case "${statuses[$number]}:$last" in + 3:*"its checks passed"*) say " ok shard $number: $last" ;; + 77:*) say " NOT RUN shard $number: $last"; not_run=1 ;; + *) say " FAIL shard $number (exit ${statuses[$number]}): $last"; failed=1 ;; + esac +done + +# Their evidence together: every shard's logs judged at once, a whole run's (nothing « not owed »), +# their screenshots in one folder, each session's own log beside the evidence. +mkdir -p "$evidence/shots" +for number in "${!pids[@]}"; do + cp -r "$shards/$number/e2e/shots/." "$evidence/shots/" 2>/dev/null || true + cp "$shards/$number/headless-shell.log" "$out/headless-shell-$number.log" 2>/dev/null || true +done +logs=0 +env -u KITOKEY_E2E_ONLY -u KITOKEY_E2E_PART uv run --quiet --with pyyaml==6.0.3 python scripts/e2e_logs.py "$shards" "$evidence" MANIFEST.yaml \ + > "$shards/logs.txt" 2>&1 || logs=$? +tee -a "$out/e2e.txt" < "$shards/logs.txt" +if [ "$logs" = 0 ]; then say " ok logs_read (every shard's logs)"; else say " FAIL logs_read (every shard's logs)"; failed=1; fi +say " (the run, its shards side by side: $((SECONDS - began)) s)" +if [ "$not_run" = 1 ] && [ "$failed" = 0 ]; then + say "e2e: NOT RUN — a shard could not run here" + exit 77 +fi +[ "$failed" = 0 ] && say "e2e: passed" || say "e2e: FAILED" +exit "$failed" diff --git a/modules/shell/scripts/e2e_shards.py b/modules/shell/scripts/e2e_shards.py new file mode 100644 index 00000000..1fedfb15 --- /dev/null +++ b/modules/shell/scripts/e2e_shards.py @@ -0,0 +1,89 @@ +"""The window's scenarios cut in shards, and the shards' text put back in one (#862). + + e2e_shards.py lists N e2e_window.py e2e_times.txt N lines, each a shard's names (KITOKEY_E2E_ONLY) + e2e_shards.py merge e2e_window.py SHARD... one text, the scenarios in main()'s order + +The lists are balanced by each scenario's measured time, the longest first into the lightest shard, +as Bazel's shard_count and pytest-xdist's load groups do; a scenario not measured counts as the median. +""" +import pathlib +import re +import statistics +import sys + +# Beside it, as e2e_window.py finds it, run with -I as the scripts are. +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +import e2e_only # noqa: E402 + +TIMED = re.compile(r"^ \(([a-z_]+): [0-9.]+ s\)$") + + +def lists(shards: int, source: str, times: str) -> list[list[str]]: + """The scenarios main() calls, in `shards` lists of about the same time, each in main()'s order.""" + called = e2e_only.scenarios(source) + measured = {} + for line in times.splitlines(): + if line.strip() and not line.startswith("#"): + name, seconds = line.split() + measured[name] = float(seconds) + median = statistics.median(measured.values()) if measured else 1.0 + load = [0.0] * shards + given: list[list[str]] = [[] for _ in range(shards)] + for name in sorted(called, key=lambda name: (-measured.get(name, median), called.index(name))): + lightest = load.index(min(load)) + given[lightest].append(name) + load[lightest] += measured.get(name, median) + return [[name for name in called if name in shard] for shard in given if shard] + + +def blocks(text: str) -> tuple[list[str], dict[str, list[str]]]: + """A shard's text: its lines outside any scenario, and each scenario's own, by its name — every + line after the window's « partial run: … » or the scenario before it, up to the line that says + its time (scripts/e2e_window.py's `timed`).""" + lines = text.splitlines() + starts = [number for number, line in enumerate(lines) if line.startswith("partial run: ")] + begin = starts[-1] + 1 if starts else 0 + outside = lines[:begin] + found: dict[str, list[str]] = {} + pending: list[str] = [] + for line in lines[begin:]: + pending.append(line) + timed = TIMED.match(line) + if timed: + found[timed.group(1)] = pending + pending = [] + # After the last scenario: the logs read, the shard's verdict; or a scenario cut short, unnamed. + outside.extend(pending) + return outside, found + + +def merge(source: str, shards: list[str]) -> str: + """The tray's shard as it ran, then main()'s own scenarios and every one it calls, in its order, + whichever shard played them, then what each window shard said outside its scenarios.""" + tray, *windows = shards + lines = tray.splitlines() + rest: list[tuple[int, list[str]]] = [] + every: dict[str, list[str]] = {} + for number, text in enumerate(windows, start=1): + outside, found = blocks(text) + every.update(found) + rest.append((number, outside)) + # main()'s own scenarios first, as main() plays them, then each it calls. + for name in ["main", *e2e_only.scenarios(source)]: + lines.extend(every.get(name, [f"{name}: NOT RUN — no shard said it"])) + for number, outside in rest: + lines.append(f"shard {number}:") + lines.extend(f" {line}" for line in outside) + return "\n".join(lines) + "\n" + + +if __name__ == "__main__": + if sys.argv[1] == "lists": + source = pathlib.Path(sys.argv[3]).read_text() + for shard in lists(int(sys.argv[2]), source, pathlib.Path(sys.argv[4]).read_text()): + print(",".join(shard)) + elif sys.argv[1] == "merge": + source = pathlib.Path(sys.argv[2]).read_text() + print(merge(source, [pathlib.Path(path).read_text() for path in sys.argv[3:]]), end="") + else: + raise SystemExit(__doc__) diff --git a/modules/shell/scripts/e2e_times.txt b/modules/shell/scripts/e2e_times.txt new file mode 100644 index 00000000..eda1c69e --- /dev/null +++ b/modules/shell/scripts/e2e_times.txt @@ -0,0 +1,50 @@ +# Each window scenario's time, in seconds, as a full run said it (scripts/e2e_window.py's « (name: N s) »): +# what scripts/e2e_shards.py balances the shards by. Measured at 9eae465 (#865), 2026-11-15; a scenario +# not listed counts as the median. +model_offered 22.7 +models_listed 11.3 +list_refreshed 1.5 +speech_offered 4.2 +service_named 11.9 +models_guided 4.9 +transcription_guided 3.7 +ollama_pulled 13.1 +first_run 29.5 +context_written 19.6 +confidential_kept 23.1 +meeting_language 6.0 +transcript_corrected 10.9 +corrections_gated 3.7 +press_on_the_page_left 35.8 +context_gaps 4.7 +two_panes 19.8 +sidebar_folded 3.5 +app_language 5.6 +confidential_every_way 1.8 +meeting_told_once 2.9 +minutes_copied 3.7 +nothing_silent 59.2 +gestures_answer 24.0 +window_looks 11.0 +pages_seen 9.3 +actions_rows 1.9 +announced 37.1 +heard_checked 25.1 +microphone_chosen 169.9 +microphone_latest_answer 2.2 +microphone_rollback 4.4 +sound_checked 32.5 +bar_window 6.0 +bar_opened 116.8 +recording_found 1.0 +recording_found_not_forgotten 6.8 +context_before_start 11.7 +own_models 2.3 +cancelled_at_once 23.3 +models_advanced 28.1 +meeting_named 2.3 +word_after_a_gap 1.3 +minutes_checked 27.4 +meeting_renamed 12.3 +trial_over 17.1 +trial_left 3.8 diff --git a/modules/shell/scripts/e2e_window.py b/modules/shell/scripts/e2e_window.py index 89bbcdb9..aee7aafe 100644 --- a/modules/shell/scripts/e2e_window.py +++ b/modules/shell/scripts/e2e_window.py @@ -7965,11 +7965,14 @@ def played(*args, **kwargs): def main() -> int: now = dt.datetime.now().astimezone() - # Each scenario main() plays, timed (#862). + began = time.monotonic() + # Each scenario main() plays, timed (#862). In the shard that plays main()'s own scenarios alone + # (KITOKEY_E2E_PART=main, scripts/e2e_sharded.sh), the others are the other shards'. import e2e_only + inline = os.environ.get("KITOKEY_E2E_PART", "") == "main" for name in e2e_only.scenarios(Path(__file__).read_text()): - globals()[name] = timed(globals()[name]) + globals()[name] = (lambda now: None) if inline else timed(globals()[name]) # A partial run (pytest's -k, scripts/e2e_only.py): the scenarios KITOKEY_E2E_ONLY names, alone, # said first — never read as a full run: e2e.sh says it again, and never passes it. if os.environ.get("KITOKEY_E2E_ONLY", "").strip(): @@ -9648,6 +9651,8 @@ def aside(folder): there and "supprimé pour faire de la place" not in browser.execute_script(no_player), browser.execute_script(no_player)) # None remembered before the run, as on a desktop where Kitokey never played: none of the user's to keep. check("the volume the system remembers for the user's Kitokey is left as it was", kept is None or same_volume(remembered(), kept), [remembered(), kept]) + # main()'s own scenarios, H to R, timed as one (#862). + print(f" (main: {time.monotonic() - began:.1f} s)") model_offered(now) models_listed(now) list_refreshed(now) diff --git a/modules/shell/scripts/headless.sh b/modules/shell/scripts/headless.sh index 77beef34..7cc855d1 100755 --- a/modules/shell/scripts/headless.sh +++ b/modules/shell/scripts/headless.sh @@ -11,6 +11,8 @@ # scripts/headless.sh (scripts/e2e.sh alone runs on the user's desktop, as before) set -euo pipefail here=$(cd "$(dirname "$0")" && pwd) +# Where its text goes: the module's `.evidence`, or a shard's own folder (scripts/e2e_sharded.sh). +out=${KITOKEY_E2E_OUT:-$here/../.evidence} if [ "${1:-}" != --inside ]; then missing="" @@ -19,14 +21,20 @@ if [ "${1:-}" != --inside ]; then done [ -d /usr/share/gnome-shell/extensions/appindicatorsupport@rgcjonas.gmail.com ] || missing="$missing AppIndicator-extension" if [ -n "$missing" ]; then - mkdir -p "$here/../.evidence" - echo "e2e: NOT RUN — no GNOME to run it in here, missing:$missing" | tee "$here/../.evidence/e2e.txt"; exit 77 + mkdir -p "$out" + echo "e2e: NOT RUN — no GNOME to run it in here, missing:$missing" | tee "$out/e2e.txt"; exit 77 fi # A partial run's names checked before the session is made (scripts/e2e_only.py): a typo refused # at once, named, as e2e.sh would refuse it minutes later. if ! asked=$(python3 -I "$here/e2e_only.py" --asked "$here/e2e_window.py" 2>&1); then - mkdir -p "$here/../.evidence" - echo "$asked" | tee "$here/../.evidence/e2e.txt"; exit 3 + mkdir -p "$out" + echo "$asked" | tee "$out/e2e.txt"; exit 3 + fi + # A full run is cut in shards side by side, each a session of its own like this one (#862): the + # tray's part, and the window's scenarios balanced by their measured times. KITOKEY_E2E_SHARDS=1 + # runs it whole, in this one session, as before. + if [ -z "${KITOKEY_E2E_PART:-}" ] && [ -z "$asked" ] && [ "${KITOKEY_E2E_SHARDS:-3}" -gt 1 ]; then + exec bash "$here/e2e_sharded.sh" fi root=${XDG_CACHE_HOME:-$HOME/.cache}/kitokey-headless/run-$$ mkdir -p "$root/run" "$root/user/.config" "$root/user/.local/share" "$root/user/.local/state" "$root/user/.cache" "$root/tmp" @@ -45,7 +53,7 @@ if [ "${1:-}" != --inside ]; then trap ended EXIT # Of the user's environment, their tools and caches and NapkinStack's, and the scenarios a partial # run plays (KITOKEY_E2E_ONLY, scripts/e2e_only.py); nothing of their desktop. - mapfile -t kept < <(env | grep -E '^(NSTACK_[A-Z_]*|CARGO_TARGET_DIR|KITOKEY_SCREENSHOTS|KITOKEY_E2E_ONLY)=' || true) + mapfile -t kept < <(env | grep -E '^(NSTACK_[A-Z_]*|CARGO_TARGET_DIR|KITOKEY_SCREENSHOTS|KITOKEY_E2E_ONLY|KITOKEY_E2E_PART|KITOKEY_E2E_OUT)=' || true) setsid env -i PATH="$PATH" USER="$USER" LOGNAME="$USER" LANG="${LANG:-C.UTF-8}" "${kept[@]}" \ CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}" RUSTUP_HOME="${RUSTUP_HOME:-$HOME/.rustup}" \ UV_CACHE_DIR="${UV_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/uv}" \ @@ -145,14 +153,14 @@ GLib.MainLoop().run() EOF for _ in $(seq 100); do [ -s "$logs/keyboard" ] && break; sleep 0.1; done if [ ! -s "$logs/keyboard" ]; then - mkdir -p "$here/../.evidence" - echo "e2e: FAILED — the session has no keyboard, so no window would have the focus:" | tee "$here/../.evidence/e2e.txt" - sed 's/^/ /' "$logs/keyboard.log" | tee -a "$here/../.evidence/e2e.txt"; exit 1 + mkdir -p "$out" + echo "e2e: FAILED — the session has no keyboard, so no window would have the focus:" | tee "$out/e2e.txt" + sed 's/^/ /' "$logs/keyboard.log" | tee -a "$out/e2e.txt"; exit 1 fi status=0 "$here/e2e.sh" "$@" || status=$? # The session's own log beside the run's evidence, never in it: what GNOME says of a session with # no logind nor accounts is no line of Kitokey's, and NapkinStack audits every log there. -cp "$logs/shell.log" "$here/../.evidence/headless-shell.log" 2>/dev/null || true +cp "$logs/shell.log" "$out/headless-shell.log" 2>/dev/null || true exit "$status" From 488230501c7ff98c21da4d9ac27152b6ae76c2bc Mon Sep 17 00:00:00 2001 From: "kitokey-sam[bot]" <356216031+kitokey-sam[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:11:27 +0100 Subject: [PATCH 2/4] shell: e2e ends and counts its own session's Kitokeys alone, never another shard's (#862) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 00ccda7's sharded run: the four window shards died together on WebDriver errors (« session deleted because of page crash or hang »). instances() read every process whose exe is the binary under test — the same for all shards — and Window.__exit__ sent each a TERM: a shard closing a window ended the others' Kitokeys (ines's reading). It now keeps those of this session alone, by their XDG_RUNTIME_DIR, as headless.sh's own ended() does; e2e.sh's count of running Kitokeys after a second start the same. Agent-Session: 92ded11e-58ef-492d-ba56-c820b9011de8 Co-Authored-By: Claude Opus 5.5 --- modules/shell/scripts/e2e.sh | 11 ++++++++++- modules/shell/scripts/e2e_window.py | 7 +++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/shell/scripts/e2e.sh b/modules/shell/scripts/e2e.sh index db12c7fa..68ff71cf 100755 --- a/modules/shell/scripts/e2e.sh +++ b/modules/shell/scripts/e2e.sh @@ -111,11 +111,20 @@ start() { # the language, the settings file's text, the recorder say " (started: its tray item found in $((SECONDS - started_at)) s, $tries look(s))" bus=${item%@*}; menu=${item#*@}/Menu } +# This session's Kitokeys alone: a run cut in shards plays the same binary side by side, each session +# its own XDG_RUNTIME_DIR (#862). +ours() { + local pid count=0 + for pid in $(pgrep -f "^$bin" || true); do + grep -qzx "XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-}" "/proc/$pid/environ" 2>/dev/null && count=$((count + 1)) + done + echo "$count" +} again() { # a second start, the first one's settings: it hands over to the running one and leaves LANGUAGE= LC_ALL=fr_FR.UTF-8 LANG=fr_FR.UTF-8 XDG_CONFIG_HOME="$work/config" XDG_DATA_HOME="$work/data" XDG_STATE_HOME="$work/state" \ KITOKEY_KEYRING=memory timeout 10 "$bin" "$@" 2>> "$work/errors" && left=0 || left=$? check is "$left" 0 - check is "$(pgrep -c -f "^$bin" || true)" 1 + check is "$(ours)" 1 } greyed() { busctl --user call "$bus" "$menu" com.canonical.dbusmenu GetLayout iias 0 -- -1 0 | grep -o '"enabled" b false' | wc -l; } labels() { # busctl writes what is not ASCII as escapes: printf reads them back diff --git a/modules/shell/scripts/e2e_window.py b/modules/shell/scripts/e2e_window.py index aee7aafe..6f3d473b 100644 --- a/modules/shell/scripts/e2e_window.py +++ b/modules/shell/scripts/e2e_window.py @@ -427,11 +427,14 @@ def session(folder: Path, started: dt.datetime, minutes: float | None, files: di def instances() -> list[int]: - """The processes of the Kitokey under test.""" + """The processes of the Kitokey under test, in this session alone: a run cut in shards plays the + same binary in sessions side by side, each its own XDG_RUNTIME_DIR, and never ends another's (#862).""" + session = f"XDG_RUNTIME_DIR={os.environ.get('XDG_RUNTIME_DIR', '')}".encode() found = [] for process in Path("/proc").iterdir(): try: - if process.name.isdigit() and os.readlink(process / "exe") == str(BINARY.resolve()): + if (process.name.isdigit() and os.readlink(process / "exe") == str(BINARY.resolve()) + and session in (process / "environ").read_bytes().split(b"\0")): found.append(int(process.name)) except OSError: pass From 4f93c927a3a6d99166b10a5b0806a94e04b7ff17 Mon Sep 17 00:00:00 2001 From: "kitokey-sam[bot]" <356216031+kitokey-sam[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:34:59 +0100 Subject: [PATCH 3/4] shell: e2e AD sets up the models its Settings are measured with, as K leaves them (#862) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4882305's sharded run: AD (two_panes) drew Settings with no model on this computer — K, which writes two, played in another shard — so the guided step stood in the models' place: « Settings, 420 px wide » failed on it, and « Avancé » could not be clicked, ending its shard's run there. AD now writes the same two files when they are not there; a whole run, where K wrote them, is unchanged. Agent-Session: 92ded11e-58ef-492d-ba56-c820b9011de8 Co-Authored-By: Claude Opus 5.5 --- modules/shell/scripts/e2e_window.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/shell/scripts/e2e_window.py b/modules/shell/scripts/e2e_window.py index 6f3d473b..2ee49d1c 100644 --- a/modules/shell/scripts/e2e_window.py +++ b/modules/shell/scripts/e2e_window.py @@ -5620,6 +5620,13 @@ def meeting_told_once(now: dt.datetime) -> None: def two_panes(now: dt.datetime) -> None: """AD. The window in two panes: the meetings in a sidebar, the one chosen beside them (D61).""" print("AD. the window in two panes: the sidebar, the meeting chosen beside it, as wide as the window (D61)") + # Its Settings with two models on this computer, as K leaves them in a whole run: played in a shard + # of its own, Settings would draw the guided step in their place (#862). + models = WORK / "data" / "kitokey" / "models" + models.mkdir(parents=True, exist_ok=True) + for name in ("ggml-large-v3-turbo-q8_0.bin", "ggml-small.bin"): + if not (models / name).exists(): + (models / name).write_bytes(b"x" * 1000) meetings = WORK / "panes" names = [f"2026-10-{day:02d}_10-00" for day in range(10, 24)] for index, name in enumerate(names): From 0155b8b9b02f5c968999d42ab18f2c7d832fb7b7 Mon Sep 17 00:00:00 2001 From: "kitokey-sam[bot]" <356216031+kitokey-sam[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:01:28 +0100 Subject: [PATCH 4/4] shell: e2e starts a window once no Kitokey holds its single-instance name on the session's bus (#853, #862) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4f93c92's sharded run: shard 4 died in first_run on « tauri-driver opened no session in a minute; Kitokey's processes: [] », its log ending on « shell.started » and nothing — #853's signature, five sessions side by side making it likelier. A start made while the Kitokey before is still leaving hands its arguments to it and leaves; /proc cannot say a process that is exiting is Kitokey, but its single-instance name on the bus is held to its last instant. Window.__enter__ now waits, up to 20 s, until neither is there; a session that still opens none says whether the name was held. Agent-Session: 92ded11e-58ef-492d-ba56-c820b9011de8 Co-Authored-By: Claude Opus 5.5 --- modules/shell/scripts/e2e_window.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/shell/scripts/e2e_window.py b/modules/shell/scripts/e2e_window.py index 2ee49d1c..4dff91bd 100644 --- a/modules/shell/scripts/e2e_window.py +++ b/modules/shell/scripts/e2e_window.py @@ -441,6 +441,16 @@ def instances() -> list[int]: return found +def single_instance_held() -> bool: + """Whether a Kitokey still holds its single-instance name on this session's bus + (`com.napkinstack.Kitokey.SingleInstance…`, tauri-plugin-single-instance): a start made meanwhile + hands its arguments over to it and leaves, logging « shell.started » and nothing else (#853). The + name is held to the last instant of a Kitokey that is leaving, when /proc can no longer say it is + one; and each session has its bus, so another shard's never counts.""" + listed = subprocess.run(["busctl", "--user", "--timeout=1", "list", "--no-legend"], capture_output=True, text=True).stdout + return any(line.split()[0].startswith("com.napkinstack.Kitokey.SingleInstance") for line in listed.splitlines() if line.strip()) + + def tray_entries() -> tuple[str, str, list[tuple[int, str]]]: """The tray's menu of the Kitokey under test, as the desktop reads it: its bus, its path, and each entry's number and words (D64).""" @@ -538,8 +548,8 @@ def __init__(self, sessions: Path, language: str, more: str = "", ollama: str = def __enter__(self) -> webdriver.Remote: # One Kitokey per session: one still leaving takes this start's arguments and this one # leaves, its session never opened (#510). Waited for. - until = time.monotonic() + 10 - while instances() and time.monotonic() < until: + until = time.monotonic() + 20 + while (instances() or single_instance_held()) and time.monotonic() < until: time.sleep(0.1) port, native = free_port(), free_port() self.driver_process = subprocess.Popen( @@ -563,7 +573,8 @@ def __enter__(self) -> webdriver.Remote: except ReadTimeoutError: self.driver_process.terminate() self.driver_process.wait(timeout=10) - raise RuntimeError(f"tauri-driver opened no session in a minute; Kitokey's processes: {instances()}") from None + raise RuntimeError(f"tauri-driver opened no session in a minute; Kitokey's processes: {instances()}," + f" its single-instance name held: {single_instance_held()}") from None except (WebDriverException, HTTPError): time.sleep(0.2) else: