Skip to content

emrg: escape PowerShell braces in stop_tui ps_cmd (Windows emrg stop crash) - #817

Merged
argszero merged 2 commits into
argszero:masterfrom
pm25coder:fix/stop-tui-ps-format-brace-escape
Aug 17, 2026
Merged

emrg: escape PowerShell braces in stop_tui ps_cmd (Windows emrg stop crash)#817
argszero merged 2 commits into
argszero:masterfrom
pm25coder:fix/stop-tui-ps-format-brace-escape

Conversation

@pm25coder

Copy link
Copy Markdown
Contributor

Fix a Windows runtime crash in emrg stop introduced by the #811 merge: emrg/_stop_all.py stop_tui() builds its PowerShell CIM query with str.format(own=own) but the template contains literal PowerShell script-block braces (Where-Object { ... } / ForEach-Object { ... }). str.format() parses those as replacement fields and raises ValueError: unexpected '{' in field name on every Windows run of emrg stop — before stop_bundled_git() and verify() ever execute, so the installer's bundled-git orphan cleanup (#683/#689/#692 family) never runs.

Why CI missed it: tests/test_stop_all.py monkeypatches stop_tui entirely (orchestration tests), and test_installer_stop.py only 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 the stop_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 — new TestStopTuiPsTemplate::test_stop_tui_renders_ps_template_win: forces the Windows branch (is_win → True), monkeypatches subprocess.run to capture the command, calls stop_tui(), and asserts (a) no ValueError is raised, (b) the invoking-PID exclusion is substituted, (c) the literal Where-Object { / ForEach-Object { blocks survive. This pins the render path so a regression is caught at the unit level. (Discriminative: the unfixed template raises ValueError at 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 --help OK.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

✅ 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.

@argszero
argszero merged commit 9f1ad30 into argszero:master Aug 17, 2026
2 checks passed
argszero added a commit that referenced this pull request Aug 17, 2026
…tures #781-#817 entries (#819)

Co-authored-by: EMRG Evolution <emrg@argszero.dev>
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