Repository navigation
Conversation
…3872) Closes #3862. ## Why #3475 added a warning when the machine and user `Path` together expand past 3700 characters, and left the operator to work out which entries could go. The maintainer rescoped #3862 on 2026-11-04 so that `upgrade-host.ps1` removes dead and duplicate entries itself. ## What Changed - **`upgrade-host.ps1 -CleanPath`** removes three kinds of entry: - a duplicate, compared after expansion, case folding, quote removal, and trimming a trailing `\` or `\.`, keeping the first in effective order (machine, then user) - a dead entry, whose root answers while the directory does not - an empty entry - **Entries it keeps and lists without judging:** - an entry under a root that does not answer - an entry holding a variable that does not expand - an entry that is not a full path - an entry holding a variable whose stored value changed after the terminal started - **Writes.** It reads and writes each half's raw registry value, keeping `REG_EXPAND_SZ` and every kept entry's unexpanded text and order. It prints the previous value before writing and broadcasts `WM_SETTINGCHANGE` after. After the prompt it reads each half again and writes nothing where one changed. - **Elevation is detected, never required.** - Unelevated, it cleans the user half, lists the machine findings with `gsudo` as the remedy, and exits 0. - Elevated as the owner of the session's Explorer, it cleans both halves. - Elevated as another account, or in a session with no Explorer, it cleans the machine half and says why it left the user half alone. - **`-Status`** lists what `-CleanPath` would remove. `-Help` documents the action. - **`menu.ps1`** gains entry 6 for the action, and the later entries move down one. No test or document pins their numbers. - **Docs.** `host-setup/windows/README.md` gains "Cleaning Path" and drops the stance that nothing edits `Path`. Both READMEs now name two menu entries with no Linux peer. - **Tests.** `tests/test_upgrade_host.py` drives the script's own functions against a stubbed registry read and write, directory probe, session-user check, and broadcast. It covers the duplicate rules, the dead-versus-unreadable split, the unexpanded round trip, a changed variable, a half changed during the prompt, and each elevation case. The Path-length harness in `tests/test_install_tools.py` gains two stubs, since `Show-Status` now reaches the cleanup. ## Verification - `tests/test_upgrade_host.py` 19 OK, `test_install_tools.py` 48 OK, `test_cli_usage.py` 16 OK, `test_bootstrap.py` 150 OK, natively on Windows. - ruff format and check, mypy, the prose gate (with comments allowed), PSScriptAnalyzer, markdownlint, and editorconfig-checker are clean. - Native runs on this Windows 11 host, whose only finding is one empty user entry: - Unelevated, at `1d4ff084`: `-Status` and `-CleanPath -DryRun` both list it and exit 0. The dry run plans the user write only. - Under `gsudo`, at `700e1fc1` and again at `1d4ff084`: both exit 0, and the dry run plans the user write. That confirms a same-user elevation passes the session-user check. - Local strict review: the first pass raised five findings, all fixed in `1d4ff084`. The second pass over the whole diff raised none. The `comments` label is wanted. The new functions carry why-comments in the style the script already uses. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
There was a problem hiding this comment.
🟡 Changes recommended
Several unresolved moderate and critical issues remain in Windows PATH and environment-variable cleanup, including incorrect root normalization, stale-variable handling, duplicate suppression, and percent-sign detection.
4 open issues
What changed in this PR
Adds the Windows upgrade-host.ps1 -CleanPath action for identifying and removing dead, duplicate, empty, and file-naming Path entries. The change includes elevation-aware registry updates, dry-run and status reporting, concurrency safeguards, menu integration, documentation, and PowerShell-backed tests.
Changes:
- Adds guarded
Pathcleanup while preserving registry value kinds, ordering, and unexpanded text. - Handles elevation scope, concurrent changes, environment broadcasts, and write failures.
- Adds cleanup tests and updates Windows host documentation and menu entries.
- Review identified one critical issue, four moderate issues, and three nits requiring attention.
| File | Summary |
|---|---|
tests/test_upgrade_host.py |
Adds stubbed PowerShell coverage for cleanup planning, writes, elevation, dry runs, failures, and status output. |
tests/test_install_tools.py |
Stubs cleanup functions for existing path-length test isolation. |
host-setup/windows/upgrade-host.ps1 |
Implements cleanup, registry writes, elevation handling, reporting, and safeguards. Findings cover drive-root normalization, deleted-variable detection, referenced-variable revalidation, unresolved-variable parsing, and preserving later live duplicates. |
host-setup/windows/README.md |
Documents cleanup rules, write behavior, and elevation limits. One clarification is needed for elevated cleanup behavior. |
host-setup/README.md |
Updates the host setup overview with the Windows cleanup capability. The cleanup claim should be limited to -CleanPath. |
host-setup/menu.ps1 |
Adds the cleanup menu entry and shifts subsequent choices. |
Review effort: Lite
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3873 +/- ##
=======================================
Coverage 83.31% 83.31%
=======================================
Files 29 29
Lines 9956 9956
=======================================
Hits 8295 8295
Misses 1661 1661
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…anup (#3874) Part of #3862, answering Copilot's round on promotion #3873. ## Why Copilot's round on the promotion raised two real defects in the `-CleanPath` duplicate and variable checks that #3872 added. - The duplicate key trimmed `C:\` to `C:`. `C:` names the current directory on drive C rather than its root, so a `C:` entry was removed as a repeat of `C:\`. - Any `%` left after expansion marked an entry as unexpanded. A directory whose name holds a literal `%` was therefore never judged. This is the second round to raise it. ## What Changed - `Get-PathEntryKey` holds the duplicate key. A drive root keeps its `\`, and a bare `C:` stays `C:`. - An entry is unjudged as unexpanded only where a whole `%NAME%` token survives expansion. - Two tests cover both. ## Verification - `tests/test_upgrade_host.py` 26 OK natively on Windows. - ruff, mypy, the prose gate, and PSScriptAnalyzer are clean. - A local strict review of the diff raised nothing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Defer approval because the change performs destructive Windows registry Path writes and relies on native elevation, CIM session-user detection, and WM_SETTINGCHANGE behavior that could not be executed or independently verified in this environment.
No open issues 🎉
4 resolved since last review
Review effort: Lite
|
Answering the round's headline on
|


Summary
Promotes #3872 and #3874 to
main.Closes #3862.
upgrade-host.ps1 -CleanPath, which removes duplicate, dead, empty and file-naming entries from the machine and userPath.-Statuslists what it would remove.REG_EXPAND_SZkind.gsudofor the machine half. Elevated as the session's own user, it cleans both.C:is no longer a repeat ofC:\. A literal%in a directory name no longer leaves the entry unjudged.menu.ps1gains entry 6 for the action.host-setup/windows/README.mdgains "Cleaning Path".Verified natively on Windows 11, unelevated and under
gsudo, with-Statusand-CleanPath -DryRun. The host's only finding was one empty user entry, so no live cleanup was run against it. The dead, duplicate and write paths are covered bytests/test_upgrade_host.py, against a stubbed registry.🤖 Generated with Claude Code