diff options
| author | Ty Dunn <ty@tydunn.com> | 2023-07-03 19:42:38 -0700 | 
|---|---|---|
| committer | Ty Dunn <ty@tydunn.com> | 2023-07-03 19:42:38 -0700 | 
| commit | 6016e78b353d5afae9fe0a68c718fa2b2216dc5c (patch) | |
| tree | 5602740ba169db7ac40ac6abac5ac6beb176d263 /extension/src | |
| parent | 99cd41b8901a09c4f5e5a1e0fc78a93ee2306f2e (diff) | |
| parent | 227c0635cf324ff212200fe38835b8015a3635bd (diff) | |
| download | sncontinue-6016e78b353d5afae9fe0a68c718fa2b2216dc5c.tar.gz sncontinue-6016e78b353d5afae9fe0a68c718fa2b2216dc5c.tar.bz2 sncontinue-6016e78b353d5afae9fe0a68c718fa2b2216dc5c.zip | |
Merge branch 'main' of github.com:continuedev/continue
Diffstat (limited to 'extension/src')
| -rw-r--r-- | extension/src/__mocks__/vscode.ts | 7 | ||||
| -rw-r--r-- | extension/src/activation/environmentSetup.ts | 17 | ||||
| -rw-r--r-- | extension/src/activation/test/environmentSetup.test.ts | 70 | ||||
| -rw-r--r-- | extension/src/test/suite/terminalEmulator.test.ts | 28 | 
4 files changed, 79 insertions, 43 deletions
| diff --git a/extension/src/__mocks__/vscode.ts b/extension/src/__mocks__/vscode.ts new file mode 100644 index 00000000..d415b5a0 --- /dev/null +++ b/extension/src/__mocks__/vscode.ts @@ -0,0 +1,7 @@ +const vscode = { +  window: { +    onDidChangeVisibleTextEditors: jest.fn(), +  }, +}; + +module.exports = vscode; diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 4e6be9b3..71b774d9 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -4,7 +4,6 @@ const exec = util.promisify(require("child_process").exec);  const { spawn } = require("child_process");  import * as path from "path";  import * as fs from "fs"; -import rebuild from "@electron/rebuild";  import { getContinueServerUrl } from "../bridge";  import fetch from "node-fetch";  import * as vscode from "vscode"; @@ -60,7 +59,7 @@ async function runCommand(cmd: string): Promise<[string, string | undefined]> {    return [stdout, stderr];  } -async function getPythonPipCommands() { +export async function getPythonPipCommands() {    var [stdout, stderr] = await runCommand("python3 --version");    let pythonCmd = "python3";    if (stderr) { @@ -111,10 +110,8 @@ async function getPythonPipCommands() {        );        throw new Error("Python3.8 or greater is not installed.");      } -  } else { -    pythonCmd = `python${major}.${minor}`; -    pipCmd = `pip${major}.${minor}`;    } +    return [pythonCmd, pipCmd];  } @@ -368,16 +365,6 @@ export async function startContinuePythonServer() {    });  } -async function installNodeModules() { -  console.log("Rebuilding node-pty for Continue extension..."); -  await rebuild({ -    buildPath: getExtensionUri().fsPath, // Folder containing node_modules -    electronVersion: "19.1.8", -    onlyModules: ["node-pty"], -  }); -  console.log("Successfully rebuilt node-pty"); -} -  export function isPythonEnvSetup(): boolean {    let pathToEnvCfg = getExtensionUri().fsPath + "/scripts/env/pyvenv.cfg";    return fs.existsSync(path.join(pathToEnvCfg)); diff --git a/extension/src/activation/test/environmentSetup.test.ts b/extension/src/activation/test/environmentSetup.test.ts new file mode 100644 index 00000000..ca487416 --- /dev/null +++ b/extension/src/activation/test/environmentSetup.test.ts @@ -0,0 +1,70 @@ +const child_process = require("child_process"); +import { platform } from "os"; +import { getPythonPipCommands } from "../environmentSetup"; + +jest.mock("os"); +jest.mock("child_process"); + +function mockPythonVersionMappings(mappings: { [pythonCmd: string]: string }) { +  (child_process.exec as jest.Mock).mockImplementation( +    (command: string, options: any) => { +      const pythonCmd = command.split(" ")[0]; +      if (pythonCmd in mappings) { +        return Promise.resolve([mappings[pythonCmd], ""]); +      } else { +        return Promise.resolve(["", stubStderr]); +      } +    } +  ); +} + +const stubStderr = +  "This is a stub stderr, but will be checked only for existence."; +describe("getPythonPipCommands", () => { +  describe("on Windows", () => { +    it("should return the correct Python and Pip commands", async () => { +      (platform as jest.Mock).mockReturnValue("win32"); +      mockPythonVersionMappings({ +        python: "Python 3.8.0", +      }); + +      const [pythonCmd, pipCmd] = await getPythonPipCommands(); + +      expect(pythonCmd).toBe("python"); +      expect(pipCmd).toBe("pip"); + +      jest.restoreAllMocks(); +    }); +    describe("on MacOS", () => { +      (platform as jest.Mock).mockReturnValue("darwin"); +      it("should check through all python versions after finding 3.7", async () => { +        mockPythonVersionMappings({ +          python: "", +          python3: "Python 3.7.0", +          "python3.11": "Python 3.11.0", +        }); + +        const [pythonCmd, pipCmd] = await getPythonPipCommands(); + +        expect(pythonCmd).toBe("python3.11"); +        expect(pipCmd).toBe("pip3.11"); + +        jest.restoreAllMocks(); +      }); + +      it("should use python3 if that maps to valid version", async () => { +        mockPythonVersionMappings({ +          python: "", +          python3: "Python 3.8.0", +        }); + +        const [pythonCmd, pipCmd] = await getPythonPipCommands(); + +        expect(pythonCmd).toBe("python3"); +        expect(pipCmd).toBe("pip3"); + +        jest.restoreAllMocks(); +      }); +    }); +  }); +}); diff --git a/extension/src/test/suite/terminalEmulator.test.ts b/extension/src/test/suite/terminalEmulator.test.ts deleted file mode 100644 index c4c159a4..00000000 --- a/extension/src/test/suite/terminalEmulator.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { test, describe } from "mocha"; -import * as assert from "assert"; -import { PythonTracebackSnooper } from "../../terminal/snoopers"; - -suite("Snoopers", () => { -  suite("PythonTracebackSnooper", () => { -    test("should detect traceback given all at once", async () => { -      let traceback = `Traceback (most recent call last): -              File "/Users/natesesti/Desktop/continue/extension/examples/python/main.py", line 10, in <module> -                sum(first, second) -              File "/Users/natesesti/Desktop/continue/extension/examples/python/sum.py", line 2, in sum -                return a + b -            TypeError: unsupported operand type(s) for +: 'int' and 'str'`; -      let returnedTraceback = await new Promise((resolve) => { -        let callback = (data: string) => { -          resolve(data); -        }; -        let snooper = new PythonTracebackSnooper(callback); -        snooper.onData(traceback); -      }); -      assert( -        returnedTraceback === traceback, -        "Detected \n" + returnedTraceback -      ); -    }); -    test("should detect traceback given in chunks", () => {}); -  }); -}); | 
