Skip to content

complete BRAT to Playwright migration - #17713

Merged
kevinushey merged 5 commits into
mainfrom
test/migrate-brat-guardrails-and-md
May 21, 2026
Merged

kevinushey merged 5 commits into
mainfrom
test/migrate-brat-guardrails-and-md

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

Finishes the BRAT-to-Playwright migration: the src/cpp/tests/automation/testthat/ directory is now empty. 37 new passing Playwright tests + 7 test.fixme placeholders + 1 test.skip cover what used to live there, and a fixture optimization shaves ~2s off every Playwright test we run.

Commits

  1. port path-based guardrails BRAT tests to Playwright -- 27 path tests in chat-guardrails-paths.test.ts driving .rs.chat.injectBindings() / restoreBindings() directly via a .rs.test.guardrails(quote(...)) helper installed in beforeAll. Each test batches pre; helper; post into one console submission and polls for an R-runtime-generated marker instead of sleeping. Also drops the click({ timeout: 2000 }) blind wait in rstudio.fixture.ts:beforeEach -- it was adding ~2 seconds to every test in the no-dialog case.
  2. port portable rmarkdown and quarto BRAT tests -- rmarkdown_chunks.test.ts (6 + 1 skip) + quarto_chunks.test.ts (4). Uses the executeCommand rstudioCallbacks bridge for chunk runs (no console-history pollution), waits on chunk-specific signals in console output. Deletes the BRAT rmarkdown.R and quarto.R; the 17 skip_on_ci BRAT tests they contained (visual-mode round-trips, chunk-options popup UI) were dropped, not ported -- noted in the migration doc for follow-up.
  3. drop orphaned helper-pane-layout.R -- both its callers were already deleted in earlier migration PRs.
  4. doc tweak -- reflect helper removal.
  5. delete remaining 3 BRAT files; add 6 test.fixme stubs for the tests that couldn't be ported as-is (4 guardrails binding-lifecycle, 2 debugger package-build cycle; the 1 edit-suggestions ghost-text focus bug already had its fixme since port edit-suggestions BRAT tests to Playwright (4 of 5) #17705).

Stats

BRAT files at start of branch 6 (5 test files + 1 helper)
BRAT files at end of branch 0
New passing Playwright tests 37
New test.fixme placeholders 6
New test.skip placeholders 1 (nb.html-on-save via the bridge)
Per-test fixture overhead saved ~2s

Open follow-ups (not in this PR)

  • nb.html-on-save investigation: saveSourceDoc via the executeCommand rstudioCallbacks bridge doesn't trigger nb.html generation. The same call via typeInConsole(".rs.api.executeCommand('saveSourceDoc')") worked in BRAT. Probably a missing step somewhere in the bridge path.
  • Visual-mode round-trip helper + ChunkOptionsPopup page object: would unblock porting the 17 skip_on_ci rmarkdown/quarto tests that were dropped with the BRAT files.
  • Wave 6 decommissioning (per MIGRATION_FROM_BRAT_PROGRESS.md): CLI flags (--run-automation, --automation-filter, --automation-markers), R helpers (.rs.automation.*, .rs.test, .rs.markers), .claude/CLAUDE.md BRAT references, the reference_brat_automation.md user memory.

Test plan

  • npx playwright test tests/panes/posit-assistant-chat/chat-guardrails-paths.test.ts -- 27 pass, 4 fixme (1.3m total)
  • npx playwright test tests/panes/editor/rmarkdown_chunks.test.ts -- 6 pass, 1 skip (1.6m total)
  • npx playwright test tests/panes/editor/quarto_chunks.test.ts -- 4 pass (1.0m total)
  • npx playwright test (full suite, Desktop + Server) -- not run locally; CI to confirm
  • Verify the fixture beforeEach optimization doesn't regress other suites in CI

Adds chat-guardrails-paths.test.ts covering 27 tests from
test-automation-guardrails.R: read denials (~/.aws/credentials, ssh,
.env/.Renviron/.Rprofile variants, etc.), read allows (SSH pubkey,
normal files), write denials (outside project, ~/.ssh, file.create /
file.remove / unlink / file.copy / file.rename), write allows (tempdir),
connection denials (file() to sensitive paths, deferred-open variant),
error-message structure (Action/Path/Reason fields), system-file
denials (/etc/passwd, /etc/shadow), and path traversal.

Drives the guardrails directly via .rs.chat.injectBindings() /
.rs.chat.restoreBindings() through a one-shot .rs.test.guardrails(quote(...))
helper installed in beforeAll. Each test runs `pre; helper(...); post` as
one console submission, batching plant/guard/cleanup, and polls for an
R-runtime-generated marker (won't match the input echo) instead of
sleeping. Run time is ~1.3 min for the 27 tests vs ~3.2 min with the
naive blind-sleep design.

Trimmed test-automation-guardrails.R to the 4 binding-lifecycle tests
that stay in BRAT: .rs.chat.safeEval returns errors as conditions rather
than printing them to the console, so the "blocked in console" pattern
the Playwright tests rely on doesn't apply to safeEval/double-inject
coverage. Tracking note added inline.

Side fix: rstudio.fixture.ts:beforeEach was calling
`page.locator(DONT_SAVE_BTN).click({ timeout: 2000 })`, which polls for
the full 2s in the (overwhelmingly common) no-dialog case, adding ~2s
of dead wait to every test. Replaced with `isVisible()` + `waitFor({
state: 'hidden' })` -- no implicit wait when nothing is there, positive
signal when there is.

Migration doc updates: corrects the console.R and data-viewer.R rows
that earlier PRs reverted back to "Partial" via bad merge conflict
resolution; refreshes the summary stats and the "remaining waves"
section to reflect the current state (24 Complete / 4 Partial / 3
Dropped / 1 Fixme).
rmarkdown_chunks.test.ts: 7 tests (1 test.skip) covering the
non-skip_on_ci subset of test-automation-rmarkdown.R -- warn-option
round-trip, chunk-widget visibility, error-halt, command-history-after-
error (#16006), patchwork S3-method dump (#13470), paged-table auto vs
explicit (#16483). nb.html-on-save is `test.skip`'d -- `saveSourceDoc`
via the `executeCommand` bridge doesn't trigger nb.html generation;
needs follow-up to understand whether the console path is doing
something the bridge isn't.

quarto_chunks.test.ts: 4 tests covering the non-skip_on_ci subset of
test-automation-quarto.R -- warn-option round-trip on .qmd, chunk-
widget visibility (#11745), variable-width nested-chunk folding
(#15191) via the existing AceEditor wrapper, empty-quarto-block
highlight regression (#16463).

Both new files use the `executeCommand` rstudioCallbacks bridge for
chunk runs instead of `typeInConsole(".rs.api.executeCommand(...)")`
-- the latter pollutes console history, which breaks the
history-after-error test (Up-arrow walks back through the typed
command strings instead of the chunk code).

The 10 skip_on_ci rmarkdown tests (visual-mode round-trips, chunk-
options popup UI) and 7 skip_on_ci quarto tests (visual-mode +
chunk-options popup + doc outline) are dropped along with their BRAT
files. Porting them would need a chunk-options modal helper and a
visual-mode round-trip helper.

Migration doc updated: rmarkdown and quarto now Complete; summary
stats refreshed; remaining-work section rewritten.
The helper was sourced by test-automation-tabs.R and
test-automation-chat-satellite.R, both of which were deleted in earlier
migration PRs. No remaining BRAT file references it, so the helper is
unused -- removing.
…cases

The last three BRAT files (debugger, edit-suggestions, guardrails) had
2-4 tests each retained because they didn't fit the existing Playwright
porting patterns. Rather than keep BRAT alive for those, drop the files
and convert each retained case into a test.fixme placeholder in the
Playwright file that would naturally host it:

- chat-guardrails-paths.test.ts: 4 fixmes for the binding-lifecycle
  tests (.rs.chat.safeEval auto-restore, double-inject reentrancy
  guard, safeEval blocks writes outside project, safeEval restores on
  user error). These ARE portable -- the natural form checks
  file.exists() or a follow-up write succeeding rather than the
  "blocked in console" pattern -- but they were left as TODOs so the
  next person can verify them end-to-end before un-fixme-ing.

- debugger_extras.test.ts: 2 fixmes for the package-build cycle
  tests (#15201 and the #9450 package-rebuild half). Each needs a
  full `devtools::build()` invocation, which takes ~minutes and
  doesn't fit the current fixture model. The BRAT comments are
  preserved so the next port has a starting point.

- edit_suggestions.test.ts: already had its test.fixme since #17705
  (`ghost text suggestions survive document mutations`); the BRAT
  counterpart is now removed.

Migration doc updated: BRAT files remaining = 0; the per-file table
flips debugger / edit-suggestions / guardrails to Complete (with the
fixme counts called out explicitly); the "Remaining" section is now
an inventory of the Playwright TODOs rather than BRAT TODOs.

The Wave 6 decommissioning checklist items (CLI flags, R helpers,
`.claude/CLAUDE.md` BRAT references, the `reference_brat_automation.md`
user memory) are not in this commit -- those land in a follow-up.
@kevinushey kevinushey added this to the Blue Plumbago milestone May 21, 2026
@posit-snyk-bot

posit-snyk-bot commented May 21, 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.

@kevinushey
kevinushey merged commit b980d25 into main May 21, 2026
1 check was pending
@kevinushey
kevinushey deleted the test/migrate-brat-guardrails-and-md branch May 21, 2026 02:51
kevinushey added a commit that referenced this pull request May 21, 2026
The BRAT tests have been ported to Playwright (#17713), so the BRAT
framework and its CLI plumbing are no longer needed. The `--automation-agent`
flag is preserved -- Playwright uses it to expose `window.rstudioCallbacks`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants