diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c7009eb74..272550e27 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -160,8 +160,8 @@ PR CI, main pushes and manual runs execute the full supported suites on every OS. Linux and macOS run the same Node and Interactive editor tests, including the actual VS Code Electron runtime check with no Node executable on PATH and successful session creation using the default VS Code runtime. -Windows also runs managed Interactive runtime/editor tests; individual Unix shell -fixtures and existing-arf adoption tests remain excluded. Linux additionally runs the tmux launcher survival case +Windows also runs managed Interactive runtime/editor tests and the tests that +discover and adopt existing arf sessions; individual Unix shell fixtures remain excluded. Linux additionally runs the tmux launcher survival case once with tmux enabled and uses Xvfb for extension-host tests. Source/bootstrap checks, installed identity verification and sess package tests run on every OS. diff --git a/package.json b/package.json index 5597ad723..239d7b46f 100644 --- a/package.json +++ b/package.json @@ -2622,6 +2622,7 @@ "test:interactive:examples": "pnpm run compile && tsc && node src/test/examples/run.cjs" }, "devDependencies": { + "@microsoft/tui-test": "0.1.1", "@types/ejs": "^3.1.5", "@types/mocha": "^10.0.10", "@types/node": "^22.20.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6ead3f5d3..8b2e2104c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,6 +36,9 @@ importers: specifier: ^1.2.5 version: 1.2.5 devDependencies: + '@microsoft/tui-test': + specifier: 0.1.1 + version: 0.1.1 '@types/ejs': specifier: ^3.1.5 version: 3.1.5 @@ -512,6 +515,156 @@ packages: '@jridgewell/trace-mapping@0.3.31': resolution: {integrity: sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==} + '@koromix/koffi-android-arm64@3.3.8': + resolution: {integrity: sha512-Y0lt2JexRGXlg1PxFuegfi5p6bIcLMj7Mig0WapZRKEM3Yv2L9J3Ej4XHPYMsB0TRNttBRHiliaJOH6EedEIXg==} + cpu: [arm64] + os: [android] + + '@koromix/koffi-android-x64@3.3.8': + resolution: {integrity: sha512-ZOwUZJoQ7Xd0rRF85Qc5XyIBjZPKGNLNgoTFakWdxn55AoZ6zdGEYvOXQMIN8JLjQ6qYUiQMtlFlusddZr+pjA==} + cpu: [x64] + os: [android] + + '@koromix/koffi-darwin-arm64@3.3.8': + resolution: {integrity: sha512-7tzlnYSePCQW66iEIi+wgN9HgTiF431KL9wIDhH9b+32KOYZXBdA+JyDgRVi2E5AIyJ1hdkQFNg7YCAOft2mKw==} + cpu: [arm64] + os: [darwin] + + '@koromix/koffi-darwin-x64@3.3.8': + resolution: {integrity: sha512-Pw1EsCT9Yov4Szo4joLhABbQfqNgYhwfkhWZiIbEZ2b3sGyv9Yj2N0p00jOpdTfQ+u9QFFi8XhNivJbBTqMTPA==} + cpu: [x64] + os: [darwin] + + '@koromix/koffi-freebsd-arm64@3.3.8': + resolution: {integrity: sha512-bpkvHfxUn5EqaHQO9k42lqO8+5t9aF8McgJyOsXx+vd/xicA0Zc0vP2kz0MjQu760ZdsR3WI4VFiNh2xHRP6Lw==} + cpu: [arm64] + os: [freebsd] + + '@koromix/koffi-freebsd-ia32@3.3.8': + resolution: {integrity: sha512-h2WI3Ofb+TioTqWDTMXPgtZ2LAghY2CPwZwMM3mZeGAzKygo9RxZ4PRGq8bvrdvinR4VN9ZK+H48m9GV3/u3mQ==} + cpu: [ia32] + os: [freebsd] + + '@koromix/koffi-freebsd-x64@3.3.8': + resolution: {integrity: sha512-Z1VAr2CfWaHYfqJ1UlbZBH2IcPqZHilBSCgSqDmVhmyN/tSz5kSjaRfxcBGloJted3CCvsNFg8lOJiKkPiAUNQ==} + cpu: [x64] + os: [freebsd] + + '@koromix/koffi-linux-arm64@3.3.8': + resolution: {integrity: sha512-7yknlwsy7X76+Qy7leuI+RTQfYHX1W8Uv+CFpyiMsdLnpaSCpNJDIpCr6/qnQzpLx93mRncB+VBBD2PB/IMX8g==} + cpu: [arm64] + os: [linux] + + '@koromix/koffi-linux-arm@3.3.8': + resolution: {integrity: sha512-9c9IfIz5sFpzbuwV2HomSBWOakpbd9tJ3FChmE556KdPzw9iXrJoMT5JyzPnUe10Soag2NK6SMKrDafOsR6J2A==} + cpu: [arm] + os: [linux] + + '@koromix/koffi-linux-ia32@3.3.8': + resolution: {integrity: sha512-/AqDOcvQzeSDnwDsdqfJP2LjBgCX6CJZwSuYJc+YZCFFtUvsIDq9sRfSvyDy6xTC3HTkJKaT1SrrlE6Ji1aZCA==} + cpu: [ia32] + os: [linux] + + '@koromix/koffi-linux-loong64@3.3.8': + resolution: {integrity: sha512-XgqxynMlKdcPZ5Hu0EyhFqfvEMcqm1RzLj8vbhRTtwV/GhrAMoToExzcF5uHXqiVL/EsWE1V/BmdrCfjlUsqtA==} + cpu: [loong64] + os: [linux] + + '@koromix/koffi-linux-ppc64@3.3.8': + resolution: {integrity: sha512-nzoG1pIu00cdwbMmQ+U4Tr1Xaej1L/XP39wG0nQMviDf/7tlZeM8i/yD1ggNHeSYao/CHcaJr0eW5IjmkfO10Q==} + cpu: [ppc64] + os: [linux] + + '@koromix/koffi-linux-riscv64@3.3.8': + resolution: {integrity: sha512-i6CtjaydMXmhvUPz5gCCodgCBCQOA27Cs0mCTcodHzaJCmICqlmGr0y7ManHIeqTxzrDNIJERa0BFNBpoPpe4A==} + cpu: [riscv64] + os: [linux] + + '@koromix/koffi-linux-x64@3.3.8': + resolution: {integrity: sha512-0KyTCxjxzjdwCxTA8HdEFCLeJLZPQdOqpJQVvf2KJA8izmnDlM/g2NZd6jNJ4lwvuU8+R6fN7zW0OrwSM6pHzA==} + cpu: [x64] + os: [linux] + + '@koromix/koffi-openbsd-arm64@3.3.8': + resolution: {integrity: sha512-HY1pfpsHrHL248y3TRg0FAa8MlSLuVMABkkieiKINqNvIWWvuMekZO/zQM+BtmgFQHXO+t/Hd0W55fzH/U2EYA==} + cpu: [arm64] + os: [openbsd] + + '@koromix/koffi-openbsd-ia32@3.3.8': + resolution: {integrity: sha512-745gBEJnFhO9N7mnRVRkd2NQnQGbBUKkEUsJcm2Di5KBkkTyfjf2BQSvzegJE+ab6gLnQ57ZEA0UwBBdS0MlrA==} + cpu: [ia32] + os: [openbsd] + + '@koromix/koffi-openbsd-x64@3.3.8': + resolution: {integrity: sha512-bwcuk5PquAQGgR1DYAVrZwInSEeKuq0RXFylejAs5kQCJCBoyUOipkAJj4q4HYdOtCCxwqdrMm/+XwXrwtf3ZQ==} + cpu: [x64] + os: [openbsd] + + '@koromix/koffi-win32-arm64@3.3.8': + resolution: {integrity: sha512-f43sCr9lxFIvkOEE0Br+Qr5+KH2XqRm/EAQgAflYprIsjCz4eBTPVwEjbuymyN/6iDEKyO7EDz/7xQgNiyvIyA==} + cpu: [arm64] + os: [win32] + + '@koromix/koffi-win32-ia32@3.3.8': + resolution: {integrity: sha512-aBozU1HP1mWzanVAoo2fkJBLJsEVVs2b3/FbtqbotrgDFsBt8r71LNX+mKX7d4YASXMIAsUPG3iXBpNtk7+Y8Q==} + cpu: [ia32] + os: [win32] + + '@koromix/koffi-win32-x64@3.3.8': + resolution: {integrity: sha512-Ef9XpIn/AfnZWMI1lvA6IOjCsTVRlako+BXosp4cRaLZZXkgjwiBVqYXXhqZix1G8e+27UAv97XBTmDEyfS7jA==} + cpu: [x64] + os: [win32] + + '@microsoft/tui-test-darwin-arm64@0.1.1': + resolution: {integrity: sha512-5AbGcOKsDnvRiYuJPc/5vensFgSjG7Jo1H8B80zcPb2CTC78Z+Ma33hANweE3xgUjNrrBP0Jxkg1j94Ex0PfLQ==} + engines: {node: '>=20'} + cpu: [arm64] + os: [darwin] + + '@microsoft/tui-test-darwin-x64@0.1.1': + resolution: {integrity: sha512-XR2Eg0XL6xBERebPTIHjfBiINL2CLJ/AXgCmtHfiE70eW+ZcBwjnf7anqDLXswGl1FobHwIm+51AA61OFRjS+A==} + engines: {node: '>=20'} + cpu: [x64] + os: [darwin] + + '@microsoft/tui-test-linux-arm64-gnu@0.1.1': + resolution: {integrity: sha512-jG5MBkD+09IdVWvsnljG1Kme3L+i4rKI36MnPvQkYuCCK5c9Jazyad9cvlQy12dmbNzk8TqrP/bC3md6eusc8Q==} + engines: {node: '>=20'} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@microsoft/tui-test-linux-arm64-musl@0.1.1': + resolution: {integrity: sha512-zyqOILGPz3/zqcxYgdZj3G0yQwr+1y2oY0O+RZ6/VoG3Crl1h5zuad6Bd6u0eq9EMWnnMQotebHYvfx2khVkrQ==} + engines: {node: '>=20'} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@microsoft/tui-test-linux-x64-gnu@0.1.1': + resolution: {integrity: sha512-0ebPAuhPVz31veE2aiiL269vTuRV9HjyoT6WoZ0YrjTjycSkkGvCtXGPv5fgKGpu/Kut3D4Zrp35mP/utTioPQ==} + engines: {node: '>=20'} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@microsoft/tui-test-linux-x64-musl@0.1.1': + resolution: {integrity: sha512-VeSWaERhRwSYFpvEwSerYQ28UYu7g0ZaM5m30XGFIdZUwaZfEVanh+f5si+046PsorKtrPNA3jzglUC4GOU8jw==} + engines: {node: '>=20'} + cpu: [x64] + os: [linux] + libc: [musl] + + '@microsoft/tui-test-win32-x64-msvc@0.1.1': + resolution: {integrity: sha512-TfKzP136m7W9DWZLCt86A1ucVPRhgQROgsBYAgE7mulAHPDGSdUO4JVow2tcKWF0PWTsiezB8s12LFPZs1zUpA==} + engines: {node: '>=20'} + cpu: [x64] + os: [win32] + + '@microsoft/tui-test@0.1.1': + resolution: {integrity: sha512-wIovmT/fkcHve2lYKJdtlIQcBrzA98yVp7l5hdjEHFmSELPTzdtCfJ5H+6rMqXEYpC0PDPdErUVqYp4YnTDNfg==} + engines: {node: '>=20'} + '@napi-rs/keyring-darwin-arm64@1.3.0': resolution: {integrity: sha512-pl76hJvdYUBn6I24bXiOBMA9nbDapo3I5B+f3OorjDU4dUMSypXeKbOVehJe8fhgTiH24flMyTS3aAIy43xegQ==} engines: {node: '>= 10'} @@ -1811,6 +1964,9 @@ packages: jws@4.0.1: resolution: {integrity: sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==} + koffi@3.3.8: + resolution: {integrity: sha512-CTDlV3BDh8LFyCgv9vamD+5eu49HQ5wBetAJ9wxERAoAy6rfodahgo28tqhz010l2OGcZvrnBC6MOTyQUt4EIQ==} + lie@3.3.0: resolution: {integrity: sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==} @@ -2740,6 +2896,99 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.5 + '@koromix/koffi-android-arm64@3.3.8': + optional: true + + '@koromix/koffi-android-x64@3.3.8': + optional: true + + '@koromix/koffi-darwin-arm64@3.3.8': + optional: true + + '@koromix/koffi-darwin-x64@3.3.8': + optional: true + + '@koromix/koffi-freebsd-arm64@3.3.8': + optional: true + + '@koromix/koffi-freebsd-ia32@3.3.8': + optional: true + + '@koromix/koffi-freebsd-x64@3.3.8': + optional: true + + '@koromix/koffi-linux-arm64@3.3.8': + optional: true + + '@koromix/koffi-linux-arm@3.3.8': + optional: true + + '@koromix/koffi-linux-ia32@3.3.8': + optional: true + + '@koromix/koffi-linux-loong64@3.3.8': + optional: true + + '@koromix/koffi-linux-ppc64@3.3.8': + optional: true + + '@koromix/koffi-linux-riscv64@3.3.8': + optional: true + + '@koromix/koffi-linux-x64@3.3.8': + optional: true + + '@koromix/koffi-openbsd-arm64@3.3.8': + optional: true + + '@koromix/koffi-openbsd-ia32@3.3.8': + optional: true + + '@koromix/koffi-openbsd-x64@3.3.8': + optional: true + + '@koromix/koffi-win32-arm64@3.3.8': + optional: true + + '@koromix/koffi-win32-ia32@3.3.8': + optional: true + + '@koromix/koffi-win32-x64@3.3.8': + optional: true + + '@microsoft/tui-test-darwin-arm64@0.1.1': + optional: true + + '@microsoft/tui-test-darwin-x64@0.1.1': + optional: true + + '@microsoft/tui-test-linux-arm64-gnu@0.1.1': + optional: true + + '@microsoft/tui-test-linux-arm64-musl@0.1.1': + optional: true + + '@microsoft/tui-test-linux-x64-gnu@0.1.1': + optional: true + + '@microsoft/tui-test-linux-x64-musl@0.1.1': + optional: true + + '@microsoft/tui-test-win32-x64-msvc@0.1.1': + optional: true + + '@microsoft/tui-test@0.1.1': + dependencies: + koffi: 3.3.8 + optionalDependencies: + '@microsoft/tui-test-darwin-arm64': 0.1.1 + '@microsoft/tui-test-darwin-x64': 0.1.1 + '@microsoft/tui-test-linux-arm64-gnu': 0.1.1 + '@microsoft/tui-test-linux-arm64-musl': 0.1.1 + '@microsoft/tui-test-linux-x64-gnu': 0.1.1 + '@microsoft/tui-test-linux-x64-musl': 0.1.1 + '@microsoft/tui-test-win32-x64-msvc': 0.1.1 + '@napi-rs/keyring-darwin-arm64@1.3.0': optional: true @@ -3820,6 +4069,29 @@ snapshots: jwa: 2.0.1 safe-buffer: 5.1.2 + koffi@3.3.8: + optionalDependencies: + '@koromix/koffi-android-arm64': 3.3.8 + '@koromix/koffi-android-x64': 3.3.8 + '@koromix/koffi-darwin-arm64': 3.3.8 + '@koromix/koffi-darwin-x64': 3.3.8 + '@koromix/koffi-freebsd-arm64': 3.3.8 + '@koromix/koffi-freebsd-ia32': 3.3.8 + '@koromix/koffi-freebsd-x64': 3.3.8 + '@koromix/koffi-linux-arm': 3.3.8 + '@koromix/koffi-linux-arm64': 3.3.8 + '@koromix/koffi-linux-ia32': 3.3.8 + '@koromix/koffi-linux-loong64': 3.3.8 + '@koromix/koffi-linux-ppc64': 3.3.8 + '@koromix/koffi-linux-riscv64': 3.3.8 + '@koromix/koffi-linux-x64': 3.3.8 + '@koromix/koffi-openbsd-arm64': 3.3.8 + '@koromix/koffi-openbsd-ia32': 3.3.8 + '@koromix/koffi-openbsd-x64': 3.3.8 + '@koromix/koffi-win32-arm64': 3.3.8 + '@koromix/koffi-win32-ia32': 3.3.8 + '@koromix/koffi-win32-x64': 3.3.8 + lie@3.3.0: dependencies: immediate: 3.0.6 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 02afa87f4..b40626c1e 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -8,3 +8,6 @@ overrides: allowBuilds: '@vscode/vsce-sign': false esbuild: true + # koffi's install script provides the native library that @microsoft/tui-test + # uses for the pseudo-terminal in the interactive arf runtime test. + koffi: true diff --git a/src/interactive/README.md b/src/interactive/README.md index 5b542a1b1..29d0809ea 100644 --- a/src/interactive/README.md +++ b/src/interactive/README.md @@ -130,7 +130,8 @@ Both providers report notebook stdin/debugger support as unavailable: arf IPC R terminals for `readline`, `scan`, and debugger interaction. arf IPC is experimental; the integration requires arf 0.7.2-rc.1 or later and is tested with the version pinned in `src/test/node/mise.toml`. Managed sessions also support -Windows with detached supervision; existing-arf discovery/adoption remains Unix-only. +Windows with detached supervision, and existing arf sessions are discovered and +adopted on every platform. [SessGraphics](backends/sessGraphics.ts) owns jgd negotiation, its font-metrics worker, plot attribution/coalescing, SVG production, and resize transport. It emits display payloads with stable identities. The agent stores assets and journals references. Static graphics remains available without jgd; another backend can supply SVG/PNG directly. diff --git a/src/test/node/interactiveRuntime.test.ts b/src/test/node/interactiveRuntime.test.ts index 523b18a13..c47065367 100644 --- a/src/test/node/interactiveRuntime.test.ts +++ b/src/test/node/interactiveRuntime.test.ts @@ -2057,10 +2057,246 @@ ggplot(diamonds, aes(x = carat, y = price, color = cut)) + } } }); - test('adopts an existing arf process without losing its objects', async function () { - if (process.platform === 'win32') { + // An arf that runs in a terminal, driven through a pseudo-terminal on + // every platform: it is discovered and adopted, evaluates and interrupts + // through IPC, refuses Stop, and keeps its terminal after the agent closes. + test('adopts an interactive arf, which refuses Stop and keeps its terminal', async function () { + this.timeout(180000); + if (process.platform === 'win32' && process.arch !== 'x64') { + // The pseudo-terminal package is published for x64 Node only on + // Windows. The headless adoption test still runs. this.skip(); } + const arf = process.env.ARF_PATH ?? 'arf'; + try { + await run(arf, ['--version']); + } catch (error) { + if (process.env.ARF_PATH) { + throw error; + } + this.skip(); + } + const { TuiTest } = await import('@microsoft/tui-test'); + const directory = path.join(temporary, `interactive-arf-${randomUUID()}`); + const pidFile = path.join(directory, 'arf.pid'); + // An empty configuration keeps the user's arf settings, such as the + // prompt, out of the test. + const config = path.join(directory, 'arf.toml'); + fs.mkdirSync(path.join(directory, 'history'), { recursive: true }); + fs.writeFileSync(config, ''); + const env: Record = Object.fromEntries( + Object.entries({ + ...process.env, + ARF_IPC_SESSIONS_DIR: path.join(directory, 'sessions'), + }).filter((entry): entry is [string, string] => entry[1] !== undefined), + ); + const terminal = TuiTest.ephemeral('vscode-r-interactive-arf'); + let adopted: SessionAgent | undefined; + let connection: AgentClient | undefined; + const facts: Record = {}; + // Each read has its own deadline: a Mocha timeout would not cancel it. + const screen = async (): Promise => { + let timer: NodeJS.Timeout | undefined; + try { + return await Promise.race([ + terminal.text({ full: true }), + new Promise((resolve) => { + timer = setTimeout(() => resolve('(terminal text timed out)'), 5000); + }), + ]); + } catch (error) { + return `(terminal text unavailable: ${String(error)})`; + } finally { + clearTimeout(timer); + } + }; + const prompt = /R [\d.]+>/; + const shown = async (text: string, timeout = 20000): Promise => { + const deadline = Date.now() + timeout; + while (!(await screen()).includes(text)) { + if (Date.now() >= deadline) { + throw new Error(`The terminal did not show ${JSON.stringify(text)}`); + } + await delay(100); + } + }; + try { + await terminal.run( + arf, + [ + '--with-ipc', + '--ipc-pid-file', + pidFile, + '--history-dir', + path.join(directory, 'history'), + '--config', + config, + '--no-banner', + '--vanilla', + ], + { + cwd: directory, + env, + cols: 120, + rows: 30, + timeouts: { + text: 20000, + idle: 20000, + command: 30000, + exit: 30000, + ready: 60000, + }, + }, + ); + // The prompt shows the R version, such as `R 4.5.2>`. + const deadline = Date.now() + 60000; + while (!prompt.test(await screen())) { + if (Date.now() >= deadline) { + throw new Error('arf did not show its prompt'); + } + await delay(100); + } + // arf creates the PID file before writing it, so read until it holds a PID. + let pid = 0; + await until(() => { + try { + pid = Number(fs.readFileSync(pidFile, 'utf8').trim()); + } catch { + pid = 0; + } + return Number.isSafeInteger(pid) && pid > 0; + }, 30000); + facts.pid = pid; + // arf asks before running visible IPC evaluations unless allowed. + await terminal.submit(':ipc send-policy allow'); + await shown('IPC send policy: allow'); + + const discovery = await discoverArf(arf, directory, env); + facts.discovery = discovery; + assert.ok(discovery.available); + const listed = discovery.sessions.filter((session) => session.pid === pid); + assert.strictEqual(listed.length, 1); + assert.strictEqual(listed[0].session_type, 'interactive'); + const probed = await probeArfSession(listed[0], 5000); + assert.ok(probed); + facts.sessionId = probed.session_id; + + const id = randomUUID(); + adopted = new SessionAgent({ + id, + generation: randomUUID(), + label: 'Interactive arf', + directory, + storage: path.join(root, id), + rPath: 'R', + library, + resources, + provider: 'arf-existing', + arfEndpoint: probed.socket_path, + arfSessionId: probed.session_id, + arfPid: probed.pid, + arfPath: path.join(root, 'missing-arf'), + supervision: 'test', + plotBackend: 'standard', + historyLimit: 50, + maxOutputBytes: 1048576, + maxJournalBytes: 16777216, + }); + connection = new AgentClient(await adopted.start()); + await connection.connect(); + const observed: SessionEvent[] = []; + connection.on('event', (event) => observed.push(event as SessionEvent)); + await connection.subscribe(0); + const active = connection; + const evaluate = async (code: string): Promise => { + const execution = randomUUID(); + await active.request('submit', { submission: { id: execution, code } }); + await until( + () => + observed.some( + (event) => event.executionId === execution && event.type === 'finished', + ), + 30000, + observed, + ); + return active.request('execution', { id: execution }); + }; + assert.strictEqual((await evaluate('adopted_value <- 17')).state, 'success'); + assert.strictEqual((await evaluate('stopifnot(adopted_value == 17)')).state, 'success'); + + // Wait until R runs the code before interrupting it through IPC. + const running = randomUUID(); + await connection.request('submit', { + submission: { + id: running, + code: '{ sess::display("interrupt ready", "text/plain"); for (i in seq_len(300)) Sys.sleep(0.1) }', + }, + }); + await until( + () => + observed.some( + (event) => + event.executionId === running && + event.type === 'display' && + event.data.text === 'interrupt ready', + ), + 30000, + observed, + ); + await connection.request('interrupt', { id: running }); + await until( + () => + observed.some( + (event) => event.executionId === running && event.type === 'finished', + ), + 30000, + observed, + ); + assert.strictEqual( + (await connection.request('execution', { id: running })).state, + 'interrupted', + ); + + await assert.rejects(connection.request('stop'), /terminal that started arf/); + process.kill(pid, 0); + assert.notStrictEqual((await connection.snapshot()).manifest.status, 'stopping'); + assert.strictEqual((await evaluate('stopifnot(adopted_value == 17)')).state, 'success'); + + connection.close(); + connection = undefined; + await adopted.close(); + adopted = undefined; + process.kill(pid, 0); + await terminal.submit('cat("after agent", adopted_value + 1, "\\n")'); + await shown('after agent 18'); + // The echoed command does not contain the output, and a prompt + // after the output shows that the REPL takes input again. + const ready = Date.now() + 20000; + while (!prompt.test((await screen()).split('after agent 18').at(-1)!)) { + if (Date.now() >= ready) { + throw new Error('arf did not show a prompt after the terminal evaluation'); + } + await delay(100); + } + // Quitting R lets arf remove its socket and session registration, + // which are outside the suite's temporary directory. + await terminal.submit("q('no')"); + await terminal.waitExit({ timeout: 10000 }); + } catch (error) { + facts.terminal = await screen(); + throw new Error( + `${error instanceof Error ? error.stack : String(error)}\n${JSON.stringify(facts, null, 2)}`, + ); + } finally { + try { + connection?.close(); + await adopted?.close(); + } finally { + await terminal.closeQuiet(); + } + } + }); + test('adopts an existing arf process without losing its objects', async function () { const arf = process.env.ARF_PATH ?? 'arf'; try { await run(arf, ['--version']); diff --git a/website/docs/features/r-interactive.md b/website/docs/features/r-interactive.md index 62a062baa..57393604e 100644 --- a/website/docs/features/r-interactive.md +++ b/website/docs/features/r-interactive.md @@ -8,7 +8,7 @@ R Interactive was introduced in vscode-R 3.2.0 ([PR #1805](https://github.com/RE ## Requirements and setup -Use **VS Code 1.101.0 or newer**. R Interactive supports Linux, macOS, and Windows. On Windows, [connecting to an existing arf session](#connect-to-an-existing-arf-session) is not yet supported. Existing R terminal workflows remain available. +Use **VS Code 1.101.0 or newer**. R Interactive supports Linux, macOS, and Windows, including [connecting to an existing arf session](#connect-to-an-existing-arf-session). Existing R terminal workflows remain available. For Remote SSH, install this extension **on the remote host**. R, its packages, optional executables, and session storage must be available on that host. For local use, the same requirements apply to your computer. @@ -76,7 +76,7 @@ Run **R: New Persistent Interactive Session**, choose **arf**, and name the sess Adoption lists running sessions with `arf ipc list` and connects to their IPC sockets on the R host. It does not depend on a particular terminal multiplexer or session manager. Listing needs the arf CLI on the R host, found through `r.interactive.arfPath`, and runs with the extension host's environment. If you start arf with a custom `ARF_IPC_SESSIONS_DIR`, set the same absolute path for the VS Code server or extension host; only that directory is listed, not the default one as well. As arf requires, make that directory private to your user, particularly on a shared R host: arf keeps the permissions of a directory that already exists, and the extension connects to the sessions it lists. If the sessions cannot be listed, the session picker says so and offers to configure arf, and the R Interactive output shows the details. -1. Start arf in your preferred terminal or session manager as usual. +1. Enable IPC in arf, in your preferred terminal or session manager. In an arf that is already running, type `:ipc start` at its prompt, which keeps the objects you have created there. To start a new arf with IPC, run `arf --with-ipc`. 2. Run **R: Connect Interactive to Session** and select the discovered arf PID and working directory. 3. Arf controls permission to execute visible IPC requests. Approve its prompt, or explicitly choose `:ipc send-policy allow` in that arf process if you want unattended editor submissions. The extension does not bypass this policy using silent evaluation. 4. Name the session. Its independent agent adopts the existing R process and preserves `.GlobalEnv`. An incompatible loaded `sess` is disconnected and unloaded before loading the private bridge; if another package prevents unloading, resolve that dependency in the terminal and reconnect.