Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.
Shell agent-teamsai-agentai-automationanthropicautonomous-agentawsbusiness-operationsclaudeclaude-codeclaude-code-plugindevopsecommerceinbox-zeroklaviyomarketingmcpmorning-briefingpr-automationshopifyterminal
fix(gog): resolve the account and unlock the keyring before every call (#928)
Aurora Capital5c719593dad5
diff --git a/claude-ops/bin/ops-autofix b/claude-ops/bin/ops-autofixindex a9b68579..84c92167 100755--- a/claude-ops/bin/ops-autofix+++ b/claude-ops/bin/ops-autofix@@ -214,17 +214,18 @@ fix_channel_health() {fi# ── Email (gog): auth'd but API broken ──+ # shellcheck source=../lib/gog-account.sh+ . "$(cd "$(dirname "$0")/.." && pwd)/lib/gog-account.sh"if command -v gog >/dev/null 2>&1; then- GOG_AUTH=$(gog auth status 2>&1)- if echo "$GOG_AUTH" | grep -qi "authenticated\|logged in\|valid"; then- GOG_TEST=$(gog gmail labels list --json 2>/dev/null | head -5)+ if ops_gog_ready; then+ GOG_TEST=$(gog gmail labels list -a "$OPS_GOG_ACCOUNT" --json 2>/dev/null | head -5)if [ -z "$GOG_TEST" ] || echo "$GOG_TEST" | grep -qi "error\|failed"; then- log_fail "gog-health: authenticated but Gmail API failing (token may need refresh — run gog auth login)"+ log_fail "gog-health: $OPS_GOG_ACCOUNT resolves but Gmail API failing (token may need refresh — run gog auth add $OPS_GOG_ACCOUNT)"else- log_skip "gog-health: email working"+ log_skip "gog-health: email working ($OPS_GOG_ACCOUNT)"fielse- log_skip "gog-health: not authenticated"+ log_fail "gog-health: $OPS_GOG_NOTE"fifidiff --git a/claude-ops/bin/ops-dash b/claude-ops/bin/ops-dashindex 60375420..a08f75d6 100755--- a/claude-ops/bin/ops-dash+++ b/claude-ops/bin/ops-dash@@ -441,9 +441,10 @@ TOTAL_PROBES=13# 13) Calendar — today's events across ALL calendars (PR #286 wired into dash)(CAL_JSON='{"configured":false,"events":[]}'- if command -v gog &>/dev/null; then- # Probe auth first — gog calendar exits non-zero or returns error if no auth- RAW=$(gog calendar events --all --today -j --sort start --no-input 2>/dev/null || echo '')+ # shellcheck source=../lib/gog-account.sh+ . "${PLUGIN_ROOT}/lib/gog-account.sh"+ if ops_gog_ready; then+ RAW=$(gog calendar events -a "$OPS_GOG_ACCOUNT" --all --today -j --sort start --no-input 2>/dev/null || echo '')if [[ -n "$RAW" ]] && echo "$RAW" | jq -e '.events' >/dev/null 2>&1; thenCAL_JSON=$(echo "$RAW" | jq '{configured: true,@@ -456,10 +457,10 @@ TOTAL_PROBES=13}))}' 2>/dev/null || echo '{"configured":true,"events":[]}')else- CAL_JSON='{"configured":false,"events":[],"note":"gog not authenticated"}'+ CAL_JSON='{"configured":true,"events":[]}'fielse- CAL_JSON='{"configured":false,"events":[],"note":"gog CLI not installed"}'+ CAL_JSON=$(jq -nc --arg n "$OPS_GOG_NOTE" '{configured:false,events:[],note:$n}')fiecho "$CAL_JSON" > "$TMPDIR_DASH/calendar.json"touch "$TMPDIR_DASH/done_calendar"diff --git a/claude-ops/bin/ops-inbox-live-watch.sh b/claude-ops/bin/ops-inbox-live-watch.shindex 0ff5bdcd..dc64898a 100755--- a/claude-ops/bin/ops-inbox-live-watch.sh+++ b/claude-ops/bin/ops-inbox-live-watch.sh@@ -26,11 +26,17 @@ command -v gog >/dev/null 2>&1 || { echo "ops-inbox-live-watch: gog not founcommand -v python3 >/dev/null 2>&1 || { echo "ops-inbox-live-watch: python3 not found on PATH" >&2; exit 2; }GMAIL_ACCOUNT="${GMAIL_ACCOUNT:-${GOG_ACCOUNT:-}}"-if [ -z "$GMAIL_ACCOUNT" ]; then- GMAIL_ACCOUNT="$(gog whoami 2>/dev/null | head -1 | grep -oE '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+' || true)"+# gog rejects every call without an explicit --account once more than one token+# is stored, and again when the keyring is locked. lib/gog-account.sh resolves+# both and reports the real reason instead of a silent empty snapshot.+# shellcheck source=../lib/gog-account.sh+. "$(cd "$(dirname "$0")/.." && pwd)/lib/gog-account.sh"+if ! ops_gog_ready; then+ echo "ops-inbox-live-watch: $OPS_GOG_NOTE" >&2+ exit 2fi-ACCT_ARGS=()-[ -n "$GMAIL_ACCOUNT" ] && ACCT_ARGS=(-a "$GMAIL_ACCOUNT")+GMAIL_ACCOUNT="$OPS_GOG_ACCOUNT"+ACCT_ARGS=(-a "$GMAIL_ACCOUNT")SEEN="$(mktemp "${TMPDIR:-/tmp}/.ops-inbox-seen-ids.XXXXXX")"trap 'rm -f "$SEEN" "${SEEN}.err"' EXITdiff --git a/claude-ops/bin/ops-inbox-scan b/claude-ops/bin/ops-inbox-scanindex ef7f0f17..fb11f143 100755--- a/claude-ops/bin/ops-inbox-scan+++ b/claude-ops/bin/ops-inbox-scan@@ -347,8 +347,17 @@ GMAIL_OK=0if [ "$DO_EMAIL" = 1 ]; thenGMAIL_JSON_FILE="$(mktemp "${TMPDIR:-/tmp}/ois-gmail.XXXXXX")"trap 'rm -f "$GMAIL_JSON_FILE" "${OIS_SENDLOG_FILE:-}"' EXIT+ # gog rejects a bare call once more than one token is stored, and again when+ # the keyring is locked. Resolve the account and unlock first, so a config+ # problem never reads as an empty inbox.+ # shellcheck source=../lib/gog-account.sh+ . "$(cd "$(dirname "$0")/.." && pwd)/lib/gog-account.sh"ACCT_ARGS=()- [ -n "$GMAIL_ACCOUNT" ] && ACCT_ARGS=(-a "$GMAIL_ACCOUNT")+ if ops_gog_ready; then+ ACCT_ARGS=(-a "$OPS_GOG_ACCOUNT")+ else+ GMAIL_ERR="$OPS_GOG_NOTE"+ fi# FULL INBOX, always. The working set is "not archived" -- i.e. everything# still carrying the INBOX label -- never "unread", and never a recency slice.# This used to be `in:inbox newer_than:${DAYS}d --max 30`, which silently hiddiff --git a/claude-ops/bin/ops-inbox-zero b/claude-ops/bin/ops-inbox-zeroindex 3f5f813e..a20eea5b 100755--- a/claude-ops/bin/ops-inbox-zero+++ b/claude-ops/bin/ops-inbox-zero@@ -138,12 +138,18 @@ log "scan OK → $SCAN_OUT ($(wc -c <"$SCAN_OUT" | tr -d ' ') bytes)"GMAIL_OUT="/tmp/gmail-inbox.json"if [ "$DO_EMAIL" = 1 ]; thenlog "step 3/9 — gog gmail search in:inbox"- if ! gog gmail search "in:inbox" --max 40 -j --results-only --no-input > "$GMAIL_OUT" 2>"$GMAIL_OUT.err"; then- log "gmail search failed (likely keyring/auth) — see $GMAIL_OUT.err"+ # shellcheck source=../lib/gog-account.sh+ . "$(cd "$(dirname "$0")/.." && pwd)/lib/gog-account.sh"+ if ! ops_gog_ready; then+ log "gmail unavailable — $OPS_GOG_NOTE"+ log "agent must reauth via email-domain-ops → references/gog-oauth-cdp-reauth.md"+ DO_EMAIL=0+ elif ! gog gmail search -a "$OPS_GOG_ACCOUNT" "in:inbox" --max 40 -j --results-only --no-input > "$GMAIL_OUT" 2>"$GMAIL_OUT.err"; then+ log "gmail search failed for $OPS_GOG_ACCOUNT — see $GMAIL_OUT.err"log "agent must reauth via email-domain-ops → references/gog-oauth-cdp-reauth.md"DO_EMAIL=0else- log "gmail scan OK → $GMAIL_OUT ($(wc -c <"$GMAIL_OUT" | tr -d ' ') bytes)"+ log "gmail scan OK ($OPS_GOG_ACCOUNT) → $GMAIL_OUT ($(wc -c <"$GMAIL_OUT" | tr -d ' ') bytes)"fifidiff --git a/claude-ops/bin/ops-setup-preflight b/claude-ops/bin/ops-setup-preflightindex e5febd42..1057c56a 100755--- a/claude-ops/bin/ops-setup-preflight+++ b/claude-ops/bin/ops-setup-preflight@@ -145,12 +145,14 @@ cred_get() {{# gog/Gmail probe- if command -v gog &>/dev/null; then- gog auth status 2>&1 > "$OUT/gog-auth.txt"- gog gmail labels list --json 2>/dev/null | head -5 > "$OUT/gog-gmail.json" || echo '{"error":"failed"}' > "$OUT/gog-gmail.json"- gog calendar calendars --json 2>/dev/null | head -30 > "$OUT/gog-cal.json" || echo '{"error":"failed"}' > "$OUT/gog-cal.json"+ # shellcheck source=../lib/gog-account.sh+ . "$(cd "$(dirname "$0")/.." && pwd)/lib/gog-account.sh"+ if ops_gog_ready; then+ echo "gog=ok account=$OPS_GOG_ACCOUNT" > "$OUT/gog-auth.txt"+ gog gmail labels list -a "$OPS_GOG_ACCOUNT" --json 2>/dev/null | head -5 > "$OUT/gog-gmail.json" || echo '{"error":"failed"}' > "$OUT/gog-gmail.json"+ gog calendar calendars -a "$OPS_GOG_ACCOUNT" --json 2>/dev/null | head -30 > "$OUT/gog-cal.json" || echo '{"error":"failed"}' > "$OUT/gog-cal.json"else- echo "gog=missing" > "$OUT/gog-auth.txt"+ echo "gog=unavailable: $OPS_GOG_NOTE" > "$OUT/gog-auth.txt"fi} &diff --git a/claude-ops/bin/ops-unread b/claude-ops/bin/ops-unreadindex c70c50f0..29d9de4e 100755--- a/claude-ops/bin/ops-unread+++ b/claude-ops/bin/ops-unread@@ -36,25 +36,14 @@ elsefi# ── Email via gog ──-GMAIL_ACCT="${GMAIL_ACCOUNT:-}"-if command -v gog &>/dev/null; then- # Auto-detect account if not set- if [ -z "$GMAIL_ACCT" ]; then- GMAIL_ACCT=$(gog gmail search -j --results-only --no-input --max 1 "in:inbox" 2>/dev/null | python3 -c "-import json, sys-try:- data = json.loads(sys.stdin.read())- # gog worked without -a, so default account is fine- print('auto')-except:- print('')-" 2>/dev/null || echo "")- fi+# gog needs BOTH an explicit --account (any multi-token store rejects a bare+# call) and an unlocked keyring. lib/gog-account.sh resolves both and reports+# the real reason on failure instead of a blanket "not authenticated".+# shellcheck source=../lib/gog-account.sh+. "$(cd "$(dirname "$0")/.." && pwd)/lib/gog-account.sh"- if [ -n "$GMAIL_ACCT" ]; then- ACCT_FLAG=""- [ "$GMAIL_ACCT" != "auto" ] && ACCT_FLAG="-a $GMAIL_ACCT"- EMAIL_COUNT=$(gog gmail search $ACCT_FLAG -j --results-only --no-input --max 50 "in:inbox" 2>/dev/null | python3 -c "+if ops_gog_ready; then+ EMAIL_COUNT=$(gog gmail search -a "$OPS_GOG_ACCOUNT" -j --results-only --no-input --max 50 "in:inbox" 2>/dev/null | python3 -c "import json, systry:data = json.loads(sys.stdin.read())@@ -63,13 +52,12 @@ try:except:print(0)" 2>/dev/null || echo "0")- [[ "$EMAIL_COUNT" =~ ^[0-9]+$ ]] || EMAIL_COUNT="0"- RESULT=$(echo "$RESULT" | jq --argjson c "$EMAIL_COUNT" '.channels.email = {"inbox_count": $c, "available": true}')- else- RESULT=$(echo "$RESULT" | jq '.channels.email = {"inbox_count": 0, "available": false, "note": "gog not authenticated — run: gog gmail auth"}')- fi+ [[ "$EMAIL_COUNT" =~ ^[0-9]+$ ]] || EMAIL_COUNT="0"+ RESULT=$(echo "$RESULT" | jq --argjson c "$EMAIL_COUNT" --arg a "$OPS_GOG_ACCOUNT" \+ '.channels.email = {"inbox_count": $c, "available": true, "account": $a}')else- RESULT=$(echo "$RESULT" | jq '.channels.email = {"inbox_count": 0, "available": false, "note": "gog not installed — install gogcli: `brew install gogcli` (macOS/Linuxbrew), `winget install -e --id steipete.gogcli` (Windows), or see https://github.com/steipete/gogcli"}')+ RESULT=$(echo "$RESULT" | jq --arg n "$OPS_GOG_NOTE" \+ '.channels.email = {"inbox_count": 0, "available": false, "note": $n}')fi# ── Slack — multi-workspace support ──diff --git a/claude-ops/bin/ops-voice b/claude-ops/bin/ops-voiceindex d5a642d3..ad472131 100755--- a/claude-ops/bin/ops-voice+++ b/claude-ops/bin/ops-voice@@ -688,11 +688,12 @@ cmd_join() {esacdone- command -v gog >/dev/null 2>&1 || {- emit_err "join requires gog CLI (calendar lookup)"; exit 1; }+ # shellcheck source=../lib/gog-account.sh+ . "$(cd "$(dirname "$0")/.." && pwd)/lib/gog-account.sh"+ ops_gog_ready || { emit_err "join requires gog calendar access: $OPS_GOG_NOTE"; exit 1; }local raw- raw="$(gog calendar events --all --today -j --sort start --no-input 2>/dev/null)"+ raw="$(gog calendar events -a "$OPS_GOG_ACCOUNT" --all --today -j --sort start --no-input 2>/dev/null)"[[ -z "$raw" ]] && { emit_err "gog returned no calendar data"; exit 1; }# Build a parallel TSV of (idx, start_epoch, end_epoch) using the portablediff --git a/claude-ops/lib/gog-account.sh b/claude-ops/lib/gog-account.shnew file mode 100644index 00000000..87863fbb--- /dev/null+++ b/claude-ops/lib/gog-account.sh@@ -0,0 +1,125 @@+#!/usr/bin/env bash+# lib/gog-account.sh — resolve the gog account + unlock its token store.+#+# Why this exists: `gog` refuses every command with+# "missing --account (or set GOG_ACCOUNT, ...)"+# as soon as more than one token is stored, and it refuses again with+# "no TTY available for keyring file backend password prompt"+# when the keyring password is not in the environment. Both failures exit+# non-zero with a message on stderr, which callers used to swallow into+# "gog not authenticated" — a checker that cannot measure reading as a clean+# negative result. Source this file instead of guessing.+#+# Usage:+# source "$PLUGIN_ROOT/lib/gog-account.sh"+# if ops_gog_ready; then+# gog gmail search -a "$OPS_GOG_ACCOUNT" ...+# else+# echo "$OPS_GOG_NOTE"+# fi+#+# Resolution order for the account:+# 1. $GOG_ACCOUNT / $GMAIL_ACCOUNT+# 2. .gmail_account in preferences.json+# 3. the account marked "default" by `gog auth list`+# 4. the only stored oauth account, if there is exactly one+#+# Resolution order for the keyring password (only when unset):+# 1. $GOG_KEYRING_PASSWORD+# 2. $OPS_GOG_ENV_FILE+# 3. $HOME/.config/claude-ops/gog.env+# 4. $HOME/.env-load.sh (sourced in a subshell, value exported back)+#+# No secret is ever printed; only the account address is echoed.++OPS_GOG_ACCOUNT=""+OPS_GOG_NOTE=""++_ops_gog_load_keyring_password() {+ [ -n "${GOG_KEYRING_PASSWORD:-}" ] && return 0++ local f+ for f in "${OPS_GOG_ENV_FILE:-}" "$HOME/.config/claude-ops/gog.env"; do+ [ -n "$f" ] && [ -r "$f" ] || continue+ # shellcheck disable=SC1090+ local v+ v=$(set -a; . "$f" >/dev/null 2>&1; printf '%s' "${GOG_KEYRING_PASSWORD:-}")+ if [ -n "$v" ]; then+ export GOG_KEYRING_PASSWORD="$v"+ return 0+ fi+ done++ if [ -r "$HOME/.env-load.sh" ]; then+ local v+ v=$(. "$HOME/.env-load.sh" >/dev/null 2>&1; printf '%s' "${GOG_KEYRING_PASSWORD:-}")+ if [ -n "$v" ]; then+ export GOG_KEYRING_PASSWORD="$v"+ return 0+ fi+ fi++ return 1+}++_ops_gog_resolve_account() {+ local acct="${GOG_ACCOUNT:-${GMAIL_ACCOUNT:-}}"++ if [ -z "$acct" ]; then+ local prefs="${PREFS_PATH:-${CLAUDE_PLUGIN_DATA_DIR:-$HOME/.claude/plugins/data/ops-ops-marketplace}/preferences.json}"+ if [ -r "$prefs" ] && command -v jq >/dev/null 2>&1; then+ acct=$(jq -r '.gmail_account // .channels.email.account // empty' "$prefs" 2>/dev/null)+ fi+ fi++ if [ -z "$acct" ]; then+ local list+ list=$(gog auth list 2>/dev/null) || list=""+ if [ -n "$list" ]; then+ acct=$(printf '%s\n' "$list" | awk -F'\t' '$2=="default"{print $1; exit}')+ if [ -z "$acct" ]; then+ local n+ n=$(printf '%s\n' "$list" | awk -F'\t' '$NF=="oauth"' | wc -l | tr -d ' ')+ [ "$n" = "1" ] && acct=$(printf '%s\n' "$list" | awk -F'\t' '$NF=="oauth"{print $1; exit}')+ fi+ fi+ fi++ printf '%s' "$acct"+}++# ops_gog_ready — 0 when gog can actually run a call, non-zero otherwise.+# Sets OPS_GOG_ACCOUNT on success, OPS_GOG_NOTE with the real reason on failure.+ops_gog_ready() {+ if ! command -v gog >/dev/null 2>&1; then+ OPS_GOG_NOTE="gog CLI not installed"+ return 1+ fi++ OPS_GOG_ACCOUNT=$(_ops_gog_resolve_account)+ if [ -z "$OPS_GOG_ACCOUNT" ]; then+ OPS_GOG_NOTE="no gog account — run: gog auth add <email> --services gmail,calendar"+ return 1+ fi++ _ops_gog_load_keyring_password || true++ local probe+ probe=$(gog gmail search -a "$OPS_GOG_ACCOUNT" -j --results-only --no-input --max 1 "in:inbox" 2>&1)+ case "$probe" in+ *"no TTY available"*|*GOG_KEYRING_PASSWORD*)+ OPS_GOG_NOTE="gog token store locked — set GOG_KEYRING_PASSWORD (or \$HOME/.config/claude-ops/gog.env)"+ return 1+ ;;+ *"missing --account"*)+ OPS_GOG_NOTE="gog rejected account '$OPS_GOG_ACCOUNT'"+ return 1+ ;;+ *"invalid_grant"*|*"token expired"*|*"unauthorized"*)+ OPS_GOG_NOTE="gog token for $OPS_GOG_ACCOUNT expired — re-run: gog auth add $OPS_GOG_ACCOUNT"+ return 1+ ;;+ esac++ return 0+}diff --git a/claude-ops/scripts/crsproxy-reauth/test_lease_cooldown.py b/claude-ops/scripts/crsproxy-reauth/test_lease_cooldown.pyindex 765e7186..740734a3 100644--- a/claude-ops/scripts/crsproxy-reauth/test_lease_cooldown.py+++ b/claude-ops/scripts/crsproxy-reauth/test_lease_cooldown.py@@ -43,6 +43,24 @@ def test_lease_stale_seconds():print("PASS: Lease stale threshold is 600 seconds (10 min)")+def _lease_race_worker(lease_path_str, q):+ """Child-process body for the concurrency test.++ MUST stay at module level. Under the `spawn` start method (the default on+ macOS since Python 3.8, and on every platform from 3.14) the target is+ pickled by qualified name, and a function nested inside the test raises+ "Can't pickle local object" before a single racer ever runs — the guard+ then fails for a reason that has nothing to do with the lease.+ """+ sys.path.insert(0, str(Path(__file__).resolve().parent))+ import bu_reauth as br++ br.LEASE_FILE = Path(lease_path_str)+ br.LEGACY_LEASE_FILE = Path(lease_path_str + ".legacy")+ # max_wait=0 so a loser returns immediately instead of polling.+ q.put(br.acquire_lease("claude", max_wait=0))++def test_acquire_lease_is_atomic_under_concurrency():"""Only ONE of N concurrent acquirers may win the lease.@@ -53,24 +71,20 @@ def test_acquire_lease_is_atomic_under_concurrency():"""import multiprocessing- def _worker(lease_path_str, q):- sys.path.insert(0, str(Path(__file__).resolve().parent))- import bu_reauth as br- br.LEASE_FILE = Path(lease_path_str)- br.LEGACY_LEASE_FILE = Path(lease_path_str + ".legacy")- # max_wait=0 so a loser returns immediately instead of polling.- q.put(br.acquire_lease("claude", max_wait=0))-with tempfile.TemporaryDirectory() as tmpdir:lease_path = str(Path(tmpdir) / "lease.json")q = multiprocessing.Queue()- procs = [multiprocessing.Process(target=_worker, args=(lease_path, q))+ procs = [multiprocessing.Process(target=_lease_race_worker, args=(lease_path, q))for _ in range(8)]for pr in procs:pr.start()for pr in procs:pr.join(30)- results = [q.get() for _ in range(len(procs))]+ # Collect before joining is impossible here (queue is drained after),+ # so assert every child actually ran rather than trusting a short queue.+ for pr in procs:+ assert pr.exitcode == 0, f"racer exited {pr.exitcode}, not 0"+ results = [q.get(timeout=30) for _ in range(len(procs))]winners = sum(1 for r in results if r is True)assert winners == 1, f"Expected exactly 1 winner, got {winners} of {len(results)}"diff --git a/claude-ops/tests/run-all.sh b/claude-ops/tests/run-all.shindex 5c1d92f0..45ebb0fa 100755--- a/claude-ops/tests/run-all.sh+++ b/claude-ops/tests/run-all.sh@@ -37,6 +37,7 @@ run_suite "$TESTS_DIR/test-skills-lint.sh"run_suite "$TESTS_DIR/test-agents-lint.sh"run_suite "$TESTS_DIR/test-compact-discovery.sh"run_suite "$TESTS_DIR/test-bin-scripts.sh"+run_suite "$TESTS_DIR/test-gog-account.sh"run_suite "$TESTS_DIR/test-ops-speedup.sh"run_suite "$TESTS_DIR/test-ops-update-stale-clone.sh"run_suite "$TESTS_DIR/test-ops-status.sh"diff --git a/claude-ops/tests/test-gog-account.sh b/claude-ops/tests/test-gog-account.shnew file mode 100755index 00000000..de01346d--- /dev/null+++ b/claude-ops/tests/test-gog-account.sh@@ -0,0 +1,116 @@+#!/usr/bin/env bash+# test-gog-account.sh — lib/gog-account.sh must distinguish "cannot measure"+# from "nothing there".+#+# Regression: bin/ops-unread probed `gog gmail search` with no --account. Any+# store holding more than one token answers "missing --account" on stderr and+# the caller swallowed it into "gog not authenticated" — an authenticated+# mailbox rendered identically to a broken one on the dashboard. Same shape for+# a locked keyring ("no TTY available ... GOG_KEYRING_PASSWORD").+set -uo pipefail++LIB="$(cd "$(dirname "$0")/.." && pwd)/lib/gog-account.sh"+pass=0+fail=0++ok() {+ echo " PASS: $1"+ pass=$((pass + 1))+}+no() {+ echo " FAIL: $1"+ fail=$((fail + 1))+}++BIN_DIR=$(mktemp -d)+PREFS_DIR=$(mktemp -d)+trap 'rm -rf "$BIN_DIR" "$PREFS_DIR"' EXIT++mk_gog() { # $1 = behaviour+ cat >"$BIN_DIR/gog" <<EOF+#!/usr/bin/env bash+BEHAVIOUR="$1"+case "\$1 \$2" in+ "auth list")+ printf '[email protected]\t\tservice-account\t2026-01-01\tservice_account\n'+ printf '[email protected]\tdefault\tgmail,calendar\t2026-01-01\toauth\n'+ exit 0+ ;;+esac+# every real call requires an explicit -a; a bare call is the bug under test+case " \$* " in+ *" -a "*) ;;+ *) echo "missing --account (or set GOG_ACCOUNT, ...)" >&2; exit 1 ;;+esac+case "\$BEHAVIOUR" in+ locked) echo "gmail options: token source: no TTY available for keyring file backend password prompt; set GOG_KEYRING_PASSWORD" >&2; exit 1 ;;+ expired) echo "oauth2: invalid_grant" >&2; exit 1 ;;+ ok) echo '[]'; exit 0 ;;+esac+EOF+ chmod +x "$BIN_DIR/gog"+}++run_probe() { # runs ops_gog_ready in a clean shell, echoes "rc|account|note"+ env -i HOME="$PREFS_DIR" PATH="$BIN_DIR:/usr/bin:/bin:/usr/local/bin:/opt/homebrew/bin" \+ PREFS_PATH="$PREFS_DIR/preferences.json" \+ bash -c ". '$LIB'; if ops_gog_ready; then echo \"0|\$OPS_GOG_ACCOUNT|\"; else echo \"1|\$OPS_GOG_ACCOUNT|\$OPS_GOG_NOTE\"; fi"+}++echo "gog-account resolver"++# 1. authenticated store with several tokens must resolve, not report "not authenticated"+mk_gog ok+echo '{"gmail_account":"[email protected]"}' >"$PREFS_DIR/preferences.json"+out=$(run_probe)+[[ "$out" == 0\|[email protected]\|* ]] &&+ ok "multi-token store resolves the account from preferences" ||+ no "multi-token store should resolve, got: $out"++# 2. no preferences → falls back to the account gog marks default+mk_gog ok+rm -f "$PREFS_DIR/preferences.json"+out=$(run_probe)+[[ "$out" == 0\|[email protected]\|* ]] &&+ ok "falls back to the gog default account" ||+ no "expected default-account fallback, got: $out"++# 3. locked keyring must NOT read as an empty/clean mailbox+mk_gog locked+echo '{"gmail_account":"[email protected]"}' >"$PREFS_DIR/preferences.json"+out=$(run_probe)+[[ "$out" == 1\|* && "$out" == *GOG_KEYRING_PASSWORD* ]] &&+ ok "locked keyring reports the lock, not a clean result" ||+ no "locked keyring must surface GOG_KEYRING_PASSWORD, got: $out"++# 4. expired token names re-auth, and never claims success+mk_gog expired+out=$(run_probe)+[[ "$out" == 1\|* && "$out" == *expired* ]] &&+ ok "expired token reports re-auth" ||+ no "expired token should report re-auth, got: $out"++# 5. gog absent is its own distinct note+out=$(env -i HOME="$PREFS_DIR" PATH="/usr/bin:/bin" PREFS_PATH="$PREFS_DIR/preferences.json" \+ bash -c ". '$LIB'; ops_gog_ready; echo \"\$OPS_GOG_NOTE\"")+[[ "$out" == *"not installed"* ]] &&+ ok "missing gog binary is distinguished from missing auth" ||+ no "expected 'not installed', got: $out"++# 6. no bin/ caller may invoke gog without an explicit account.+# Command position only: start of line, or after ( ! | && ; $( — so log+# strings and comments that merely mention "gog gmail search" don't trip it.+ROOT="$(cd "$(dirname "$0")/.." && pwd)"+offenders=$(grep -rnE '(^|[|&;!]|\$\()[[:space:]]*gog[[:space:]]+(gmail|calendar)[[:space:]]+[a-z]' "$ROOT/bin" 2>/dev/null |+ awk -F: '{ line=$0; sub(/^[^:]*:[0-9]*:/, "", line); if (line ~ /^[[:space:]]*#/) next; print }' |+ grep -v -- '-a ' | grep -v -- '--account' | grep -v 'ACCT_ARGS' || true)+if [ -z "$offenders" ]; then+ ok "no bin/ caller invokes gog without an account"+else+ no "gog called without an account:"+ echo "$offenders" | head -5+fi++echo ""+echo "Results: $pass passed, $fail failed"+[ "$fail" -eq 0 ]