Repository navigation
[Testing] Make ShellHelper process-safe - #40833
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The regression test can hide pipe-draining failures by not awaiting the task, and its timeout cleanup can leave the descendant process running.
2 open issues
What changed in this PR
Hardens process execution in .NET MAUI’s Appium test utilities to prevent redirected-output deadlocks while preserving existing shell-command behavior.
Changes:
- Drains stdout and stderr concurrently, with a 10-second post-exit drain limit for discard calls.
- Adds structured-argument command APIs while retaining platform-specific shell parsing.
- Adds regression tests for high-volume output, argument handling, Windows quoting, and inherited pipes.
| File | Description |
|---|---|
src/TestUtils/tests/TestUtils.UnitTests/TestUtils.UnitTests.csproj |
References the child-process test helper. |
src/TestUtils/tests/TestUtils.UnitTests/ShellHelperTests.cs |
Adds process-output, quoting, and timeout regression tests. |
src/TestUtils/tests/ProcessTestHelper/Program.cs |
Implements argument echoing, concurrent output, and inherited-pipe scenarios. |
src/TestUtils/tests/ProcessTestHelper/ProcessTestHelper.csproj |
Defines the non-packable helper executable. |
src/TestUtils/src/UITest.Appium/ShellHelper.cs |
Implements concurrent draining, structured commands, and platform-aware process setup. |
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Selected Tests
🧪 Test selection — click to expand
🧪 UI tests — the full suite on every platform❌ Could not queue GPT-6.2 Sol: Run the full UI suite because ShellHelper changes shared Appium process execution on all four platforms. 🧪 Running — 77 categories on Android, iOS, MacCatalyst, WindowsThe complete 🧪 Device tests — the full suite on every platform❌ Could not queue GPT-6.2 Sol: Skip device tests because the changes are limited to the Appium UI harness and its unit tests. 🧪 Running — 105 categories on Android, iOS, MacCatalyst, WindowsThe complete 🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)UI testsEach model chose independently; every test that runs was selected by at least one of them.
GPT-6.2 Sol — Run the full UI suite because ShellHelper changes shared Appium process execution on all four platforms.
MAI Code 2 — ShellHelper process and output-draining changes affect shared UI-test infrastructure across all platforms, so run the full UI suite.
Device testsEach model chose independently; every test that runs was selected by at least one of them.
GPT-6.2 Sol — Skip device tests because the changes are limited to the Appium UI harness and its unit tests.
MAI Code 2 — Shared
Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
MAUI Autopilot — Retrying@kubaflo ❌ The fix round failed. The loop retries it once. Run. Error |

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
ae78b95b980b8f6001dd75789af7e6a15649f3a9↑ Full TestUtils Debug passes 65 tests with 2 expected Windows skips.
↑ Focused Release passes 4 ShellHelper tests with 1 expected Windows skip.
↑ The old Windows run's 128-byte failure is directly covered by legacy
cmd.exe /Cserialization and an added Windows command-text test.↓ The new Windows head has not completed CI locally.
↑ The old Windows CI run returned only 128 bytes of the expected 1 MiB.
↑ Inline review identified the independent inherited-pipe join and discard-assertion gaps.
↑ Inherited-pipe coverage waits for the bounded 10-second drain, returns while the descendant still holds the pipes, and cleans it up.
↑ Direct structured arguments round-trip exactly.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Target Branch
mainnet11, for reviewThis is .NET 12 test infrastructure work, so the initial base is
main.For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into
net11; agents must not retarget or merge.Description of Change
ShellHelperredirected stdout and stderr before waiting for the child, but its no-output path never drained either stream and its capture path drained stdout fully before stderr. A child writing enough data to both pipes could deadlock. The pre-fix reproduction timed out after 5 seconds, and the first Windows CI run captured only 128 bytes of the expected 1 MiB./C {command}toProcessStartInfo.Arguments; the whole command is not passed through .NET'sArgumentListserializer forcmd.exe.-cplus the command text as separateArgumentListentries.ExecuteCommandandExecuteCommandWithOutputentry points that useArgumentListthroughout, so new callers can avoid shell parsing when it is unnecessary.Process.RunAndCaptureTextAsyncwhen output is requested so stdout and stderr drain concurrently.Stream.Null, wait for the process with the integer overload that does not implicitly join asynchronous readers, and bound inherited-pipe draining to 10 seconds before cancellation.KillOnParentExitonly on Windows and Linux. macOS is intentionally excluded because the .NET 11/12 platform surface does not support that property there.mainwas merged into the feature branch with normal history after the review.No direct open or closed-unmerged PR was found for these
ShellHelperquoting and pipe-drain defects. Existing PRs #26096, #27370, and #28644 introduced, generalized, or extended the helper but did not attempt this process-lifecycle fix.Validation
dotnet format Microsoft.Maui.sln --no-restore --include src/TestUtils/src/UITest.Appium/ShellHelper.cs src/TestUtils/tests/TestUtils.UnitTests/ShellHelperTests.cs src/TestUtils/tests/ProcessTestHelper/Program.cs --exclude Templates/src --exclude-diagnostics CA1822dotnet build src/TestUtils/src/UITest.Appium/UITest.Appium.csproj -v:minimal -p:ArtifactsDir=$PWD/artifacts/shell-helper-review/builddotnet test --project src/TestUtils/tests/TestUtils.UnitTests/TestUtils.UnitTests.csproj -c Debug -p:ArtifactsDir=$PWD/artifacts/shell-helper-review/full-debug -- --report-trx --results-directory $PWD/artifacts/shell-helper-review/full-debug-resultsdotnet test --project src/TestUtils/tests/TestUtils.UnitTests/TestUtils.UnitTests.csproj -c Release -p:ArtifactsDir=$PWD/artifacts/shell-helper-review/full-release -- --filter-class Microsoft.Maui.TestUtils.UnitTests.ShellHelperTests --report-trx --results-directory $PWD/artifacts/shell-helper-review/full-release-resultsThe child helper writes 1 MiB without newlines to stdout and stderr concurrently. Capture and discard modes both verify a completion marker written only after both streams finish. Direct structured arguments round-trip through spaces, quotes, backslashes, an empty value, semicolons, and literal
$. The inherited-pipe test leaves a descendant alive with stdout/stderr open, verifies the discard call returns after the 10-second bound, and terminates the descendant in cleanup.Local execution used macOS ARM64. Windows
cmd.exeand Linux runtime paths are not available locally; the focused Windows command-text test and the original Windows flood regression run in the PR'smaui-prWindows unit-test leg. In the prior run, that leg failed on the old head exactly as predicted (expected 1 MiB, got 128 bytes); its Pack failure was unrelated infrastructure (service connection ... could not be found). No Linux VM/container daemon is running locally.Issues Fixed
N/A. This was found by the local process/build-tooling audit; no direct tracked issue or duplicate ShellHelper PR was found.
Let AI finish this PR