Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup-test-tools
- uses: ./.github/actions/prepare-test-runtime
- name: Test on-demand activation (Linux)
if: runner.os == 'Linux'
run: xvfb-run -a pnpm run test:activation
- name: Test on-demand activation
if: runner.os != 'Linux'
run: pnpm run test:activation
- name: Run plot lifecycle extension tests (Linux)
if: runner.os == 'Linux'
run: xvfb-run -a pnpm run test:extension --label plot-lifecycle
Expand All @@ -128,6 +134,7 @@ jobs:
with:
name: extension-test-logs-${{ runner.os }}
path: |
.vscode-test/activation/*.log
.vscode-test/user-data/**/logs/**/exthost/exthost.log
.vscode-test/user-data/**/logs/**/exthost/output_logging_*/*.log
retention-days: 7
Expand Down
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ in Node/Mocha, then runs the extension-host suites.
supervision. After preparing once with `pnpm run pretest`, use `pnpm run test:node`
and `pnpm run test:extension` to rerun either layer without rebuilding.

Run `pnpm run test:activation` after compiling to check activation in fresh
VS Code windows. It verifies that unrelated workspaces and Python Interactive
windows keep vscode-R inactive, and that R files, commands, terminal profiles,
tasks, notebooks, and restored native R Interactive inputs activate it. It also
checks that a persistent R terminal retains its process and workspace across a
window reload, then reconnects after explicit R activation. This case needs R
and the `sess` Imports installed, and installs the bundled package into a
temporary library. Each case uses temporary profiles without the normal suite's
forced activation.
`VSCR_ACTIVATION_VSCODE` selects an existing VS Code executable; otherwise the
runner downloads current stable. `VSCR_ACTIVATION_CASES` selects a comma-separated
subset of cases from `scripts/test-activation.cjs`. On headless Linux, use
`xvfb-run -a pnpm run test:activation`.

To debug extension-host tests, select **Extension Tests** in Run and Debug and
press **F5**. The pre-launch task runs `pnpm run pretest`, and the debugger then
asks which `.vscode-test.mjs` configuration to run (`provider-tests`,
Expand Down
24 changes: 17 additions & 7 deletions R/tests/attach_sess.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ writeLines(
)

runner <- file.path(root, "run-case.R")
# Match production: the follower waits through the owner's consent, install and load.
# Source installation can take more than a minute on Windows runners.
parallel_setup_timeout <- 300
writeLines(
c(
"args <- commandArgs(TRUE)",
Expand Down Expand Up @@ -370,9 +373,7 @@ writeLines(
"} else if (mode %in% c('parallel_approve', 'parallel_decline', 'parallel_third',",
" 'parallel_failure', 'parallel_retry')) {",
" timeout <- 10",
# The follower budget covers the owner's whole source install, which can
# take well over 20 seconds on Windows runners.
" parallel_setup_timeout <- 60",
sprintf(" parallel_setup_timeout <- %d", parallel_setup_timeout),
" if (mode == 'parallel_approve') {",
" result <- attach_sess(timeout=timeout, setup_timeout=parallel_setup_timeout)",
" stopifnot(identical(result, TRUE), 'sess' %in% loadedNamespaces())",
Expand Down Expand Up @@ -466,7 +467,11 @@ r_binary <- file.path(R.home("bin"), if (.Platform$OS.type == "windows") "R.exe"
r_literal <- function(value) encodeString(value, quote = "\"")
read_child_logs <- function(paths) {
read_log <- function(path) {
tryCatch(readLines(path, warn = FALSE), error = function(e) paste("could not read", path))
# Windows can deny reads while a child still has its redirected stream open.
suppressWarnings(tryCatch(
readLines(path, warn = FALSE),
error = function(e) paste("could not read", path)
))
}
c(read_log(paths$stdout), read_log(paths$stderr))
}
Expand Down Expand Up @@ -898,16 +903,17 @@ start_parallel_child <- function(case_root, mode, role, result_file, install_hel

wait_for_child <- function(paths, description) {
# Must exceed the parallel follower's setup budget so its own diagnostic wins.
deadline <- Sys.time() + 90
deadline <- Sys.time() + parallel_setup_timeout + 30
while (!file.exists(paths$result) && Sys.time() < deadline) {
Sys.sleep(0.01)
}
child_output <- read_child_logs(paths)
if (!file.exists(paths$result)) {
child_output <- read_child_logs(paths)
stop(paste(description, "timed out; child output:", paste(child_output, collapse = "\n")))
}
result <- readLines(paths$result, warn = FALSE)
if (!identical(result, "ok")) {
child_output <- read_child_logs(paths)
stop(paste(
description,
"failed:",
Expand Down Expand Up @@ -977,7 +983,11 @@ run_parallel_setup <- function(approve) {
wait_for_file(follower_observed, 10, "follower observation of the held setup lock")

if (approve) {
wait_for_file(description_visible, 60, "installed package metadata while owner holds lock")
wait_for_file(
description_visible,
parallel_setup_timeout - 30,
"installed package metadata while owner holds lock"
)
stopifnot(dir.exists(lock_path), file.exists(file.path(managed_library, "sess", "DESCRIPTION")))
stopifnot(!file.exists(load_log), !file.exists(ready_path))
file.create(install_release)
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
"onWebviewPanel:r.htmlViewer",
"onLanguage:r",
"onLanguage:rmd",
"onNotebook:r-interactive",
"onNotebook:interactive",
"onStartupFinished"
"onNotebook:r-interactive"
],
"main": "./dist/extension",
"contributes": {
Expand Down Expand Up @@ -2457,7 +2455,7 @@
"tags": ["experimental"],
"type": "boolean",
"default": true,
"description": "Reconnect the workspace’s Interactive sessions when VS Code reopens."
"description": "Automatically reconnect the workspace’s Interactive sessions when R features are used."
},
"r.interactive.historyLimit": {
"tags": ["experimental"],
Expand Down Expand Up @@ -2603,6 +2601,7 @@
"test": "pnpm run test:node && pnpm run test:extension",
"test:node": "mocha \"out/test/node/**/*.test.js\" --config .mocharc.interactive.cjs",
"test:extension": "vscode-test",
"test:activation": "node --test scripts/activation-environment.test.cjs && node scripts/test-activation.cjs",
"lint": "oxlint src",
"format": "oxfmt .",
"format:check": "oxfmt --check .",
Expand Down
27 changes: 27 additions & 0 deletions scripts/activation-environment.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const assert = require('node:assert/strict');
const { spawnSync } = require('node:child_process');
const { test } = require('node:test');
const { clearElectronNodeMode } = require('./test-activation.cjs');

function childEnvironment(environment) {
const child = spawnSync(process.execPath, ['-e', `
const flags = Object.keys(process.env).filter(key => key.toUpperCase() === 'ELECTRON_RUN_AS_NODE');
process.stdout.write(JSON.stringify({ flags, marker: process.env.VSCR_ACTIVATION_MARKER }));
`], { env: environment, encoding: 'utf8' });
assert.equal(child.status, 0, child.stderr);
return JSON.parse(child.stdout);
}

test('an empty Electron Node-mode flag is still present in a spawned process', () => {
const environment = { ...process.env, ELECTRON_RUN_AS_NODE: '' };
assert.equal(childEnvironment(environment).flags.length, 1);
});

test('activation launches remove inherited Electron Node mode and preserve other settings', () => {
for (const value of ['', '1']) {
const environment = { ...process.env, ELECTRON_RUN_AS_NODE: value,
electron_run_as_node: value, Electron_Run_As_Node: value, VSCR_ACTIVATION_MARKER: 'preserved' };
clearElectronNodeMode(environment);
assert.deepEqual(childEnvironment(environment), { flags: [], marker: 'preserved' });
}
});
Loading
Loading