emrg: escape PowerShell braces in stop_tui ps_cmd (Windows emrg stop crash) - #817
Merged
argszero merged 2 commits intoAug 17, 2026
Merged
Conversation
argszero
reviewed
Aug 17, 2026
argszero
left a comment
Owner
There was a problem hiding this comment.
✅ LGTM — cycle (review): genuine bug caught — my #811's stop_tui() used str.format(own=own) on a template containing literal PowerShell { } script-block braces, which raises ValueError: unexpected '{' in field name on every Windows emrg stop run before stop_bundled_git/verify execute. Verified the discriminator both ways: master's template raises ValueError, the escaped {{ }} template renders correctly with the PID exclusion substituted. The new unit test forces the Windows branch and pins the render path (positive + negative states). Merge conflict resolved by author (Agent.md 869). CI test + test-windows PASS.
This was referenced Aug 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix a Windows runtime crash in
emrg stopintroduced by the #811 merge:emrg/_stop_all.py stop_tui()builds its PowerShell CIM query withstr.format(own=own)but the template contains literal PowerShell script-block braces (Where-Object { ... }/ForEach-Object { ... }).str.format()parses those as replacement fields and raisesValueError: unexpected '{' in field nameon every Windows run ofemrg stop— beforestop_bundled_git()andverify()ever execute, so the installer's bundled-git orphan cleanup (#683/#689/#692 family) never runs.Why CI missed it:
tests/test_stop_all.pymonkeypatchesstop_tuientirely (orchestration tests), andtest_installer_stop.pyonly does textual wiring asserts — the template is never rendered anywhere in the test suite. This regressed on Windows immediately after the merge.Changes:
emrg/_stop_all.py— escape the literal braces as{{ }}in thestop_tui()ps_cmd template, keeping{own}as the only real replacement field. Verified the rendered PowerShell is byte-identical to the intended command (e.g.Where-Object { $_.ProcessId -ne 12345 ... }).tests/test_stop_all.py— newTestStopTuiPsTemplate::test_stop_tui_renders_ps_template_win: forces the Windows branch (is_win → True), monkeypatchessubprocess.runto capture the command, callsstop_tui(), and asserts (a) noValueErroris raised, (b) the invoking-PID exclusion is substituted, (c) the literalWhere-Object {/ForEach-Object {blocks survive. This pins the render path so a regression is caught at the unit level. (Discriminative: the unfixed template raisesValueErrorat the.format()line.)Agent.md— Python test count 858 → 859 (doc-count guard).Verified:
uv run pytest tests/ -v→ 859 collected (799 passed + 60 skipped) green; import +python -m emrg --helpOK.