Skip to content

fix(BUG-021+BUG-022): pre-export DOTFILES_REPO_DIR + race-free healthcheck probe (cross-OS)#87

Merged
mlorentedev merged 1 commit into
mainfrom
fix/BUG-021-022-pre-export-and-probe-race
May 21, 2026
Merged

fix(BUG-021+BUG-022): pre-export DOTFILES_REPO_DIR + race-free healthcheck probe (cross-OS)#87
mlorentedev merged 1 commit into
mainfrom
fix/BUG-021-022-pre-export-and-probe-race

Conversation

@mlorentedev
Copy link
Copy Markdown
Owner

@mlorentedev mlorentedev commented May 21, 2026

Summary

Two micro-fixes surfaced by user's post-merge setup-windows.ps1 run output:

```
doctor sec env-vars: [warn] DOTFILES_REPO_DIR unset; default would be applied with -Fix
healthcheck sec 4: FAIL: claude-mem hook path resolution FAILED (BUG-015)
healthcheck sec 12: FAIL: diff-check.ps1 exited with code 2 (setup error)
```

BUG-021: pre-export DOTFILES_REPO_DIR in setup before doctor/healthcheck

BUG-020 (PR #86) added the `DOTFILES_REPO_DIR` export to `profile.ps1` + `.bashrc` + `.zshrc`. But the shell running setup already has the OLD profile loaded — doctor + diff-check see the var unset until next shell restart. Mirror the same pre-export pattern as SCRIPTS_DIR / GEMINI_HOME / etc.

Cross-OS: `setup-linux.sh` line 952-954 had the same gap (pre-exports GEMINI_HOME/COPILOT_HOME/OPENCODE_HOME but not DOTFILES_REPO_DIR). Both setup scripts fixed in this PR.

BUG-022: healthcheck BUG-015 probe races via break; }; done

The probe added by BUG-015 (PR #81) uses the SAME race-prone cascade pattern that BUG-017 patched away in the upstream hooks. From Windows pwsh-spawned bash, the EPIPE race fires on the probe itself → spurious FAIL even when the install is healthy. Apply the same Option A `done | head -n1` to make the probe race-free.

Cross-OS: healthcheck.sh probe (line 201) has the same pattern; race is silent on Linux due to SIGPIPE handling but worth fixing for consistency.

Test plan

  • `bash -n setup-linux.sh scripts/healthcheck.sh` → OK
  • PowerShell AST + PSScriptAnalyzer clean on `.ps1` files
  • ASCII-only check passes
  • Empirical probe (Bash subprocess) returns valid `_P` path
  • CI green
  • Post-merge re-run setup: doctor reports 10/10 ok (no warn), healthcheck sec 4 BUG-015 PASS, healthcheck sec 12 returns exit 0 or 1 (no setup error)

Diff

```
scripts/healthcheck.ps1 | 7 ++++++-
scripts/healthcheck.sh | 9 +++++++--
setup-linux.sh | 4 ++++
setup-windows.ps1 | 14 ++++++++++----
4 files changed, 27 insertions(+), 7 deletions(-)
```

Below spec-gate threshold (27 LOC). Skip SDD.

Companion

…check probe (cross-OS)

Two micro-fixes surfaced by user's post-merge setup run:

## BUG-021: doctor + diff-check warn/fail when profile hasn't reloaded

BUG-020 (PR #86) added the DOTFILES_REPO_DIR export to profile.ps1 +
.bashrc + .zshrc, but the shell already running setup has the OLD
profile loaded in memory. doctor + diff-check (invoked by healthcheck
sec 12) see the var unset until the user opens a fresh shell.

Fix: pre-export DOTFILES_REPO_DIR in setup-{windows.ps1,linux.sh}
RIGHT BEFORE invoking doctor/healthcheck. Same pre-export pattern as
SCRIPTS_DIR / GEMINI_HOME / COPILOT_HOME / OPENCODE_HOME.

## BUG-022: healthcheck BUG-015 probe itself races via `break; }; done`

The probe added by BUG-015 (PR #81) to detect upstream hook resolution
failures uses the SAME `{ printf; ls; printf; } | while ... break`
cascade pattern that BUG-017 patched in the upstream hooks themselves.
The probe hits the EPIPE race when invoked from Windows pwsh-spawned
bash (Git Bash subprocess sandbox), reporting false-positive FAIL even
when the install is healthy.

Fix: apply the same Option A `done | head -n1` to the probe in both
healthcheck.sh and healthcheck.ps1. The probe now drains the upstream
pipe fully, then head -n1 takes the first match. No EPIPE.

Note: on Linux, SIGPIPE is silent so the race rarely fires, but cross-OS
parity with the Windows fix matters for consistency.

Combined diff: 27 LOC (14 setup-windows.ps1 + 4 setup-linux.sh + 7
healthcheck.ps1 + 9 healthcheck.sh + small minus markers). Below
spec-gate threshold (50 LOC). Skip SDD per "mechanical cross-OS mirror"
rule.

Empirical post-fix behavior:
- doctor sec env-vars: 10/10 ok (DOTFILES_REPO_DIR no longer warn)
- healthcheck sec 4 BUG-015: PASS reports actual resolved path
  (no spurious FAIL)
- healthcheck sec 12 diff-check: exit 0 or 1 (real drift state), no
  more exit 2 "setup error"

Cross-OS scope justified: setup-linux.sh had the same gap (export block
at line 950-954); healthcheck.sh probe had the same race-prone pattern
(line 201). Both fixed in this PR to keep cross-OS contract symmetric.
@mlorentedev mlorentedev merged commit 5a870be into main May 21, 2026
7 checks passed
@mlorentedev mlorentedev deleted the fix/BUG-021-022-pre-export-and-probe-race branch May 21, 2026 20:06
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