refactor(computer-use): injectable win32 runner for host-agnostic backend tests - #5912
Conversation
… exec }) Follow-up to the closed Hmbown#5910, per the maintainer's invitation after the bug itself was fixed and merged in Hmbown#5903. This PR is refactor-only: it keeps main's merged behavior and adds a cleaner test seam. Previously the win32 backend's PowerShell runner (ps/psOk/psJson) lived at module scope, so backend tests had to fake powershell.exe on PATH (or run on Windows). Move the runner helpers into create() as instance-local functions that default to the production runner but can be overridden with create({ exec: { run } }) — the same injection pattern the harmonyos backend already uses. tests/win32.test.mjs now exercises the win32 backend on any host through the injected runner: actions run without powershell, nonzero exits reject (fail-truthful), and targeted mouse-down is verified to move + press with the User32 type defined in-process. Verified on macOS with no Windows involved: node --test tests/win32.test.mjs (4/4) and tests/backends.test.mjs (10/10, no regression). Refs Hmbown#5903, Hmbown#5910. Signed-off-by: EvanProgramming <evangonggyf@gmail.com>
|
Thanks @EvanProgramming for taking the time to contribute. This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered. Please read |
Hmbown
left a comment
There was a problem hiding this comment.
Verified locally on the PR head: the plugin suite passes (47/47 via npm test), the create({ exec }) seam matches the harmonyos backend's shape, and create() with no args is behavior-identical to main. The four new tests pin exactly the #5903 guarantees (in-process User32 prelude, nonzero exit rejects, targeted left_mouse_down moves and presses) without a Windows host. Merging once CI finishes.
Summary
Refactor-only follow-up, as invited on the closed #5910: the win32 input bug was already fixed and merged in #5903 — this PR does not re-touch that logic. It keeps main's merged behavior and adds the instance-local injectable runner seam that was called out as cleaner than the fake-powershell.exe-on-PATH fixture.
Why
crates/tui/plugins/computer-use/src/backends/win32.mjsdefined its PowerShell runner helpers (ps/psOk/psJson) at module scope, so backend tests either needed a realpowershell.exeor a PATH fixture. Moving them intocreate()lets a test passcreate({ exec: { run } })— the exact injection pattern the harmonyos backend already uses.Changes
create(opts = {}):ps/psOk/psJsonbecome instance-local and default to the production runner;opts.exec.runoverrides it. No production behavior change whencreate()is called with no args.tests/win32.test.mjsexercising the win32 backend on any host (no Windows, no fake powershell):left_mouse_downmoves and presses, with theUser32type defined in-process;Verification
node --test tests/win32.test.mjs→ 4/4 pass;node --test tests/backends.test.mjs→ 10/10 pass (no regression). All on macOS.Refs #5903, #5910.