Repository navigation
Description
Summary
The window.rstudioCallbacks automation bridge exposes prefGet(name), prefSet(name, value), and prefClear(name) for the --automation-agent test harness (see ApplicationAutomation.java). For most preferences these callbacks return without doing anything -- no JS-side exception, no log line, no effect on the preference value.
Reproduction
Launch RStudio with --automation-agent and from JS:
const cb = window.rstudioCallbacks;
cb.prefSet('default_project_location', '/tmp/foo');
console.log(cb.prefGet('default_project_location')); // nullExpected: returns '/tmp/foo'. Actual: null (or whatever the underlying default is once the pref is eventually registered).
The Playwright suite hits this in tests/projects/ignorefiles.test.ts -- the test sets default_project_location via the bridge so the New Project wizard creates a project under the sandbox, but the wizard reads the unchanged value, falls back to ~, and the project is created in the wrong directory.
Root cause
All three callbacks dispatch through setPref(name, value) / userPrefs_.getPrefValue(name):
Prefs.PrefValue<?> pref = userPrefs_.getPrefValue(name);
if (pref == null)
throw new RuntimeException(\"Unknown user preference: \" + name);Prefs.getPrefValue(name) reads from Prefs.values_, which is populated lazily -- only when the corresponding factory method (e.g. UserPrefsAccessor.defaultProjectLocation()) has been invoked at least once. Most preferences are never accessed at startup, so they're not in values_ when the bridge call lands. pref == null, the RuntimeException fires.
The exception doesn't propagate to JS because GWT's \$entry wrapper installs the uncaught-exception handler and swallows it (logged to GWT console, but the JSNI callback returns normally). From the JS side it looks like the call succeeded -- silent failure.
Suggested fix
Call userPrefs_.allPrefs() once during ApplicationAutomation.initializeAgent(). allPrefs() runs every factory method (defaultProjectLocation(), saveWorkspace(), ...), and each factory registers its PrefValue in values_ as a side effect. After that, all preferences are addressable by name.
A similar warm-up call may be appropriate for UserState callbacks if any are added later.
Why this matters
- Playwright tests that drive prefs via the bridge can't be trusted: a passing test may have run with the wrong pref value entirely (no error to alert on).
- Any downstream consumer of
--automation-agent(extensions, scripts) hits the same trap.
Activity
automation: reshape bridge as window.rstudio.* namespaced API (#17728)