Skip to content

fix(powershell): leave $? False when hf re-runs a failing command; 0.2.7 - #12

Merged
NaNIsaac merged 1 commit into
mainfrom
fix/hf-status
Oct 28, 2026
Merged

NaNIsaac merged 1 commit into
mainfrom
fix/hf-status

Conversation

@NaNIsaac

Copy link
Copy Markdown
Owner

In PowerShell, $? was True after hf re-ran a command that failed (#11): hf is a plain function, and a function that returns normally leaves $? True whatever ran inside it. Prompts that show the last status reported success.

  • hf is now an advanced function. After the fixed command, a new native exit code that is not 0, or a new $Error[0], means it failed; hf then writes an error record with ErrorAction Ignore, which sets the caller's $? to False without printing anything or adding to $Error. These are the cases where $? would be False had the line been typed. $LASTEXITCODE was already right. bash and zsh were not affected (the function returns the command's status).
  • The names are added to CODIGEST_RUNNERS only if they are not there yet, so sourcing the setup again (. $PROFILE, source ~/.bashrc) no longer lists them twice.
  • The . __cdg { } strip in the PowerShell function stays: codigest 0.12.2, the current release, still leaves that form in the engine history (fixed on its main in feat(hook): let programs that run commands keep the terminal codigest#53, not released). The comment now says which versions need it. It can go once a codigest release with that fix is out.

Version 0.2.7. This is step 1 of the codigest/hanfix design (the next steps move the re-run into codigest's Enter handling); nothing here depends on that.

Tests

  • tests/shells.ps1: $? is True after a successful hf -y and False (exit code 3) after one that fails; the setup is sourced twice before the runner check, which still expects hf ㅗㄹ. The status check fails with 0.2.6 ($?=True exit=3).
  • tests/shells.sh (bash, zsh, fish on Linux CI): the setup is sourced twice; the existing runners: hf ㅗㄹ check now covers duplicates.
  • cargo test: the init script is advanced and registers the names once.
  • Local, Windows ConPTY, fresh pwsh -NoProfile with PSReadLine history pointed at a temp file, codigest's hook from main 9c4cf56: after hf -y of a mistyped cmd /c exit 3, $? False and $LASTEXITCODE 3 with hanfix loaded before the hook, after it, and without it (0.2.6: True in all three). The earlier end-to-end (a codex probe through ㅗㄹ keeps the terminal, a captured probe through hf -y is captured under its fixed line, pwsh and Git Bash, both orders): 4/4.

local-ci: 79074a8 | cargo test --release --locked 4 passed; tests/shells.ps1 with the built 0.2.7 (ok powershell, ok powershell with codigest) and fails with 0.2.6; ConPTY status probe 3/3 and end-to-end 4/4 above; conventions.py check: 0 findings; sh -n tests/shells.sh | tests/shells.sh (needs util-linux script) and macOS only in CI

hf now sets the caller's $? from the command it ran, and the runner names
are registered once when the setup is sourced again.

Fixes #11
@NaNIsaac
NaNIsaac merged commit 7420c0a into main Oct 28, 2026
21 checks passed
@NaNIsaac
NaNIsaac deleted the fix/hf-status branch October 28, 2026 16:56
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.

1 participant