From 7f24099c73fe344709060054c813fcd6a962011e Mon Sep 17 00:00:00 2001 From: Jeremy Deceuster Date: Fri, 23 Oct 2026 14:26:54 +0200 Subject: [PATCH 1/2] fix: verify reads only the CLI's stdout as the status document `verify` merged stderr into the `status --probe --json` output it hands to jq. Varlatch 0.19.0's CLI warns on stderr when it runs on a Node.js release without its line's security fixes (varlatch/varlatch#62); with that line first, jq fails, and under `set -euo pipefail` the action exits without a notification. stderr now goes to a temporary file and is shown only when the command fails. Co-Authored-By: Claude Opus 5.5 --- bin/varlatch-menu | 11 ++++++++--- tests/fake-varlatch | 11 ++++++++++- tests/run.sh | 19 ++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/bin/varlatch-menu b/bin/varlatch-menu index 37c93ac..c42ab38 100755 --- a/bin/varlatch-menu +++ b/bin/varlatch-menu @@ -240,9 +240,14 @@ case "${1:-}" in verify) # The one explicitly network-touching read: --probe checks each stored - # credential against its server. - out=$(eval "$CMD status --probe --json" 2>&1) \ - || { notify "verify failed: $out"; exit 1; } + # credential against its server. Only stdout is the document: the CLI + # can warn on stderr, as on a Node.js release without its security fixes. + err=$(mktemp) + if ! out=$(eval "$CMD status --probe --json" 2>"$err"); then + msg=$(cat "$err"); rm -f "$err" + notify "verify failed: ${msg:-$out}"; exit 1 + fi + rm -f "$err" summary=$(echo "$out" | jq -r '.servers[] | "\(.server): \(.probe.state // "unknown")\(if .probe.detail then " (\(.probe.detail))" else "" end)"') notify "${summary:-no stored credentials}" refresh_widget diff --git a/tests/fake-varlatch b/tests/fake-varlatch index 1a82d0c..3fc8fda 100755 --- a/tests/fake-varlatch +++ b/tests/fake-varlatch @@ -2,11 +2,20 @@ # A stand-in for the varlatch CLI, for tests/run.sh. Every call is recorded # in $HOME/calls.log. `status` prints $HOME/status.json (no sessions when it # is missing), and the FAKE_* variables choose how sign-ins end. +# FAKE_STDERR is a line every call writes to stderr first, as the CLI warns +# on a Node.js release without its security fixes; FAKE_STATUS_FAIL makes +# `status` fail as an unreachable server does. echo "cli $*" >> "$HOME/calls.log" +[ -n "${FAKE_STDERR:-}" ] && echo "$FAKE_STDERR" >&2 case "${1:-}" in --version) echo "varlatch ${FAKE_VERSION:-0.15.0} (migration 26)"; exit 0 ;; --help) echo "Usage: varlatch "; exit 0 ;; - status) cat "$HOME/status.json" 2>/dev/null || echo '{"version":1,"servers":[],"repo":null}'; exit 0 ;; + status) + if [ -n "${FAKE_STATUS_FAIL:-}" ]; then + echo "varlatch status: cannot reach https://vl.example.com" >&2 + exit 69 + fi + cat "$HOME/status.json" 2>/dev/null || echo '{"version":1,"servers":[],"repo":null}'; exit 0 ;; logout) echo "Logged out."; exit 0 ;; login) ;; *) exit 64 ;; diff --git a/tests/run.sh b/tests/run.sh index a66ef43..d0aa766 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -86,7 +86,7 @@ EOF MENU="$T/.config/omarchy/extensions/omarchy-menu.jsonc" widget '{}' unset FAKE_VERSION FAKE_WAIT FAKE_CHOICE FAKE_LOGIN_RC FAKE_LOGIN_SLEEP FAKE_START_FAIL \ - FAKE_LATEST FAKE_CURL_FAIL FAKE_SERVER_VERSION VARLATCH_SERVER + FAKE_LATEST FAKE_CURL_FAIL FAKE_SERVER_VERSION FAKE_STDERR FAKE_STATUS_FAIL VARLATCH_SERVER } # The widget's entry in shell.json: the fake CLI plus the given settings. @@ -208,6 +208,23 @@ check "no device sign-in row before 0.14.0" "menu_has 'has(\"varlatch.device\") echo '{"current": "0.14.0", "latest": "0.15.0", "updateAvailable": true, "install": "release"}' > "$U"; "$H" sync-menu check "Update CLI row for a release install" "menu_has '.[\"varlatch.update\"].description == \"0.14.0 → 0.15.0\"'" +# -------------------------------------------------------------------------- +section "verify (status --probe)" +new_home +jq -n '{version: 1, repo: null, servers: [{server: "https://vl.example.com", name: null, + issuedAt: "2026-10-07T06:00:00Z", expiresAt: "2099-01-01T00:00:00Z", expired: false, expiring: false, + probe: {state: "valid"}}]}' > "$T/status.json" +"$H" verify +check "each server's probe state in the notification" \ + "calls | grep -F 'notify-send -a Varlatch Varlatch https://vl.example.com: valid'" "$(calls)" +NODE_WARNING="varlatch: Node.js 26.12.0 is missing security fixes; update it to 26.12.1 or later. VARLATCH_NODE_CHECK=off hides this warning." +: > "$T/calls.log"; FAKE_STDERR="$NODE_WARNING" "$H" verify +check "a CLI warning on stderr leaves the document readable" \ + "calls | grep -F 'notify-send -a Varlatch Varlatch https://vl.example.com: valid'" "$(calls)" +: > "$T/calls.log"; FAKE_STDERR="$NODE_WARNING" FAKE_STATUS_FAIL=1 "$H" verify && rc=0 || rc=$? +check "a failure notifies what the CLI said on stderr" \ + "[ $rc -eq 1 ] && calls | grep -F 'notify-send -a Varlatch Varlatch verify failed:' && calls | grep -qF 'cannot reach https://vl.example.com'" "$(calls)" + # -------------------------------------------------------------------------- section "sign-in state (login, login-check, login-cancel)" new_home From 6dfc27b045d2103265185116c3cdf83e220768cd Mon Sep 17 00:00:00 2001 From: Jeremy Deceuster Date: Fri, 23 Oct 2026 15:30:54 +0200 Subject: [PATCH 2/2] fix: verify removes its stderr file even when it is stopped Review round 1: a SIGTERM during the probe left the temporary file behind. An EXIT trap now removes it, and HUP, INT and TERM become exits so that trap runs (bash skips it when a signal kills the shell). Co-Authored-By: Claude Opus 5.5 --- bin/varlatch-menu | 7 +++++-- tests/fake-varlatch | 4 +++- tests/run.sh | 9 ++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/varlatch-menu b/bin/varlatch-menu index c42ab38..7974df1 100755 --- a/bin/varlatch-menu +++ b/bin/varlatch-menu @@ -243,11 +243,14 @@ case "${1:-}" in # credential against its server. Only stdout is the document: the CLI # can warn on stderr, as on a Node.js release without its security fixes. err=$(mktemp) + # Removed however the action ends. bash skips the EXIT trap when a + # signal kills it, so those become exits. + trap 'rm -f "$err"' EXIT + trap 'exit 129' HUP; trap 'exit 130' INT; trap 'exit 143' TERM if ! out=$(eval "$CMD status --probe --json" 2>"$err"); then - msg=$(cat "$err"); rm -f "$err" + msg=$(cat "$err") notify "verify failed: ${msg:-$out}"; exit 1 fi - rm -f "$err" summary=$(echo "$out" | jq -r '.servers[] | "\(.server): \(.probe.state // "unknown")\(if .probe.detail then " (\(.probe.detail))" else "" end)"') notify "${summary:-no stored credentials}" refresh_widget diff --git a/tests/fake-varlatch b/tests/fake-varlatch index 3fc8fda..8057d15 100755 --- a/tests/fake-varlatch +++ b/tests/fake-varlatch @@ -4,13 +4,15 @@ # is missing), and the FAKE_* variables choose how sign-ins end. # FAKE_STDERR is a line every call writes to stderr first, as the CLI warns # on a Node.js release without its security fixes; FAKE_STATUS_FAIL makes -# `status` fail as an unreachable server does. +# `status` fail as an unreachable server does, and FAKE_STATUS_SLEEP makes it +# take that many seconds. echo "cli $*" >> "$HOME/calls.log" [ -n "${FAKE_STDERR:-}" ] && echo "$FAKE_STDERR" >&2 case "${1:-}" in --version) echo "varlatch ${FAKE_VERSION:-0.15.0} (migration 26)"; exit 0 ;; --help) echo "Usage: varlatch "; exit 0 ;; status) + sleep "${FAKE_STATUS_SLEEP:-0}" if [ -n "${FAKE_STATUS_FAIL:-}" ]; then echo "varlatch status: cannot reach https://vl.example.com" >&2 exit 69 diff --git a/tests/run.sh b/tests/run.sh index d0aa766..e31731c 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -86,7 +86,7 @@ EOF MENU="$T/.config/omarchy/extensions/omarchy-menu.jsonc" widget '{}' unset FAKE_VERSION FAKE_WAIT FAKE_CHOICE FAKE_LOGIN_RC FAKE_LOGIN_SLEEP FAKE_START_FAIL \ - FAKE_LATEST FAKE_CURL_FAIL FAKE_SERVER_VERSION FAKE_STDERR FAKE_STATUS_FAIL VARLATCH_SERVER + FAKE_LATEST FAKE_CURL_FAIL FAKE_SERVER_VERSION FAKE_STDERR FAKE_STATUS_FAIL FAKE_STATUS_SLEEP VARLATCH_SERVER } # The widget's entry in shell.json: the fake CLI plus the given settings. @@ -224,6 +224,13 @@ check "a CLI warning on stderr leaves the document readable" \ : > "$T/calls.log"; FAKE_STDERR="$NODE_WARNING" FAKE_STATUS_FAIL=1 "$H" verify && rc=0 || rc=$? check "a failure notifies what the CLI said on stderr" \ "[ $rc -eq 1 ] && calls | grep -F 'notify-send -a Varlatch Varlatch verify failed:' && calls | grep -qF 'cannot reach https://vl.example.com'" "$(calls)" +# Its stderr file goes, whether verify succeeds, fails, or is stopped. +mkdir "$T/tmp" +TMPDIR="$T/tmp" "$H" verify +TMPDIR="$T/tmp" FAKE_STATUS_FAIL=1 "$H" verify || true +TMPDIR="$T/tmp" FAKE_STATUS_SLEEP=2 "$H" verify & helper=$! +sleep 0.5; kill -TERM "$helper"; wait "$helper" && rc=0 || rc=$? +check "no temporary file is left, even after SIGTERM" "[ $rc -eq 143 ] && [ -z \"\$(ls -A '$T/tmp')\" ]" "rc=$rc; $(ls -A "$T/tmp")" # -------------------------------------------------------------------------- section "sign-in state (login, login-check, login-cancel)"