From bff60dbd1ba60fe9c2e416534132657d23ac9ec8 Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:41:25 +0100 Subject: [PATCH 1/8] capture: the e2e runs on a PipeWire of its own, no hardware in it On the desktop's graph, AirPods connected during the attest of #787 became the default input and scenarios J, K, L and O recorded from them. The e2e now starts its own PipeWire, WirePlumber (no ALSA, no Bluetooth monitor) and pipewire-pulse, as private_graph.sh does, and never speaks to the desktop's. A guard reads the graph every half second: a device, or a source or sink not the run's own, or a sound card held by the run's capture, kills capture and the graph at once; the run ends NOT RUN, exit 77. The desktop's defaults are read before and after: the same. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/capture/README.md | 10 +-- modules/capture/scripts/e2e.sh | 128 +++++++++++++++++++++++++-------- 2 files changed, 103 insertions(+), 35 deletions(-) diff --git a/modules/capture/README.md b/modules/capture/README.md index 5a98fe50..184f24da 100644 --- a/modules/capture/README.md +++ b/modules/capture/README.md @@ -50,14 +50,16 @@ Bluetooth headset may switch to its call profile while it listens, and the syste (ADR-0015's amendment of 2026-11-07); `me`'s first `device` says `headset: true` then, `false` for any other microphone — absent where the graph does not read (D88). It is never part of a recording. -**`nstack e2e capture`** runs the scenarios without a call and without a voice: for about -three minutes the system's default output and input are two silent devices of its own, a note +**`nstack e2e capture`** runs the scenarios without a call and without a voice, on a PipeWire +of its own that sees no hardware — the computer's microphones, speakers and headsets, a pair +of AirPods connecting during the run included, are not in it, and the desktop's defaults are +never moved: its default output and input are two silent devices of its own, a note is played into each, and the program records them in both forms — stopped as a user stops it, read while it writes, left silent, killed, and with the same sound in both sources to see that the tracks keep one clock. The second form's notes rest away from zero and carry two unequal channels in 24 bits, so that a track centred, mixed or cut shows; and one source stops and -comes back. It runs nothing where there is no sound server, or while an application holds a -microphone; what it saw is in `.evidence/e2e.txt`, its logs in `$NSTACK_EVIDENCE/logs` +comes back. It runs nothing where PipeWire is missing, and stops at once, NOT RUN, if a +device not its own shows in its graph or a sound card is held; what it saw is in `.evidence/e2e.txt`, its logs in `$NSTACK_EVIDENCE/logs` (`.evidence/e2e/logs` when run alone), where nstack reads them after the run: a warning or an error the manifest's `evidence.provoked` does not declare is said. A real call, a real microphone and a headset stay a person's to try. Scenario P listens, stopped by `stop`, by a TERM signal and by its input closed, and with a named diff --git a/modules/capture/scripts/e2e.sh b/modules/capture/scripts/e2e.sh index 80c4a53a..7ee258cc 100755 --- a/modules/capture/scripts/e2e.sh +++ b/modules/capture/scripts/e2e.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash # The module's end-to-end scenarios (cycle 01, D3), on sound made here and on devices made -# for the run: nobody is recorded. It needs a PipeWire or PulseAudio desktop; where there is -# none — a CI runner — or where a microphone is in use, it says so and runs nothing. -# -# For about two minutes the system's default output and input are two silent devices of its -# own; they are put back whatever happens. +# for the run: nobody is recorded. It runs on a PipeWire and a WirePlumber of its own, as +# private_graph.sh does: their own runtime folder, no hardware monitored, the desktop's graph +# never spoken to. No microphone or speaker of the computer, nor one connected during the run, +# can be opened, and the desktop's defaults are never moved — on the desktop's graph, AirPods +# connected during a run were taken as the default input (2026-11-13). Where PipeWire is +# missing — a CI runner — it says so and runs nothing. set -euo pipefail cd "$(dirname "$0")/.." mkdir -p .evidence @@ -13,16 +14,7 @@ say() { echo "$*" | tee -a .evidence/e2e.txt; } # The run's logs, where NapkinStack reads them after it (nstack e2e capture). evidence=${NSTACK_EVIDENCE:-$PWD/.evidence/e2e} -if ! command -v pactl >/dev/null || ! pactl info >/dev/null 2>&1; then - say "e2e: NOT RUN — no sound server here"; exit 77 -fi -if [ -n "$(pactl list short source-outputs)" ]; then - say "e2e: NOT RUN — an application holds a microphone: a call may be in progress"; exit 77 -fi -if pactl list short sinks | awk -v d="$(pactl get-default-sink)" '$2 == d && $NF == "RUNNING" {found = 1} END {exit !found}'; then - say "e2e: NOT RUN — the system is playing sound: its output would be taken from it"; exit 77 -fi -for tool in ffmpeg ffprobe pw-play pw-dump pw-cli pw-loopback pw-metadata python3; do +for tool in pipewire wireplumber pipewire-pulse pactl ffmpeg ffprobe pw-play pw-dump pw-cli pw-loopback pw-metadata python3; do command -v "$tool" >/dev/null || { say "e2e: NOT RUN — $tool is missing"; exit 77; } done @@ -34,30 +26,101 @@ for _ in $(seq 60); do [ "$(cut -d. -f1 /proc/loadavg)" -lt "$quiet" ] && break; if [ "$(cut -d. -f1 /proc/loadavg)" -ge "$quiet" ]; then say "e2e: NOT RUN — the machine is busy (load $(cut -d' ' -f1 /proc/loadavg), $(nproc) processors): a clock cannot be measured on it"; exit 77 fi -bin=${CARGO_TARGET_DIR:-$PWD/target}/release/kitokey-capture # where cargo built it +bin=$(realpath "${CARGO_TARGET_DIR:-$PWD/target}/release/kitokey-capture") # where cargo built it work=$(mktemp -d) # Its logs in the run's evidence, this run's alone, never the user's (ADR-0007). export KITOKEY_LOG_DIR="$evidence/logs" rm -rf "$KITOKEY_LOG_DIR" -# A run that was killed outright could not put anything back: its devices are removed first, -# and the system falls back on its own. -for stale in $(pactl list short modules | awk '/(kitokey|wholeheard)_e2e_/ {print $1}'); do - say "e2e: a device of an earlier run that was killed is removed"; pactl unload-module "$stale" || true -done -old_sink=$(pactl get-default-sink); old_source=$(pactl get-default-source) -out=$(pactl load-module module-null-sink sink_name=kitokey_e2e_out) -mic=$(pactl load-module module-null-sink sink_name=kitokey_e2e_mic) + +# The desktop's defaults, read before the run and after it: the run never speaks to its graph, so +# they are the same, unless someone changed them meanwhile. "none" where there is no desktop. +graph_vars="XDG_RUNTIME_DIR PIPEWIRE_RUNTIME_DIR PIPEWIRE_REMOTE PULSE_SERVER XDG_CONFIG_HOME XDG_STATE_HOME XDG_CACHE_HOME XDG_DATA_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY WAYLAND_DISPLAY" +# shellcheck disable=SC2086 +desktop=$(declare -p $graph_vars 2>/dev/null || true) +desktop_defaults() { + # shellcheck disable=SC2086 + ( unset $graph_vars; eval "$desktop" + echo "$(pactl get-default-sink 2>/dev/null || echo none) $(pactl get-default-source 2>/dev/null || echo none)" ) +} +desktop_before=$(desktop_defaults) + +# The run's own graph, as private_graph.sh's. A socket's path is short: never under a long folder. +graph=$(mktemp -d /tmp/wh-XXXXXX) +export XDG_RUNTIME_DIR=$graph/rt PIPEWIRE_RUNTIME_DIR=$graph/rt XDG_CONFIG_HOME=$graph/cfg XDG_STATE_HOME=$graph/state +export XDG_CACHE_HOME=$graph/cache XDG_DATA_HOME=$graph/data DBUS_SESSION_BUS_ADDRESS=disabled: +unset PIPEWIRE_REMOTE PULSE_SERVER DISPLAY WAYLAND_DISPLAY +mkdir -p "$graph/rt" "$graph/cfg/wireplumber/wireplumber.conf.d" +chmod 700 "$graph/rt" +cat > "$graph/cfg/wireplumber/wireplumber.conf.d/90-no-hardware.conf" < "$graph/pipewire.log" 2>&1 & daemon=$! +for _ in $(seq 20); do [ -S "$graph/rt/pipewire-0" ] && break; sleep 0.25; done +wireplumber > "$graph/wireplumber.log" 2>&1 & manager=$! +pipewire-pulse > "$graph/pipewire-pulse.log" 2>&1 & pulse=$! +for _ in $(seq 20); do pactl info > /dev/null 2>&1 && break; sleep 0.25; done restore() { + status=$? pkill -P $$ 2>/dev/null || true - pactl set-default-sink "$old_sink" 2>/dev/null || true - pactl set-default-source "$old_source" 2>/dev/null || true - pactl unload-module "$out" 2>/dev/null || true - pactl unload-module "$mic" 2>/dev/null || true - # Scenario J's own, when it was stopped before it took them away. - for module in ${mic_b:-} ${out_b:-} ${out_c:-} ${mic_c:-} ${mic_d:-}; do pactl unload-module "$module" 2>/dev/null || true; done - rm -rf "$work" + kill "$pulse" "$manager" "$daemon" 2>/dev/null || true + wait "$pulse" "$manager" "$daemon" 2>/dev/null || true + rm -rf "$work" "$graph" + if [ -e "$work.real" ]; then + say "e2e: NOT RUN — a real device appeared: $(cat "$work.real")"; rm -f "$work.real"; exit 77 + fi + exit "$status" } trap restore EXIT +trap 'exit 77' TERM + +# The guard, the whole run long: in the run's graph no device, and no source or sink but the run's +# own `kitokey_e2e_*`; no capture of this run holding a sound card of the computer directly. One +# seen: every capture of this run and the graph killed at once, the run NOT RUN — exit 77, as a run +# that cannot run here (.nstack/handbook/09-platform.md). +real_devices() { + python3 - "$bin" <<'GUARD' +import json, os, subprocess, sys +seen = [] +try: # a graph slow to answer is read again half a second later; the cards below are read anyway + dump = subprocess.run(["pw-dump"], capture_output=True, text=True, timeout=5).stdout +except subprocess.TimeoutExpired: + dump = "" +# A device of any kind, or a source or sink not the run's own: streams (Stream/…) are the programs'. +for obj in json.loads(dump or "[]"): + props = (obj.get("info") or {}).get("props") or {} + name = str(props.get("node.name") or props.get("device.name") or obj.get("id")) + device = obj.get("type", "").endswith(":Device") + stranger = str(props.get("media.class", "")).startswith("Audio/") and not name.startswith("kitokey_e2e_") + if device or stranger: + seen.append(f"{name} ({props.get('media.class') or obj.get('type')})") +for pid in filter(str.isdigit, os.listdir("/proc")): + try: + if os.readlink(f"/proc/{pid}/exe") != sys.argv[1]: + continue + held = [os.readlink(f"/proc/{pid}/fd/{fd}") for fd in os.listdir(f"/proc/{pid}/fd")] + except OSError: + continue + seen += [f"{card} held by {pid}" for card in held if card.startswith("/dev/snd/pcm")] +print(", ".join(seen)) +sys.exit(1 if seen else 0) +GUARD +} +stop_all() { + echo "$1" > "$work.real" + for pid in /proc/[0-9]*; do + [ "$(readlink "$pid/exe" 2>/dev/null)" = "$bin" ] && kill -KILL "${pid#/proc/}" 2>/dev/null + done + kill -KILL "$daemon" 2>/dev/null || true + kill -TERM $$ +} +if ! seen=$(real_devices); then stop_all "$seen"; fi +( while sleep 0.5; do seen=$(real_devices) || { stop_all "$seen"; break; }; done ) & guard=$! +# The guard's own trial: E2E_INTRUDER= brings a sink not the run's that long after, as a +# headset connecting — the run must end NOT RUN, exit 77, naming it. +[ -z "${E2E_INTRUDER:-}" ] || { sleep "$E2E_INTRUDER"; pactl load-module module-null-sink sink_name=intruder > /dev/null; } & + +out=$(pactl load-module module-null-sink sink_name=kitokey_e2e_out) +mic=$(pactl load-module module-null-sink sink_name=kitokey_e2e_mic) pactl set-default-sink kitokey_e2e_out pactl set-default-source kitokey_e2e_mic.monitor @@ -722,5 +785,8 @@ PY check headset_said_once check unchanged +kill "$guard" 2>/dev/null || true; wait "$guard" 2>/dev/null || true +say "The desktop's defaults, before and after the run: $desktop_before" +check test "$(desktop_defaults)" = "$desktop_before" [ "$failed" = 0 ] && say "e2e: passed" || say "e2e: FAILED" exit "$failed" From cb3d6980ae40f227cb5e669ab24b6eb7eedb3597 Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 15:32:24 +0100 Subject: [PATCH 2/8] capture: the e2e sealed in a bubblewrap without /dev/snd; the guard fails closed A graph of its own does not keep ALSA from the sound cards: the run now starts in bwrap with a /dev of its own (no /dev/snd), its own processes, and neither the desktop's runtime folder nor the system bus. Inside, no card must be in sight before anything starts. The guard stops the run when pw-dump is late or empty, reads every process of the seal for anything under /dev/snd, and is tried with a sink, a source and a device (E2E_INTRUDER=:). The desktop's defaults are compared outside the seal. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/capture/README.md | 15 +++-- modules/capture/scripts/e2e.sh | 106 +++++++++++++++++++++------------ 2 files changed, 78 insertions(+), 43 deletions(-) diff --git a/modules/capture/README.md b/modules/capture/README.md index 184f24da..01d61d71 100644 --- a/modules/capture/README.md +++ b/modules/capture/README.md @@ -50,16 +50,19 @@ Bluetooth headset may switch to its call profile while it listens, and the syste (ADR-0015's amendment of 2026-11-07); `me`'s first `device` says `headset: true` then, `false` for any other microphone — absent where the graph does not read (D88). It is never part of a recording. -**`nstack e2e capture`** runs the scenarios without a call and without a voice, on a PipeWire -of its own that sees no hardware — the computer's microphones, speakers and headsets, a pair -of AirPods connecting during the run included, are not in it, and the desktop's defaults are -never moved: its default output and input are two silent devices of its own, a note +**`nstack e2e capture`** runs the scenarios without a call and without a voice, sealed off the +computer's sound: in a bubblewrap (`bwrap`) whose `/dev` holds no sound card and which reaches +neither the desktop's PipeWire nor the system bus, on a PipeWire of its own that sees no +hardware — the computer's microphones, speakers and headsets, a pair of AirPods connecting +during the run included, cannot be opened, and the desktop's defaults are never moved: its +default output and input are two silent devices of its own, a note is played into each, and the program records them in both forms — stopped as a user stops it, read while it writes, left silent, killed, and with the same sound in both sources to see that the tracks keep one clock. The second form's notes rest away from zero and carry two unequal channels in 24 bits, so that a track centred, mixed or cut shows; and one source stops and -comes back. It runs nothing where PipeWire is missing, and stops at once, NOT RUN, if a -device not its own shows in its graph or a sound card is held; what it saw is in `.evidence/e2e.txt`, its logs in `$NSTACK_EVIDENCE/logs` +comes back. It runs nothing where PipeWire or `bwrap` is missing or where the system refuses +it a namespace, and stops at once, NOT RUN, if a device not its own shows in its graph, a sound +card is held, or the graph does not answer; what it saw is in `.evidence/e2e.txt`, its logs in `$NSTACK_EVIDENCE/logs` (`.evidence/e2e/logs` when run alone), where nstack reads them after the run: a warning or an error the manifest's `evidence.provoked` does not declare is said. A real call, a real microphone and a headset stay a person's to try. Scenario P listens, stopped by `stop`, by a TERM signal and by its input closed, and with a named diff --git a/modules/capture/scripts/e2e.sh b/modules/capture/scripts/e2e.sh index 7ee258cc..2b57e81a 100755 --- a/modules/capture/scripts/e2e.sh +++ b/modules/capture/scripts/e2e.sh @@ -1,19 +1,53 @@ #!/usr/bin/env bash # The module's end-to-end scenarios (cycle 01, D3), on sound made here and on devices made -# for the run: nobody is recorded. It runs on a PipeWire and a WirePlumber of its own, as -# private_graph.sh does: their own runtime folder, no hardware monitored, the desktop's graph -# never spoken to. No microphone or speaker of the computer, nor one connected during the run, -# can be opened, and the desktop's defaults are never moved — on the desktop's graph, AirPods -# connected during a run were taken as the default input (2026-11-13). Where PipeWire is -# missing — a CI runner — it says so and runs nothing. +# for the run: nobody is recorded. The run is sealed off the computer's sound (2026-11-13: on the +# desktop's graph, AirPods connected during a run were taken as the default input): +# - in a bubblewrap of its own (bwrap, Flatpak's sandbox): a /dev with no /dev/snd — no sound card +# can be opened, through PipeWire or ALSA directly —, its own processes, and no desktop's +# runtime folder nor system bus — the desktop's graph and Bluetooth cannot be reached; +# - on a PipeWire, WirePlumber and pipewire-pulse of its own, as private_graph.sh's, no hardware +# monitored; a guard stops the run, NOT RUN, at anything there not its own. +# The desktop's defaults are never moved: read before and after, outside the seal, the same. +# Where PipeWire or bubblewrap is missing — a CI runner — it says so and runs nothing. set -euo pipefail cd "$(dirname "$0")/.." mkdir -p .evidence -: > .evidence/e2e.txt say() { echo "$*" | tee -a .evidence/e2e.txt; } # The run's logs, where NapkinStack reads them after it (nstack e2e capture). evidence=${NSTACK_EVIDENCE:-$PWD/.evidence/e2e} +if [ -z "${KITOKEY_E2E_SEALED:-}" ]; then + : > .evidence/e2e.txt + command -v bwrap > /dev/null || { say "e2e: NOT RUN — bwrap (bubblewrap) is missing"; exit 77; } + command -v pactl > /dev/null || { say "e2e: NOT RUN — pactl is missing"; exit 77; } + desktop_defaults() { echo "$(pactl get-default-sink 2>/dev/null || echo none) $(pactl get-default-source 2>/dev/null || echo none)"; } + desktop_before=$(desktop_defaults) + # A /dev of its own, without /dev/snd; its own /proc and processes, all ended with it; the + # desktop's runtime folder (its PipeWire, its pulse) and the system bus (Bluetooth) hidden. + sealed=(bwrap --dev-bind / / --dev /dev --tmpfs /dev/shm --unshare-pid --proc /proc --die-with-parent) + for hidden in "${XDG_RUNTIME_DIR:-}" "/run/user/$(id -u)" /run/dbus /run/pulse /run/pipewire; do + [ -n "$hidden" ] && [ -d "$hidden" ] && sealed+=(--tmpfs "$hidden") + done + "${sealed[@]}" -- true 2>> .evidence/e2e.txt || + { say "e2e: NOT RUN — this system refuses the run a namespace of its own (bwrap)"; exit 77; } + status=0 + "${sealed[@]}" --setenv KITOKEY_E2E_SEALED 1 -- bash "$(realpath "$0")" "$@" || status=$? + say "The desktop's defaults, before and after the run: $desktop_before" + if [ "$(desktop_defaults)" = "$desktop_before" ]; then + say " ok the desktop's defaults the same" + else + say " FAIL the desktop's defaults now $(desktop_defaults): the run never speaks to them — a device plugged in meanwhile?" + [ "$status" = 0 ] && status=1 + fi + exit "$status" +fi + +# Sealed from here. No sound card in sight: the first of the guard's assertions. +if [ -e /dev/snd ] || { command -v aplay > /dev/null && ! aplay -l 2>&1 | grep -q 'no soundcards'; }; then + say "e2e: NOT RUN — a sound card is in sight inside the seal: $(ls /dev/snd 2>/dev/null | tr '\n' ' ')"; exit 77 +fi +say "Sealed: /dev holds $(ls /dev | tr '\n' ' ')" + for tool in pipewire wireplumber pipewire-pulse pactl ffmpeg ffprobe pw-play pw-dump pw-cli pw-loopback pw-metadata python3; do command -v "$tool" >/dev/null || { say "e2e: NOT RUN — $tool is missing"; exit 77; } done @@ -32,18 +66,6 @@ work=$(mktemp -d) export KITOKEY_LOG_DIR="$evidence/logs" rm -rf "$KITOKEY_LOG_DIR" -# The desktop's defaults, read before the run and after it: the run never speaks to its graph, so -# they are the same, unless someone changed them meanwhile. "none" where there is no desktop. -graph_vars="XDG_RUNTIME_DIR PIPEWIRE_RUNTIME_DIR PIPEWIRE_REMOTE PULSE_SERVER XDG_CONFIG_HOME XDG_STATE_HOME XDG_CACHE_HOME XDG_DATA_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY WAYLAND_DISPLAY" -# shellcheck disable=SC2086 -desktop=$(declare -p $graph_vars 2>/dev/null || true) -desktop_defaults() { - # shellcheck disable=SC2086 - ( unset $graph_vars; eval "$desktop" - echo "$(pactl get-default-sink 2>/dev/null || echo none) $(pactl get-default-source 2>/dev/null || echo none)" ) -} -desktop_before=$(desktop_defaults) - # The run's own graph, as private_graph.sh's. A socket's path is short: never under a long folder. graph=$(mktemp -d /tmp/wh-XXXXXX) export XDG_RUNTIME_DIR=$graph/rt PIPEWIRE_RUNTIME_DIR=$graph/rt XDG_CONFIG_HOME=$graph/cfg XDG_STATE_HOME=$graph/state @@ -73,20 +95,24 @@ restore() { trap restore EXIT trap 'exit 77' TERM -# The guard, the whole run long: in the run's graph no device, and no source or sink but the run's -# own `kitokey_e2e_*`; no capture of this run holding a sound card of the computer directly. One -# seen: every capture of this run and the graph killed at once, the run NOT RUN — exit 77, as a run -# that cannot run here (.nstack/handbook/09-platform.md). +# The guard, the whole run long, failing closed: the graph read (an answer late or empty stops the +# run), no device in it, no source or sink but the run's own `kitokey_e2e_*`, and no process of the +# run — every process in the seal is — holding anything under /dev/snd (`pcm*`, `control*`). One seen: +# every capture and the graph's daemon killed at once; the script ends at its next step (a scenario's +# `sleep` runs out first, the sound already cut), NOT RUN — exit 77, as a run that cannot run here +# (.nstack/handbook/09-platform.md). real_devices() { - python3 - "$bin" <<'GUARD' + python3 - <<'GUARD' import json, os, subprocess, sys seen = [] -try: # a graph slow to answer is read again half a second later; the cards below are read anyway - dump = subprocess.run(["pw-dump"], capture_output=True, text=True, timeout=5).stdout -except subprocess.TimeoutExpired: - dump = "" +try: + dump = json.loads(subprocess.run(["pw-dump"], capture_output=True, text=True, timeout=3).stdout or "null") +except (subprocess.TimeoutExpired, ValueError): + dump = None +if not dump: + seen.append("the run's graph did not answer pw-dump: nothing seen is not nothing there") # A device of any kind, or a source or sink not the run's own: streams (Stream/…) are the programs'. -for obj in json.loads(dump or "[]"): +for obj in dump or []: props = (obj.get("info") or {}).get("props") or {} name = str(props.get("node.name") or props.get("device.name") or obj.get("id")) device = obj.get("type", "").endswith(":Device") @@ -95,12 +121,10 @@ for obj in json.loads(dump or "[]"): seen.append(f"{name} ({props.get('media.class') or obj.get('type')})") for pid in filter(str.isdigit, os.listdir("/proc")): try: - if os.readlink(f"/proc/{pid}/exe") != sys.argv[1]: - continue held = [os.readlink(f"/proc/{pid}/fd/{fd}") for fd in os.listdir(f"/proc/{pid}/fd")] except OSError: continue - seen += [f"{card} held by {pid}" for card in held if card.startswith("/dev/snd/pcm")] + seen += [f"{card} held by {pid}" for card in held if card.startswith("/dev/snd/")] print(", ".join(seen)) sys.exit(1 if seen else 0) GUARD @@ -115,9 +139,19 @@ stop_all() { } if ! seen=$(real_devices); then stop_all "$seen"; fi ( while sleep 0.5; do seen=$(real_devices) || { stop_all "$seen"; break; }; done ) & guard=$! -# The guard's own trial: E2E_INTRUDER= brings a sink not the run's that long after, as a -# headset connecting — the run must end NOT RUN, exit 77, naming it. -[ -z "${E2E_INTRUDER:-}" ] || { sleep "$E2E_INTRUDER"; pactl load-module module-null-sink sink_name=intruder > /dev/null; } & +# The guard's own trial: E2E_INTRUDER=: brings one not the run's that +# long after the start, as a headset or a card appearing — the run must end NOT RUN, exit 77, naming it. +if [ -n "${E2E_INTRUDER:-}" ]; then + ( + sleep "${E2E_INTRUDER#*:}" + case ${E2E_INTRUDER%%:*} in + sink) pactl load-module module-null-sink sink_name=intruder_sink > /dev/null ;; + source) pw-cli create-node adapter factory.name=support.null-audio-sink node.name=intruder_source \ + media.class=Audio/Source/Virtual object.linger=true audio.position=[FL,FR] > /dev/null ;; + device) { echo "create-device api.alsa.enum.udev"; sleep 600; } | pw-cli > /dev/null ;; + esac + ) & +fi out=$(pactl load-module module-null-sink sink_name=kitokey_e2e_out) mic=$(pactl load-module module-null-sink sink_name=kitokey_e2e_mic) @@ -786,7 +820,5 @@ check headset_said_once check unchanged kill "$guard" 2>/dev/null || true; wait "$guard" 2>/dev/null || true -say "The desktop's defaults, before and after the run: $desktop_before" -check test "$(desktop_defaults)" = "$desktop_before" [ "$failed" = 0 ] && say "e2e: passed" || say "e2e: FAILED" exit "$failed" From c78430fd30e26e212e785581709a465fd668184c Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 18:55:28 +0100 Subject: [PATCH 3/8] capture: the e2e's graph without pipewire-pulse's fallback sink; the guard's trial judged by its intruder pipewire-pulse loads module-always-sink by default: its `auto_null` sink, in a graph with no sink yet, stopped every run at the guard's first look, the trial included (S1 at cb3d698 named `auto_null`, not `intruder_sink`). Off by pulse.cmd.always-sink = false, the condition pipewire-pulse.conf puts on it. With E2E_INTRUDER set, a run stopped by anything but intruder_, or not stopped, now fails; the device intruder is named intruder_device. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/capture/scripts/e2e.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/capture/scripts/e2e.sh b/modules/capture/scripts/e2e.sh index 2b57e81a..ed44f192 100755 --- a/modules/capture/scripts/e2e.sh +++ b/modules/capture/scripts/e2e.sh @@ -71,11 +71,16 @@ graph=$(mktemp -d /tmp/wh-XXXXXX) export XDG_RUNTIME_DIR=$graph/rt PIPEWIRE_RUNTIME_DIR=$graph/rt XDG_CONFIG_HOME=$graph/cfg XDG_STATE_HOME=$graph/state export XDG_CACHE_HOME=$graph/cache XDG_DATA_HOME=$graph/data DBUS_SESSION_BUS_ADDRESS=disabled: unset PIPEWIRE_REMOTE PULSE_SERVER DISPLAY WAYLAND_DISPLAY -mkdir -p "$graph/rt" "$graph/cfg/wireplumber/wireplumber.conf.d" +mkdir -p "$graph/rt" "$graph/cfg/wireplumber/wireplumber.conf.d" "$graph/cfg/pipewire/pipewire-pulse.conf.d" chmod 700 "$graph/rt" cat > "$graph/cfg/wireplumber/wireplumber.conf.d/90-no-hardware.conf" < "$graph/cfg/pipewire/pipewire-pulse.conf.d/90-no-always-sink.conf" < "$graph/pipewire.log" 2>&1 & daemon=$! for _ in $(seq 20); do [ -S "$graph/rt/pipewire-0" ] && break; sleep 0.25; done wireplumber > "$graph/wireplumber.log" 2>&1 & manager=$! @@ -88,8 +93,14 @@ restore() { wait "$pulse" "$manager" "$daemon" 2>/dev/null || true rm -rf "$work" "$graph" if [ -e "$work.real" ]; then - say "e2e: NOT RUN — a real device appeared: $(cat "$work.real")"; rm -f "$work.real"; exit 77 + say "e2e: NOT RUN — a real device appeared: $(cat "$work.real")" + # The guard's trial passes only stopped by its intruder: stopped by anything else, or not at all, it fails. + if [ -n "${E2E_INTRUDER:-}" ] && ! grep -q "intruder_${E2E_INTRUDER%%:*}" "$work.real"; then + say " FAIL the guard stopped the run, not at intruder_${E2E_INTRUDER%%:*}"; rm -f "$work.real"; exit 1 + fi + rm -f "$work.real"; exit 77 fi + if [ -n "${E2E_INTRUDER:-}" ]; then say " FAIL the guard let intruder_${E2E_INTRUDER%%:*} through"; exit 1; fi exit "$status" } trap restore EXIT @@ -140,7 +151,8 @@ stop_all() { if ! seen=$(real_devices); then stop_all "$seen"; fi ( while sleep 0.5; do seen=$(real_devices) || { stop_all "$seen"; break; }; done ) & guard=$! # The guard's own trial: E2E_INTRUDER=: brings one not the run's that -# long after the start, as a headset or a card appearing — the run must end NOT RUN, exit 77, naming it. +# long after the start, as a headset or a card appearing — the run must end NOT RUN, exit 77, naming it +# (`intruder_sink`, `intruder_source`, `intruder_device`); stopped by anything else, or not, it fails. if [ -n "${E2E_INTRUDER:-}" ]; then ( sleep "${E2E_INTRUDER#*:}" @@ -148,7 +160,7 @@ if [ -n "${E2E_INTRUDER:-}" ]; then sink) pactl load-module module-null-sink sink_name=intruder_sink > /dev/null ;; source) pw-cli create-node adapter factory.name=support.null-audio-sink node.name=intruder_source \ media.class=Audio/Source/Virtual object.linger=true audio.position=[FL,FR] > /dev/null ;; - device) { echo "create-device api.alsa.enum.udev"; sleep 600; } | pw-cli > /dev/null ;; + device) { echo "create-device api.alsa.enum.udev { device.name = intruder_device }"; sleep 600; } | pw-cli > /dev/null ;; esac ) & fi From b6609237cfdb04ebc3a77d4fb3caab3630ab022f Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:33:48 +0100 Subject: [PATCH 4/8] capture: the guard's device trial on a stubbed pw-dump, and a trial that proves nothing ends at once No Device factory runs in the seal without hardware or a bus: `api.alsa.enum.udev` made none, and the trial went on through the whole run. The device intruder is now a Device added to the guard's own pw-dump answer. The trial fails within 3 s when its intruder does not appear, or appears and the run is not stopped. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/capture/scripts/e2e.sh | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/modules/capture/scripts/e2e.sh b/modules/capture/scripts/e2e.sh index ed44f192..60c190e1 100755 --- a/modules/capture/scripts/e2e.sh +++ b/modules/capture/scripts/e2e.sh @@ -96,10 +96,11 @@ restore() { say "e2e: NOT RUN — a real device appeared: $(cat "$work.real")" # The guard's trial passes only stopped by its intruder: stopped by anything else, or not at all, it fails. if [ -n "${E2E_INTRUDER:-}" ] && ! grep -q "intruder_${E2E_INTRUDER%%:*}" "$work.real"; then - say " FAIL the guard stopped the run, not at intruder_${E2E_INTRUDER%%:*}"; rm -f "$work.real"; exit 1 + say " FAIL the guard stopped the run, not at intruder_${E2E_INTRUDER%%:*}"; rm -f "$work.real" "$work.trial"; exit 1 fi - rm -f "$work.real"; exit 77 + rm -f "$work.real" "$work.trial"; exit 77 fi + if [ -e "$work.trial" ]; then say " FAIL $(cat "$work.trial")"; rm -f "$work.trial"; exit 1; fi if [ -n "${E2E_INTRUDER:-}" ]; then say " FAIL the guard let intruder_${E2E_INTRUDER%%:*} through"; exit 1; fi exit "$status" } @@ -113,7 +114,7 @@ trap 'exit 77' TERM # `sleep` runs out first, the sound already cut), NOT RUN — exit 77, as a run that cannot run here # (.nstack/handbook/09-platform.md). real_devices() { - python3 - <<'GUARD' + PATH="${trial_bin:-}$PATH" python3 - <<'GUARD' import json, os, subprocess, sys seen = [] try: @@ -148,20 +149,51 @@ stop_all() { kill -KILL "$daemon" 2>/dev/null || true kill -TERM $$ } +# The device trial's intruder: no Device factory runs without hardware or a bus (the installed SPA +# ones are api.alsa.{pcm,acp,compress.offload}.device, api.bluez5.device, api.libcamera.device), and +# `api.alsa.enum.udev` in the seal made none (2026-11-14). The guard's pw-dump answers for it then: the +# graph's own dump, and the Device as pw-dump prints one once the trial brings it. +if [[ ${E2E_INTRUDER:-} == device:* ]]; then + mkdir -p "$graph/trial" && trial_bin=$graph/trial: + cat > "$graph/trial/pw-dump" <: brings one not the run's that # long after the start, as a headset or a card appearing — the run must end NOT RUN, exit 77, naming it # (`intruder_sink`, `intruder_source`, `intruder_device`); stopped by anything else, or not, it fails. +# The trial ends at once when it proves nothing: its intruder not in the guard's pw-dump within 3 s, +# or there and the run not stopped 3 s later — never a whole run to learn it. if [ -n "${E2E_INTRUDER:-}" ]; then ( + kind=${E2E_INTRUDER%%:*} sleep "${E2E_INTRUDER#*:}" - case ${E2E_INTRUDER%%:*} in + case $kind in sink) pactl load-module module-null-sink sink_name=intruder_sink > /dev/null ;; source) pw-cli create-node adapter factory.name=support.null-audio-sink node.name=intruder_source \ media.class=Audio/Source/Virtual object.linger=true audio.position=[FL,FR] > /dev/null ;; - device) { echo "create-device api.alsa.enum.udev { device.name = intruder_device }"; sleep 600; } | pw-cli > /dev/null ;; + device) touch "$graph/intruder_device" ;; esac + there= + for _ in $(seq 12); do + if PATH="${trial_bin:-}$PATH" pw-dump 2>/dev/null | grep -q "\"intruder_$kind\""; then there=1; break; fi + sleep 0.25 + done + if [ -z "$there" ]; then # the guard may have stopped the graph first: then it saw it + [ -e "$work.real" ] || { echo "the trial's intruder did not appear: intruder_$kind" > "$work.trial"; kill -TERM $$; } + exit 0 + fi + sleep 3 + echo "the guard let intruder_$kind through" > "$work.trial"; kill -TERM $$ ) & fi From 92ba771b4630bf84a58c9593eec481f76210be70 Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 04:37:13 +0100 Subject: [PATCH 5/8] capture: e2e waits on E2's signallers alone, and its cleanup outlives a cut run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit E2's bare `wait` waited on every child: the run's graph daemons are the script's children now, and never end — S2 hung an hour in E2. It waits on the three signallers by their PIDs. The cleanup kills pipewire, wireplumber and pipewire-pulse by their PIDs, with KILL after two seconds, and ignores further signals while it runs: `timeout` signals the script and then its group, and a second TERM in the EXIT trap ended the shell before `rm -rf`. INT and HUP end the run through the same cleanup. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/capture/scripts/e2e.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/capture/scripts/e2e.sh b/modules/capture/scripts/e2e.sh index 60c190e1..478d5177 100755 --- a/modules/capture/scripts/e2e.sh +++ b/modules/capture/scripts/e2e.sh @@ -88,8 +88,16 @@ pipewire-pulse > "$graph/pipewire-pulse.log" 2>&1 & pulse=$! for _ in $(seq 20); do pactl info > /dev/null 2>&1 && break; sleep 0.25; done restore() { status=$? + # Cleaning is never cut short: `timeout` signals the script, then its whole group, a second TERM. + trap '' TERM INT HUP pkill -P $$ 2>/dev/null || true + # The graph's daemons by their PIDs, killed outright if they have not ended within two seconds. kill "$pulse" "$manager" "$daemon" 2>/dev/null || true + for _ in $(seq 20); do + alive=0; for p in "$pulse" "$manager" "$daemon"; do kill -0 "$p" 2>/dev/null && alive=1; done + [ "$alive" = 0 ] && break; sleep 0.1 + done + kill -KILL "$pulse" "$manager" "$daemon" 2>/dev/null || true wait "$pulse" "$manager" "$daemon" 2>/dev/null || true rm -rf "$work" "$graph" if [ -e "$work.real" ]; then @@ -106,6 +114,8 @@ restore() { } trap restore EXIT trap 'exit 77' TERM +trap 'exit 130' INT +trap 'exit 129' HUP # The guard, the whole run long, failing closed: the graph read (an answer late or empty stops the # run), no device in it, no source or sink but the run's own `kitokey_e2e_*`, and no process of the @@ -332,6 +342,7 @@ for run in part flac again; do eval "recorder_$run=$!" done sleep 65 +signallers=() for run in part flac again; do folder=$(ls -d "$work/kept-$run"/*/ | head -1) pid=$(eval echo "\$recorder_$run") @@ -340,12 +351,14 @@ for run in part flac again; do flac) python3 scripts/e2e_measure_v2.py signal-at "$folder" "$pid" SIGKILL local.flac & ;; again) python3 scripts/e2e_measure_v2.py signal-at "$folder" "$pid" SIGTERM local.flac.part & ;; esac + signallers+=("$!") done sleep 0.5 kill -INT "$recorder_part" "$recorder_flac" "$recorder_again" wait "$recorder_part" "$recorder_flac" 2>/dev/null || true again_as=0; wait "$recorder_again" || again_as=$? -wait +# Its signallers alone: the graph's daemons are children of this script too, and never end. +wait "${signallers[@]}" 2>/dev/null || true kill "$mic_player" "$others_player" 2>/dev/null || true for run in part flac again; do folder=$(ls -d "$work/kept-$run"/*/ | head -1) From 154f34d549380df144d1fea5334fc14caead92db Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 04:38:47 +0100 Subject: [PATCH 6/8] capture: a TERM from outside ends e2e as stopped, 143, never as NOT RUN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The guard's own stop still says NOT RUN, exit 77: it writes "$work.real" before its TERM, and the cleanup reads it there. Any other TERM — a runner's timeout, a person — now exits 143, so nothing running e2e.sh directly reads a cut run as a skip. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/capture/scripts/e2e.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/capture/scripts/e2e.sh b/modules/capture/scripts/e2e.sh index 478d5177..2a0571e9 100755 --- a/modules/capture/scripts/e2e.sh +++ b/modules/capture/scripts/e2e.sh @@ -113,7 +113,8 @@ restore() { exit "$status" } trap restore EXIT -trap 'exit 77' TERM +# A TERM is a stop, never a skip: the guard's own says NOT RUN through "$work.real", read in restore. +trap 'exit 143' TERM trap 'exit 130' INT trap 'exit 129' HUP From 5b0823ce493633c436aa3ce2d560829d3dbdcfe9 Mon Sep 17 00:00:00 2001 From: "kitokey-sam[bot]" <356216031+kitokey-sam[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 05:55:48 +0100 Subject: [PATCH 7/8] capture: E2 fails when a signaller sends nothing (#814) E2 dropped the exit status of its three signal-at helpers, so it passed when none of them signalled. Each status is now checked. signal-at exits 0 when it sent its signal, and also when the recorder ended before the moment (gone, or a zombie not yet waited for): on a fast machine the .part file may never be seen. It says which in its line. It exits 1 on an error: the moment never came while the recorder ran, or a failure. Agent-Session: 92ded11e-58ef-492d-ba56-c820b9011de8 Co-Authored-By: Claude Opus 5.5 --- modules/capture/scripts/e2e.sh | 5 +++-- modules/capture/scripts/e2e_measure_v2.py | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/capture/scripts/e2e.sh b/modules/capture/scripts/e2e.sh index 2a0571e9..d1dea9f8 100755 --- a/modules/capture/scripts/e2e.sh +++ b/modules/capture/scripts/e2e.sh @@ -358,8 +358,9 @@ sleep 0.5 kill -INT "$recorder_part" "$recorder_flac" "$recorder_again" wait "$recorder_part" "$recorder_flac" 2>/dev/null || true again_as=0; wait "$recorder_again" || again_as=$? -# Its signallers alone: the graph's daemons are children of this script too, and never end. -wait "${signallers[@]}" 2>/dev/null || true +# Its signallers alone — the graph's daemons are children of this script too, and never end —, each +# judged: one that failed sent nothing, and the folders after would be those of recordings merely stopped. +for signaller in "${signallers[@]}"; do check wait "$signaller"; done kill "$mic_player" "$others_player" 2>/dev/null || true for run in part flac again; do folder=$(ls -d "$work/kept-$run"/*/ | head -1) diff --git a/modules/capture/scripts/e2e_measure_v2.py b/modules/capture/scripts/e2e_measure_v2.py index f8dafaec..97d22fbe 100644 --- a/modules/capture/scripts/e2e_measure_v2.py +++ b/modules/capture/scripts/e2e_measure_v2.py @@ -358,6 +358,15 @@ def call_followed(folder, events, call, default, heard, left, after): assert not near(left), f"remote: {left} Hz, played on the output the call had left, is in its track" +def ended(pid): + """The process is gone, or has ended and waits for its parent to read its status.""" + try: + with open(f"/proc/{pid}/stat") as stat: + return stat.read().rpartition(")")[2].split()[0] == "Z" + except FileNotFoundError: + return True + + def main(what, folder, *args): if what == "pause": # Not a measure: stops the recorder's own stream for a track, then starts it again. @@ -391,12 +400,22 @@ def main(what, folder, *args): return print(f" {', '.join(names)}: each track whole") if what == "signal-at": # Not a measure: the signal `args[1]` to the recorder `args[0]` the moment `args[2]` is in the folder. + # Exits 0 once sent, and when the recorder ended before the moment: on a fast machine a `.part` + # comes and goes between two looks, and what is left is judged whole all the same. Exits 1 + # otherwise: the moment not come in two minutes with the recorder still running, or a failure. pid, sent, name = int(args[0]), getattr(signal, args[1]), args[2] until = time.monotonic() + 120 while not os.path.exists(os.path.join(folder, name)): - assert time.monotonic() < until, f"{name} never appeared" + if ended(pid): + return print(f" {args[1]} not sent: the recorder ended before {name} appeared") + assert time.monotonic() < until, f"{name} never appeared, the recorder still running" time.sleep(0.0005) - os.kill(pid, sent) + try: + if ended(pid): + raise ProcessLookupError + os.kill(pid, sent) + except ProcessLookupError: + return print(f" {args[1]} not sent: the recorder ended as {name} appeared") return print(f" {args[1]} sent as {name} appeared") if what == "followed": return followed(folder, *args) From 1f4fe88f9e1f3d2bc1b986f42ed016abd9623db7 Mon Sep 17 00:00:00 2001 From: "kitokey-sam[bot]" <356216031+kitokey-sam[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 11:58:12 +0100 Subject: [PATCH 8/8] capture: an unused variable in e2e_measure_v2.py named `_` (ruff F841) For the pre-commit hook to come on capture's scripts. Agent-Session: 92ded11e-58ef-492d-ba56-c820b9011de8 Co-Authored-By: Claude Opus 5.5 --- modules/capture/scripts/e2e_measure_v2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/capture/scripts/e2e_measure_v2.py b/modules/capture/scripts/e2e_measure_v2.py index 97d22fbe..d01b15af 100644 --- a/modules/capture/scripts/e2e_measure_v2.py +++ b/modules/capture/scripts/e2e_measure_v2.py @@ -496,7 +496,7 @@ def main(what, folder, *args): elif what == "stopped-source": # The remote source was stopped for several seconds: the capture wrote zeros and said which. points, silences, _ = clocks["remote"] - remote, rate = tracks["remote"], tracks["remote"]["rate"] + _, rate = tracks["remote"], tracks["remote"]["rate"] assert silences, "remote stopped for seconds, and the clock says no silence of ours" zeros = sum(to - start for start, to in silences) assert zeros >= 2 * rate, f"{zeros / rate:.1f} s of zeros said for a stop of several seconds"