Drain AsyncStreamReader in GetStatus to fix flaky pwsh log-capture
Summary
Closes the deeper root cause behind the flaky WindowsPowerShellE2ETests that PR #317's RunToCompletion accumulator papered over. The race:
- Script writes a single line + exits within 50ms
- Test polls
GetStatus→BuildStatusreadsHasExited=true→ returns Complete - .NET's
AsyncStreamReaderhasn't yet dispatched theOutputDataReceivedcallback for the last line → log file on disk is still empty -
ReadLogsAndCursorreturns empty list → test sees state=Complete + 0 lines
CompleteScript already drains via WaitForExit() (no-arg) at LocalScriptService.cs:594. GetStatus is the OTHER way state=Complete becomes observable — when the test polls before invoking CompleteScript. This PR adds the same drain to BuildStatus.
-
DrainAsyncReadersOnce(RunningScript)— gates onInterlocked.Exchangeof a newDrainedAsyncReadersflag so concurrent polls don't double-call - Regression test — 5-iteration fast-exit script, first-Complete-poll asserts marker present
- Affects every Windows-only PR; multiple flakes traced to this race across #317, #320
Test plan
-
Unit: 5212/5212 pass locally -
Build: zero errors -
Windows CI: WindowsPowerShellE2ETests + LocalScriptServiceTests stable across runs