Repository: stateful/vscode-runme (ts)

Issue:
Update CLI provider to point to the shipped Runme CLI
Currently we have a CLI button for every code block that is suppose to use the Runme CLI to execute the command inside:

![cli](https://user-images.githubusercontent.com/731337/224189757-28cf1108-4e08-4daf-8454-58a7b14c9246.gif)

The button is using the `CliProvider` class which checks whether the CLI is installed to run the action. Now that we have the CLI shipped as part of the extension we can just point directly to it.

@sourishkrout happy to take a stab at this if you think this make sense.

Pull request description:
Remove check for runme to be installed
Fixes #288 

Removes parts of the code that require runme installed - we should just use the bundled/configured one instead.

Patch:
diff --git a/src/extension/commands/index.ts b/src/extension/commands/index.ts
index 8961be38..19a2917b 100644
--- a/src/extension/commands/index.ts
+++ b/src/extension/commands/index.ts
@@ -8,7 +8,6 @@ import {
 
 import { getBinaryPath, getTLSDir, getTLSEnabled } from '../../utils/configuration'
 import { Kernel } from '../kernel'
-import { CliProvider } from '../provider/cli'
 import { getAnnotations, getTerminalByCell } from '../utils'
 import RunmeServer from '../server/runmeServer'
 import { GrpcRunnerEnvironment } from '../runner'
@@ -46,7 +45,6 @@ export function runCLICommand(
   kernel: Kernel
 ) {
  return async function(cell: NotebookCell) {
-    let runmeExecutable: string
     const cwd = path.dirname(cell.document.uri.fsPath)
 
     const args = [
@@ -56,9 +54,9 @@ export function runCLICommand(
 
     const envs: Record<string, string> = { }
 
-    if (grpcRunner) {
-      runmeExecutable = getBinaryPath(extensionBaseUri, os.platform()).fsPath
+    const runmeExecutable = getBinaryPath(extensionBaseUri, os.platform()).fsPath
 
+    if (grpcRunner) {
       envs['RUNME_SERVER_ADDR'] = server.address()
 
       if (getTLSEnabled()) {
@@ -71,17 +69,6 @@ export function runCLICommand(
       if(runnerEnv && runnerEnv instanceof GrpcRunnerEnvironment) {
         envs['RUNME_SESSION'] = runnerEnv.getSessionId()
       }
-    } else {
-      if (!await CliProvider.isCliInstalled()) {
-        return window.showInformationMessage(
-          'Runme CLI is not installed. Do you want to download it?',
-          'Download now'
-        ).then((openBrowser) => openBrowser && env.openExternal(
-          Uri.parse('https://github.com/stateful/runme/releases')
-        ))
-      }
-
-      runmeExecutable = 'runme'
     }
 
     const annotations = getAnnotations(cell)
@@ -90,6 +77,7 @@ export function runCLICommand(
       cwd,
       env: envs,
     })
+
     term.show(false)
     term.sendText(`${runmeExecutable} run ${annotations.name} ${args.join(' ')}`)
   }
diff --git a/src/extension/provider/cli.ts b/src/extension/provider/cli.ts
index f2bf9b09..257abdce 100644
--- a/src/extension/provider/cli.ts
+++ b/src/extension/provider/cli.ts
@@ -1,5 +1,3 @@
-import { spawn } from 'node:child_process'
-
 import vscode, { NotebookCellKind } from 'vscode'
 
 import { getAnnotations } from '../utils'
@@ -25,12 +23,4 @@ export class CliProvider implements vscode.NotebookCellStatusBarItemProvider {
     item.command = 'runme.runCliCommand'
     return item
   }
-
-  public static async isCliInstalled(): Promise<boolean> {
-    const child = spawn('which runme', { shell: true, env: process.env })
-    return new Promise<boolean>((resolve, reject) => {
-      child.on('exit', () => resolve(child.exitCode === 0))
-      child.on('error', (err) => reject(err))
-    })
-  }
 }


Test patch:
diff --git a/tests/extension/commands/index.test.ts b/tests/extension/commands/index.test.ts
index a57fe17e..806480bd 100644
--- a/tests/extension/commands/index.test.ts
+++ b/tests/extension/commands/index.test.ts
@@ -11,7 +11,8 @@ import {
   NotebookDocument,
   TextDocument,
   ViewColumn,
-  NotebookCellData
+  NotebookCellData,
+  Uri,
 } from 'vscode'
 
 import {
@@ -24,7 +25,7 @@ import {
   createNewRunmeNotebook
 } from '../../../src/extension/commands'
 import { getTerminalByCell, getAnnotations } from '../../../src/extension/utils'
-import { CliProvider } from '../../../src/extension/provider/cli'
+import { getBinaryPath } from '../../../src/utils/configuration'
 
 vi.mock('vscode', () => import(path.join(process.cwd(), '__mocks__', 'vscode')))
 vi.mock('vscode-telemetry')
@@ -32,6 +33,9 @@ vi.mock('../../../src/extension/utils', () => ({
   getAnnotations: vi.fn(),
   getTerminalByCell: vi.fn()
 }))
+vi.mock('../../../src/utils/configuration', () => ({
+  getBinaryPath: vi.fn(),
+}))
 vi.mock('../../../src/extension/provider/cli', () => ({
   CliProvider: {
     isCliInstalled: vi.fn()
@@ -67,34 +71,21 @@ test('copyCellToClipboard', () => {
   expect(window.showInformationMessage).toBeCalledTimes(1)
 })
 
-test('runCLICommand if CLI is not installed', async () => {
+test('runCLICommand', async () => {
   const cell: any = {
     metadata: { name: 'foobar' },
     document: { uri: { fsPath: '/foo/bar/README.md' }}
   }
+  vi.mocked(getAnnotations).mockReturnValueOnce({
+    name: 'foo-bar',
+  } as any)
+  vi.mocked(getBinaryPath).mockReturnValueOnce(Uri.file('/bin/runme'))
   vi.mocked(window.showInformationMessage).mockResolvedValueOnce(false as any)
-  await runCLICommand({} as any, false, {} as any, {} as any)(cell)
-  expect(env.openExternal).toBeCalledTimes(0)
-  vi.mocked(window.showInformationMessage).mockResolvedValue(true as any)
-  await runCLICommand({} as any, false, {} as any, {} as any)(cell)
-  expect(env.openExternal).toBeCalledTimes(1)
-})
 
-test('runCLICommand if CLI is installed', async () => {
-  const cell: any = {
-    metadata: { name: 'foobar' },
-    document: { uri: { fsPath: '/foo/bar/README.md' }}
-  }
-  vi.mocked(CliProvider.isCliInstalled).mockResolvedValue(true)
-  vi.mocked(getAnnotations).mockReturnValue(cell.metadata)
   await runCLICommand({} as any, false, {} as any, {} as any)(cell)
-  expect(window.createTerminal).toBeCalledWith({
-    cwd: '/foo/bar',
-    env: {},
-    name: 'CLI: foobar'
-  })
-  expect(terminal.show).toBeCalledTimes(1)
-  expect(terminal.sendText).toBeCalledWith('runme run foobar --chdir="/foo/bar" --filename="README.md"')
+  expect(vi.mocked((terminal as any).sendText)).toHaveBeenCalledWith(
+    '/bin/runme run foo-bar --chdir="/foo/bar" --filename="README.md"'
+  )
 })
 
 test('open markdown as Runme notebook', (file: NotebookDocument) => {