Repository navigation
Description
Playwright vs BRAT: State Isolation in RStudio Tests
Comparison of how the two RStudio test setups isolate per-user state, and why
Playwright runs leave leftovers (open documents, settings) visible in a normal
RStudio Desktop launch afterward, while BRAT runs do not.
Where the state actually lives
RStudio scatters per-user state across three roots, all overridable:
| Env var | XDG fallback | Default on macOS | What's in it |
|---|---|---|---|
RSTUDIO_CONFIG_HOME |
XDG_CONFIG_HOME |
~/.config/rstudio |
rstudio-prefs.json (user prefs) |
RSTUDIO_DATA_HOME |
XDG_DATA_HOME |
~/.local/share/rstudio |
session DB, source database (open docs), monitored user-state, Posit Assistant |
Electron userData (controlled by --user-data-dir) |
n/a | ~/Library/Application Support/RStudio |
Chromium profile: window state, recent files, cookies, localStorage |
src/cpp/core/system/Xdg.cpp and src/node/desktop/src/core/xdg.ts are where
the lookups happen.
What BRAT does (src/cpp/session/modules/automation/SessionAutomation.R:421-547)
- Wipes the env first — strips every
RS_*/RSTUDIO_*and
R_SESSION_TMPDIRfrom the child's environment so the inner RStudio looks
brand-new (lines 433-439). - Creates
tempfile("rstudio-automation-state-")and points all four at
subdirs:RSTUDIO_CONFIG_ROOT,RSTUDIO_CONFIG_HOME,RSTUDIO_CONFIG_DIR,
RSTUDIO_DATA_HOME(line 461)
- Passes
--user-data-dir=<browserDataDir>to Electron (line 526) —
isolates the Chromium profile. - Adds
RS_NO_SPLASH,RS_CRASH_HANDLER_PROMPT,
RSTUDIO_DISABLE_CHECK_FOR_UPDATES(479-481).
End result: every disk surface RStudio writes to is under tempfile(...). The
real user profile is never touched.
What Playwright does (e2e/rstudio/fixtures/desktop.fixture.ts:70-164)
- Inherits
process.envas-is — noRS_*/RSTUDIO_*wipe. - Creates
mkdtempSync(.../pw_rstudio_config_)and sets only three vars:RSTUDIO_CONFIG_ROOT,RSTUDIO_CONFIG_HOME,RSTUDIO_CONFIG_DIR
RSTUDIO_DATA_HOMEis intentionally not set — see the comment at line
162: "intentionally not overridden -- share local Posit Assistant
install/login".- Does not pass
--user-data-dirto Electron at all.
Why leftovers appear after Playwright
The two unisolated surfaces are exactly what shows up:
- Open documents / session-suspended state / monitored user-state →
RSTUDIO_DATA_HOME(~/.local/share/rstudio). Source database lives here;
that's why last-open files come back. - Window geometry, recent files, Electron-managed UI bits → Electron
userData(~/Library/Application Support/RStudioon macOS). No
--user-data-dir, so it writes to the real profile.
The comment in desktop.fixture.ts is honest about the RSTUDIO_DATA_HOME
tradeoff (Posit Assistant install/login persistence is convenient for dev). The
--user-data-dir omission appears to be a plain gap rather than a deliberate
choice — there's no comment defending it, and BRAT shows it's safe to use.
e2e/rstudio/README.md:118 references issue #17520 for tracking server-mode
parity, and useSuiteSandbox() in utils/sandbox.ts redirects R-side cwd
writes — but neither addresses the data-home or Electron-userData gap.
Minimal changes to match BRAT's isolation
- Set
RSTUDIO_DATA_HOMEto a temp subdir (and accept losing Posit Assistant
persistence, or carry it over selectively). - Pass
--user-data-dir=<temp>/browser-datain the spawn args.
Activity
ronblum commentedon May 8, 2026
Environment variables pointing at a sandbox:
Environment variables not set or not redirected:
I can't touch RSTUDIO_DATA_HOME because of the Posit Assistant tests, until I set up automated authentication. The tests rely on the user authenticating manually (so they currently all fail in GitHub Actions runners). RSTUDIO_DATA_HOME is at the top of the list to address. Any others?
ronblum commentedon May 8, 2026
A sandbox gets created where any file writing and project creation. I had RSTUDIO_DATA_HOME directed at the sandbox, but it causes a problem with Posit Assistant, so I took it out temporarily, continuing to rely on the user's local info. I think that once I get automated authentication going, I can put it back.
Another option: I think that I can set it up so that by default, RSTUDIO_DATA_HOME points at a temporary directory, but you can override it and set to a fixed directory. So
Would this be useful as a temporary measure?
gtritchie commentedon May 8, 2026
Sounds reasonable (default to isolation, allow an override to unblock posit assistant tests).
Also wonder if we could symlink just the part needed by Posit AI to somewhere else, and leave the rest isolated.
In addition, also need the mentioned Electron userdata isolation (
--user-data-dir).ronblum commentedon May 8, 2026
For the last one, you can pass RStudio options if you include them in the environment variable
PW_RSTUDIO_EXTRA_ARGS.ronblum commentedon May 11, 2026
There's a sandbox already implemented, but it includes some itmes. Here's the full plan. What are you thoughts?
In addition to the sandbox, there are some files and directories that can be controlled by the user, including the location of the sandbox itself (a temporary directory by default).
Also, there's a default rstudio-pres.json; it's needed, for example, for setting some dialog boxes to web-based instead of native. There's no default Rprofile and Renviron. These can be overlaid with tester-provided files (rstudio-pref.json is implemented, the other two WIP).
Let me know what you think--if there's anything more that would be useful, if you think most of these are unnecessary, or anything else.
Directory tree
Variables -- user-controlled
Dials a user or CI explicitly sets in the shell,
.env, or workflow YAML. AllPW_*vars are optional; defaults apply when unset.PW_SANDBOX<umbrella><os.tmpdir()>/pw_<runid>/and remove inglobalTeardownPW_SANDBOX_CREATE1to enablePW_SANDBOXpoints at a missing dir (default off, fail loud on typos)PW_RSTUDIO_PREFS_OVERLAY<file>base-prefs.jsoncPW_R_PROFILE_OVERLAY<file>PW_R_ENVIRON_OVERLAY<file>PW_R_LIBS_SEED<dir>r-home/r-libs/PW_USE_REAL_HOME11= rstudio inherits the real userHOME/USERPROFILE(debug aid). Unset or0= sandboxed (default).PW_HOME_OVERRIDE<path>HOME/USERPROFILEinstead of<per-worker>/homeVariables -- set automatically by the fixture
Set on rstudio spawn by
desktop.fixture.ts. The user does not need to set these; the fixture computes the values from the umbrella and per-worker root and passes them in the spawnenv(or as a CLI arg for--user-data-dir). Values in the user's own shell are overridden for the rstudio child process.RSTUDIO_CONFIG_ROOT<per-worker>/SessionAutomation.Rwrites it for BRAT child processes. Kept in anticipation of porting BRAT tests to Playwright.RSTUDIO_CONFIG_HOME<per-worker>/config-homeRSTUDIO_CONFIG_DIR<per-worker>/config-dirRSTUDIO_DATA_HOME<per-worker>/data-homeR_LIBS_USER<per-worker>/r-home/r-libsR_PROFILE_USER<per-worker>/r-home/RprofileR_ENVIRON_USER<per-worker>/r-home/RenvironR_HISTFILE<per-worker>/r-home/RhistoryHOMEredirection (would otherwise default to<per-worker>/home/.Rhistory); kept for tidier grouping underr-home/.TMPDIR/TMP/TEMP<umbrella>/os.tmpdir()both flow hereHOME(POSIX)<per-worker>/homeUSERPROFILE(Windows)<per-worker>/homeHOMEDRIVE/HOMEPATH(Windows)<per-worker>/home%HOMEDRIVE%%HOMEPATH%concatenation--user-data-dir=<per-worker>/electron-userdataRSTUDIO_EXTRA_ARGS(user value wins, last-wins switch parsing)Base file locations (in repo)
e2e/rstudio/fixtures/base-prefs.jsoncPW_RSTUDIO_PREFS_OVERLAYper workere2e/rstudio/fixtures/base.RprofilePW_R_PROFILE_OVERLAYe2e/rstudio/fixtures/base.RenvironPW_R_ENVIRON_OVERLAYbase-prefs.jsoncexists today;base.Rprofileandbase.Renvironare to be added as part of the plan implementation.ronblum commentedon May 17, 2026
Sandbox updated to include
RSTUDIO_DATA_HOMEanduser-data-dirto the sandbox.