From 0539b839ec6c704cb2a62c1bc57a65aac7f3f2aa Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 9 Nov 2026 16:02:10 -0800 Subject: [PATCH] Write the WinUI E2E ready marker atomically so the test never reads an empty file (#21932) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **What failed:** `[vscode] Aspire WinUI debug E2E > debugs an unpackaged WinUI project through its generated apphost executable` failed on attempt 1 in [42448442647](https://github.com/microsoft/aspire/actions/runs/42448442647/job/128635064936) (tracker #21600, unowned rank 1): ``` AssertionError [ERR_ASSERTION]: The input did not match the regular expression /^ready:\d+$/. Input: '' ``` **Why:** The generated WinUI fixture app wrote its ready marker with `File.WriteAllText(readyFile, …)`. That call creates the file before it writes the content. `waitForReadyMarker` polls for the file and returns its first successful read, so a poll that landed in that gap returned `''` and failed the assertion. The app had started correctly; the test read the file before the content was written. **How fixed:** The fixture app (`extension/scripts/run-e2e.js`) now writes `ready:` to `.tmp` and then `File.Move(…, overwrite: true)` renames it into place. Because the rename is atomic, the marker path is either missing or holds the full content, so the test's first read is always complete. The assertion, timeouts and polling are unchanged. The existing `e2eLaunchProfile` unit test now checks for the atomic write and rejects a direct `File.WriteAllText(readyFile, …)`. ## Failure stats (14d, attempt 1) | Scope | Attempt-1 test failures / runs where the job executed | Rate | Passed on rerun | |---|---|---|---| | PR | 4 / 457 | 0.9% | 4 / 4 | | main | 0 / 99 | 0% | n/a | Main over 30 days: 0 test-level failures in 216 runs (0 / 99 in the last 14d plus 0 / 117 in the 16 days before). This job had 9 other attempt-1 failures that never reached the test and are excluded: 8 were "hosted runner lost communication" and 1 was an `aspire-extension` artifact download failure. Test-level failures (all four): - [42448442647](https://github.com/microsoft/aspire/actions/runs/42448442647/job/128635064936) (PR #21921, unrelated Java debug change): `The input did not match the regular expression /^ready:\d+$/. Input: ''` ← **fixed by this PR** - [42257446455](https://github.com/microsoft/aspire/actions/runs/42257446455/job/128037952447) (PR branch `aspireagent/fix-e2e-notification-dismiss-hover-race`): `Timed out after 120000ms waiting for the C# language server to resolve generated InitializeComponent … Last definitions: []` (the `tree-actions` shard also failed in the same attempt) - [41532732531](https://github.com/microsoft/aspire/actions/runs/41532732531/job/125585902027) (PR #20950): `Timed out after 240000ms waiting for the WinUI OnLaunched marker.` AppHost hosting startup took 1m42s, and 4 other Windows shards failed in the same attempt. - [41501727353](https://github.com/microsoft/aspire/actions/runs/41501727353/job/125481870825) (PR #21183): `The C# definition probe for InitializeComponent … Timed out after 129ms waiting for E2E control revision`. `dotnet --list-runtimes` took 53s, Roslyn never started, and 6 other shards failed in the same attempt. All four are genuine flakes, not caused by their PRs. The last three come from whole-runner slowness on Windows, which is tracked in #21570 with telemetry in #21644. This PR does not address them because fixing them would mean raising timeouts. **Local regression evidence:** A harness ran the fixture's exact before/after C# writer against a Node reader that uses `waitForReadyMarker`'s semantics (first successful read is asserted against `/^ready:\d+$/`), polling tightly, with 500 marker publications per run: - Before (`File.WriteAllText(readyFile, …)`): **10/10 runs** saw an empty marker (475–496 torn first reads out of about 500 per run). - After (write `.tmp`, then `File.Move` with `overwrite: true`): **0/10 runs** saw an empty marker (0 torn reads out of about 4,980 publications). The harness ran on Linux. On Windows, `File.Move(overwrite: true)` maps to `MoveFileEx(MOVEFILE_REPLACE_EXISTING)` within the same directory, which is also atomic for readers. **PR CI** ([run 42472017876](https://github.com/microsoft/aspire/actions/runs/42472017876)): `VS Code extension E2E (Windows, winui-debug)` and the Windows extension unit tests (including the updated `e2eLaunchProfile` test) passed on attempt 1. Three unrelated jobs failed on attempt 1: a GitHub 'Unicorn' outage while downloading Deno in `launch-profiles`, and the known `tree-actions` flakes (`Expected e2e-worker to expose an endpoint URL`, addressed by #21914; `Timed out … waiting for running AppHost` on Linux). After reruns, all 70 checks pass. **Verdict: MODERATE.** The fixed race is proven deterministically (10/10 → 0/10) and matches the newest failure's exact signature. However, it accounts for only 1 of the 4 attempt-1 test failures in 14d. The other 3 belong to the Windows runner-slowness family in #21570. ## Confidence High that this removes the empty-marker failure mode: the gap is inherent to `File.WriteAllText` and the reader returns on its first read. Low that it changes the C# language server / OnLaunched timeout failures, which this PR does not target. **How we stop this recurring:** Fixture processes that publish readiness files for E2E polling should write a temp file and rename it into place. The unit test now enforces this for the WinUI marker. ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - [x] No **🤖 Posted by AspireAgent (AI Agent)** Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 8f00c66a046365f79e8db48073a21fa0523bccca) --- extension/scripts/run-e2e.js | 6 +++++- extension/src/test/e2eLaunchProfile.test.ts | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/extension/scripts/run-e2e.js b/extension/scripts/run-e2e.js index 0e7e06e1dcd..860c392d68f 100644 --- a/extension/scripts/run-e2e.js +++ b/extension/scripts/run-e2e.js @@ -2021,7 +2021,11 @@ public partial class App : Application { var readyFile = Environment.GetEnvironmentVariable("ASPIRE_WINUI_E2E_READY_FILE") ?? throw new InvalidOperationException("ASPIRE_WINUI_E2E_READY_FILE is required."); - File.WriteAllText(readyFile, $"ready:{Environment.ProcessId}"); + // Publish the marker atomically: the E2E test polls for this file and asserts on its + // first successful read, so it must never observe a created-but-empty file. + var pendingReadyFile = readyFile + ".tmp"; + File.WriteAllText(pendingReadyFile, $"ready:{Environment.ProcessId}"); + File.Move(pendingReadyFile, readyFile, overwrite: true); _window = new Window { diff --git a/extension/src/test/e2eLaunchProfile.test.ts b/extension/src/test/e2eLaunchProfile.test.ts index 60753cec110..52fb72d2066 100644 --- a/extension/src/test/e2eLaunchProfile.test.ts +++ b/extension/src/test/e2eLaunchProfile.test.ts @@ -1380,7 +1380,9 @@ builder.Build().Run(); assert.ok(runner.includes('true')); assert.ok(runner.includes('')); assert.ok(runner.includes('')); - assert.ok(runner.includes('File.WriteAllText(readyFile, $"ready:{Environment.ProcessId}");')); + assert.ok(runner.includes('File.WriteAllText(pendingReadyFile, $"ready:{Environment.ProcessId}");')); + assert.ok(runner.includes('File.Move(pendingReadyFile, readyFile, overwrite: true);')); + assert.ok(!runner.includes('File.WriteAllText(readyFile,')); assert.ok(spec.includes('this.timeout(1_200_000);')); assert.ok(spec.includes("const symbol = 'InitializeComponent';")); assert.ok(spec.includes("name: 'getDefinitions'"));