Skip to content

[Testing] Make ShellHelper process-safe - #40833

Merged
kubaflo merged 3 commits into
mainfrom
simonrozsival-process-tooling-hardening
Nov 30, 2026
Merged

kubaflo merged 3 commits into
mainfrom
simonrozsival-process-tooling-hardening

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: ae78b95b980b8f6001dd75789af7e6a15649f3a9

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ UITest.Appium builds with zero warnings and errors.
↑ 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 /C serialization and an added Windows command-text test.
↓ The new Windows head has not completed CI locally.
Diagnosis confidence 10/10 ↑ The pre-fix child timed out after 5 seconds while writing stdout and stderr concurrently.
↑ 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.
Evidence fit 10/10 ↑ The same capture and discard paths now complete, with a child-written completion marker.
↑ 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

This PR is for Initial base
New features, API changes, or .NET 12 work (including .NET 12 fixes) main
.NET 11 servicing fixes net11, for review
Older servicing, release integration, infrastructure, or documentation The branch designated for that work

This 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

ShellHelper redirected 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.

  • Preserve legacy Windows shell parsing by assigning /C {command} to ProcessStartInfo.Arguments; the whole command is not passed through .NET's ArgumentList serializer for cmd.exe.
  • Keep bash -c plus the command text as separate ArgumentList entries.
  • Add direct ExecuteCommand and ExecuteCommandWithOutput entry points that use ArgumentList throughout, so new callers can avoid shell parsing when it is unnecessary.
  • Use Process.RunAndCaptureTextAsync when output is requested so stdout and stderr drain concurrently.
  • For discard-only calls, copy both raw base streams concurrently to 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.
  • Set KillOnParentExit only on Windows and Linux. macOS is intentionally excluded because the .NET 11/12 platform surface does not support that property there.
  • Preserve synchronous completion and the existing output rule: return stdout unless it is whitespace, otherwise return stderr. Raw shell-string APIs remain shell-interpreted for compatibility; callers should prefer direct structured commands when shell syntax is not required.

main was merged into the feature branch with normal history after the review.

No direct open or closed-unmerged PR was found for these ShellHelper quoting 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

Command Result
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 CA1822 Passed; workspace loading emitted warnings but formatting completed.
dotnet build src/TestUtils/src/UITest.Appium/UITest.Appium.csproj -v:minimal -p:ArtifactsDir=$PWD/artifacts/shell-helper-review/build Passed with 0 warnings and 0 errors.
dotnet 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-results 65 passed, 0 failed, 2 Windows-only skipped.
dotnet 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-results 4 passed, 0 failed, 1 Windows-only skipped.

The 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.exe and Linux runtime paths are not available locally; the focused Windows command-text test and the original Windows flood regression run in the PR's maui-pr Windows 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

  • Let the MAUI agent address review feedback and fix remaining issues on this PR. Maintainers still decide whether it is merged. For PRs from forks, keep "Allow edits by maintainers" on so the agent can push to your branch; otherwise it opens a follow-up PR that keeps your commits.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expert Review — 3 findings

Reviewed commit 7a07400.

See inline comments for details.

@github-actions

This comment has been minimized.

simonrozsival and others added 2 commits November 30, 2026 16:22
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival
simonrozsival marked this pull request as ready for review November 30, 2026 15:34
Copilot AI balanced review requested due to automatic review settings November 30, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expert Review — 3 findings

Reviewed commit ae78b95.

See inline comments for details.

@github-actions

Copy link
Copy Markdown
Contributor

Selected Tests

@kubaflo — AI-selected UI tests and device tests (GPT-6.2 Sol + MAI Code 2) for commit ae78b95b.

Result NOT QUEUED Platforms Android, iOS, MacCatalyst, Windows Tests all UI, all device Commit ae78b95b


🧪 Test selection — click to expand
Suite Result Selected Build
UI tests ❌ not queued all 77 categories —
Device tests ❌ not queued all 105 units —
🧪 UI tests — the full suite on every platform

❌ Could not queue maui-pr-uitests: Azure Pipelines did not start maui-pr-uitests for the dispatch branch run-tests/pr40833-46458227848 within 10 minutes. Comment /review run-tests again, or use /azp run maui-pr-uitests for the full suite.

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.

🧪 Running — 77 categories on Android, iOS, MacCatalyst, Windows

The complete maui-pr-uitests suite runs on every platform (same as /azp run).

🧪 Device tests — the full suite on every platform

❌ Could not queue maui-pr-devicetests: Azure Pipelines did not start maui-pr-devicetests for the dispatch branch run-devicetests/pr40833-46458227848 within 10 minutes. Comment /review run-tests again, or use /azp run maui-pr-devicetests for the full suite.

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 src/TestUtils process execution infrastructure changed, so run the complete device suite on all supported platforms.

🧪 Running — 105 categories on Android, iOS, MacCatalyst, Windows

The complete maui-pr-devicetests suite runs on every platform (same as /azp run).

🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)

UI tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android all categories all categories
iOS all categories all categories
MacCatalyst all categories all categories
Windows all categories all categories

GPT-6.2 Sol — Run the full UI suite because ShellHelper changes shared Appium process execution on all four platforms.

  • UITest.Appium/ShellHelper.cs changes shell arguments and stdout/stderr handling in the shared UI harness, so the risk is not limited to one category.
  • ProcessTestHelper and ShellHelperTests are unit-test fixtures and do not add UI categories.

MAI Code 2 — ShellHelper process and output-draining changes affect shared UI-test infrastructure across all platforms, so run the full UI suite.

  • ShellHelper is shared by UITest.Appium, so command execution and pipe handling can affect any UI test and warrants the full UI run.
  • Changes are platform-neutral host-process behavior; run Android, iOS, MacCatalyst, and Windows UI coverage.
  • Device selection is full-run because the change touches shared test infrastructure under src/TestUtils, not a device control-specific area.
  • Narrow control categories are omitted because no product control or feature behavior changed.

Device tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android — all categories
iOS — all categories
MacCatalyst — all categories
Windows — all categories

GPT-6.2 Sol — Skip device tests because the changes are limited to the Appium UI harness and its unit tests.

  • UITest.Appium is referenced by UI test projects, not Helix device test projects.
  • The new process helper is referenced only by TestUtils.UnitTests; no device test app or shared device runner changed.

MAI Code 2 — Shared src/TestUtils process execution infrastructure changed, so run the complete device suite on all supported platforms.

  • ShellHelper and its unit-test support live in shared test infrastructure under src/TestUtils, which has suite-wide blast radius.
  • The process invocation, output draining, and inherited-pipe logic are platform-neutral; include Android, iOS, MacCatalyst, and Windows.
  • Run all device units rather than control-specific categories because the diff does not isolate impact to one device-test subsystem.

Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/autopilot-running MAUI Autopilot loop is running; remove this label to stop it label Nov 30, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) label Nov 30, 2026
@kubaflo
kubaflo merged commit a6a5234 into main Nov 30, 2026
5 of 8 checks passed
@kubaflo
kubaflo deleted the simonrozsival-process-tooling-hardening branch November 30, 2026 22:22
@github-actions github-actions Bot added the s/autopilot-retrying maui-expert-autopilot: retrying a step that failed once label Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

MAUI Autopilot — Retrying

@kubaflo ❌ The fix round failed. The loop retries it once. Run.

Error
safe_outputs: ✗ Message 1 (push_to_pull_request_branch) failed: Branch simonrozsival-process-tooling-hardening no longer exists on origin (it may have been deleted), can't push to it.
safe_outputs: 1 safe output(s) failed:

@kubaflo kubaflo removed s/autopilot-running MAUI Autopilot loop is running; remove this label to stop it s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) s/autopilot-retrying maui-expert-autopilot: retrying a step that failed once labels Dec 1, 2026
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.

3 participants