Skip to content

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:

  1. Discarded intermediate polls — WaitForCompletion only checked state, threw away log responses
  2. In-memory vs persisted-logs off-by-one in LocalScriptService.cs:383 (uses LastLogSequence - 1) vs :387 (uses LastLogSequence raw) — boundary log entry falls through the crack
  3. Race on _scripts dict removal — depending on timing, the final GetStatus hits the in-memory or persisted-logs path with different sequence semantics

Fix

New RunToCompletion(ticket, timeout) helper:

  • Accumulates ALL log entries across GetStatus polls (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.

Merge request reports

Loading