diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a42e9fc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version: 22 + - name: Install qrencode + run: sudo apt-get update -q && sudo apt-get install -yq qrencode + - name: shellcheck + run: shellcheck -S warning bin/varlatch-menu tests/run.sh tests/fake-varlatch + - name: Tests + run: tests/run.sh diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..64e3307 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,42 @@ +# Changelog + +## 0.4.0 (2026-10-07) + +- **First run.** Without the `varlatch` CLI, the panel and the menu offer + to install it: a terminal asks for your server's address to install the + CLI version it runs, checks the download like an update, installs it as + `~/.local/bin/varlatch`, and offers the first sign-in. With no server known + yet, the panel asks for its address; **add server** signs in to another. +- **Sign in from another device** (CLI 0.14.0 or newer), for when the + browser here has no passkey: the panel shows an address, a code, and a QR + code of the address. Start it with **other device** on a waiting sign-in, + **Log in from another device** in the menu, or the buttons on a failed + sign-in's and the expiry notifications. +- **Session length:** the `sessionHours` setting (1 to 24; 0 keeps the + server's default of 12 hours) applies to every sign-in the widget starts. +- **Fresher release check:** opening the panel checks again when the last + check is over an hour old, and a cache older than the installed CLI is + checked again; never more than once an hour. +- **Fix:** a sign-in whose process died before it could clean up (killed, + or from before a reboot) no longer stays on the panel with a cancel that + did nothing. +- The renew rows in the menu have a glyph. +- Offline tests (`tests/run.sh`) and CI: shellcheck, the manifest, and the + helper's menu, sign-in, device sign-in, release check, and install paths. + +## 0.3.0 (2026-10-07) + +- Install with `omarchy plugin add`; the widget adds its own submenu to the + Omarchy menu and keeps it in step with your sessions. +- The repository is public; release checks and downloads are anonymous. + +## 0.2.0 (2026-09-28) + +- The panel shows the CLI version and, with `checkUpdates` on, newer + releases, with release notes and a checked update of the release CLI. +- The CLI version is read again when the panel opens. + +## 0.1.0 (2026-09-25) + +- First release: sessions, expiry, and sign-in, renewal, and sign-out in the + Omarchy bar, read offline from `varlatch status --json`. diff --git a/README.md b/README.md index 7947807..0dee052 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,18 @@ Requires `jq`, `python3`, and the Varlatch CLI 0.8.0 or newer, which the panel can install (see [First run](#first-run)). With a CLI before 0.10.0, the widget works out the *expiring* state itself. +## Development + +`tests/run.sh` tests the manifest and `bin/varlatch-menu` offline, each test +in a throwaway `HOME` with stand-ins for the CLI (`tests/fake-varlatch`), +`curl`, `notify-send`, and the omarchy commands. It needs `jq`, `python3`, +and Node.js 22 or newer, and checks the QR code when `qrencode` is +installed. CI runs it with `shellcheck` on every pull request. The QML is +checked by hand on a live bar: `omarchy restart shell` after editing it, +and `omarchy-shell varlatch debugState` for the widget's state. + +See [`CHANGELOG.md`](CHANGELOG.md) for what changed in each release. + ## License Copyright © 2026 Robotsson. Licensed under the Apache License 2.0; see diff --git a/manifest.json b/manifest.json index 28d090a..c80a856 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "id": "varlatch", "name": "Varlatch", - "version": "0.3.0", + "version": "0.4.0", "author": "Varlatch", "license": "Apache-2.0", "description": "Varlatch sessions in the Omarchy bar: which servers you hold credentials for, when they expire, and quick sign-in and sign-out, all read offline from `varlatch status --json`.", diff --git a/tests/fake-varlatch b/tests/fake-varlatch new file mode 100755 index 0000000..1a82d0c --- /dev/null +++ b/tests/fake-varlatch @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# 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. +echo "cli $*" >> "$HOME/calls.log" +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 ;; + logout) echo "Logged out."; exit 0 ;; + login) ;; + *) exit 64 ;; +esac + +mode="browser" +for arg in "$@"; do + case "$arg" in --start) mode="start" ;; --wait) mode="wait" ;; esac +done + +case "$mode" in + start) + if [ -n "${FAKE_START_FAIL:-}" ]; then + echo "varlatch login: the server refused to start a sign-in (NOT_FOUND)" >&2 + exit 1 + fi + echo '{"verificationUri":"https://vl.example.com/device","userCode":"BCDF-GHJK","expiresAt":"2099-01-01T00:10:00.000Z"}' + ;; + wait) + # FAKE_WAIT: approve | pending-once | deny | expire | hang + n=$(cat "$HOME/wait-count" 2>/dev/null || echo 0) + n=$((n + 1)); echo "$n" > "$HOME/wait-count" + case "${FAKE_WAIT:-approve}" in + approve) ;; + pending-once) + if [ "$n" -eq 1 ]; then + sleep 1 + echo '{"state":"pending"}' + echo "varlatch login: not approved yet." >&2 + exit 75 + fi ;; + deny) echo '{"state":"denied"}'; echo "varlatch login: the sign-in was denied." >&2; exit 77 ;; + expire) echo '{"state":"expired"}'; echo "varlatch login: the sign-in expired." >&2; exit 77 ;; + hang) sleep 60; exit 75 ;; + esac + echo '{"state":"signed-in","credentialId":"crd_test","expiresAt":"2099-01-01T12:00:00Z"}' + ;; + browser) + echo "Open this address to sign in: https://vl.example.com/enroll?state=test" + sleep "${FAKE_LOGIN_SLEEP:-0}" + if [ "${FAKE_LOGIN_RC:-0}" -ne 0 ]; then + echo "varlatch login: browser sign-in failed: no passkey" >&2 + exit "$FAKE_LOGIN_RC" + fi + echo "Issued CLI credential (expires 2099-01-01T12:00:00Z)." + ;; +esac diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 0000000..3123286 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,355 @@ +#!/usr/bin/env bash +# Offline tests for the manifest and bin/varlatch-menu. Each test runs in a +# throwaway HOME, with the plugin linked where Omarchy puts it and +# stand-ins for the varlatch CLI (tests/fake-varlatch), curl, notify-send, +# and the omarchy commands. Needs bash, jq, python3, and Node.js 22 or +# newer; with qrencode installed, the QR code is checked too. +# +# tests/run.sh +set -uo pipefail + +ROOT=$(cd "$(dirname "$0")/.." && pwd) +FAKE_CLI="$ROOT/tests/fake-varlatch" +# PATH without any real varlatch CLI, so "missing" means missing. +BASE_PATH=$(printf '%s' "$PATH" | tr ':' '\n' | while read -r dir; do + [ -n "$dir" ] && [ ! -x "$dir/varlatch" ] && printf '%s:' "$dir" +done) +BASE_PATH=${BASE_PATH%:} +BOOT=$(cat /proc/sys/kernel/random/boot_id 2>/dev/null || true) +HOMES=() +passed=0; failed=0 + +ok() { passed=$((passed + 1)); echo "ok $1"; } +not_ok() { + failed=$((failed + 1)); echo "FAIL $1" + [ -n "${2:-}" ] && printf '%s\n' "$2" | sed 's/^/ /' + return 0 +} +# check