core test cleanup
This commit is contained in:
parent
3622c50f2c
commit
02f40d04bd
34 changed files with 72 additions and 824 deletions
|
|
@ -4,7 +4,7 @@ import path from "path";
|
|||
|
||||
import Parser from "web-tree-sitter";
|
||||
import { Position } from "../../../..";
|
||||
import { testIde } from "../../../../test/util/fixtures";
|
||||
import { testIde } from "../../../../test/fixtures";
|
||||
import { getAst, getTreePathAtCursor } from "../../../util/ast";
|
||||
import { ImportDefinitionsService } from "../../ImportDefinitionsService";
|
||||
import { RootPathContextService } from "../RootPathContextService";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
import { setUpTestDir, tearDownTestDir } from "../../../test/util/testDir";
|
||||
import {
|
||||
setUpTestDir,
|
||||
tearDownTestDir,
|
||||
} from "../../../indexing/test/testWorkspaceDir";
|
||||
|
||||
import { TEST_CASES_WITH_DIFF, TEST_CASES_WITHOUT_DIFF } from "./testCases";
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import fs from "node:fs";
|
|||
import path from "node:path";
|
||||
|
||||
import Mock from "../../../llm/llms/Mock";
|
||||
import { testConfigHandler, testIde } from "../../../test/util/fixtures";
|
||||
import { testConfigHandler, testIde } from "../../../test/fixtures";
|
||||
import { CompletionProvider } from "../../CompletionProvider";
|
||||
import { AutocompleteInput } from "../../util/types";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import { testConfigHandler } from "../test/util/fixtures";
|
||||
import { TEST_DIR } from "../test/util/testDir";
|
||||
import { testConfigHandler } from "../test/fixtures";
|
||||
import { TEST_DIR } from "../indexing/test/testWorkspaceDir";
|
||||
import { getConfigTsPath } from "../util/paths";
|
||||
|
||||
import { defaultConfig } from "./default";
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import {
|
|||
ContextProviderExtras,
|
||||
ContextProviderWithParams,
|
||||
IContextProvider,
|
||||
} from "../../..";
|
||||
import { ConfigHandler } from "../../../config/ConfigHandler";
|
||||
import { contextProviderClassFromName } from "../../../context/providers";
|
||||
import { ControlPlaneClient } from "../../../control-plane/client";
|
||||
import FileSystemIde from "../../../util/filesystem";
|
||||
import { TEST_DIR } from "../../util/testDir";
|
||||
} from "../..";
|
||||
import { ConfigHandler } from "../../config/ConfigHandler";
|
||||
import { contextProviderClassFromName } from ".";
|
||||
import { ControlPlaneClient } from "../../control-plane/client";
|
||||
import FileSystemIde from "../../util/filesystem";
|
||||
import { TEST_DIR } from "../../indexing/test/testWorkspaceDir";
|
||||
|
||||
const CONTEXT_PROVIDERS_TO_TEST: ContextProviderWithParams[] = [
|
||||
{ name: "diff", params: {} },
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
import { jest } from "@jest/globals";
|
||||
|
||||
import { testIde } from "../test/util/fixtures";
|
||||
import { testIde } from "../test/fixtures";
|
||||
import {
|
||||
insertMockChunks,
|
||||
mockPathAndCacheKey,
|
||||
updateIndexAndAwaitGenerator,
|
||||
} from "../test/util/indexing";
|
||||
} from "./test/indexing";
|
||||
|
||||
import { CodeSnippetsCodebaseIndex } from "./CodeSnippetsIndex";
|
||||
import { DatabaseConnection, SqliteDb } from "./refreshIndex";
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ import path from "node:path";
|
|||
import { jest } from "@jest/globals";
|
||||
|
||||
import { ContinueServerClient } from "../continueServer/stubs/client.js";
|
||||
import { testConfigHandler, testIde } from "../test/util/fixtures.js";
|
||||
import { testConfigHandler, testIde } from "../test/fixtures.js";
|
||||
import {
|
||||
addToTestDir,
|
||||
setUpTestDir,
|
||||
tearDownTestDir,
|
||||
TEST_DIR,
|
||||
} from "../test/util/testDir.js";
|
||||
} from "./test/testWorkspaceDir.js";
|
||||
import { getIndexSqlitePath } from "../util/paths.js";
|
||||
|
||||
import { CodebaseIndexer, PauseToken } from "./CodebaseIndexer.js";
|
||||
|
|
@ -76,8 +76,8 @@ describe("CodebaseIndexer", () => {
|
|||
setUpTestDir();
|
||||
|
||||
execSync("git init", { cwd: TEST_DIR });
|
||||
execSync("git config user.email \"test@example.com\"", { cwd: TEST_DIR });
|
||||
execSync("git config user.name \"Test\"", { cwd: TEST_DIR });
|
||||
execSync('git config user.email "test@example.com"', { cwd: TEST_DIR });
|
||||
execSync('git config user.name "Test"', { cwd: TEST_DIR });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
@ -100,9 +100,7 @@ describe("CodebaseIndexer", () => {
|
|||
|
||||
async function refreshIndexFiles(files: string[]) {
|
||||
const updates = [];
|
||||
for await (const update of codebaseIndexer.refreshFiles(
|
||||
files,
|
||||
)) {
|
||||
for await (const update of codebaseIndexer.refreshFiles(files)) {
|
||||
updates.push(update);
|
||||
}
|
||||
return updates;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import {
|
|||
insertMockChunks,
|
||||
mockPathAndCacheKey,
|
||||
updateIndexAndAwaitGenerator,
|
||||
} from "../test/util/indexing";
|
||||
} from "./test/indexing";
|
||||
|
||||
import { FullTextSearchCodebaseIndex } from "./FullTextSearchCodebaseIndex";
|
||||
import { DatabaseConnection, SqliteDb } from "./refreshIndex";
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import lance from "vectordb";
|
||||
|
||||
import { testConfigHandler, testIde } from "../test/util/fixtures";
|
||||
import { testConfigHandler, testIde } from "../test/fixtures";
|
||||
import {
|
||||
mockPathAndCacheKey,
|
||||
mockTag,
|
||||
testContinueServerClient,
|
||||
updateIndexAndAwaitGenerator,
|
||||
} from "../test/util/indexing";
|
||||
} from "./test/indexing";
|
||||
import { getLanceDbPath } from "../util/paths";
|
||||
|
||||
import { LanceDbIndex } from "./LanceDbIndex";
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import { jest } from "@jest/globals";
|
||||
|
||||
import { testIde } from "../../test/util/fixtures";
|
||||
import { testIde } from "../../test/fixtures";
|
||||
import {
|
||||
mockFileContents,
|
||||
mockFilename,
|
||||
mockPathAndCacheKey,
|
||||
testContinueServerClient,
|
||||
updateIndexAndAwaitGenerator,
|
||||
} from "../../test/util/indexing";
|
||||
import { addToTestDir } from "../../test/util/testDir";
|
||||
} from "../test/indexing";
|
||||
import { addToTestDir } from "../test/testWorkspaceDir";
|
||||
import { DatabaseConnection, SqliteDb } from "../refreshIndex";
|
||||
import { IndexResultType } from "../types";
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import os from "os";
|
|||
import { jest } from "@jest/globals";
|
||||
|
||||
import { ContinueConfig } from "../..";
|
||||
import { testConfigHandler } from "../../test/util/fixtures";
|
||||
import { testConfigHandler } from "../../test/fixtures";
|
||||
import FileSystemIde from "../../util/filesystem";
|
||||
|
||||
import DocsCrawler, { ChromiumInstaller, type PageData } from "./DocsCrawler";
|
||||
|
|
|
|||
|
|
@ -2,19 +2,12 @@ import { jest } from "@jest/globals";
|
|||
|
||||
import { IndexTag } from "../..";
|
||||
import { IContinueServerClient } from "../../continueServer/interface";
|
||||
import { ChunkCodebaseIndex } from "../../indexing/chunk/ChunkCodebaseIndex";
|
||||
import { tagToString } from "../../indexing/refreshIndex";
|
||||
import {
|
||||
CodebaseIndex,
|
||||
PathAndCacheKey,
|
||||
RefreshIndexResults,
|
||||
} from "../../indexing/types";
|
||||
|
||||
import { testIde } from "./fixtures";
|
||||
import { addToTestDir, TEST_DIR } from "./testDir";
|
||||
|
||||
|
||||
import { ChunkCodebaseIndex } from "../chunk/ChunkCodebaseIndex";
|
||||
import { tagToString } from "../refreshIndex";
|
||||
import { CodebaseIndex, PathAndCacheKey, RefreshIndexResults } from "../types";
|
||||
|
||||
import { testIde } from "../../test/fixtures";
|
||||
import { addToTestDir, TEST_DIR } from "./testWorkspaceDir";
|
||||
|
||||
export const mockFilename = "test.py";
|
||||
export const mockPathAndCacheKey = {
|
||||
|
|
@ -3,7 +3,7 @@ import os from "os";
|
|||
import path from "path";
|
||||
|
||||
// Want this outside of the git repository so we can change branches in tests
|
||||
export const TEST_DIR = path.join(os.tmpdir(), "testDir");
|
||||
export const TEST_DIR = path.join(os.tmpdir(), "testWorkspaceDir");
|
||||
|
||||
export function setUpTestDir() {
|
||||
if (fs.existsSync(TEST_DIR)) {
|
||||
|
|
@ -6,7 +6,7 @@ import {
|
|||
setUpTestDir,
|
||||
tearDownTestDir,
|
||||
addToTestDir,
|
||||
} from "../test/util/testDir";
|
||||
} from "./test/testWorkspaceDir";
|
||||
import FileSystemIde from "../util/filesystem";
|
||||
|
||||
const ide = new FileSystemIde(TEST_DIR);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
// https://github.com/mswjs/msw/issues/1576#issuecomment-1482643055
|
||||
|
||||
import fs from "fs";
|
||||
import { TextDecoder, TextEncoder } from "util";
|
||||
|
||||
import { jest } from "@jest/globals";
|
||||
|
|
@ -12,23 +11,20 @@ if (process.env.DEBUG === "jest") {
|
|||
const globalThis = global as any;
|
||||
|
||||
globalThis.jest = jest;
|
||||
|
||||
// https://github.com/mswjs/msw/issues/1576#issuecomment-1482643055
|
||||
globalThis.fetch = fetch;
|
||||
globalThis.Request = Request;
|
||||
globalThis.Response = Response;
|
||||
globalThis.TextEncoder = TextEncoder;
|
||||
globalThis.TextDecoder = TextDecoder;
|
||||
|
||||
// Trying to delete this when for some reason SQLite is still in use causes tests to fail
|
||||
// globalThis.beforeAll(() => {
|
||||
// // We can ignore TS warnings here since we set this explicitly in `./jest.global-setup.ts`
|
||||
// TODO - currently causing tests to fail because sqlite is still running for some reason
|
||||
// const clearTestDirectory = () => {
|
||||
// if (fs.existsSync(process.env.CONTINUE_GLOBAL_DIR!)) {
|
||||
// fs.rmSync(process.env.CONTINUE_GLOBAL_DIR!, { recursive: true });
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
||||
// globalThis.afterAll(() => {
|
||||
// // We can ignore TS warnings here since we set this explicitly in `./jest.global-setup.ts`
|
||||
// if (fs.existsSync(process.env.CONTINUE_GLOBAL_DIR!)) {
|
||||
// fs.rmSync(process.env.CONTINUE_GLOBAL_DIR!, { recursive: true });
|
||||
// }
|
||||
// });
|
||||
// globalThis.beforeAll(clearTestDirectory);
|
||||
// globalThis.afterAll(clearTestDirectory);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
import * as dotenv from "dotenv";
|
||||
|
||||
import { CompletionOptions } from "../";
|
||||
import { BaseLLM } from "../llm/";
|
||||
import OpenAI from "../llm/llms/OpenAI";
|
||||
|
||||
// jest.setTimeout(100_000);
|
||||
import { CompletionOptions } from "..";
|
||||
import { BaseLLM } from ".";
|
||||
import OpenAI from "./llms/OpenAI";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
"description": "The Continue Core contains functionality that can be shared across web, VS Code, or Node.js",
|
||||
"scripts": {
|
||||
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
||||
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage && open ./coverage/lcov-report/index.html",
|
||||
"tsc:check": "tsc -p ./ --noEmit",
|
||||
"build:npm": "tsc -p ./tsconfig.npm.json",
|
||||
"lint": "eslint . --ext ts",
|
||||
|
|
|
|||
1
core/test/.gitignore
vendored
1
core/test/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
|||
scratch.test.ts
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
def average(nums: list) -> float:
|
||||
pass
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import { ConfigHandler } from "../../config/ConfigHandler";
|
||||
import { ControlPlaneClient } from "../../control-plane/client";
|
||||
import FileSystemIde from "../../util/filesystem";
|
||||
import { ConfigHandler } from "../config/ConfigHandler";
|
||||
import { ControlPlaneClient } from "../control-plane/client";
|
||||
import FileSystemIde from "../util/filesystem";
|
||||
|
||||
import { TEST_DIR } from "./testDir";
|
||||
import { TEST_DIR } from "../indexing/test/testWorkspaceDir";
|
||||
|
||||
export const testIde = new FileSystemIde(TEST_DIR);
|
||||
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
// File generated by Continue
|
||||
import { dedentAndGetCommonWhitespace } from "../../util";
|
||||
|
||||
describe("dedentAndGetCommonWhitespace", () => {
|
||||
let originalString: string;
|
||||
|
||||
beforeEach(() => {
|
||||
// Setup any global variables or states if needed
|
||||
originalString = " line1\n line2\n line3";
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Tear down any changes to global variables or states if needed
|
||||
originalString = "";
|
||||
});
|
||||
|
||||
test("should dedent and return common whitespace for a simple case", () => {
|
||||
const input = " line1\n line2\n line3";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual(["line1\nline2\nline3", " "]);
|
||||
});
|
||||
|
||||
test("should handle empty string", () => {
|
||||
const input = "";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual(["", ""]);
|
||||
});
|
||||
|
||||
test("should handle string with only whitespace", () => {
|
||||
const input = " ";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual(["", ""]);
|
||||
});
|
||||
|
||||
test("should handle string with mixed whitespace and content", () => {
|
||||
const input = " line1\n line2\n line3";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual([" line1\nline2\n line3", " "]);
|
||||
});
|
||||
|
||||
test("should handle string with no common leading whitespace", () => {
|
||||
const input = "line1\n line2\n line3";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual([input, ""]);
|
||||
});
|
||||
|
||||
test("should handle string with empty lines", () => {
|
||||
const input = " line1\n\n line3";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual(["line1\n\nline3", " "]);
|
||||
});
|
||||
|
||||
test("should handle string with only empty lines", () => {
|
||||
const input = "\n\n";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual(["\n\n", ""]);
|
||||
});
|
||||
|
||||
test("should handle string with tabs as whitespace", () => {
|
||||
const input = "\tline1\n\tline2\n\tline3";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual(["line1\nline2\nline3", "\t"]);
|
||||
});
|
||||
|
||||
test("should handle string with mixed tabs and spaces", () => {
|
||||
const input = "\t line1\n\t line2\n\t line3";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual(["line1\nline2\nline3", "\t "]);
|
||||
});
|
||||
|
||||
test("should handle string with different leading whitespace lengths", () => {
|
||||
const input = " line1\n line2\n line3";
|
||||
const output = dedentAndGetCommonWhitespace(input);
|
||||
expect(output).toEqual([" line1\nline2\n line3", " "]);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
// File generated by Continue
|
||||
import { getLastNPathParts } from "../../util";
|
||||
|
||||
describe("getLastNPathParts", () => {
|
||||
const SEP_REGEX = /[\\/]+/;
|
||||
|
||||
beforeAll(() => {
|
||||
// Setup code if needed
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
// Teardown code if needed
|
||||
});
|
||||
|
||||
test("returns the last N parts of a filepath with forward slashes", () => {
|
||||
const filepath = "home/user/documents/project/file.txt";
|
||||
expect(getLastNPathParts(filepath, 2)).toBe("project/file.txt");
|
||||
});
|
||||
|
||||
test("returns the last N parts of a filepath with backward slashes", () => {
|
||||
const filepath = "C:\\home\\user\\documents\\project\\file.txt";
|
||||
expect(getLastNPathParts(filepath, 3)).toBe("documents/project/file.txt");
|
||||
});
|
||||
|
||||
test("returns the last part if N is 1", () => {
|
||||
const filepath = "/home/user/documents/project/file.txt";
|
||||
expect(getLastNPathParts(filepath, 1)).toBe("file.txt");
|
||||
});
|
||||
|
||||
test("returns the entire path if N is greater than the number of parts", () => {
|
||||
const filepath = "home/user/documents/project/file.txt";
|
||||
expect(getLastNPathParts(filepath, 10)).toBe(
|
||||
"home/user/documents/project/file.txt",
|
||||
);
|
||||
});
|
||||
|
||||
test("returns an empty string if N is 0", () => {
|
||||
const filepath = "home/user/documents/project/file.txt";
|
||||
expect(getLastNPathParts(filepath, 0)).toBe("");
|
||||
});
|
||||
|
||||
test("handles paths with mixed forward and backward slashes", () => {
|
||||
const filepath = "home\\user/documents\\project/file.txt";
|
||||
expect(getLastNPathParts(filepath, 3)).toBe("documents/project/file.txt");
|
||||
});
|
||||
|
||||
test("handles edge case with empty filepath", () => {
|
||||
const filepath = "";
|
||||
expect(getLastNPathParts(filepath, 2)).toBe("");
|
||||
});
|
||||
});
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
// This file is generated by Continue
|
||||
import { longestCommonSubsequence } from "../../util/lcs";
|
||||
|
||||
describe("longestCommonSubsequence", () => {
|
||||
beforeAll(() => {
|
||||
// Setup if needed
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
// Teardown if needed
|
||||
});
|
||||
|
||||
test("should return the longest common subsequence for non-empty strings", () => {
|
||||
expect(longestCommonSubsequence("abcde", "ace")).toBe("ace");
|
||||
expect(longestCommonSubsequence("abc", "abc")).toBe("abc");
|
||||
expect(longestCommonSubsequence("abc", "def")).toBe("");
|
||||
});
|
||||
|
||||
test("should handle cases where one or both strings are empty", () => {
|
||||
expect(longestCommonSubsequence("", "abc")).toBe("");
|
||||
expect(longestCommonSubsequence("abc", "")).toBe("");
|
||||
expect(longestCommonSubsequence("", "")).toBe("");
|
||||
});
|
||||
|
||||
test("should handle cases with no common subsequence", () => {
|
||||
expect(longestCommonSubsequence("abc", "def")).toBe("");
|
||||
expect(longestCommonSubsequence("xyz", "abc")).toBe("");
|
||||
});
|
||||
|
||||
test("should handle cases with special characters", () => {
|
||||
expect(longestCommonSubsequence("a!@#b$c", "!@#$")).toBe("!@#$");
|
||||
expect(longestCommonSubsequence("a!@#b$c", "xyz")).toBe("");
|
||||
});
|
||||
|
||||
test("should handle long strings efficiently", () => {
|
||||
const str1 = "a".repeat(1000) + "b".repeat(1000);
|
||||
const str2 = "a".repeat(1000) + "c".repeat(1000);
|
||||
expect(longestCommonSubsequence(str1, str2)).toBe("a".repeat(1000));
|
||||
});
|
||||
});
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
// File generated by Continue
|
||||
import { mergeJson } from "../../util/merge";
|
||||
|
||||
describe("mergeJson", () => {
|
||||
it("should merge two simple JSON objects", () => {
|
||||
const first = { a: 1, b: 2 };
|
||||
const second = { b: 3, c: 4 };
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: 1, b: 3, c: 4 });
|
||||
});
|
||||
|
||||
it("should overwrite values when mergeBehavior is \"overwrite\"", () => {
|
||||
const first = { a: 1, b: 2 };
|
||||
const second = { b: 3, c: 4 };
|
||||
const result = mergeJson(first, second, "overwrite");
|
||||
expect(result).toEqual({ a: 1, b: 3, c: 4 });
|
||||
});
|
||||
|
||||
it("should merge nested objects", () => {
|
||||
const first = { a: { b: 1 } };
|
||||
const second = { a: { c: 2 } };
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: { b: 1, c: 2 } });
|
||||
});
|
||||
|
||||
it("should merge arrays without mergeKeys", () => {
|
||||
const first = { a: [1, 2] };
|
||||
const second = { a: [3, 4] };
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: [1, 2, 3, 4] });
|
||||
});
|
||||
|
||||
it("should merge arrays with mergeKeys", () => {
|
||||
const first = {
|
||||
a: [
|
||||
{ id: 1, value: "first" },
|
||||
{ id: 2, value: "second" },
|
||||
],
|
||||
};
|
||||
const second = {
|
||||
a: [
|
||||
{ id: 2, value: "updated" },
|
||||
{ id: 3, value: "third" },
|
||||
],
|
||||
};
|
||||
const mergeKeys = {
|
||||
a: (item1: any, item2: any) => item1.id === item2.id,
|
||||
};
|
||||
const result = mergeJson(first, second, undefined, mergeKeys);
|
||||
expect(result).toEqual({
|
||||
a: [
|
||||
{ id: 1, value: "first" },
|
||||
{ id: 2, value: "updated" },
|
||||
{ id: 3, value: "third" },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle non-object values correctly", () => {
|
||||
const first = { a: 1, b: "string", c: true };
|
||||
const second = { a: 2, b: "new string", c: false };
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: 2, b: "new string", c: false });
|
||||
});
|
||||
|
||||
it("should handle null and undefined values correctly", () => {
|
||||
const first = { a: 1, b: null };
|
||||
const second = { b: 2, c: undefined };
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: 1, b: 2, c: undefined });
|
||||
});
|
||||
|
||||
it("should handle empty objects", () => {
|
||||
const first = {};
|
||||
const second = { a: 1 };
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: 1 });
|
||||
});
|
||||
|
||||
it("should handle empty second object", () => {
|
||||
const first = { a: 1 };
|
||||
const second = {};
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: 1 });
|
||||
});
|
||||
|
||||
it("should handle errors gracefully", () => {
|
||||
const first = { a: 1 };
|
||||
const second = { b: () => {} }; // Functions are not serializable in JSON
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: 1, b: expect.any(Function) });
|
||||
});
|
||||
|
||||
it("should merge deeply nested objects", () => {
|
||||
const first = { a: { b: { c: 1 } } };
|
||||
const second = { a: { b: { d: 2 } } };
|
||||
const result = mergeJson(first, second);
|
||||
expect(result).toEqual({ a: { b: { c: 1, d: 2 } } });
|
||||
});
|
||||
});
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
// This file is generated by Continue
|
||||
|
||||
import { getRangeInString } from "../../../util/ranges";
|
||||
|
||||
describe.skip("getRangeInString", () => {
|
||||
let content: string;
|
||||
|
||||
beforeEach(() => {
|
||||
content = `Line 1
|
||||
Line 2
|
||||
Line 3
|
||||
Line 4
|
||||
Line 5`;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
content = "";
|
||||
});
|
||||
|
||||
test("should return substring within the same line", () => {
|
||||
const range = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 1, character: 4 },
|
||||
};
|
||||
expect(getRangeInString(content, range)).toBe("Line");
|
||||
});
|
||||
|
||||
test("should return substring spanning multiple lines", () => {
|
||||
const range = {
|
||||
start: { line: 1, character: 2 },
|
||||
end: { line: 3, character: 3 },
|
||||
};
|
||||
const expected = `ne 2
|
||||
Line 3
|
||||
Line 4`;
|
||||
expect(getRangeInString(content, range)).toBe(expected);
|
||||
});
|
||||
|
||||
test("should handle range that starts and ends at the same character", () => {
|
||||
const range = {
|
||||
start: { line: 2, character: 0 },
|
||||
end: { line: 2, character: 0 },
|
||||
};
|
||||
expect(getRangeInString(content, range)).toBe("L");
|
||||
});
|
||||
|
||||
test("should handle range that spans entire content", () => {
|
||||
const range = {
|
||||
start: { line: 0, character: 0 },
|
||||
end: { line: 4, character: 5 },
|
||||
};
|
||||
expect(getRangeInString(content, range)).toBe(content);
|
||||
});
|
||||
|
||||
test("should handle range that spans to the end of the last line", () => {
|
||||
const range = {
|
||||
start: { line: 3, character: 2 },
|
||||
end: { line: 4, character: 5 },
|
||||
};
|
||||
const expected = `ne 4
|
||||
Line 5`;
|
||||
expect(getRangeInString(content, range)).toBe(expected);
|
||||
});
|
||||
|
||||
test("should handle empty content", () => {
|
||||
content = "";
|
||||
const range = {
|
||||
start: { line: 0, character: 0 },
|
||||
end: { line: 0, character: 0 },
|
||||
};
|
||||
expect(getRangeInString(content, range)).toBe("");
|
||||
});
|
||||
|
||||
test("should handle invalid range (start line > end line)", () => {
|
||||
const range = {
|
||||
start: { line: 3, character: 0 },
|
||||
end: { line: 2, character: 0 },
|
||||
};
|
||||
expect(getRangeInString(content, range)).toBe("");
|
||||
});
|
||||
|
||||
test("should handle invalid range (start character > end character on same line)", () => {
|
||||
const range = {
|
||||
start: { line: 1, character: 5 },
|
||||
end: { line: 1, character: 2 },
|
||||
};
|
||||
expect(getRangeInString(content, range)).toBe("");
|
||||
});
|
||||
|
||||
test("should handle range that starts and ends at the same line but different characters", () => {
|
||||
const range = {
|
||||
start: { line: 1, character: 2 },
|
||||
end: { line: 1, character: 6 },
|
||||
};
|
||||
expect(getRangeInString(content, range)).toBe("ne 2");
|
||||
});
|
||||
|
||||
test("should handle range that starts and ends at the same line and same characters", () => {
|
||||
const range = {
|
||||
start: { line: 1, character: 2 },
|
||||
end: { line: 1, character: 2 },
|
||||
};
|
||||
expect(getRangeInString(content, range)).toBe("n");
|
||||
});
|
||||
});
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
// This file is generated by Continue
|
||||
|
||||
import { intersection } from "../../../util/ranges";
|
||||
|
||||
interface Position {
|
||||
line: number;
|
||||
character: number;
|
||||
}
|
||||
|
||||
interface Range {
|
||||
start: Position;
|
||||
end: Position;
|
||||
}
|
||||
|
||||
describe("intersection", () => {
|
||||
let rangeA: Range;
|
||||
let rangeB: Range;
|
||||
|
||||
beforeEach(() => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 3, character: 5 },
|
||||
};
|
||||
|
||||
rangeB = {
|
||||
start: { line: 2, character: 2 },
|
||||
end: { line: 4, character: 0 },
|
||||
};
|
||||
});
|
||||
|
||||
test("returns correct intersection for overlapping ranges", () => {
|
||||
const result = intersection(rangeA, rangeB);
|
||||
expect(result).toEqual({
|
||||
start: { line: 2, character: 2 },
|
||||
end: { line: 3, character: 5 },
|
||||
});
|
||||
});
|
||||
|
||||
test("returns null for non-overlapping ranges", () => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 2, character: 0 },
|
||||
};
|
||||
|
||||
rangeB = {
|
||||
start: { line: 3, character: 0 },
|
||||
end: { line: 4, character: 0 },
|
||||
};
|
||||
|
||||
const result = intersection(rangeA, rangeB);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
// TODO
|
||||
test.skip("returns correct intersection for single line overlap", () => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 1, character: 5 },
|
||||
};
|
||||
|
||||
rangeB = {
|
||||
start: { line: 1, character: 3 },
|
||||
end: { line: 2, character: 0 },
|
||||
};
|
||||
|
||||
const result = intersection(rangeA, rangeB);
|
||||
expect(result).toEqual({
|
||||
start: { line: 1, character: 3 },
|
||||
end: { line: 1, character: 5 },
|
||||
});
|
||||
});
|
||||
|
||||
test("returns null for single line non-overlapping ranges", () => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 1, character: 2 },
|
||||
};
|
||||
|
||||
rangeB = {
|
||||
start: { line: 1, character: 3 },
|
||||
end: { line: 1, character: 5 },
|
||||
};
|
||||
|
||||
const result = intersection(rangeA, rangeB);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
test("returns correct intersection when one range is fully within another", () => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 4, character: 5 },
|
||||
};
|
||||
|
||||
rangeB = {
|
||||
start: { line: 2, character: 2 },
|
||||
end: { line: 3, character: 3 },
|
||||
};
|
||||
|
||||
const result = intersection(rangeA, rangeB);
|
||||
expect(result).toEqual({
|
||||
start: { line: 2, character: 2 },
|
||||
end: { line: 3, character: 3 },
|
||||
});
|
||||
});
|
||||
|
||||
test("returns correct intersection when ranges touch at the edge", () => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 2, character: 0 },
|
||||
};
|
||||
|
||||
rangeB = {
|
||||
start: { line: 2, character: 0 },
|
||||
end: { line: 3, character: 0 },
|
||||
};
|
||||
|
||||
const result = intersection(rangeA, rangeB);
|
||||
expect(result).toEqual({
|
||||
start: { line: 2, character: 0 },
|
||||
end: { line: 2, character: 0 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
import { maxPosition, minPosition } from "../../../util/ranges";
|
||||
|
||||
// This file is generated by Continue
|
||||
interface Position {
|
||||
line: number;
|
||||
character: number;
|
||||
}
|
||||
|
||||
describe("Position comparison functions", () => {
|
||||
let pos1: Position;
|
||||
let pos2: Position;
|
||||
let pos3: Position;
|
||||
let pos4: Position;
|
||||
|
||||
beforeAll(() => {
|
||||
// Setup: Initializing positions
|
||||
pos1 = { line: 1, character: 5 };
|
||||
pos2 = { line: 2, character: 3 };
|
||||
pos3 = { line: 1, character: 7 };
|
||||
pos4 = { line: 2, character: 3 }; // Same as pos2 to test equality
|
||||
});
|
||||
|
||||
describe("maxPosition", () => {
|
||||
it("should return the position with the greater line number", () => {
|
||||
expect(maxPosition(pos1, pos2)).toEqual(pos2);
|
||||
});
|
||||
|
||||
it("should return the position with the greater character number when lines are equal", () => {
|
||||
expect(maxPosition(pos1, pos3)).toEqual(pos3);
|
||||
});
|
||||
|
||||
it("should return the first position when both positions are equal", () => {
|
||||
expect(maxPosition(pos2, pos4)).toEqual(pos2);
|
||||
});
|
||||
|
||||
it("should handle positions with negative line numbers", () => {
|
||||
const posNegative = { line: -1, character: 0 };
|
||||
expect(maxPosition(posNegative, pos1)).toEqual(pos1);
|
||||
});
|
||||
|
||||
it("should handle positions with negative character numbers", () => {
|
||||
const posNegativeChar = { line: 1, character: -1 };
|
||||
expect(maxPosition(posNegativeChar, pos1)).toEqual(pos1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("minPosition", () => {
|
||||
it("should return the position with the lesser line number", () => {
|
||||
expect(minPosition(pos1, pos2)).toEqual(pos1);
|
||||
});
|
||||
|
||||
it("should return the position with the lesser character number when lines are equal", () => {
|
||||
expect(minPosition(pos1, pos3)).toEqual(pos1);
|
||||
});
|
||||
|
||||
it("should return the first position when both positions are equal", () => {
|
||||
expect(minPosition(pos2, pos4)).toEqual(pos2);
|
||||
});
|
||||
|
||||
it("should handle positions with negative line numbers", () => {
|
||||
const posNegative = { line: -1, character: 0 };
|
||||
expect(minPosition(posNegative, pos1)).toEqual(posNegative);
|
||||
});
|
||||
|
||||
it("should handle positions with negative character numbers", () => {
|
||||
const posNegativeChar = { line: 1, character: -1 };
|
||||
expect(minPosition(posNegativeChar, pos1)).toEqual(posNegativeChar);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
import { union } from "../../../util/ranges";
|
||||
|
||||
// This file is generated by Continue
|
||||
interface Position {
|
||||
line: number;
|
||||
character: number;
|
||||
}
|
||||
|
||||
interface Range {
|
||||
start: Position;
|
||||
end: Position;
|
||||
}
|
||||
|
||||
describe("union", () => {
|
||||
let rangeA: Range;
|
||||
let rangeB: Range;
|
||||
|
||||
beforeEach(() => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 3, character: 5 },
|
||||
};
|
||||
|
||||
rangeB = {
|
||||
start: { line: 2, character: 3 },
|
||||
end: { line: 4, character: 2 },
|
||||
};
|
||||
});
|
||||
|
||||
test("should return the union of two overlapping ranges", () => {
|
||||
const result = union(rangeA, rangeB);
|
||||
expect(result).toEqual({
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 4, character: 2 },
|
||||
});
|
||||
});
|
||||
|
||||
test("should return the union when ranges are identical", () => {
|
||||
const result = union(rangeA, rangeA);
|
||||
expect(result).toEqual(rangeA);
|
||||
});
|
||||
|
||||
test("should return the union when ranges do not overlap but are adjacent", () => {
|
||||
rangeB = {
|
||||
start: { line: 3, character: 5 },
|
||||
end: { line: 4, character: 2 },
|
||||
};
|
||||
const result = union(rangeA, rangeB);
|
||||
expect(result).toEqual({
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 4, character: 2 },
|
||||
});
|
||||
});
|
||||
|
||||
test("should return the union when one range is completely within the other", () => {
|
||||
rangeB = {
|
||||
start: { line: 2, character: 1 },
|
||||
end: { line: 2, character: 4 },
|
||||
};
|
||||
const result = union(rangeA, rangeB);
|
||||
expect(result).toEqual(rangeA);
|
||||
});
|
||||
|
||||
test("should return the union when ranges do not overlap and are not adjacent", () => {
|
||||
rangeB = {
|
||||
start: { line: 4, character: 3 },
|
||||
end: { line: 5, character: 1 },
|
||||
};
|
||||
const result = union(rangeA, rangeB);
|
||||
expect(result).toEqual({
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 5, character: 1 },
|
||||
});
|
||||
});
|
||||
|
||||
// TODO
|
||||
test.skip("should handle edge case where start and end lines are the same", () => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 1, character: 5 },
|
||||
};
|
||||
rangeB = {
|
||||
start: { line: 1, character: 3 },
|
||||
end: { line: 1, character: 7 },
|
||||
};
|
||||
const result = union(rangeA, rangeB);
|
||||
expect(result).toEqual({
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 1, character: 7 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -4,20 +4,7 @@ import { removeQuotesAndEscapes } from ".";
|
|||
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "../protocol";
|
||||
import type { IMessenger } from "./messenger";
|
||||
|
||||
/**
|
||||
* Removes code blocks from a message.
|
||||
*
|
||||
* Return modified message text.
|
||||
*/
|
||||
function removeCodeBlocksAndTrim(msgText: string): string {
|
||||
const codeBlockRegex = /```[\s\S]*?```/g;
|
||||
|
||||
// Remove code blocks from the message text
|
||||
const textWithoutCodeBlocks = msgText.replace(codeBlockRegex, "");
|
||||
|
||||
return textWithoutCodeBlocks.trim();
|
||||
}
|
||||
import { removeCodeBlocksAndTrim } from "./markdown";
|
||||
|
||||
export class ChatDescriber {
|
||||
static prompt: string | undefined =
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { Session } from "../..";
|
||||
import historyManager from "../../util/history";
|
||||
import { getSessionFilePath } from "../../util/paths";
|
||||
import { Session } from "..";
|
||||
import historyManager from "./history";
|
||||
import { getSessionFilePath } from "./paths";
|
||||
|
||||
const sessionId = uuidv4();
|
||||
const testSession: Session = {
|
||||
13
core/util/markdown.ts
Normal file
13
core/util/markdown.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* Removes code blocks from a message.
|
||||
*
|
||||
* Return modified message text.
|
||||
*/
|
||||
export function removeCodeBlocksAndTrim(text: string): string {
|
||||
const codeBlockRegex = /```[\s\S]*?```/g;
|
||||
|
||||
// Remove code blocks from the message text
|
||||
const textWithoutCodeBlocks = text.replace(codeBlockRegex, "");
|
||||
|
||||
return textWithoutCodeBlocks.trim();
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { exec, ChildProcess } from "child_process";
|
||||
import os from "node:os";
|
||||
|
||||
import { removeCodeBlocksAndTrim } from "./markdown";
|
||||
|
||||
import type { IMessenger } from "./messenger";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "../protocol";
|
||||
|
||||
|
|
@ -8,27 +10,13 @@ import type { FromCoreProtocol, ToCoreProtocol } from "../protocol";
|
|||
// a zombie after executing .kill()
|
||||
const ttsKillTimeout: number = 5000;
|
||||
|
||||
/**
|
||||
* Removes code blocks from a message.
|
||||
*
|
||||
* Return modified message text.
|
||||
*/
|
||||
function removeCodeBlocks(msgText: string): string {
|
||||
const codeBlockRegex = /```[\s\S]*?```/g;
|
||||
|
||||
// Remove code blocks from the message text
|
||||
const textWithoutCodeBlocks = msgText.replace(codeBlockRegex, "");
|
||||
|
||||
return textWithoutCodeBlocks.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans a message text to safely be used in 'exec' context on host.
|
||||
*
|
||||
* Return modified message text.
|
||||
*/
|
||||
function sanitizeMessageForTTS(message: string): string {
|
||||
message = removeCodeBlocks(message);
|
||||
export function sanitizeMessageForTTS(message: string): string {
|
||||
message = removeCodeBlocksAndTrim(message);
|
||||
|
||||
// Remove or replace problematic characters
|
||||
message = message
|
||||
|
|
|
|||
|
|
@ -1,69 +0,0 @@
|
|||
import {
|
||||
withExponentialBackoff,
|
||||
RETRY_AFTER_HEADER,
|
||||
} from "./withExponentialBackoff";
|
||||
const MAX_RETRIES = 4;
|
||||
const INITIAL_DELAY = 0.01; // so the tests run fast
|
||||
|
||||
describe("withExponentialBackoff", () => {
|
||||
// beforeEach(() => {
|
||||
// jest.useFakeTimers();
|
||||
// jest.clearAllMocks();
|
||||
// });
|
||||
|
||||
// afterEach(() => {
|
||||
// jest.useRealTimers();
|
||||
// });
|
||||
|
||||
it("should return result on first successful API call", async () => {
|
||||
const apiCall = jest.fn().mockResolvedValue("success");
|
||||
|
||||
const result = await withExponentialBackoff(apiCall, MAX_RETRIES);
|
||||
|
||||
expect(result).toBe("success");
|
||||
expect(apiCall).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
it("should retry on API rate limit and succeed", async () => {
|
||||
const apiCall = jest
|
||||
.fn()
|
||||
.mockRejectedValueOnce({
|
||||
response: {
|
||||
status: 429,
|
||||
headers: new Map([[RETRY_AFTER_HEADER, "1"]]),
|
||||
},
|
||||
})
|
||||
.mockResolvedValue("success");
|
||||
|
||||
const start = Date.now();
|
||||
|
||||
const result = await withExponentialBackoff(apiCall, MAX_RETRIES);
|
||||
|
||||
const duration = (Date.now() - start) / 1000;
|
||||
|
||||
expect(result).toBe("success");
|
||||
expect(apiCall).toHaveBeenCalledTimes(2);
|
||||
expect(duration).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
it("should stop retrying after maxRetries and throw error", async () => {
|
||||
const apiCall = jest.fn().mockRejectedValue({
|
||||
response: {
|
||||
status: 429,
|
||||
headers: new Map(),
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
withExponentialBackoff(apiCall, MAX_RETRIES, INITIAL_DELAY),
|
||||
).rejects.toThrow("Failed to make API call after multiple retries");
|
||||
expect(apiCall).toHaveBeenCalledTimes(MAX_RETRIES);
|
||||
});
|
||||
|
||||
it("should throw on non-rate limit errors", async () => {
|
||||
const apiCall = jest.fn().mockRejectedValue(new Error("Server Error"));
|
||||
|
||||
await expect(withExponentialBackoff(apiCall, MAX_RETRIES)).rejects.toThrow(
|
||||
"Server Error",
|
||||
);
|
||||
expect(apiCall).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue