Skip to content

treat an empty PW_RSTUDIO_R_LIBS_USER as unset - #18390

Merged
kevinushey merged 3 commits into
mainfrom
bugfix/e2e-r-libs-empty-override
Jul 29, 2026
Merged

kevinushey merged 3 commits into
mainfrom
bugfix/e2e-r-libs-empty-override

Conversation

@kevinushey

@kevinushey kevinushey commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The consolidated Linux e2e workflow (#18360) sets, in Run Playwright tests:

PW_RSTUDIO_R_LIBS_USER: ${{ needs.setup.outputs.preinstall_r_packages == 'true'
                           && format('{0}/R-libs', github.workspace) || '' }}

with the stated intent that the empty branch means "the harness default". But an Actions env: value of '' is exported as a defined empty string, and rLibsUserTemplate() read it with ??:

return process.env[RSTUDIO_R_LIBS_USER_ENV] ?? defaultRLibsUserTemplate();

'' is not nullish, so it won, and the R_LIBS_USER template became "".

R treats an empty R_LIBS_USER as unset and computes its HOME-relative default. globalSetup runs with the real HOME, so it installed REQUIRED_PACKAGES into /home/runner/R/x86_64-pc-linux-gnu-library/4.5; the session under test runs with HOME redirected into the per-run sandbox (desktop.fixture.ts), so it resolved a different, empty library. That is precisely the hazard r-libs-setup.ts's header comment warns about. The default template is immune because os.homedir() is resolved before the redirect, producing an absolute path.

One line in the job log shows it, comparing the same branch before and after #18360 landed:

[r-libs] user library:
before /home/runner/.cache/rstudio-playwright/r-libs/x86_64-pc-linux-gnu/4.5
after /home/runner/R/x86_64-pc-linux-gnu-library/4.5

Everything else in those two runs is identical, including the GWT cache hash.

Impact

citations.test.ts:147 "inserts an R Package citation into the document" fails both attempts, deterministically, on linux-desktop shard 1 of every branch that has main merged in (runs 30296790097, 30429212918). The panel calls getRPackageState() and Fuse-searches the session's installed packages; with the empty library there is no knitr, and the trace contains "No matching packages".

Affected: the five engines with preinstall_r_packages: "" -- ubuntu-22-x86_64, ubuntu-24-x86_64, ubuntu-24-arm64, ubuntu-26-x86_64, debian-13-arm64. Fedora/Rocky pass a real path; macOS, Windows, and Linux Server never set the variable.

Beyond the one red test, the harness's REQUIRED_PACKAGES pre-population was landing in a library the session never saw, so those engines were quietly running against a much thinner library.

Fix

?? -> ||, which makes the workflow's documented intent true and also covers server.fixture.ts, and the prep log now names where the resolved library came from:

[r-libs] user library: /home/runner/.cache/rstudio-playwright/r-libs/x86_64-pc-linux-gnu/4.5 [harness default]
[r-libs] user library: /home/runner/work/rstudio/rstudio/R-libs [PW_RSTUDIO_R_LIBS_USER=/home/runner/work/rstudio/rstudio/R-libs]
[r-libs] user library: ... [harness default (PW_RSTUDIO_R_LIBS_USER set but empty)]

so a future override mismatch is visible in the job output instead of surfacing as a missing package.

Verification

  • npm run typecheck clean in e2e/rstudio.
  • Resolution checked directly against both revisions -- unset and explicit path are unchanged; '' returns "" on main and the default template here.
  • Confirmed at the first push: linux-desktop / E2E (ubuntu-24-x86_64) went green, shard 1 passed citations.test.ts:147, and the log read [r-libs] user library: /home/runner/.cache/rstudio-playwright/... [harness default].

Review follow-ups (089f2fd)

From the review, the items worth taking, all in the same file:

  • CRLF manifest parsing: required-packages.txt was split on '\n' only; on a Windows checkout the trailing \r defeats /#.*$/ (\r is a regex line terminator, so . stops at it and $ anchors past it) and every comment line was passed to install.packages() as a package name -- which is exactly the permanent [r-libs] WARNING: failed to install: # R packages ... noise every Windows shard has been printing. Now split(/\r?\n/). Verified against a CRLF rendition of the real manifest: old parse leaks 6 comment lines, new parse is byte-identical to the LF parse. (The action-side parser is R, not bash, and R's . crosses \r, so it needs no change.)
  • tools::: -> base:::: .expand_R_libs_env_var lives in base, so tools::: errored on every call and the reduced gsub fallback ran unconditionally. Harmless for the %p/%v templates in use (verified both paths expand identically), but %U/%S/%% would have been wrong. The fallback now writes a marker so a silent downgrade shows up in the prep log as a WARNING.
  • Provenance before the early returns: the template + source line now prints as the first thing prepareRLibs() does, so skip-prep runs and expansion failures are no longer diagnostic-free.
  • Docs: module header and the README env-var table now state that an empty value is treated as unset.

Deliberately not taken: console.warn for the "set but empty" case (empty is the intended per-engine signal in the Linux workflow -- warning on it would fire on every run of five engines, permanently).

Preinstall on every engine (aa7dbc6)

The review also observed that with the resolution fixed, the five preinstall_r_packages: "" engines install the 23-package set into the harness-default library -- which no workflow cache covers -- on every run. This flips preinstall_r_packages: "true" for all five, routing the install through os-e2e-deps into the cached R-libs tree (keyed on the manifest via -req<hash>) and pointing PW_RSTUDIO_R_LIBS_USER at it, so a warm run installs nothing.

Two of them (ubuntu-24-x86_64, ubuntu-26-x86_64) also get explicit cache scopes (noble-amd64 / resolute-amd64): both used the legacy shared Linux key, which was tolerable for pak's DESCRIPTION deps but is an ABI hazard once the cache carries the full compiled package set -- whichever engine saved first on main would hand its binaries to the other, and the presence check would count them as installed. Their caches start cold and warm on the next main-scoped run.

The review's own suggested shape (unconditional PW_RSTUDIO_R_LIBS_USER) would not have worked: the R-libs cache is saved inside the action -- before globalSetup runs, and only from main -- so anything globalSetup installs into that tree still never persists; and dropping the conditional would decouple the cache key from the manifest, since -req<hash> only applies when install-required-packages is set.

With this commit the ubuntu-24 job's expected log line changes from the .cache/rstudio-playwright path (verified at the first push, above) to [r-libs] user library: /home/runner/work/rstudio/rstudio/R-libs [PW_RSTUDIO_R_LIBS_USER=...], with os-e2e-deps doing the install instead.

No NEWS.md entry: CI-only, and the regression never reached a release.

The consolidated Linux e2e workflow (#18360) sets

  PW_RSTUDIO_R_LIBS_USER: ${{ ... == 'true' && format(...) || '' }}

intending the empty branch to mean "use the harness default". A GitHub
Actions env: value of '' is exported as a defined empty string, so
rLibsUserTemplate()'s `??` took it as an explicit override and the
R_LIBS_USER template became "".

R treats an empty R_LIBS_USER as unset and computes its HOME-relative
default, so globalSetup installed REQUIRED_PACKAGES under the real HOME
while the session under test -- whose HOME the desktop fixture redirects
into the per-run sandbox -- resolved a different, empty library. That is
the exact hazard this file's header comment describes.

citations.test.ts "inserts an R Package citation" then failed both
attempts on every affected engine (the five with preinstall_r_packages
empty: ubuntu-22/24-x86_64/24-arm64/26, debian-13): the panel searches
the session's installed packages, finds no knitr, and reports "No
matching packages".

Use || so an empty override falls back, and name the source of the
resolved library in the prep log so a future mismatch is visible in the
job output rather than only as a missing package.
@kevinushey kevinushey added this to the 2026.08 (Yellow Yarrow) milestone Jul 29, 2026
@posit-snyk-bot

posit-snyk-bot commented Jul 29, 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 requested a review from gtritchie July 29, 2026 17:08
@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated multi-agent review. The fix itself is correct and verified: R's etc/Renviron uses R_LIBS_USER=${R_LIBS_USER:-'%U'}, and :- substitutes on empty as well as unset, so the mechanism described in the PR body holds. The linux-desktop / E2E (ubuntu-24-x86_64) job logs the new line as intended and citations.test.ts:147 passes. No critical issues.

Important

  1. e2e/rstudio/fixtures/r-libs-setup.ts:22 and e2e/rstudio/README.md:548 — both still state that PW_RSTUDIO_R_LIBS_USER "overrides the default template entirely", which is now false for the empty value this PR exists to handle. The module header is the first thing a reader hits and the correction is 70 lines below it; the README table is the documented contract for the suite. Fix: add "an empty value is treated as unset" to both.

  2. e2e/rstudio/fixtures/r-libs-setup.ts:225 — the new provenance log is reachable only after expandRLibsUserTemplate() and fs.mkdirSync() both succeed. The PW_RSTUDIO_R_LIBS_SKIP_PREP return (:210-213) and the expansion-failure warning (:217-222) print no provenance, and workerRLibsUser() / server.fixture.ts:115 never log it at all — so a skip-prep run, the configuration most likely to have a wrong library, still has zero diagnostics. Fix: emit the template plus source as the first statement of prepareRLibs(), keeping :225 as an additive resolved-path line.

  3. e2e/rstudio/fixtures/r-libs-setup.ts:102-111 — the set but empty case is reported via console.log, mid-line. That is the one condition that motivated this PR: a caller's explicit override silently discarded. CI triage greps for WARNING. Fix: console.warn on its own line.

Suggestions

  1. e2e/rstudio/fixtures/r-libs-setup.ts:102-111 — rLibsUserSource() re-reads the env var and re-encodes "truthy wins", so if rLibsUserTemplate() ever changes the log will lie about provenance. Fix: have one internal resolver return { template, source }.

  2. e2e/rstudio/fixtures/r-libs-setup.ts:94 — a whitespace-only override is still taken verbatim as a library path (' ' is truthy). ?? and || are behaviorally identical for every input except ''. Fix: .trim() the value if the guard is meant to be real.

  3. e2e/rstudio/fixtures/r-libs-setup.ts:89-91 — the substance is accurate but the wording isn't: "with ?? that silently won the fallback" parses two ways, and the trailing (empty) means the directory is package-less, not the path. "See rLibsUserSource()." points at a log-string formatter that explains nothing about the mechanism — drop it. Consider stating it as an invariant rather than a changelog: "Do not switch to ??: GHA exports an empty env: value as a defined empty string."

  4. .github/workflows/os-test-e2e-rstudio-desktop-linux.yml:853 — the fix restores correctness, but on the five affected engines the harness default library (~/.cache/rstudio-playwright) is not in the workflow cache, so globalSetup now installs 23 packages plus dependencies from PPM on every run. That is the pre-consolidate linux desktop e2e workflows into one parameterized workflow #18360 behavior, so it is not a regression from this PR. Pointing PW_RSTUDIO_R_LIBS_USER at the already-cached job-level $R_LIBS_USER unconditionally would let those installs persist across runs and make the conditional expression unnecessary.

Pre-existing, adjacent — not introduced by this PR

Flagged because they sit in the same file and the same failure class. Out of scope to fix here.

  1. e2e/rstudio/fixtures/r-libs-setup.ts:53 — CRLF breaks comment stripping in the required-packages.txt parser. .split('\n') leaves a trailing \r; in /#.*$/ the . will not cross \r (a line terminator for .) and $ without m anchors past it, so comments are never stripped on Windows checkouts. All four Windows shards of this PR's run print [r-libs] WARNING: failed to install: # R packages pre-installed into the shared R library by globalSetup, ..., which means the one signal that would reveal a genuinely missing package is permanent noise on Windows. Fix: split on /\r?\n/, or drop the $ anchor. Check .github/actions/os-e2e-deps/action.yml's bash parser of the same file for the equivalent issue.

  2. e2e/rstudio/fixtures/r-libs-setup.ts:146 — .expand_R_libs_env_var lives in base, not tools, and ::: does not inherit, so tools:::.expand_R_libs_env_var errors (object '.expand_R_libs_env_var' not found on R 4.6.0). Every call silently takes the hand-rolled gsub fallback at :147-155, which handles a fixed token subset and not %U. The comment at :136-141 describes a path that never executes. Fix: base:::, and cat a marker in the handler so the log shows which expander produced the path.

  3. e2e/rstudio/fixtures/r-libs-setup.ts:251-266 — a failed package install exits 0. install.packages() warns rather than errors, so the R-side [r-libs] WARNING: failed to install: prints while the process exits 0; the TypeScript side only checks res.status !== 0, returns the path as success, and exports PW_R_LIBS_TEMPLATE, so an incomplete library is hardlink-cloned to every parallel worker. Same silent-failure shape this PR fixes.

Note on CI

The failing windows / e2e-desktop-windows (4) check is unrelated to this change: run-with-heartbeat: no output for 300s after project_editor_theme.test.ts. Windows passes a real path, so || vs ?? cannot affect it.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review findings posted

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

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

Passed Failed Skipped Flaky
1681 0 303 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ desktop-linux 250 0 34 0
✅ desktop-macos 477 0 85 1
✅ desktop-windows 477 0 90 1
✅ server-linux 459 0 94 0
✅ setup 18 0 0 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 aa7dbc6326f7e9fb564dcecd983b067eeb6c3876 - Run #384

…ogging

Follow-ups from the review on #18390, all in the file this PR already
touches:

- required-packages.txt was split on '\n' only, so a Windows checkout
  (core.autocrlf=true on the GHA runners) left a trailing '\r' on every
  line. '\r' is a line terminator for JS regex, so in /#.*$/ the '.'
  cannot cross it and '$' anchors past it -- no comment was ever
  stripped, and all six header lines were passed to install.packages()
  as package names. Every Windows shard has been printing
  "[r-libs] WARNING: failed to install: # R packages pre-installed ..."
  as a result, which made the one signal that would reveal a genuinely
  missing package permanent noise.

- .expand_R_libs_env_var lives in base, not tools, and ':::' does not
  inherit, so tools:::.expand_R_libs_env_var errored on every call and
  the reduced gsub fallback ran unconditionally. It happens to agree
  with R for the %p / %v templates we actually use, so nothing was
  mis-expanded, but the documented path never executed and %U / %S /
  %%-escaping would have been wrong. The fallback now marks itself so a
  future regression is visible in the prep log.

- The template and its provenance are logged before prepareRLibs()'s
  early returns, so a skip-prep run -- the configuration most likely to
  be pointed at the wrong library -- is no longer diagnostic-free.

- The module header and the README entry for PW_RSTUDIO_R_LIBS_USER now
  state that an empty value is treated as unset.
The five engines with PPM binary coverage (ubuntu-22/24/26 x86_64,
ubuntu-24 arm64, debian-13 arm64) left preinstall_r_packages empty, so
globalSetup installed the 23-package REQUIRED_PACKAGES set into the
harness-default library (~/.cache/rstudio-playwright) -- which is not in
any workflow cache -- on every single run. Flipping the flag routes the
install through os-e2e-deps into the job-level R-libs tree, which is
cached (keyed on the manifest via -req<hash>), and points globalSetup at
it via PW_RSTUDIO_R_LIBS_USER, so a warm run installs nothing.

ubuntu-24-x86_64 and ubuntu-26-x86_64 also get explicit cache scopes
(noble-amd64 / resolute-amd64): both used the legacy empty scope, i.e.
one shared "Linux" key. Tolerable while the cache held only pak's
DESCRIPTION deps, but with the full compiled package set in the tree,
noble and resolute sharing a library is an ABI hazard -- whichever
engine saved first on main would hand its binaries to the other, and the
presence check would see them as installed. The new scopes start those
two caches cold; they warm on the next main-scoped run.

No heartbeat change: fedora/rocky raise it because a cache miss can
source-compile at test time, but these engines install binaries in the
deps step, outside the watchdog's scope.
@kevinushey
kevinushey merged commit b286425 into main Jul 29, 2026
6 checks passed
@kevinushey
kevinushey deleted the bugfix/e2e-r-libs-empty-override branch July 29, 2026 18:54
kevinushey added a commit that referenced this pull request Aug 10, 2026
…#18487)

The Windows and macOS e2e workflows never passed install-required-packages
to the os-e2e-deps action, so the harness's REQUIRED_PACKAGES set (DBI,
shinytest2, rmarkdown, ...) was installed from cran.r-project.org at test
time on every run: by globalSetup when it could, and by per-test
ensurePackages self-healing when it could not. During a CRAN outage those
installs hang mid-suite (s4_unloaded_package, shinytest2 in the pr-18449
all-platforms run) instead of failing fast.

Pass install-required-packages to the deps action on every desktop engine,
matching Linux (PR #18390), so the set is installed from PPM into the cached
R library before tests and a warm cache installs nothing at all. The macOS
workflows and the scheduled Windows autocomplete workflow also gain the
PW_RSTUDIO_R_LIBS_USER wiring that points globalSetup at that same library
(the main Windows workflow already had it).

The Linux Server workflow deliberately keeps its own system-library seed:
its sessions run as a per-run user, and tests that exercise uninstall flows
(fortunes, DBI) cannot remove packages from a root-owned library.
kevinushey added a commit that referenced this pull request Aug 10, 2026
…18489

commit 849c42d
Author: Kevin Ushey <[email protected]>
Date:   Mon Aug 10 13:43:21 2026 -0700

    keep tidyverse; add it to required-packages.txt

    Restores tidyverse in the e2e DESCRIPTION (dropped in the previous
    review commit) and adds it to required-packages.txt, so globalSetup's
    presence check covers it and CI preinstalls it into the cached library.

commit 5bd28d4
Merge: 0e36677 aebb191
Author: Kevin Ushey <[email protected]>
Date:   Mon Aug 10 13:42:52 2026 -0700

    Merge remote-tracking branch 'origin/main' into test/e2e-rlibs-consolidation

    # Conflicts:
    #	.github/actions/os-e2e-deps/action.yml

commit 0e36677
Author: Kevin Ushey <[email protected]>
Date:   Mon Aug 10 13:32:26 2026 -0700

    address review feedback

    - scope the provision-step chown to the resolved USER_LIB rather than a
      hardcoded ~/R, so the guard and the ownership handover stay in lockstep
    - fail the provision step with names when required packages are missing
      from the test user library, instead of echoing an unasserted count
    - pin the action's install step to R_LIBS_USER = the r-libs-user input,
      so the install can't diverge from the cache path and exported lookup
    - drop tidyverse from e2e/rstudio/DESCRIPTION (referenced by no test;
      the components tests use come via required-packages.txt)

commit 6d2dcf3
Author: Kevin Ushey <[email protected]>
Date:   Fri Aug 7 17:10:38 2026 -0700

    e2e: consolidate R package provisioning in the os-e2e-deps action

    Getting the harness's required R packages installed where the session can
    see them previously took a hand-wired pair in every workflow -- the
    install-required-packages input plus a PW_RSTUDIO_R_LIBS_USER env var
    pointing at the same path -- and configuring one without the other silently
    degraded to test-time installs from cran.r-project.org (the failure class
    behind #18390 and the pr-18449 Windows CRAN-outage hangs). The Linux Server
    workflow had a third mechanism: a separately curated list seeded into a
    root-owned system library, which uninstall-flow tests could never touch.

    Make the os-e2e-deps action own the whole contract: default
    install-required-packages to true and export PW_RSTUDIO_R_LIBS_USER from
    the action itself (skipped when the caller defines it or opts out), then
    delete the per-workflow wiring on Windows, macOS, and Linux desktop. The
    Linux engines keep their per-engine escape hatch (an empty value still
    opts out).

    The server workflow now copies the action-populated library into the
    per-run test user's default user library (~/R/%p-library/%v) and chowns
    it: rserver rebuilds each session's environment from scratch (#18348), so
    only R's own default path can reach the rsessions. Sessions get every
    package read-write, so uninstall-flow tests (missing_packages_banner)
    keep working, and the system-library seed is retired. Of its curated
    list, readr is genuinely used (import_dataset.test.ts) and moves into
    required-packages.txt; tidyverse is referenced by no test and is dropped.

    Addresses #18488.

commit 02d8c6e
Author: Kevin Ushey <[email protected]>
Date:   Fri Aug 7 16:41:44 2026 -0700

    e2e: pre-install required R packages on the windows and macos runners

    The Windows and macOS e2e workflows never passed install-required-packages
    to the os-e2e-deps action, so the harness's REQUIRED_PACKAGES set (DBI,
    shinytest2, rmarkdown, ...) was installed from cran.r-project.org at test
    time on every run: by globalSetup when it could, and by per-test
    ensurePackages self-healing when it could not. During a CRAN outage those
    installs hang mid-suite (s4_unloaded_package, shinytest2 in the pr-18449
    all-platforms run) instead of failing fast.

    Pass install-required-packages to the deps action on every desktop engine,
    matching Linux (PR #18390), so the set is installed from PPM into the cached
    R library before tests and a warm cache installs nothing at all. The macOS
    workflows and the scheduled Windows autocomplete workflow also gain the
    PW_RSTUDIO_R_LIBS_USER wiring that points globalSetup at that same library
    (the main Windows workflow already had it).

    The Linux Server workflow deliberately keeps its own system-library seed:
    its sessions run as a per-run user, and tests that exercise uninstall flows
    (fortunes, DBI) cannot remove packages from a root-owned library.
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