Skip to content

fix: normalize REMEMBER_HOOK_CWD before testing it, not after (#448) - #454

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/448
Aug 29, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/448

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #448.

scripts/resolve-paths.sh tested REMEMBER_HOOK_CWD for directory existence ([ -d ]) before the Windows backslash/drive-letter normalization block that would have made a Windows-native-spelled cwd resolvable -- that block only ever ran against whatever PROJECT_DIR had already been selected, never against REMEMBER_HOOK_CWD at the point it was tested. A cwd arriving with backslash separators or a bare drive letter was therefore tested in the form the shell cannot resolve, discarded, and resolution fell through to the loud failure -- silently, via each hook's own || exit 0 -- on a host with no CLAUDE_PROJECT_DIR (Codex, Gemini CLI, which is exactly when #411/#444's REMEMBER_HOOK_CWD fallback is load-bearing).

Fix: the normalization is now a function, _remember_normalize_win_path, called on every PROJECT_DIR candidate before it is tested or selected, instead of once after a candidate was already chosen. CLAUDE_PROJECT_DIR gets the same normalize-then-trust treatment it always implicitly had (it was never -d-tested before selection either, only validated once at the very end). REMEMBER_HOOK_CWD keeps its own existence test before selection, now against the normalized form, so a value that still doesn't resolve to a real directory falls through to the next candidate exactly as before, rather than being adopted and hard-failing later with a less specific message.

Grade: reasoned, not observed -- found by reading, in a session with no Windows or Git Bash shell (the issue's own caveat). Settled by the Windows CI leg exercising the new tests, not by anything run in this session.

Tests: tests/test_windows_native_hook_cwd_448.py covers all four hooks that read this fallback (session-start-hook.sh, session-end-hook.sh since #411; user-prompt-hook.sh, post-tool-hook.sh since #444) via tests/_bash_runner.py's resolve_bash() (#432/#439) so the Windows CI leg actually exercises it instead of skipping -- a blanket skip here would have reproduced the #442 defect (a Windows-only regression test skipped on the platform that could catch it) in the lane meant to fix a Windows bug. It also carries a platform-independent structural pin asserting the REMEMBER_HOOK_CWD existence-test line in the source routes through the normalizer -- this is the one assertion that is provably red against the pre-fix source and green after, verified locally (both runs quoted in the agent report). The four hook-level 'resolves' tests pass identically before and after locally on macOS, since $OSTYPE never triggers the msys/cygwin branch here; their own docstrings say so plainly rather than overclaiming coverage they don't have.

Self-review: Explore reviewer returned NO FINDINGS. oss:auditor returned one finding -- the test file's original module-level pytestmark skip also silenced the structural pin, which has no bash dependency and doesn't need the skip; fixed in a second commit by moving the skip to a per-function _needs_bash marker applied only to the six bash-dependent tests, verified by forcing resolve_bash() to return None and confirming the pin still runs and passes while the six others report SKIPPED.

Docs: README.md is this repo's only docs_targets entry and is held by lane #437 -- not read, not touched. changelog.d/448.fixed.md added and validated against .oss/assemble_changelog.py --check (25 fragments, ok).

Not touched: scripts/session-start-hook.sh, scripts/session-end-hook.sh, scripts/user-prompt-hook.sh, scripts/post-tool-hook.sh, scripts/log.sh are read (the new tests run them as subprocesses) but not edited -- all four are held by sibling lanes #437/#450/#451 per the brief.

fix/448, 2 commits, on top of origin/main @ 163bc51.

…ce test, not after (#448)

scripts/resolve-paths.sh tested REMEMBER_HOOK_CWD with `[ -d ]` before the
Windows backslash/drive-letter normalization block that would have made a
Windows-native-spelled cwd resolvable -- the normalization only ever ran
against whatever PROJECT_DIR was already selected. A cwd arriving in
Windows-native spelling was therefore tested in the form the shell cannot
resolve, discarded, and resolution fell through to the loud failure
(silently, via each hook's || exit 0) on a host with no CLAUDE_PROJECT_DIR
(Codex, Gemini CLI).

The normalization is now a function called on every PROJECT_DIR candidate
before it is tested, not once after a candidate is already chosen.
CLAUDE_PROJECT_DIR gets the same normalize-then-trust treatment it always
implicitly had; REMEMBER_HOOK_CWD keeps its own existence test before
selection, now against the normalized form, so a still-unusable value falls
through to the next candidate exactly as before.

tests/test_windows_native_hook_cwd_448.py covers all four hooks that read
this fallback via tests/_bash_runner.py's resolve_bash() so the Windows CI
leg exercises it instead of skipping, plus a platform-independent structural
pin on the fix's ordering (the actual local red/green: the pin fails against
the pre-fix source and passes after) and the existing "must not fire"
positive control.

Co-Authored-By: Max <noreply>
Self-review (oss:auditor) found that the module-level `pytestmark =
pytest.mark.skipif(BASH is None, ...)` silenced
test_remember_hook_cwd_is_normalized_before_its_existence_test along with
the six bash-dependent hook tests -- but that test is a pure source-text
pin with no bash dependency at all, and its own docstring calls it
"checkable identically on every platform". A module-level skip for a
missing bash therefore misreported what always ran. The skip is now a
named marker, `_needs_bash`, applied per-function to the six tests that
actually spawn bash; the structural pin carries no such decorator and now
runs (and was verified to still pass) even when BASH is None.

Co-Authored-By: Max <noreply>
…slash ones

Windows CI (windows-latest, 3.10 and 3.12) went red on the four hook-level
tests: 4 failed / 700 passed. The failure was not inside resolve-paths.sh's
candidate logic at all -- it was session-start-hook.sh and user-prompt-hook.sh
failing to source their own sibling scripts ("./resolve-paths.sh: No such
file or directory", "./lib-clock.sh: No such file or directory") before
ever reaching REMEMBER_HOOK_CWD resolution.

Cause: this test file invoked each hook as `[BASH, str(script)]`, and
pathlib.Path.__str__ renders native separators -- backslashes on Windows.
session-start-hook.sh's self-location step, `_HOOK_DIR="${BASH_SOURCE[0]%/*}"`,
cannot derive a directory from a path with no forward slash in it, so every
`./sibling.sh` it then sources resolves against the wrong (unset/empty)
directory. This is a harness bug, not evidence against the #448 fix: real
hook dispatch never hands a hook a backslash-spelled $0 (hooks/hooks.json's
own command template is `"${CLAUDE_PLUGIN_ROOT}/scripts/session-start-hook.sh"`,
forward-slash, and this repo's own tests/test_hooks_json.py already
established forward-slash-always as its Windows-Git-Bash convention for
exactly this reason -- this file just failed to follow it).

Added `_win_bash_path()`, applied to the script argv and to HOME /
CLAUDE_PLUGIN_ROOT in `_env`, matching test_hooks_json.py's own
`.replace("\", "/")` convention. The REMEMBER_HOOK_CWD stdin payload value
itself is deliberately left native-spelled (str(project), unconverted) --
that native spelling is the actual thing #448's fix is about, and
converting it too would test nothing.

This is the first real Windows-CI-leg verdict this issue will get; nothing
in the previous two commits' local runs could exercise the platform
difference this fix targets.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit f79f1c5 into main Aug 29, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/448 branch August 29, 2026 10:21
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.

resolve-paths.sh tests REMEMBER_HOOK_CWD for directory existence before the Windows path normalization that would make it resolvable

1 participant