Skip to content

fix(config): iterate PowerShell uniformly with other shells - #2581

Merged
max-sixty merged 2 commits into
mainfrom
unify-powershell-env
May 4, 2026
Merged

max-sixty merged 2 commits into
mainfrom
unify-powershell-env

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • Adds PowerShell to default_shells unconditionally; the Shell::is_installed() filter (added in fix(config): clean up wt config show shell-integration section #2574) now hides Skipped pwsh on hosts without pwsh, the same way Skipped fish is hidden on a stock zsh-only Mac
  • should_auto_configure_powershell() still gates allow_create, so users who have pwsh installed but never opened it don't get an unsolicited profile written (issue PowerShell shell integration is not working #885 behavior unchanged)
  • Removes the iteration asymmetry that left PowerShell invisible in wt config show for users who configured a profile but aren't currently in a PS session

Visible changes

Host state Before After
pwsh on PATH, profile exists, not in PS session invisible shown as configured
pwsh on PATH, no profile, not in PS session invisible Skipped pwsh; profile not found
pwsh absent invisible (iteration gate) invisible (is_installed() filter)
in PS session, no profile auto-creates auto-creates (unchanged)

Test plan

  • cargo test --test integration (1622 passed)
  • pre-commit run --all-files
  • Extended test_configure_shell_skipped_lists_only_installed_shells to flag pwsh installed and assert it appears as Skipped

🤖 Generated with Claude Code

Before: PowerShell was excluded from `default_shells` unless we detected
a PS session (PSModulePath set, or SHELL absent on Windows). This made
PS invisible in `wt config show` and `wt config shell install` output
for users who have pwsh installed but aren't currently in a PS shell —
even when they have a configured profile.

Now: PowerShell is iterated alongside bash/zsh/fish/nushell, and the
same `is_installed()` filter that hides "Skipped fish" on a stock
zsh-only Mac hides "Skipped pwsh" on a host without pwsh.

The PS-session signal (`should_auto_configure_powershell()`) still
gates `allow_create` so we don't write a profile for users who
installed pwsh once and never opened it (issue #885 unchanged).

Net visible changes:
- pwsh on PATH, profile exists, not in PS session: shown as `configured`
  (was: invisible).
- pwsh on PATH, no profile, not in PS session: shown as `Skipped pwsh;
  profile not found` (was: invisible).
- pwsh absent: invisible via `is_installed()` (was: invisible via
  iteration gate). Same outcome, different mechanism.
- in PS session: auto-creates profile if missing. Unchanged.

Co-Authored-By: Claude <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes May 4, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change reads cleanly: is_installed() (added in #2574) was always going to be the right place to filter pwsh on hosts without it, so removing the iteration gate is the natural follow-up. Behavior table matches what I traced through scan_shell_configs.

One drive-by: the comment for WORKTRUNK_TEST_POWERSHELL_ENV in src/testing/mod.rs (lines 266–269) is now stale — after this PR it no longer "gates whether PS is iterated at all in scan_shell_configs"; iteration is unconditional and the env var only controls allow_create via should_auto_configure_powershell(). Happy to push a one-line comment fix as a follow-up if you'd like.

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows CI failed on the test this PR modified — test_configure_shell_skipped_lists_only_installed_shells. The new "Skipped powershell" line includes the platform-specific profile path, which the snapshot assumes is the Unix ~/.config/powershell/... form:

- Skipped powershell; ~/.config/powershell/Microsoft.PowerShell_profile.ps1 not found
+ Skipped powershell; _PARENT_/Documents/PowerShell/Microsoft.PowerShell_profile.ps1 not found

Same root cause as the Windows-ignore on test_powershell_env_detection — dirs::document_dir() can't be overridden via HOME/set_temp_home_env. Three options:

  1. Mirror the sibling test and add #[cfg_attr(windows, ignore = "Windows uses Documents folder which can't be easily overridden")] — simplest, loses Windows coverage for the new assertion.
  2. Drop assert_cmd_snapshot! and assert on substrings (Skipped + powershell) so the path is irrelevant — keeps Windows coverage.
  3. Add an insta path filter that normalizes the Documents prefix.

Option 2 is probably best since the test's belief is "pwsh appears as Skipped when installed but profile missing" — the exact path is incidental. Happy to push that fix if you'd like.

@worktrunk-bot
worktrunk-bot dismissed their stale review May 4, 2026 07:45

CI failed — Windows snapshot assertion in the modified test

The previous attempt extended `test_configure_shell_skipped_lists_only_installed_shells`
to also flag pwsh as installed, but that test runs cross-platform and the
PowerShell profile path differs on Windows
(`~/Documents/PowerShell/...` vs `~/.config/powershell/...`), so the inline
snapshot mismatched on Windows CI.

Restore the cross-platform test to its original bash+fish form and add
`test_powershell_skipped_when_installed_no_profile`, gated on `cfg(unix)`,
to cover the new uniform PowerShell behavior with the Unix profile path.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 61046fb into main May 4, 2026
27 checks passed
@max-sixty
max-sixty deleted the unify-powershell-env branch May 4, 2026 08:01
max-sixty added a commit that referenced this pull request May 4, 2026
…ELL_ENV (#2585)

## Summary

After #2581, PowerShell iterates unconditionally in `scan_shell_configs`
alongside the other shells. The comment for
`WORKTRUNK_TEST_POWERSHELL_ENV` in `src/testing/mod.rs` still claimed
the var "gates whether PS is iterated at all" — that's now stale.
Updated to reflect that the var only controls `allow_create` via
`should_auto_configure_powershell()`.

Caught by the auto-reviewer on #2581.

## Test plan

- [x] No code changes; comment-only.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
max-sixty added a commit that referenced this pull request May 4, 2026
…#2586)

The test wrote `tracked.txt` as `"original"` then `"modified"` — both 8
bytes. `wt step commit --dry-run --stage=tracked` runs `git add -u`
against a copy of the index, so the only signal git has for the
modification is mtime. On Linux/ext4 the recorded entry mtime and the
post-modification mtime can be indistinguishable at the kernel's
resolution; git treats the file as unchanged, the temp index keeps the
old blob hash, and `git diff --staged` returns nothing. The rendered
prompt then has empty `<diffstat>` / `<diff>` blocks and the assertion
on `"tracked.txt"` / `"modified"` fires.

Reproduces 0/200 locally on macOS APFS and passes on `test (linux)`, but
flaked on the `affected (linux, advisory)` job for PR #2581
([logs](https://github.com/max-sixty/worktrunk/actions/runs/25306727293/job/74184225239))
— that PR only touched PowerShell shell config and has no plausible
effect on this code path.

Switching the modification to `"modified content"` makes the new size
differ from the committed blob, so git's DATA_CHANGED check fires
unconditionally and the test no longer depends on mtime resolution. This
mirrors the adjacent `test_step_commit_with_stage_tracked_flag`
(`merge.rs:2113`) which uses `"initial"` → `"modified"` (different
sizes) for the same reason. PR #2433 fixed an analogous mtime-tick
collision in the picker/summary tests.

The `stdout.contains("modified")` assertion still passes since
`"modified"` is a prefix of the new content.

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

2 participants