Skip to content

refactor: extract fail_obsidian_gui() helper into utils.sh (AUDIT-005 polish)#95

Merged
mlorentedev merged 2 commits into
mainfrom
refactor/check-obsidian-gui-extract
May 22, 2026
Merged

refactor: extract fail_obsidian_gui() helper into utils.sh (AUDIT-005 polish)#95
mlorentedev merged 2 commits into
mainfrom
refactor/check-obsidian-gui-extract

Conversation

@mlorentedev
Copy link
Copy Markdown
Owner

Summary

  • obs-cli.sh and vault-health.sh both inlined the same 4-line block for "GUI not running" — error + hint + exit 2. Extracted just the error-emitter into utils.sh::fail_obsidian_gui(); each caller still owns its own probe shape (their probes are genuinely different).
  • Closes the last logic-class extraction item from AUDIT-005 polish. The audit's "-10 LOC across 3 files" estimate counted obs-cli.ps1 as well, but verify-before-act shows there's no utils.ps1 to share into and obs-cli.ps1 is the only Windows caller — extracting for one caller would be net-negative. PS1 side stays inline (correct per bootstrap-vs-logic rule).

Diff shape

File Change
scripts/utils.sh +14 (new fail_obsidian_gui() + header comment, last function in file)
scripts/obs-cli.sh -5/+1 (4-line block → <probe> || fail_obsidian_gui)
scripts/vault-health.sh -5/+1 (same)
tests/obs-cli.bats -2/+6 (test #47 now asserts both delegation AND canonical location)

Net: +10 LOC. Worse than the audit's -10 LOC estimate, but the test got stricter (was grep -q 'exit 2' obs-cli.sh — a literal-match assertion that would survive any refactor moving exit 2 elsewhere; now asserts the new SSOT in utils.sh).

Test plan

  • shellcheck on 3 source files → exit 0 (only pre-existing info-warnings)
  • bash -n on all 3 source files
  • bats tests/utils.bats tests/obs-cli.bats tests/obs-cli-ps1.bats → 62/62 PASS
  • bats tests/healthcheck.bats tests/install-precommit.bats tests/knowledge-crystallize.bats tests/load-secrets.bats tests/setup-windows.bats tests/verify-setup.bats → all PASS
  • Empirical: obs-cli and vault-health.sh still exit 2 with the same message when Obsidian is not running.

… polish)

obs-cli.sh and vault-health.sh both inlined a 4-line block to emit
'Cannot reach Obsidian GUI...' + 'Start Obsidian or run: ...' + exit 2
on GUI-probe failure. The message + exit code are the only shared bits;
each caller owns its own probe shape (obs-cli uses `obsidian --no-sandbox
vault --vault`, vault-health uses `obsidian_cmd vault | grep -q .`).

Extracted just the error-emitter into utils.sh as `fail_obsidian_gui()`.
Callers now do `<probe> || fail_obsidian_gui`, dropping 6 lines of
duplicated messaging across the two files. The audit's "-10 LOC across
3 files" estimate counted obs-cli.ps1 too — but that's the only Windows
caller and there's no utils.ps1 to share into, so it stays inline
(extracting for 1 caller would be net-negative).

Test invariant: tests/obs-cli.bats #47 rewritten to assert delegation
(grep `fail_obsidian_gui` in obs-cli.sh) AND canonical location (grep
`^fail_obsidian_gui()` + `exit 2` in utils.sh) — stricter than the
old `grep -q 'exit 2' obs-cli.sh` literal-match.

Closes the last logic-class extraction item from AUDIT-005 polish.
@mlorentedev mlorentedev merged commit 6e5b813 into main May 22, 2026
6 checks passed
@mlorentedev mlorentedev deleted the refactor/check-obsidian-gui-extract branch May 22, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant