From a9bf85c890f1f6d5a3758f773b50bfd769716562 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 1 Sep 2024 15:25:28 -0700 Subject: [PATCH] slightly unflakify tests --- core/indexing/CodeSnippetsIndex.ts | 9 ++++++++- core/indexing/CodebaseIndexer.test.ts | 5 +++-- core/indexing/FullTextSearchCodebaseIndex.test.ts | 2 +- core/indexing/LanceDbIndex.test.ts | 2 +- .../docs/{DocsCrawler.test.ts => DocsCrawler.skip.ts} | 0 core/indexing/docs/DocsService.test.ts | 6 +++--- core/jest.global-setup.ts | 4 ++++ .../context/providers/{index.test.ts => index.skip.ts} | 0 core/util/posthog.ts | 5 ++++- 9 files changed, 24 insertions(+), 9 deletions(-) rename core/indexing/docs/{DocsCrawler.test.ts => DocsCrawler.skip.ts} (100%) rename core/test/context/providers/{index.test.ts => index.skip.ts} (100%) diff --git a/core/indexing/CodeSnippetsIndex.ts b/core/indexing/CodeSnippetsIndex.ts index 9c33fb58c..f567a48d2 100644 --- a/core/indexing/CodeSnippetsIndex.ts +++ b/core/indexing/CodeSnippetsIndex.ts @@ -50,10 +50,17 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { )`); migrate("add_signature_column", async () => { - await db.exec(` + const tableInfo = await db.all("PRAGMA table_info(code_snippets)"); + const signatureColumnExists = tableInfo.some( + (column) => column.name === "signature", + ); + + if (!signatureColumnExists) { + await db.exec(` ALTER TABLE code_snippets ADD COLUMN signature TEXT; `); + } }); migrate("delete_duplicate_code_snippets", async () => { diff --git a/core/indexing/CodebaseIndexer.test.ts b/core/indexing/CodebaseIndexer.test.ts index f05acfc16..042814fa4 100644 --- a/core/indexing/CodebaseIndexer.test.ts +++ b/core/indexing/CodebaseIndexer.test.ts @@ -72,8 +72,9 @@ describe("CodebaseIndexer", () => { tearDownTestDir(); setUpTestDir(); - execSync('git config --global user.email "test@example.com"'); - execSync('git config --global user.name "Test"'); + 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 }); }); afterAll(async () => { diff --git a/core/indexing/FullTextSearchCodebaseIndex.test.ts b/core/indexing/FullTextSearchCodebaseIndex.test.ts index af59d0b3c..69e5c67e8 100644 --- a/core/indexing/FullTextSearchCodebaseIndex.test.ts +++ b/core/indexing/FullTextSearchCodebaseIndex.test.ts @@ -25,7 +25,7 @@ describe("FullTextSearchCodebaseIndex", () => { index = new FullTextSearchCodebaseIndex(); }); - it.skip("should update the index and maintain expected database state", async () => { + it("should update the index and maintain expected database state", async () => { const mockMarkComplete = jest .fn() .mockImplementation(() => Promise.resolve()) as any; diff --git a/core/indexing/LanceDbIndex.test.ts b/core/indexing/LanceDbIndex.test.ts index 0c636df6a..fecf0f15b 100644 --- a/core/indexing/LanceDbIndex.test.ts +++ b/core/indexing/LanceDbIndex.test.ts @@ -48,7 +48,7 @@ describe("ChunkCodebaseIndex", () => { * - We cannot open either the 'dev' or 'main' tag tables ubtil after we * can assume they've been created through `updateIndexAndAwaitGenerator` */ - it.skip("should update the index and maintain expected database state", async () => { + it("should update the index and maintain expected database state", async () => { const mainTag = mockTag; const mainTagTableName = index.tableNameForTag(mainTag); diff --git a/core/indexing/docs/DocsCrawler.test.ts b/core/indexing/docs/DocsCrawler.skip.ts similarity index 100% rename from core/indexing/docs/DocsCrawler.test.ts rename to core/indexing/docs/DocsCrawler.skip.ts diff --git a/core/indexing/docs/DocsService.test.ts b/core/indexing/docs/DocsService.test.ts index f1fb6295b..f0caa5b95 100644 --- a/core/indexing/docs/DocsService.test.ts +++ b/core/indexing/docs/DocsService.test.ts @@ -4,11 +4,11 @@ import { ConfigHandler } from "../../config/ConfigHandler.js"; import { ControlPlaneClient } from "../../control-plane/client.js"; import { SiteIndexingConfig } from "../../index.js"; -import DocsService from "./DocsService.js"; -import preIndexedDocs from "./preIndexedDocs.js"; -import FreeTrialEmbeddingsProvider from "../embeddings/FreeTrialEmbeddingsProvider.js"; import FileSystemIde from "../../util/filesystem.js"; import { editConfigJson } from "../../util/paths.js"; +import FreeTrialEmbeddingsProvider from "../embeddings/FreeTrialEmbeddingsProvider.js"; +import DocsService from "./DocsService.js"; +import preIndexedDocs from "./preIndexedDocs.js"; describe.skip("DocsService Integration Tests", () => { let ide: FileSystemIde; diff --git a/core/jest.global-setup.ts b/core/jest.global-setup.ts index ee9cddde4..218e10baf 100644 --- a/core/jest.global-setup.ts +++ b/core/jest.global-setup.ts @@ -1,5 +1,9 @@ +import fs from "fs"; import path from "path"; export default async function () { process.env.CONTINUE_GLOBAL_DIR = path.join(__dirname, ".continue-test"); + if (fs.existsSync(process.env.CONTINUE_GLOBAL_DIR)) { + fs.rmdirSync(process.env.CONTINUE_GLOBAL_DIR, { recursive: true }); + } } diff --git a/core/test/context/providers/index.test.ts b/core/test/context/providers/index.skip.ts similarity index 100% rename from core/test/context/providers/index.test.ts rename to core/test/context/providers/index.skip.ts diff --git a/core/util/posthog.ts b/core/util/posthog.ts index e0b5e4898..aa0f73277 100644 --- a/core/util/posthog.ts +++ b/core/util/posthog.ts @@ -14,6 +14,9 @@ export class Telemetry { properties: { [key: string]: any }, sendToTeam: boolean = false, ) { + if (process.env.NODE_ENV === "test") { + return; + } try { Telemetry.client?.capture({ distinctId: Telemetry.uniqueId, @@ -44,7 +47,7 @@ export class Telemetry { Telemetry.os = os.platform(); Telemetry.ideInfo = ideInfo; - if (!allow) { + if (!allow || process.env.NODE_ENV === "test") { Telemetry.client = undefined; } else { try {