Skip to content

fix(BUG-020): export DOTFILES_REPO_DIR in PowerShell profile (cross-OS parity)#86

Merged
mlorentedev merged 1 commit into
mainfrom
fix/BUG-020-dotfiles-repo-dir-windows-profile
May 21, 2026
Merged

fix(BUG-020): export DOTFILES_REPO_DIR in PowerShell profile (cross-OS parity)#86
mlorentedev merged 1 commit into
mainfrom
fix/BUG-020-dotfiles-repo-dir-windows-profile

Conversation

@mlorentedev
Copy link
Copy Markdown
Owner

@mlorentedev mlorentedev commented May 21, 2026

Summary

User's post-merge `setup-windows.ps1` run reported `FAIL: diff-check.ps1 exited with code 2 (setup error)` in healthcheck sec 12 (introduced by REFACTOR-003 PR #82). Tracing: diff-check.ps1 exits 2 because `DOTFILES_REPO_DIR` is unset on Windows — the script falls back to `Split-Path $PSScriptRoot` which resolves to `$env:USERPROFILE\scripts` (deploy location, NOT a git repo) and hits the "not a git repo" guard.

Linux side (.bashrc + .zshrc) has exported `DOTFILES_REPO_DIR` since forever. PowerShell profile was the only one missing it.

Changes

File Change
`powershell/profile.ps1` `$env:DOTFILES_REPO_DIR = "$env:USERPROFILE\Projects\dotfiles"` next to existing $env:DOTFILES_DIR
`env-contract.json` New entry for `DOTFILES_REPO_DIR` (required: false, validated by `doctor.{sh,ps1}`)
`tests/setup-linux.bats` 2 new asserts: profile parity + env-contract declaration

37 LOC total (17 prod + 20 test). Below spec-gate threshold. Skip SDD.

Test plan

  • PowerShell AST + PSScriptAnalyzer clean
  • ASCII-only check passes
  • `env-contract.json` valid JSON (9 entries, DOTFILES_REPO_DIR present)
  • CI green
  • Post-merge: restart PowerShell + run healthcheck → sec 12 reports PASS / FAIL based on actual drift, not "setup error" exit 2

Companion

…S parity)

Empirical: user's post-merge setup-windows.ps1 run reported
`FAIL: diff-check.ps1 exited with code 2 (setup error)` in healthcheck
sec 12. Tracing showed diff-check.ps1 exits 2 because DOTFILES_REPO_DIR
is unset on Windows -- the script falls back to Split-Path $PSScriptRoot
which resolves to $env:USERPROFILE\scripts (deploy location, NOT a
git repo) and hits the "not a git repo" guard.

Linux side (.bashrc + .zshrc) has exported DOTFILES_REPO_DIR since
forever (line 49 / line 21 respectively). PowerShell profile was the
only one missing it. REFACTOR-003 (PR #82) shipped diff-check.ps1 +
wired healthcheck sec 12 to invoke it, surfacing the asymmetry.

Changes:

1. powershell/profile.ps1: `$env:DOTFILES_REPO_DIR =
   "$env:USERPROFILE\Projects\dotfiles"` next to the existing
   $env:DOTFILES_DIR line, with a comment explaining why.

2. env-contract.json: new entry for DOTFILES_REPO_DIR (required: false
   since not every consumer needs the repo path -- only diff-check
   does). doctor.{sh,ps1} now validates it on every run.

3. tests/setup-linux.bats: 2 new asserts -- all 3 profile files export
   DOTFILES_REPO_DIR; env-contract.json declares it.

37 LOC total (17 prod + 20 test). Below spec-gate threshold. Skip SDD.

Empirical post-fix: re-running healthcheck.ps1 sec 12 with the new
env var set produces `PASS: No drift between repo and deploy-dir`
(or `FAIL: Drift detected` if there is genuine drift, exit code 1).
Closes the last "setup error" FAIL surfaced by the post-merge run.

Pairs with REFACTOR-003 (PR #82) which introduced the diff-check.ps1
that exposed the gap.
@mlorentedev mlorentedev merged commit e043898 into main May 21, 2026
7 checks passed
@mlorentedev mlorentedev deleted the fix/BUG-020-dotfiles-repo-dir-windows-profile branch May 21, 2026 19:55
mlorentedev added a commit that referenced this pull request May 21, 2026
…check probe (cross-OS) (#87)

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.
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