Fix flaky WindowsPowerShellE2ETests via cumulative log accumulation (P2-3)
Summary
Five tests in WindowsPowerShellE2ETests shared a flaky log-fetch pattern. Replaces with a deterministic RunToCompletion helper that accumulates logs across polls.
Root cause
Three interacting bugs in LocalScriptService.GetStatus + the test pattern:
-
Discarded intermediate polls —
WaitForCompletiononly checkedstate, threw away log responses -
In-memory vs persisted-logs off-by-one in
LocalScriptService.cs:383(usesLastLogSequence - 1) vs:387(usesLastLogSequenceraw) — boundary log entry falls through the crack -
Race on
_scriptsdict removal — depending on timing, the finalGetStatushits the in-memory or persisted-logs path with different sequence semantics
Fix
New RunToCompletion(ticket, timeout) helper:
- Accumulates ALL log entries across
GetStatuspolls (deduplicated) - Final
GetStatus(ticket, 0)re-read catches boundary logs - Returns
(List<ProcessOutput> Logs, int ExitCode)tuple
All 5 tests refactored to use the helper.
Test plan
-
dotnet build— 0 errors -
CI on windows-latest: previously-flaky tests no longer flake
Follow-up
The underlying LocalScriptService off-by-one is still present — TODO for a separate PR to make TryBuildStatusFromPersistedLogs consistent with the in-memory branch. For now the test is deterministic against both behaviours.
Breaking-change risk
None. Test-only file change. No production code touched.