Skip to content

test(e2e): use activeEditor bridge in autocomplete actions - #17784

Merged
gtritchie merged 1 commit into
mainfrom
bugfix/autocomplete-e2e-active-editor
May 27, 2026
Merged

gtritchie merged 1 commit into
mainfrom
bugfix/autocomplete-e2e-active-editor

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

  • AutocompleteActions.getCompletionsInEditor was iterating document.querySelectorAll('.ace_editor') and focusing the first non-console match. On the failing autocomplete_extras tests the scan landed on a stale empty source editor at DOM index 0 instead of the live editor at index 1, so gotoLine + focus moved into the empty editor and the subsequent Ctrl+Space fired with nothing for the completer to anchor to. This is the same class of bug ad175dc (test(e2e): expose active ace editor via automation bridge #17775) fixed for getEditorContent / openFile.
  • Replace both the explicit-cursor and default-cursor branches with window.rstudio.documents.activeEditor(), which maps through SourceColumnManager.getActiveNativeEditor and reliably returns the active doc's editor.
  • Add Session.getLength() to utils/ace.ts so the default-cursor branch can stay typed.

Diagnostic output from a failing run before the fix (cursor placed at row 0 / column 0 in an empty editor, while the actual active editor held the test content):

editors[0]: not-in-console, valueLength=0   <- chosen
editors[1]: not-in-console, valueLength=30  <- real one
chosen: 0
finalContent: ""
activeEditorMatch: false
activeEditorContentLength: 30

Test plan

  • npm run typecheck
  • npm run test:desktop-dev -- autocomplete_extras -- 11/11 passed
  • npm run test:desktop-dev -- tests/panes/misc/autocomplete.test.ts -- 14/14 passed

getCompletionsInEditor was iterating document.querySelectorAll('.ace_editor')
and picking the first non-console match -- same bug ad175dc (#17775) fixed
for getEditorContent / openFile. On the failing tests the scan landed on a
stale empty source editor at DOM index 0 instead of the live editor at
index 1, so gotoLine + focus moved into the empty editor and Ctrl+Space
fired with nothing for the completer to anchor to.

Replace both the explicit-cursor and default-cursor branches with
window.rstudio.documents.activeEditor(), which maps through
SourceColumnManager.getActiveNativeEditor and reliably returns the
currently-active doc's editor. Also adds Session.getLength() to utils/ace.ts
so the default-cursor branch can stay typed.

Restores six autocomplete_extras.test.ts editor tests (pipe completions,
roxygen tags in .R/.Rmd/.qmd, already-used args pref, backtick-quoted
columns, _$ placeholder) and keeps the 14 autocomplete.test.ts tests
passing locally.
@kevinushey kevinushey added this to the Blue Plumbago milestone May 27, 2026
@posit-snyk-bot

posit-snyk-bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gtritchie
gtritchie merged commit f84e454 into main May 27, 2026
3 of 8 checks passed
@gtritchie
gtritchie deleted the bugfix/autocomplete-e2e-active-editor branch May 27, 2026 20:36
kevinushey added a commit that referenced this pull request May 27, 2026
empty-marker AceEditor was scanning .ace_editor DOM nodes and picking the
first non-console match -- same stale-editor bug fixed in ad175dc
(#17775) for openFile/getEditorContent and f84e454 (#17784) for
autocomplete actions. on tests with a single open file the marker '' would
trivially match, but the matched node could be a stale editor left in the
DOM after a tab close rather than the live active editor.

route empty marker through window.rstudio.documents.activeEditor() and
keep the DOM-walk path for non-empty markers (still useful when a test
needs a specific non-active tab).
kevinushey added a commit that referenced this pull request May 28, 2026
…tor (#17788)

* test(e2e): pin desktop fixture window size to 1400x900

avoids dualwindowlayoutpanel auto-snapping the left column to maximize
on the small (~1024x645) macos gh actions virtual display, which was
hiding the source pane and breaking edit_suggestions tests.

* test(e2e): route AceEditor('') through activeEditor bridge

empty-marker AceEditor was scanning .ace_editor DOM nodes and picking the
first non-console match -- same stale-editor bug fixed in ad175dc
(#17775) for openFile/getEditorContent and f84e454 (#17784) for
autocomplete actions. on tests with a single open file the marker '' would
trivially match, but the matched node could be a stale editor left in the
DOM after a tab close rather than the live active editor.

route empty marker through window.rstudio.documents.activeEditor() and
keep the DOM-walk path for non-empty markers (still useful when a test
needs a specific non-active tab).

* test(e2e): drop eval-based runOnEditor in AceEditor

the previous shape stringified the user's callback via fn.toString() and
reconstituted it in the browser with (0, eval)('(' + fnSource + ')').
that was the only way to ferry an arbitrary user function across the
node->browser boundary through page.evaluate's single-arg form.

replace it with page.evaluateHandle to resolve the editor once, then call
handle.evaluate with the user's function natively (playwright serializes
the function itself, no eval). overload run() so callers that pass no arg
stay typed; callers that need multiple args wrap in an object.

no behavior change for callers; the eval was a workaround the bridge has
since obsoleted.
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.

3 participants