Skip to content

Provision AI credentials for Server-mode Playwright tests - #18458

Merged
ronblum merged 15 commits into
mainfrom
test/ron/e2e-server-ai-credentials
Aug 7, 2026
Merged

ronblum merged 15 commits into
mainfrom
test/ron/e2e-server-ai-credentials

Conversation

@ronblum

@ronblum ronblum commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Adds AI credential delivery for Server-mode Playwright tests, covering both deployment types the suite supports. For the spawned in-tree server, a generated --rsession-path wrapper now carries HOME, R_LIBS_USER, and an unset XDG_CONFIG_HOME into each rsession. For an external server, whose environment the harness cannot set directly, a new provisioning step pushes credentials through a live session instead.

  • Credential bytes for external servers travel over the Files pane's HTTP /upload endpoint rather than the R console, so they never enter the account's console history.
  • Remote probes are guarded against false positives from an unreadable store or a stale console read (nonce-tagged results), and the scrub manifest is written incrementally so a crash mid-run doesn't strand tokens.
  • Verified against a spawned in-tree server and an external VM, both credential sources, both providers.

Addresses #18348.

Two related but out-of-scope issues surfaced during verification and are filed separately: #18446 (pre-existing Server-mode sandbox data-home conflict) and #18457 (Posit AI credential gate doesn't account for token refresh).

@ronblum ronblum added this to the 2026.08 (Yellow Yarrow) milestone Aug 6, 2026
@posit-snyk-bot

posit-snyk-bot commented Aug 6, 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.

@ronblum

ronblum commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Review

  1. Medium — e2e/rstudio/tests/auth.setup.ts:1010: The XDG_CONFIG_HOME check ran even when only Posit AI credentials were being provisioned. That variable affects the Copilot path only, so a Posit-only external run failed unnecessarily instead of provisioning ~/.posit/ai/auth/data.json.

  2. Medium — e2e/rstudio/utils/remote-provision.ts (probe helpers): Remote probes used a helper that clears the console with a keystroke and then matches the first [1] TRUE/FALSE in the pane. The preceding write command visibly prints successful Sys.chmod/file.copy results, so a failed clear could make a probe consume stale output and falsely report success.

  3. Low — e2e/rstudio/tests/auth.setup.ts (Copilot push loop): The provisioning loop copied SQLite's auth.db-shm sidecar. This is regenerable WAL-index state, and copying it alongside a separately copied main database/WAL could leave an inconsistent SQLite store on the remote host.

  4. Low — e2e/rstudio/utils/remote-provision.ts (manifest reader): The manifest reader claimed malformed manifests throw, but accepted an array containing non-string paths and silently filtered them out. A damaged manifest could therefore lose a cleanup target and leave remote credentials behind.

Assessment

All four findings were verified directly against the code before being accepted.

  1. Confirmed: the check sat above the Posit AI branch and threw for any XDG mismatch regardless of which provider needed it. Agreed and taken.

  2. Confirmed as the most serious finding. The console-clear helper presses Ctrl+L and sleeps a fixed 500ms with no verification that the clear landed; a direct test in R confirmed the preceding write command prints [1] TRUE immediately before the probe runs. A failed clear could let a verification probe read that leftover output and vouch for a credential push that never happened. Agreed and taken, fixed locally to the remote probes rather than the shared helper used across the rest of the suite.

  3. Confirmed, though the "inconsistent store" framing overstates the risk somewhat since SQLite rebuilds a mismatched WAL index. Taken anyway: the transfer was unnecessary work, and the sidecar in the case we checked held no token data.

  4. Confirmed: the function's own documentation said a malformed manifest throws, and the implementation silently dropped bad entries instead. Agreed and taken.

One additional finding surfaced during the fix for item 2: the Copilot push loop read each local file inside the same loop that uploads it, with an HTTP round trip in between. Since the source store is live (the local agent can rewrite it on a token refresh), that window allowed a torn read across the main database and its WAL. Fixed by reading every file up front, before any upload begins.

Actions Taken

  1. Gated the XDG_CONFIG_HOME preflight on a Copilot store actually being provisioned.
  2. Replaced the console-scraping probe with one that tags each result with a per-call random value and matches only that exact tag, so stale output on the console can never satisfy it.
  3. Dropped auth.db-shm from the set of files pushed to the remote host; the existing pre-push scrub of the remote trio is unaffected.
  4. Made the manifest reader throw on any non-string path entry instead of filtering it out.
  5. Read all local Copilot files before uploading any of them, closing the torn-read window found while fixing item 2.

All five verified against a live external server: both credential sources (live sign-in and local-store copy), both providers, provisioning and teardown green in each run.

@github-actions

github-actions Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

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

Passed Failed Skipped Flaky
1978 0 377 8
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 8 0
✅ desktop-linux 490 0 90 1
✅ desktop-macos 494 0 86 2
✅ desktop-windows 493 0 90 4
✅ server-linux 477 0 95 1
✅ setup 22 0 8 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 277ba5587740f1330b685a1d45c3ba9a5101d577 - Run #471

@ronblum

ronblum commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Review of the merge commit (29dbb1d89f), which resolved a conflict in e2e/rstudio/utils/ai-credentials.ts between this branch and #18452.

Review

One finding, reported at Medium severity.

hasAiCredentials() and requireAiCredentials() can disagree on external-server runs (e2e/rstudio/utils/ai-credentials.ts:33,116)

hasAiCredentials() still reported true when sandbox credentials existed but external-server provisioning had failed, whereas requireAiCredentials() skipped those tests. That breaks the helper's stated shared-gate contract, and would let a beforeAll guarded on hasAiCredentials() run remote-incompatible setup before each test is skipped.

Suggested fix: make the shared predicate include external provisioning, or expose a shared runnable/skip-reason function and use it from both.

Assessment

Agreed, and the reasoning holds up under checking.

The divergence was real and introduced by the conflict resolution. #18452 added hasAiCredentials() as a single predicate and wired it into one caller, tests/panes/posit-assistant-chat/uninstall-posit-ai.test.ts:72, whose comment states the intent directly: "Shares hasAiCredentials with the gate so the two can't disagree." Attaching this branch's external-server check to only the gate falsified that comment.

Severity in practice is lower than Medium. The condition cannot be reached today. externalServerSkipReason returns non-null only when isExternalServerRun() is true, which requires PW_RSTUDIO_MODE=server (utils/auth.ts:450-455); the sole caller is tagged @desktop_only, and the server project's grepInvert excludes that tag (playwright.config.ts:109). The two conditions are mutually exclusive, so no current run can hit it.

Taken anyway, because the trap is cheap to close and easy to spring. The chat suite has 25 beforeAll hooks. The next server-capable one that copies this guard pattern gets a beforeAll that launches RStudio and installs Posit Assistant against a server with no credentials, before beforeEach skips every test -- exactly the failure the guard exists to prevent.

On the choice of fix: folding external provisioning into the shared predicate is faithful to #18452's intent rather than a redefinition of it. That function's own docstring describes the contract as whether "the suite is runnable," not merely whether bytes are present in the sandbox, and reaching the remote home is part of being runnable.

Actions Taken

Restructured e2e/rstudio/utils/ai-credentials.ts so both the guard and the gate derive from one function (277ba55877):

  1. Added a PROVIDERS table holding each provider's display label and missing-store hint, replacing two inline ternaries and two duplicated hint strings.
  2. Extracted the sandbox store check into a private sandboxStoreHasCredentials(), keeping the provider satisfies never exhaustiveness guard.
  3. Added aiCredentialSkipReason() as the single source of truth: it returns why a provider cannot be exercised in this run, or null when it can. hasAiCredentials() is now a thin wrapper over it, so its exported signature is unchanged and no caller needed editing.
  4. Collapsed the requireAiCredentials gate to one call against that shared reason.

Sharing the reason rather than a boolean matters: had hasAiCredentials() simply returned false for an unprovisioned store, the gate would have reported "no credentials in the sandbox" for a store that is present but never reached the remote.

Verification:

  • npx tsc --noEmit clean.
  • Desktop run of open-chat-pane.test.ts: 4 passed, 2 skipped (the two external-server-only steps, correctly skipped with no server URL set).
  • External-server run against a live server, same file: 5 passed, 0 skipped. Both providers signed in, provisioning pushed both stores to the remote and read the Copilot store back as signed in, the gated test ran rather than skipping, and teardown scrubbed all 6 provisioned paths.
  • A predicate-level check on a synthetic sandbox (valid store, remoteProvisioned absent) confirms the change fires and is not vacuous: before the fix hasAiCredentials returned true on an external-server run, after it returns false, with the desktop control staying true in both.

The external-server run confirms no regression in the real flow but cannot exercise the divergence itself, since the only caller is desktop-only and never loads in the server project. The predicate check is what covers the behavior change.

A permanent unit test for hasAiCredentials would pin this better than a one-off check. That is beyond the scope of this finding and is not included here.

@ronblum
ronblum merged commit 0731c0d into main Aug 7, 2026
27 checks passed
@ronblum
ronblum deleted the test/ron/e2e-server-ai-credentials branch August 7, 2026 16:40
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