Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
12180fb
feat(interactive): keep arf JSON-RPC errors and require arf 0.7.1
eitsupi Nov 15, 2026
5df0c24
feat(interactive): add a long-lived arf IPC connection
eitsupi Nov 15, 2026
699041a
fix(interactive): interrupt and stop arf through IPC instead of signals
eitsupi Nov 15, 2026
929bc90
ci: install arf 0.7.1 for Interactive tests with mise
eitsupi Nov 15, 2026
d68b2b3
test(interactive): run the fake arf on a named pipe on Windows
eitsupi Nov 15, 2026
d9a983f
test: experiment without attach to isolate a macOS fork failure (to b…
eitsupi Nov 15, 2026
9dcc503
Revert "test: experiment without attach to isolate a macOS fork failu…
eitsupi Nov 15, 2026
12d1e00
Merge remote-tracking branch 'upstream/main' into feat/interactive-ar…
eitsupi Nov 16, 2026
fc65185
ci: keep the arf mise config with the Node tests
eitsupi Nov 16, 2026
1fd6b11
ci: test Interactive with arf 0.7.2-rc.1
eitsupi Nov 16, 2026
bb20986
feat(interactive): run inspection as arf handler calls with deadlines
eitsupi Nov 16, 2026
50dc0d0
feat(sess): publish inspection as arf handlers
eitsupi Nov 16, 2026
01b40a5
Merge remote-tracking branch 'upstream/main' into feat/interactive-ar…
eitsupi Nov 16, 2026
55cd771
docs(sess): describe socket hover after the resolver change
eitsupi Nov 16, 2026
1a1be39
test(interactive): keep fake arf socket paths short on macOS
eitsupi Nov 16, 2026
2ec74ef
fix(interactive): do not drop waiting hover and completion requests
eitsupi Nov 16, 2026
9554b20
docs(interactive): explain requests sent after an inspection transpor…
eitsupi Nov 16, 2026
d68667d
fix(interactive): check that managed arf publishes every inspection h…
eitsupi Nov 16, 2026
c8d11da
feat(interactive): require arf 0.7.2-rc.1
eitsupi Nov 16, 2026
7e876b3
test(interactive): keep representative arf version comparisons
eitsupi Nov 16, 2026
e085dc7
fix(interactive): count local waiting towards the inspection start limit
eitsupi Nov 16, 2026
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
32 changes: 12 additions & 20 deletions .github/actions/prepare-test-runtime/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,19 @@ runs:
- name: Compile test files
run: pnpm run clean && pnpm exec tsc
shell: bash
- name: Install arf binary for Interactive tests
# src/test/node/mise.toml and mise.lock pin the arf version and its
# checksums.
- name: Install arf for Interactive tests
if: runner.os != 'Windows'
uses: jdx/mise-action@6612f0ef07ed2a736cd1e00a94a065522dd41195 # v5.2.5
with:
working_directory: src/test/node
- name: Expose arf for Interactive tests
if: runner.os != 'Windows'
shell: bash
env:
RUNNER_OS_NAME: ${{ runner.os }}
working-directory: src/test/node
run: |
ARF_ARCH="$(uname -m)"
if [ "${ARF_ARCH}" = "arm64" ]; then ARF_ARCH="aarch64"; fi
if [ "${RUNNER_OS_NAME}" = "macOS" ]; then
ARF_TARGET="${ARF_ARCH}-apple-darwin"
else
ARF_TARGET="${ARF_ARCH}-unknown-linux-gnu"
fi
ARF_ARCHIVE="arf-console-${ARF_TARGET}.tar.xz"
ARF_RELEASE="https://github.com/eitsupi/arf/releases/download/v0.5.3"
curl -fsSL "${ARF_RELEASE}/${ARF_ARCHIVE}" -o "${RUNNER_TEMP}/${ARF_ARCHIVE}"
curl -fsSL "${ARF_RELEASE}/sha256.sum" -o "${RUNNER_TEMP}/arf.sha256"
(cd "${RUNNER_TEMP}" && awk -v name="${ARF_ARCHIVE}" '$2 == name || $2 == "*" name' arf.sha256 > arf-selected.sha256 && test -s arf-selected.sha256 && shasum -a 256 -c arf-selected.sha256)
mkdir -p "${RUNNER_TEMP}/arf"
tar -xJf "${RUNNER_TEMP}/${ARF_ARCHIVE}" -C "${RUNNER_TEMP}/arf"
ARF_EXECUTABLE=$(find "${RUNNER_TEMP}/arf" -type f -name arf | head -n 1)
test -n "${ARF_EXECUTABLE}"
echo "$(dirname "${ARF_EXECUTABLE}")" >> "$GITHUB_PATH"
ARF_EXECUTABLE="$(mise which arf)"
test -x "${ARF_EXECUTABLE}"
"${ARF_EXECUTABLE}" --version
echo "ARF_PATH=${ARF_EXECUTABLE}" >> "$GITHUB_ENV"
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Interactive session. Run the source/bootstrap checks with

The [architecture and backend contract](src/interactive/README.md) live beside the implementation. User setup and behavior belong in the [R Interactive documentation page](https://reditorsupport.github.io/vscode-R/features/r-interactive).

Use Linux or macOS for Interactive runtime tests, with R and an installed arf 0.5.3 executable. Bundled sess is pure R and needs no compiler when its Imports are already installed; missing Imports are installed from the configured repository. Windows runs the remaining extension checks; persistent Interactive supervision remains limited to Linux/macOS. From the repository root, after installing pnpm dependencies, prepare a test library:
Use Linux or macOS for Interactive runtime tests, with R and arf 0.7.2-rc.1 or later. Running `mise install` in `src/test/node` installs the arf version pinned in `src/test/node/mise.toml`, which CI also uses. Bundled sess is pure R and needs no compiler when its Imports are already installed; missing Imports are installed from the configured repository. Windows runs the remaining extension checks; persistent Interactive supervision remains limited to Linux/macOS. From the repository root, after installing pnpm dependencies, prepare a test library:

```sh
export R_LIBS=/path/to/test-library
Expand All @@ -106,6 +106,8 @@ pnpm run pretest
VSCR_TEST_TMUX=1 pnpm exec mocha out/test/node/interactiveRuntime.test.js --ui tdd --timeout 60000 --grep "standalone agent survives its launcher process exiting"
```

Inspection runs as arf handler calls, whose output is captured. Tests that need to know when inspection code has started should have the R code write a file rather than wait for output.

The provider is arf. `ARF_PATH` selects its executable; `VSCR_TEST_STATIC=1` selects standard graphics. The tmux variant needs tmux and exercises a real supervised agent, as Linux CI does. These variables can be combined. Check skipped tests when assessing coverage: a missing optional runtime or package is not a verified pass for that feature.

`pnpm run test` prepares the bundle and test files, runs `src/test/node/` directly
Expand Down
11 changes: 10 additions & 1 deletion sess/R/dispatch.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#' Serialize a message with the settings used for every IPC frame (internal)
#'
#' Sharing one encoder keeps the frames on the socket and the results of arf handler calls identical
#' for the same R value.
#' @keywords internal
ipc_json <- function(data) {
jsonlite::toJSON(data, auto_unbox = TRUE, null = "null", force = TRUE, digits = NA)
}

#' Write a JSON object to the IPC pipe as a NDJSON line (internal)
#' @keywords internal
ipc_write <- function(data) {
Expand All @@ -12,7 +21,7 @@ ipc_write <- function(data) {
return(invisible(FALSE))
}

json <- jsonlite::toJSON(data, auto_unbox = TRUE, null = "null", force = TRUE, digits = NA)
json <- ipc_json(data)
line <- c(charToRaw(enc2utf8(json)), as.raw(0x0a))
tryCatch(
{
Expand Down
286 changes: 286 additions & 0 deletions sess/R/inspection_call.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
# Inspection methods for handler calls published through arf's `--ipc-expose`.
#
# Interactive reaches the same per-method logic through two transports:
#
# - The sess socket runs a request from a `later` callback, where arf does not
# deliver interrupts, so a slow request cannot be stopped.
# - An arf handler call runs on the R thread under an execution deadline, and
# arf interrupts the handler when the deadline passes.
#
# Both use the handlers of `inspection_handlers()`. Both resolve `hover` and
# `completion` with `inspection_hover()` and `inspection_completion()`, which
# never evaluate the request text. The socket turns every error into no result,
# while a handler call reports it, so the client can tell an invalid request
# from a failure. Handlers published to arf run outside arf's evaluation policy
# and approval, so they must not accept code from the client.
#
# Contract of the `vscode-r.inspect.json` namespace: a handler takes the method
# parameters as one JSON string, the same object the socket carries as
# `params`, and returns the result as one JSON string. The string is a JSON
# object with `version` and, unless the result is NULL, `result`. Omitting
# `result` for NULL keeps NULL distinct from NA, as in a socket reply. A
# strict-JSON variant that needs no string decoding would use another
# namespace.

inspection_call_namespace <- "vscode-r.inspect.json"

# The only methods that can be called. `interactive_stop` and `plot_latest` stay
# on the socket, and no entry point selects a function by name.
inspection_call_methods <- c(
"workspace",
"workspace_children",
"workspace_view",
"listview_navigate",
"listview_view",
"hover",
"completion",
"dataview_init",
"dataview_page",
"dataview_dispose"
)

# Encoded results beyond this size would exceed the client's frame limit.
inspection_call_max_bytes <- 4L * 1024L * 1024L

# Per-method logic shared by the socket and handler calls. Each function takes
# the decoded parameters of its request.
inspection_handlers <- function() {
list(
workspace = function(p) get_workspace_data(p$revision),
workspace_children = function(p) get_workspace_children(p$name, p$path, p$start, p$view_id),
workspace_view = function(p) handle_workspace_view(p$name, p$path),
listview_navigate = function(p) handle_listview_navigate(p$view_id, p$path),
listview_view = function(p) handle_listview_view(p$view_id, p$index, p$path),
dataview_init = function(p) handle_dataview_init(p),
dataview_page = function(p) handle_dataview_page(p),
dataview_dispose = function(p) handle_dataview_dispose(p)
)
}

# The table that handler calls dispatch through, in the order of
# `inspection_call_methods`.
inspection_call_handlers <- function() {
handlers <- c(
inspection_handlers(),
list(
hover = function(p) inspection_hover(p$expr),
completion = function(p) inspection_completion(p$expr, p$trigger)
)
)
handlers[inspection_call_methods]
}

# Argument validation. A check returns its value or signals an invalid request.

inspection_check_string <- function(value, name, max_bytes = 100000L) {
if (
!is.character(value) ||
length(value) != 1L ||
is.na(value) ||
nchar(value, type = "bytes") > max_bytes
) {
inspection_invalid(sprintf("%s must be a single string", name))
}
value
}

inspection_is_number <- function(value) is.numeric(value) && length(value) == 1L && is.finite(value)

inspection_check_number <- function(value, name) {
if (!inspection_is_number(value)) {
inspection_invalid(sprintf("%s must be a single finite number", name))
}
value
}

inspection_is_index <- function(value) {
inspection_is_number(value) &&
value == floor(value) &&
value >= 1 &&
value <= .Machine$integer.max
}

inspection_check_index <- function(value, name) {
if (!inspection_is_index(value)) {
inspection_invalid(sprintf("%s must be a positive whole number", name))
}
value
}

inspection_check_flag <- function(value, name) {
if (!is.logical(value) || length(value) != 1L || is.na(value)) {
inspection_invalid(sprintf("%s must be TRUE or FALSE", name))
}
value
}

inspection_check_list <- function(value, name) {
if (!is.list(value)) {
inspection_invalid(sprintf("%s must be an array or object", name))
}
value
}

inspection_max_path <- 10000L

# A path inside a list view: positive item indices.
inspection_check_index_path <- function(value, name) {
if (!is.list(value) || length(value) > inspection_max_path) {
inspection_invalid(sprintf("%s must be an array of positive whole numbers", name))
}
for (item in value) {
if (!inspection_is_index(item)) {
inspection_invalid(sprintf("%s must be an array of positive whole numbers", name))
}
}
value
}

# A path inside a workspace object: selectors of the kinds that
# `workspace_object()` resolves.
inspection_check_selector_path <- function(value, name) {
if (!is.list(value) || length(value) > inspection_max_path) {
inspection_invalid(sprintf("%s must be an array of selectors", name))
}
for (item in value) {
kind <- if (is.list(item)) item[["kind"]] else NULL
selector <- if (is.list(item)) item[["value"]] else NULL
valid <- is.character(kind) &&
length(kind) == 1L &&
!is.na(kind) &&
if (identical(kind, "index")) {
inspection_is_index(selector)
} else if (kind %in% c("name", "slot")) {
is.character(selector) &&
length(selector) == 1L &&
!is.na(selector) &&
nzchar(selector) &&
nchar(selector, type = "bytes") <= 10000L
} else {
FALSE
}
if (!valid) {
inspection_invalid(sprintf("%s must be an array of selectors", name))
}
}
value
}

# Read an optional parameter. NULL, including a JSON null, means absent.
inspection_param <- function(params, name, check, default = NULL, required = FALSE) {
value <- params[[name]]
if (is.null(value)) {
if (required) {
inspection_invalid(sprintf("%s is required", name))
}
return(default)
}
check(value, name)
}

# Validate the parameters of one method, and return only the fields that the
# method reads. Fields that are not validated never reach a handler.
inspection_validate <- function(method, params) {
string <- inspection_check_string
number <- inspection_check_number
index <- inspection_check_index
one <- function(name, check, ...) inspection_param(params, name, check, ...)
# Absent fields are omitted rather than set to NULL.
fields <- function(...) Filter(Negate(is.null), list(...))
switch(
method,
workspace = fields(revision = one("revision", number)),
workspace_children = {
view_id <- one("view_id", string)
name <- one("name", string)
if (is.null(view_id) && is.null(name)) {
inspection_invalid("name or view_id is required")
}
# A list view is addressed by item indices, a workspace object by selectors.
path_check <- if (is.null(view_id)) {
inspection_check_selector_path
} else {
inspection_check_index_path
}
fields(
name = name,
view_id = view_id,
path = one("path", path_check, default = list()),
start = one("start", index, default = 1L)
)
},
workspace_view = fields(
name = one("name", string, required = TRUE),
path = one("path", inspection_check_selector_path, default = list())
),
listview_navigate = fields(
view_id = one("view_id", string, required = TRUE),
path = one("path", inspection_check_index_path, default = list())
),
listview_view = fields(
view_id = one("view_id", string, required = TRUE),
path = one("path", inspection_check_index_path, default = list()),
index = one("index", index, required = TRUE)
),
hover = fields(expr = one("expr", string, required = TRUE)),
completion = fields(
expr = one("expr", string, required = TRUE),
trigger = one("trigger", string)
),
dataview_init = fields(view_id = one("view_id", string, required = TRUE)),
dataview_page = fields(
view_id = one("view_id", string, required = TRUE),
startRow = one("startRow", number),
endRow = one("endRow", number),
sortModel = one("sortModel", inspection_check_list),
filterModel = one("filterModel", inspection_check_list),
formatNumbers = one("formatNumbers", inspection_check_flag)
),
dataview_dispose = fields(
view_id = one("view_id", string, required = TRUE),
state_generation = one("state_generation", number)
),
inspection_invalid("unknown inspection method")
)
}

# Decode the argument string like `dispatch_message()` decodes a socket line.
inspection_decode <- function(args) {
if (!is.character(args) || length(args) != 1L || is.na(args)) {
inspection_invalid("arguments must be one JSON string")
}
params <- tryCatch(
jsonlite::fromJSON(args, simplifyVector = FALSE),
error = function(e) inspection_invalid("arguments are not valid JSON")
)
# An empty JSON object decodes to a named empty list, an array to a list
# without names.
if (!is.list(params) || (length(params) > 0L && is.null(names(params)))) {
inspection_invalid("arguments must be a JSON object")
}
params
}

# Encode a result with the socket's settings, as a classless length-1 string.
inspection_encode <- function(result) {
message <- list(version = 1L)
# Assigning NULL leaves the field out, as in a socket reply.
message$result <- result
json <- enc2utf8(as.character(ipc_json(message)))
if (nchar(json, type = "bytes") > inspection_call_max_bytes) {
stop("Inspection result exceeds the size limit", call. = FALSE)
}
json
}

# Run one inspection method for a handler call. Decoding, the handler and
# encoding all run here so that an execution deadline covers them. Errors and
# interrupts propagate: arf reports them, and neither becomes a value.
inspection_call <- function(method, args) {
handlers <- inspection_call_handlers()
if (!is.character(method) || length(method) != 1L || !method %in% names(handlers)) {
inspection_invalid("unknown inspection method")
}
params <- inspection_validate(method, inspection_decode(args))
inspection_encode(handlers[[method]](params))
}
Loading
Loading