Skip to content

e2e: harden five flaky specs from the cross-platform run - #18789

Merged
gtritchie merged 1 commit into
mainfrom
test/e2e-flake-hardening
Sep 11, 2026
Merged

gtritchie merged 1 commit into
mainfrom
test/e2e-flake-hardening

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

The all-platforms Playwright run on #18786 (report) reported 13 flaky tests across 6 files, with no hard failures. Five of the six files had a specific, identifiable race; this addresses those.

Several of them failed on all four platforms at once, which is the tell that they aren't timing noise -- they are state or protocol races that resolve the same way everywhere.

1. resetToUntitled kept a dirty Untitled placeholder (markdown.test.ts, all 4 platforms)

The failure surfaced as focusConsole: console input did not hold focus ... something is stealing focus. The screenshot shows why: a modal Save File - Untitled1 dialog, holding ggplot(mtcars, aes(wt, mpg)) + geom_point() -- the last fixture from ggplot_pipe_insert.test.ts, which ran earlier in the same worker.

resetSourcePaneState keeps one Untitled tab open so the source pane never transits the zero-tab HIDE state (#17738), and it reuses whichever untitled doc is already open. revertUnsavedTargets only reverts file-backed editors, so a dirty placeholder carried the previous spec's text across. The next saveAllSourceDocs then prompted Save As for that pathless doc, and its glass panel blocked every later click.

  • SourceColumnManager.onDocumentResetToUntitled now only reuses a clean untitled doc; a dirty one is closed with the rest and replaced (the existing create-then-close path already avoids the zero-tab gap). This event is only dispatched by the automation bridge, so it is test-facing only.
  • waitForSourcePaneReset requires the settled doc to be clean, so a reuse regression fails loudly instead of silently.
  • closeSourceAndDeleteFile drops its saveAllSourceDocs + sleep(1000). The file is deleted on the next line, so the save changed nothing -- it was purely the thing that could raise a modal.

New spec source_pane_reset.test.ts covers the invariant; verified it fails (dirty: true) with the SourceColumnManager change reverted and passes with it.

2. closeProjectIfOpen waited behind "Save workspace image?" (restart-under-agent.test.ts, macOS + Windows)

page.waitForFunction(() => project.isActive() === false) timed out at 30s. The screenshot shows a Close Project / Save workspace image to .../.RData? prompt.

The sessions all run with save_workspace: never, so this looks impossible -- but ApplicationQuit.saveAction_ is initialized to SaveAction.saveAsk() and only reaches the real value when the backend pushes SaveActionChangedEvent. A project closed seconds after it opened decides the quit inside that window and prompts. This spec closes projects in a tight open/close loop, so it lands there.

dismissSaveWorkspacePrompt (in modals.page.ts) clears it. It polls rather than waiting a fixed interval: in the common no-prompt case the quit proceeds instead, which flips window.rstudio.ready false or tears the context down, so a session that isn't going to prompt costs one poll.

openProject needs no equivalent -- the bridge fires SwitchToProjectEvent with forceSaveAll=true, which short-circuits before the prompt.

3. Editor keybindings load after ready (console_editor_keybindings.test.ts, Linux)

The startup spec reloads, waits for window.rstudio.ready, and presses the rebound shortcut. ready means R's deferred init finished; it says nothing about EditorCommandManager, which loads editor_bindings.json on EditorLoadedEvent through a separate async file read. The press can land before the rebinding exists and is swallowed (the console held gamma delta). Now the set/press/assert block is wrapped in toPass(), so the retry is the wait -- and a binding that never arrives still fails.

4. Clicking the editor before newSourceDoc produced one (vimrc_keybindings.test.ts, Windows)

locator.click: Element is not visible on .ace_content, with force: true. force skips the actionability checks, not the scroll-into-view that a zero-box element fails -- the click landed on the outgoing document's ace_content, still in the DOM but no longer rendered. executeCommand(page, 'newSourceDoc') only dispatches; the document is created over an RPC. Both tests now wait for the new editor to be active and painted. (The first test only passed because a polling assertion sat between the two steps.)

5. "No completions available" is terminal, not slow (code_suggestions.test.ts, all 4 platforms)

The status bar in the failure snapshot reads "Posit AI Pass: No completions available." -- the request completed with nothing. Nothing re-asks from there, so toBeVisible({ timeout: 30s }) waited out the full budget for a suggestion that was never coming. That is a live model declining a context, and it declines the same context on every platform, which is how one empty answer became four flaky rows.

expectGhostText now re-issues assistantRequestCompletions when the status bar reports an empty response, and still fails if nothing ever arrives.

Not changed: rmarkdown.test.ts "empty chunk does not define variables" (server-linux)

This one is not a test bug. The trace shows, right after restartRRunAllChunks:

Event listener stopped due to error (code=2, attempt=0); scheduling revival
WARNING: Error connecting with session.
1: jsonrpc error 1 (Unable to connect to service)

The session stayed unreachable for the whole 60s budget (revival cadence is 5s, so ~12 failed attempts), the console never got past Restarting R session..., and the toolbar was still showing the Session Suspended icon. The test's comment says its tight budget is deliberate -- it is the canary for #18340 -- so loosening it would hide exactly what it exists to catch. Leaving it to keep reporting.

Verification

npm run test:desktop-dev on macOS, against a worktree ant draft build:

  • source_pane_reset.test.ts -- passes; fails with the SourceColumnManager change reverted
  • ggplot_pipe_insert.test.ts + markdown.test.ts + source_pane_reset.test.ts in order (the sequence that produced the flake), --workers=1 -- 20 passed
  • vimrc_keybindings.test.ts + console_editor_keybindings.test.ts -- 8 passed
  • projects/ignorefiles.test.ts + projects/project_editor_theme.test.ts (close-project path) -- 7 passed
  • math_preview + rnotebook + notebook_inline_chunks + multiline_chunk_execution (a sample of closeSourceAndDeleteFile callers) -- 11 passed

code_suggestions.test.ts needs AI credentials and can only be exercised in CI.

https://claude.ai/code/session_0142QsQiftXXnEQzetogGZbt

Five of the six flaky files in a recent all-platforms run traced to
specific races rather than general slowness:

- resetToUntitled kept a DIRTY untitled placeholder. The placeholder is
  shared across specs, so text a previous spec left in it (ggplot_pipe_insert
  sets editor content directly) survived the reset; the next saveAllSourceDocs
  then raised a modal Save File prompt for the pathless doc, and its glass
  panel blocked the console. That is what failed the markdown HTML-preview
  spec on all four platforms, reported as "console input did not hold focus".
  SourceColumnManager now only reuses a clean untitled doc,
  waitForSourcePaneReset requires one, and closeSourceAndDeleteFile drops the
  saveAllSourceDocs it never needed (the file is deleted on the next line).

- closeProjectIfOpen could sit behind "Save workspace image?". The sessions
  run with save_workspace: never, but ApplicationQuit's saveAction_ holds its
  saveAsk() default until the backend's SaveActionChangedEvent lands, so a
  project closed seconds after it opened prompts anyway. Dismiss it.

- The console-keybindings startup spec pressed the rebound shortcut as soon as
  window.rstudio.ready went true; EditorCommandManager applies
  editor_bindings.json on a separate async read, so the press could precede
  the binding. Retry the block.

- The vimrc mid-session spec clicked the editor straight after newSourceDoc,
  which only dispatches the command -- the click landed on the outgoing
  document's unrendered ace_content. Wait for the new editor.

- The ghost-text specs treated "No completions available" as something to wait
  out. It is terminal: nothing re-asks, so a declined suggestion cost the full
  30s budget and, since the model tends to decline the same context
  everywhere, showed up as four flaky rows at once. Re-request instead.

Adds source_pane_reset.test.ts, which fails without the SourceColumnManager
change.

The sixth (rmarkdown restart-run-all-chunks on server-linux) is not a test
bug: the trace shows the event listener stopping and the session staying
unreachable for over a minute after the restart. Left alone so it keeps
reporting.

Claude-Session: https://claude.ai/code/session_0142QsQiftXXnEQzetogGZbt
@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
2760 0 186 9
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 693 0 38 3
✅ desktop-macos 701 0 33 1
✅ desktop-windows 697 0 41 2
✅ server-linux 639 0 44 3
✅ setup 28 0 20 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit ca9a65f763dc6e1e3fa06f59a74241ea7331233a - Run #946

@gtritchie
gtritchie merged commit af7ab6b into main Sep 11, 2026
34 checks passed
@gtritchie
gtritchie deleted the test/e2e-flake-hardening branch September 11, 2026 22:22
gtritchie added a commit that referenced this pull request Sep 12, 2026
Cherry-picked from af7ab6b (#18789) on main. That commit hardened five
specs; the console-keybindings one is dropped here because its feature
(#18761, custom editor keybindings in the console) is not on this branch,
so neither is the spec.

- resetToUntitled kept a DIRTY untitled placeholder. The placeholder is
  shared across specs, so text a previous spec left in it survived the
  reset; the next saveAllSourceDocs then raised a modal Save File prompt
  for the pathless doc, and its glass panel blocked the console.
  SourceColumnManager now only reuses a clean untitled doc,
  waitForSourcePaneReset requires one, and closeSourceAndDeleteFile drops
  the saveAllSourceDocs it never needed.

- closeProjectIfOpen could sit behind "Save workspace image?".
  ApplicationQuit's saveAction_ holds its saveAsk() default until the
  backend's SaveActionChangedEvent lands, so a project closed seconds
  after it opened prompts anyway. Dismiss it.

- The vimrc mid-session spec clicked the editor straight after
  newSourceDoc, so the click landed on the outgoing document's unrendered
  ace_content. Wait for the new editor.

- The ghost-text specs treated "No completions available" as something to
  wait out. It is terminal, so a declined suggestion cost the full 30s
  budget. Re-request instead.

Adds source_pane_reset.test.ts, which fails without the
SourceColumnManager change.
gtritchie added a commit that referenced this pull request Sep 17, 2026
* e2e: name the dialog blocking a project close

Cherry-picked from the e2e half of f54aaf2 (#18785) on main; the
product fix in that PR (shipping the save action in SessionInfo) is not
backported, so the "Save workspace image?" prompt this branch's sessions
can still raise stays a real possibility here.

closeProjectIfOpen waits on project.isActive() === false, and every wait
before it is satisfiable by the still-open project's console -- so a modal
the close itself raised lands there as a bare 30s waitForFunction timeout
with nothing naming the dialog. Read the visible dialog's text on timeout
and report it, carrying the original error as `cause`.

closeProjectIfOpen now returns whether dismissSaveWorkspacePrompt fired,
so a caller can assert on the prompt rather than have the sweep hide it.

* e2e: skip ai suites when the provider service is unreachable

Cherry-picked from c0f6bd8 (#18806) on main. Test-side only.

The AI gate proved the sandbox held credentials but never that the
provider could be reached, so an outage or blocked egress on the runner
failed inside the feature's own timeout instead of skipping. Probe each
provider's services from Node (utils/network.ts) as part of
requireAiCredentials, with the host list next to the provider table so
the gate, the beforeAll guard and the external-server check cannot
disagree. Under PW_AI_AUTH_STRICT an unreachable service fails instead.

For a network that degrades after the gate passed, aiServiceOutageReason
re-probes: code_suggestions turns a ghost-text or NES timeout into a
retroactive skip only when a host has since stopped answering, and
rethrows untouched otherwise. The Posit AI list includes the install
manifest on cdn.posit.co, since a timed-out manifest download leaves the
agent NotSignedIn and reads as a completion timeout.

beforeAll returns early without credentials, so the assistant setup does
not spend a minute on install prompts for tests beforeEach then skips.

* e2e: share the suggestion re-request and recover a lost bridge on open

Cherry-picked from the test-side half of 65abf11 (#18797) on main.
The two product fixes in that PR (EditorCommandManager binding load,
bounded Python discovery) are not backported, nor is the dev-launcher
GWT gating, which only affects local runs.

The re-requesting wait that #18789 gave ghost text is now
SourcePaneActions.waitForSuggestion, shared with the next-edit sites and
acceptNesRename: they still waited blindly on a provider that had already
answered "No completions available", which is terminal, so a declined
context burned the whole budget and reported as flake on every platform
at once. The re-request command has to match the kind of suggestion --
assistantRequestCompletions only asks for an at-cursor completion and its
fallback to a next-edit request is Copilot-only -- so the NES sites
re-ask through assistantAcceptNextEditSuggestion.

SourcePane.nesIndicator gives the four NES presentations one definition
in place of the or()-chain the specs each repeated.

openProject reloads once when the switched-to session never installs the
automation bridge. GWT's bootstrap has no retry, so a failed fetch of the
main cache.js leaves the window blank forever; a session that is merely
slow (bridge installed, ready still false) is left alone.

* e2e: wait for project session readiness before continuing

Cherry-picked from ff7bc1c (#18837) on main. Test-side only.

openProject's ready wait can be satisfied by the outgoing session, whose
deferred initialization completes during the switch; the incoming session
then publishes its project path before its own deferred initialization
has finished, so a helper that polls ready and the path separately can
return into a session that is still initializing. Observe both in one
predicate.

closeProjectIfOpen has the mirror problem: the project can already be
inactive while ready is still false, and returning in that interval lets
the next open race the previous session's initialization. Gate on ready
too, and move the console-idle check after it -- the earlier checks can
observe the outgoing session's console.

project-readiness.test.ts drives both helpers against a stubbed workbench
that separates project identity from deferred initialization the way a
desktop session switch does; both tests fail without the changes above.

This branch was previously deployed

1 inactive deployment
e2e-playwright — ca9a65f7 Deployed Sep 11, 2026 by kevinushey via windows / e2e-desktop-windows (4) #946
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.

2 participants