| 1 | import { jest } from "@jest/globals"; |
| 2 | |
| 3 | import { testIde } from "../../test/fixtures"; |
| 4 | import { |
| 5 | mockFileContents, |
| 6 | mockFilename, |
| 7 | mockPathAndCacheKey, |
| 8 | testContinueServerClient, |
| 9 | updateIndexAndAwaitGenerator, |
| 10 | } from "../test/indexing"; |
| 11 | import { addToTestDir } from "../../test/testDir"; |
| 12 | import { DatabaseConnection, SqliteDb } from "../refreshIndex"; |
| 13 | import { IndexResultType } from "../types"; |
| 14 | |
| 15 | import { ChunkCodebaseIndex } from "./ChunkCodebaseIndex"; |
| 16 | |
| 17 | jest.useFakeTimers(); |
| 18 | |
| 19 | describe("ChunkCodebaseIndex", () => { |
| 20 | let index: ChunkCodebaseIndex; |
| 21 | let db: DatabaseConnection; |
| 22 | |
| 23 | async function getAllChunks() { |
| 24 | return await db.all("SELECT * FROM chunks"); |
| 25 | } |
| 26 | |
| 27 | async function getAllChunkTags() { |
| 28 | return await db.all("SELECT * FROM chunk_tags"); |
| 29 | } |
| 30 | |
| 31 | beforeAll(async () => { |
| 32 | index = new ChunkCodebaseIndex( |
| 33 | testIde.readFile.bind(testIde), |
| 34 | testContinueServerClient, |
| 35 | 1000, |
| 36 | ); |
| 37 | |
| 38 | addToTestDir([[mockFilename, mockFileContents]]); |
| 39 | |
| 40 | db = await SqliteDb.get(); |
| 41 | }); |
| 42 | |
| 43 | it.skip("should update the index and maintain expected database state, following the same processing order of results as the update method", async () => { |
| 44 | const mockMarkComplete = jest |
| 45 | .fn() |
| 46 | .mockImplementation(() => Promise.resolve()) as any; |
| 47 | |
| 48 | // Compute test |
| 49 | await updateIndexAndAwaitGenerator(index, "compute", mockMarkComplete); |
| 50 | expect((await getAllChunks()).length).toBe(1); |
| 51 | expect((await getAllChunkTags()).length).toBe(1); |
| 52 | expect(mockMarkComplete).toHaveBeenCalledWith( |
| 53 | [mockPathAndCacheKey], |
| 54 | IndexResultType.Compute, |
| 55 | ); |
| 56 | |
| 57 | // RemoveTag test |
| 58 | await updateIndexAndAwaitGenerator(index, "removeTag", mockMarkComplete); |
| 59 | expect((await getAllChunkTags()).length).toBe(0); |
| 60 | expect(mockMarkComplete).toHaveBeenCalledWith( |
| 61 | [mockPathAndCacheKey], |
| 62 | IndexResultType.RemoveTag, |
| 63 | ); |
| 64 | |
| 65 | // AddTag test |
| 66 | await updateIndexAndAwaitGenerator(index, "addTag", mockMarkComplete); |
| 67 | expect((await getAllChunkTags()).length).toBe(1); |
| 68 | expect(mockMarkComplete).toHaveBeenCalledWith( |
| 69 | [mockPathAndCacheKey], |
| 70 | IndexResultType.AddTag, |
| 71 | ); |
| 72 | |
| 73 | // Delete test |
| 74 | await updateIndexAndAwaitGenerator(index, "del", mockMarkComplete); |
| 75 | expect((await getAllChunks()).length).toBe(0); |
| 76 | expect((await getAllChunkTags()).length).toBe(0); |
| 77 | expect(mockMarkComplete).toHaveBeenCalledWith( |
| 78 | [mockPathAndCacheKey], |
| 79 | IndexResultType.Delete, |
| 80 | ); |
| 81 | }); |
| 82 | }); |