Repository navigation
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
claude_config_dir() now resolves a ~ against a different home directory than the ~/.claude fallback two lines below it. worktrunk::path::expand_tilde goes through worktrunk::path::home_dir (the home crate), whose Windows home_dir_inner reads USERPROFILE and then SHGetKnownFolderPath — it never looks at HOME. The module-local home_dir() that the fallback still uses tries HOME first. So on Windows with HOME pointing somewhere other than %USERPROFILE% (MSYS2, Cygwin), CLAUDE_CONFIG_DIR=~/custom and an unset CLAUDE_CONFIG_DIR now land under different homes; before this change both followed HOME. set_temp_home_env sets both variables to the same path, so no test can see the split. #4106's item 9 called the two home rules "worth a second look rather than a fix" — this leaves home_dir() with a single remaining caller and makes one function depend on both rules, which is the harder version of that to reason about. Routing the fallback through worktrunk::path::home_dir too would settle it in the same direction the rest of the PR argues for (pi.rs and omp.rs already use it for both halves).
The same swap drops the loud failure when no home resolves at all. expand_tilde returns the path unchanged in that case, so CLAUDE_CONFIG_DIR=~/custom becomes Some("~/custom"), require_settings_path joins settings.json onto a relative path, and you get a ~ directory under the cwd plus ✓ Statusline configured — the outcome this PR set out to remove, relocated to a different trigger. The replaced code returned None there, and require_settings_path bailed with "Could not determine Claude Code config directory". An unresolvable home is an improbable environment and CLAUDE.md's Don't Defend Improbable Environments says not to carry a fallback chain for one, but it also says "Dropping a fallback still means failing with an error" — so this is worth a deliberate call rather than a side effect, whichever way it goes.
The bare ~ the PR fixes isn't pinned by a test. test_plugins_claude_install_statusline_expands_tilde_in_claude_config_dir sets CLAUDE_CONFIG_DIR=~/custom-claude, which the replaced strip_prefix("~/") already handled, and it's the only test that exercises a tilde on this path — so the regression this fixes would come back silently. Adding "~" as a second case there (assert settings.json lands at <home>/settings.json and no ~ directory appears under the cwd) covers it; happy to push that commit if you'd like.
Signed-off-by: hiro-nikaitou <[email protected]>
f3a7ad2 to
7be52a3
Compare
|
Addressed in 7be52a3 — all three points, in one commit that lands on 4 added lines.
Evidence, Windows, temp home + scratch repo,
|
`test_plugins_claude_install_statusline_expands_tilde_in_claude_config_dir`
only exercised `~/custom-claude`, which the old `strip_prefix("~/")` already
handled, so the bare `~` regression could come back silently. Parametrize the
test over both values and assert the settings file lands under the temp home.
Against the pre-fix `claude_config_dir`, `case_2_bare_tilde` fails (no
`<home>/settings.json`); with the fix both cases pass.
|
Pushed as 15c8280cf6bdba2d0c8c68b41ebcab7ceb3932c4 — I checked the new case actually fails on the code it pins: reverting Items 1 and 2 read as settled to me. Routing through the module-local |
There was a problem hiding this comment.
CLAUDE_CONFIG_DIR=~\custom still writes a literal ~ directory on Windows. str::strip_prefix("~/") only matches a forward slash and the new dir == "~" branch only matches the bare value, so a backslash form falls through to PathBuf::from(r"~\custom") and install-statusline creates <cwd>\~\custom\settings.json — the same failure this PR fixes, on the platform where a value set outside a shell is most likely to carry a backslash. The docstring now reads "A leading ~ in the value is expanded against the home directory", which states it unconditionally.
Path::strip_prefix matches whole components, so on Windows it treats \ and / alike and absorbs the bare ~ into the same branch — which is how worktrunk::path::expand_tilde matches. Suggested inline; it keeps this module on its own home_dir() (the home rule is untouched) and keeps the None that makes require_settings_path bail, and it collapses the two branches into one. I applied it locally to check: ~user/repo still doesn't match (its first component is ~user), ~/custom-claude is unchanged, and cargo check plus every test_plugins_claude_install_statusline* integration test passes.
`str::strip_prefix("~/")` only matches a forward slash, so a Windows value
like `~\custom` was returned as a literal `~` directory. Matching on path
components accepts either separator and drops the special case.
Signed-off-by: hiro-nikaitou <[email protected]>
A literal
~(rather than~/...) inCLAUDE_CONFIG_DIRwas not expanded:str::strip_prefix("~/")misses a bare~, so the value fell through toPathBuf::from("~")andinstall-statuslinewrote a directory literally named~under the cwd.The tilde is now expanded through the same
home_dir()the~/.claudefallback two lines below already uses, which is the rule that honors an explicitHOME/USERPROFILE. That keepsclaude_config_diron one home rule instead of two, and an unresolvable home stays a refusal —home_dir()returnsNone, sorequire_settings_pathbails instead of joining onto a relative~path. (Routing the fallback throughworktrunk::path::home_dirwould settle the split in the other direction, but it would leave this module'shome_dir()with no callers, and~is expanded by the shell fromHOME.)Verified on Windows, temp home + scratch repo,
CLAUDE_CONFIG_DIR=~:main:HOME_SETTINGS=False CWD_TILDE_DIR=True CWD_TILDE_SETTINGS=True— a~directory under the cwdHOME_SETTINGS=True CWD_TILDE_DIR=False—settings.jsonat<home>/settings.jsoncargo test --test integration test_plugins_claude_install_statusline_expands_tilde_in_claude_config_dirpasses, so the~/custom-claudecase is unchangedOn the third point: yes please, push the bare
~case onto that test — it is the exact shape that would have caught this, and the missing~directory under the cwd makes the assertion explicit.