refactor: extract fail_obsidian_gui() helper into utils.sh (AUDIT-005 polish)#95
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
obs-cli.shandvault-health.shboth inlined the same 4-line block for "GUI not running" — error + hint +exit 2. Extracted just the error-emitter intoutils.sh::fail_obsidian_gui(); each caller still owns its own probe shape (their probes are genuinely different).obs-cli.ps1as well, but verify-before-act shows there's noutils.ps1to share into andobs-cli.ps1is the only Windows caller — extracting for one caller would be net-negative. PS1 side stays inline (correct per bootstrap-vs-logic rule).Diff shape
scripts/utils.shfail_obsidian_gui()+ header comment, last function in file)scripts/obs-cli.sh<probe> || fail_obsidian_gui)scripts/vault-health.shtests/obs-cli.batsNet: +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
shellcheckon 3 source files → exit 0 (only pre-existing info-warnings)bash -non all 3 source filesbats tests/utils.bats tests/obs-cli.bats tests/obs-cli-ps1.bats→ 62/62 PASSbats tests/healthcheck.bats tests/install-precommit.bats tests/knowledge-crystallize.bats tests/load-secrets.bats tests/setup-windows.bats tests/verify-setup.bats→ all PASSobs-cliandvault-health.shstill exit 2 with the same message when Obsidian is not running.