Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions scripts/obs-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ if ! command_exists obsidian; then
fi

# Connectivity check: verify GUI is running
if ! obsidian --no-sandbox vault --vault "$OBS_VAULT" >/dev/null 2>&1; then
log_error "Cannot reach Obsidian GUI. Is Obsidian running?"
log_info "Start Obsidian or run: obsidian --no-sandbox &"
exit 2
fi
obsidian --no-sandbox vault --vault "$OBS_VAULT" >/dev/null 2>&1 || fail_obsidian_gui

exec obsidian --no-sandbox "$@" --vault "$OBS_VAULT"
14 changes: 14 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,17 @@ unset_var() {
unset "$1" 2>/dev/null || true
}

# Obsidian helpers

# Emits the canonical "Cannot reach Obsidian GUI" error + start hint, then
# exits 2. Caller owns the probe shape; this owns the user-facing message
# so it stays in one place across obs-cli.sh and vault-health.sh.
# Input: none
# Output: error log + info hint to stderr/stdout, then exit 2
# Usage: <your_probe> || fail_obsidian_gui
fail_obsidian_gui() {
log_error "Cannot reach Obsidian GUI. Is Obsidian running?"
log_info "Start Obsidian or run: obsidian --no-sandbox &"
exit 2
}

6 changes: 1 addition & 5 deletions scripts/vault-health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ if ! command_exists obsidian; then
fi

# Test CLI connectivity by running a simple command
if ! obsidian_cmd vault 2>/dev/null | grep -q .; then
log_error "Cannot reach Obsidian GUI. Is Obsidian running?"
echo " Hint: Start Obsidian or run: obsidian --no-sandbox &"
exit 2
fi
obsidian_cmd vault 2>/dev/null | grep -q . || fail_obsidian_gui
pass "Obsidian CLI connected to vault '$VAULT_NAME'"

if [ -d "$VAULT_DIR" ]; then
Expand Down
8 changes: 6 additions & 2 deletions tests/obs-cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ setup() {
grep -q 'command_exists obsidian' "$SCRIPTS_DIR/obs-cli.sh"
}

@test "obs-cli.sh exits 2 when GUI not running" {
grep -q 'exit 2' "$SCRIPTS_DIR/obs-cli.sh"
@test "obs-cli.sh exits 2 when GUI not running (via fail_obsidian_gui)" {
# After the AUDIT-005 extraction, the canonical "exit 2 + error message"
# lives in utils.sh::fail_obsidian_gui. obs-cli.sh delegates via `|| fail_obsidian_gui`.
grep -q 'fail_obsidian_gui' "$SCRIPTS_DIR/obs-cli.sh"
grep -q '^fail_obsidian_gui()' "$SCRIPTS_DIR/utils.sh"
grep -q 'exit 2' "$SCRIPTS_DIR/utils.sh"
}

@test "obs-cli.sh passes --no-sandbox flag" {
Expand Down
Loading