Skip to content

fix(fix-6-path): stop advertising setx for the Windows PATH write - #710

Merged
r0x0r merged 1 commit into
mainfrom
setx-fix
Oct 19, 2026
Merged

r0x0r merged 1 commit into
mainfrom
setx-fix

Conversation

@r0x0r

@r0x0r r0x0r commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Why

main's E2E tests (Strix Halo, Windows, current) lane is permanently red, and has been across every recent push run. Because the self-hosted lanes re-run on each PR, it now shows red on every open PR too — which manufactures red marks on everything we open and makes a genuine Windows regression indistinguishable from the noise.

The lane reports 145 scenarios, 141 passed, 4 failed. Three are declared xfails in tests/e2e-cucumber/expectations.toml and are tolerated. The fourth is diagnose-38, and the CLI is behaving correctly — the test was wrong.

The broken assertion

Then the CLI used PowerShell's SetEnvironmentVariable, not setx, to update the User PATH banned the substring setx across the entire output of rocm fix fix-6-path --yes. But rocm fix <id> prints the catalog recipe before it runs anything, and the fix-6-path recipe's documented Windows command was literally setx PATH "%PATH%;C:\Program Files\AMD\ROCm\<version>\bin". The step therefore tripped on the catalogue's own documentation, while the write below it was correct:

Step panicked. Captured output: setx must not appear now that the write goes through PowerShell:
  ... fix catalog listing ...
Plan: prepend C:\...\bin to your User PATH:
  [Environment]::SetEnvironmentVariable('PATH', '...', 'User')

The real defect underneath it

setx PATH "%PATH%;..." is bad advice, not just an awkward string:

  • setx truncates the value at 1024 characters while still exiting 0, silently corrupting a long PATH.
  • %PATH% expands to the combined user+system PATH, so this writes every system entry into the user PATH — a classic way to mangle someone's environment.

The codebase already knew this: fix.rs carries a doc comment warning that a setx PATH write replaces the user's real PATH, and cb9f748d moved the actual write off setx onto [Environment]::SetEnvironmentVariable for exactly these reasons. It left the documented manual commands behind, in two places.

What changed

crates/rocm-core/src/fix.rs — the fix-6-path recipe now documents the same mechanism the CLI performs:

[Environment]::SetEnvironmentVariable('PATH', 'C:\Program Files\AMD\ROCm\<version>\bin;' + [Environment]::GetEnvironmentVariable('PATH', 'User'), 'User')

GetEnvironmentVariable(..., 'User') reads the User scope only, so nothing folds the system PATH into the user's. Two notes were added: why it is not the setx one-liner, and that a PATH change only takes effect in NEW shells.

crates/rocm-core/src/diagnose.rs — the same replacement for the format!-built copy, against the real bin_dir. It now reuses the production write's ps_single_quote_escape (made pub(crate)), so an apostrophe in the bin dir cannot end the PowerShell string literal early in the printed copy either — the printed plan and the real write are one plan on two surfaces. The "only affects NEW shells" guidance is kept, reworded off setx.

tests/e2e-cucumber/ — diagnose-38 now asserts over the write region rather than the whole output, via a new user_path_write_region helper: the span from the Plan: prepend ... line through the post-write This only takes effect in NEW shells confirmation. Inside that span it asserts positively on the SetEnvironmentVariable call and negatively on setx .

Why scope it rather than just fix the catalog string? Even with the catalog corrected, a whole-output !contains("setx ") reports on the documentation, not on what the CLI did. Any future note, rationale or warning that names setx — including, deliberately, the one added here — would fail the scenario for no reason. The region is the only span in which setx means the regression the scenario guards against. Obtaining the region at all is what pins the plan line and the confirmation wording cb9f748d introduced, so the dropped third assertion is not lost.

Note that the two halves are coupled: because the new note names setx on purpose, the catalog change alone would not turn the lane green. The narrowing is what fixes it.

Verified

  • Five new unit tests in the e2e lib (cargo test --workspace on any platform) cover both directions: the region excludes catalog prose naming setx, and still catches a write regressed to setx; plus no-region cases for "the write never ran" and "the write was never confirmed", so half a write cannot vacuously satisfy both halves.
  • Against real output. rocm fix fix-6-path --dry-run was run from a binary built off this branch to capture the real catalog block, and the real Plan:/script lines were captured by driving path_export_windows directly. Feeding the assembled Windows output through the real user_path_write_region: the pre-change whole-output assertion fails, the new region assertion passes. Substituting a setx write into the same output: the new region assertion fails. Both checks were throwaway and are not in the diff.
  • Gates, all on the devbox at cac27bd8: cargo fmt --all clean; cargo test --workspace --all-targets --no-fail-fast — only the known load flake cli_progress::tests::animated_spinner_keeps_ticking_without_progress_calls, which passes in isolation on this tree; cargo clippy --workspace --all-targets -- -D warnings clean; cargo clippy --locked -p e2e-cucumber --test e2e -- -D warnings clean.
  • No unit test pinned the old setx PATH "%PATH%;... strings, and the published Doctor catalog check passes unchanged.

Not verified

The Windows scenario itself was not executed. diagnose-38 is @requires-os:windows and there is no Windows runner here, so the proof above is over output reconstructed from the real production code paths, not over a real Windows run. The Windows E2E lane on this PR is the first real execution.

`main`'s "E2E tests (Strix Halo, Windows, current)" lane is permanently
red on diagnose-38, and the CLI is behaving correctly -- the assertion
is wrong. The step banned the substring `setx ` across the *whole* of
`rocm fix fix-6-path` output, and `rocm fix <id>` prints the catalog
recipe before it runs anything, so the catalog's own documented Windows
command tripped the test the real (PowerShell) write was meant to prove.

The documented command is also wrong on its own terms, which is the
defect underneath the broken test. `setx PATH "%PATH%;<bin>"` truncates
the value at 1024 characters while still exiting 0, and `%PATH%` expands
to the combined user+system PATH, so pasting it writes every system
entry into the user's own PATH. cb9f748 moved the real write off `setx`
to `[Environment]::SetEnvironmentVariable` for exactly these reasons and
left the advertised commands behind.

- `fix.rs`: the `fix-6-path` recipe and `diagnose.rs`'s copy of the same
  plan now both document the PowerShell prepend the CLI performs --
  reading and rewriting the User scope only -- with notes saying why it
  is not `setx`. `diagnose.rs` reuses the real write's
  `ps_single_quote_escape`, so an apostrophe in the bin dir cannot break
  the printed copy either.
- diagnose-38 now asserts over the write region (the `Plan: prepend ...`
  line through the post-write confirmation) instead of the whole output,
  via `user_path_write_region`. Prose about `setx` anywhere else -- a
  note, a rationale, a future warning -- no longer fails the scenario,
  while a write that regressed to `setx` still does. Five unit tests in
  the e2e lib cover both directions on any platform.

Signed-off-by: Roman Sirokov <roman.sirokov@amd.com>
@r0x0r
r0x0r requested a review from a team as a code owner October 19, 2026 06:21
@r0x0r
r0x0r requested a review from siloteemu October 19, 2026 06:21

@jussielo-amd jussielo-amd 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.

Review — no blocking findings

Full review of the whole change (single-pass — 4 files, 226 changed lines, small enough to read completely without fan-out). No ticket named in the PR body; fix-6-path in the title/body is the catalog recipe ID, not a tracker key.

Blocking

None

Non-blocking

  • diagnose.rs's half of the fix has no test coverage — crates/rocm-core/src/diagnose.rs:1041-1055
    The PR's own framing is that the bad setx advice lived in "two places" and both needed the same fix. fix.rs's half got five new unit tests plus the diagnose-38 e2e scenario (which the PR reran locally and confirmed fails pre-fix/passes post-fix). diagnose.rs's half — the check_6_path_missing Windows suggestion, now built via ps_single_quote_escape(&bin_dir) the same way — has none: no test references SetEnvironmentVariable in diagnose.rs, there is no windows_base() test fixture for this check (only linux_base/wsl_base exist), and cargo test -p rocm-core --lib -- check_6_path against this PR's head (cac27bd8) matches zero tests. Nothing would catch this command regressing back to setx, or the escape being dropped/misapplied for a bin_dir containing an apostrophe — exactly the defect class the PR's own doc comment on ps_single_quote_escape calls out as "the same ROCMAI-449 bug moved from the write to the documentation." Scored non-blocking rather than blocking because the text is advisory (printed by rocm diagnose, never executed by the CLI itself) — but it is user-observable behavior this change introduces with no assertion anywhere.
    Fix: add a windows_base()-style fixture and a unit test asserting check_6_path_missing's Windows Fix.commands contains the SetEnvironmentVariable/GetEnvironmentVariable call, not setx, and that an apostrophe in a synthetic bin_dir survives escaped (mirroring ps_single_quote_escape_doubles_every_embedded_quote but through the real call site).

Decisions for the author

None

Positive signals

  • windows_path_prepend and ps_single_quote_escape are shared between the planned message and the actual write (crates/rocm-core/src/fix.rs:1917,1940), so the two can't disagree the way the pre-fix code's "prepend" wording vs. append-shaped write once did — a real structural fix, not just a reworded string.
  • user_path_write_region's test set is well-designed: it covers both directions (catalog prose containing setx is excluded, a write regressed to setx is still caught) plus the two "no region" edge cases (write never ran, write never confirmed) that guard against half a write vacuously satisfying the assertion.

Deployment notes

None

What this covered

Read completely: crates/rocm-core/src/fix.rs, crates/rocm-core/src/diagnose.rs, tests/e2e-cucumber/src/lib.rs, tests/e2e-cucumber/tests/e2e/diagnose_steps.rs (the full diff), plus surrounding context: run_path_export_windows/path_export_windows/windows_path_prepend and their existing unit tests, the diagnose-38/diagnose-39 feature scenarios, doctor-catalog.json, skills/rocm-doctor/reference.md, coverage-floors.toml, and the CI coverage job definition in .github/workflows/ci.yml. Diffed d4e7c751 (merge-base, matches PR's reported base)…cac27bd8 (PR head). Ran cargo test -p e2e-cucumber --lib (148 passed, including all 5 new tests) and cargo test -p rocm-core --lib plus cargo fmt --all -- --check against a worktree built from the PR head — all clean. Ran a leak scan (origin/main…PR head) — clean — and checked for merge-conflict markers — none.

Did not run: the prior-changes pass (no earlier review rounds exist on this PR to check against) and the Windows e2e scenario itself (diagnose-38 is @requires-os:windows, no Windows runner available here — matches the PR's own "Not verified" disclosure). Skill checks (skillscope) and Sphinx docs build show SKIPPED in CI but correctly so — no skill or docs files are touched by this change. Not reconciled against any discussion (fresh review, nothing to reconcile).

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