-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0956e6
commit 978f387
Showing
11 changed files
with
503 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { ChunkCodebaseIndex } from "../../indexing/chunk/ChunkCodebaseIndex"; | ||
import { DatabaseConnection, SqliteDb } from "../../indexing/refreshIndex"; | ||
import { IndexResultType } from "../../indexing/types"; | ||
import { testIde } from "../fixtures"; | ||
import { addToTestDir } from "../testUtils/testDir"; | ||
import { jest } from "@jest/globals"; | ||
import { | ||
mockFileContents, | ||
mockFilename, | ||
mockPathAndCacheKey, | ||
testContinueServerClient, | ||
updateIndexAndAwaitGenerator, | ||
} from "./utils"; | ||
|
||
jest.useFakeTimers(); | ||
|
||
describe("ChunkCodebaseIndex", () => { | ||
let index: ChunkCodebaseIndex; | ||
let db: DatabaseConnection; | ||
|
||
beforeAll(async () => { | ||
const pathSep = await testIde.pathSep(); | ||
|
||
index = new ChunkCodebaseIndex( | ||
testIde.readFile.bind(testIde), | ||
pathSep, | ||
testContinueServerClient, | ||
1000, | ||
); | ||
|
||
addToTestDir([[mockFilename, mockFileContents]]); | ||
|
||
db = await SqliteDb.get(); | ||
}); | ||
|
||
it("should update the index and maintain expected database state, following the same processing order of results as the update method", async () => { | ||
const mockMarkComplete = jest | ||
.fn() | ||
.mockImplementation(() => Promise.resolve()) as any; | ||
|
||
// Compute test | ||
await updateIndexAndAwaitGenerator(index, "compute", mockMarkComplete); | ||
|
||
const computeResult = await db.get( | ||
"SELECT * FROM chunks WHERE cacheKey = ?", | ||
[mockPathAndCacheKey.cacheKey], | ||
); | ||
|
||
expect(computeResult).toBeTruthy(); | ||
expect(mockMarkComplete).toHaveBeenCalledWith( | ||
[mockPathAndCacheKey], | ||
IndexResultType.Compute, | ||
); | ||
|
||
// AddTag test | ||
await updateIndexAndAwaitGenerator(index, "addTag", mockMarkComplete); | ||
|
||
const addTagResult = await db.get( | ||
"SELECT * FROM chunk_tags WHERE chunkId = ?", | ||
[computeResult.id], | ||
); | ||
|
||
expect(addTagResult).toBeTruthy(); | ||
expect(mockMarkComplete).toHaveBeenCalledWith( | ||
[mockPathAndCacheKey], | ||
IndexResultType.AddTag, | ||
); | ||
|
||
// RemoveTag test | ||
await updateIndexAndAwaitGenerator(index, "removeTag", mockMarkComplete); | ||
|
||
const removeTagResult = await db.get( | ||
"SELECT * FROM chunk_tags WHERE id = ?", | ||
[addTagResult.id], | ||
); | ||
|
||
expect(removeTagResult).toBeFalsy(); | ||
expect(mockMarkComplete).toHaveBeenCalledWith( | ||
[mockPathAndCacheKey], | ||
IndexResultType.RemoveTag, | ||
); | ||
|
||
// Delete test | ||
await updateIndexAndAwaitGenerator(index, "del", mockMarkComplete); | ||
|
||
const delResult = await db.get("SELECT * FROM chunks WHERE id = ?", [ | ||
computeResult.id, | ||
]); | ||
|
||
expect(delResult).toBeFalsy(); | ||
expect(mockMarkComplete).toHaveBeenCalledWith( | ||
[mockPathAndCacheKey], | ||
IndexResultType.Delete, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { CodeSnippetsCodebaseIndex } from "../../indexing/CodeSnippetsIndex"; | ||
import { DatabaseConnection, SqliteDb } from "../../indexing/refreshIndex"; | ||
import { IndexResultType } from "../../indexing/types"; | ||
import { testIde } from "../fixtures"; | ||
import { | ||
insertMockChunks, | ||
mockPathAndCacheKey, | ||
updateIndexAndAwaitGenerator, | ||
} from "./utils"; | ||
import { jest } from "@jest/globals"; | ||
|
||
describe("CodeSnippetsCodebaseIndex", () => { | ||
let index: CodeSnippetsCodebaseIndex; | ||
let db: DatabaseConnection; | ||
|
||
beforeEach(async () => { | ||
db = await SqliteDb.get(); | ||
index = new CodeSnippetsCodebaseIndex(testIde); | ||
}); | ||
|
||
it("should update the index and maintain expected database state, following the same processing order of results as the update method", async () => { | ||
const mockMarkComplete = jest | ||
.fn() | ||
.mockImplementation(() => Promise.resolve()) as any; | ||
|
||
const mockSnippet = { | ||
title: "", | ||
content: "", | ||
startLine: 0, | ||
endLine: 1, | ||
}; | ||
|
||
// We mock this fn since currently in testing the directory structure to access the tree-sitter | ||
// binaries does not match what is in the release environment. | ||
jest | ||
.spyOn(CodeSnippetsCodebaseIndex.prototype, "getSnippetsInFile") | ||
.mockResolvedValue([mockSnippet]); | ||
|
||
await insertMockChunks(); | ||
|
||
// Compute test | ||
await updateIndexAndAwaitGenerator(index, "compute", mockMarkComplete); | ||
|
||
const computeResult = await db.get( | ||
"SELECT * FROM code_snippets WHERE path = ?", | ||
[mockPathAndCacheKey.path], | ||
); | ||
|
||
const computeResultTags = await db.get( | ||
"SELECT * FROM code_snippets_tags WHERE snippetId = ?", | ||
[computeResult.id], | ||
); | ||
|
||
expect(computeResult).toBeTruthy(); | ||
expect(computeResultTags).toBeTruthy(); | ||
expect(mockMarkComplete).toHaveBeenCalledWith( | ||
[mockPathAndCacheKey], | ||
IndexResultType.Compute, | ||
); | ||
|
||
// Delete test | ||
await updateIndexAndAwaitGenerator(index, "del", mockMarkComplete); | ||
|
||
const delResult = await db.get("SELECT * FROM code_snippets WHERE id = ?", [ | ||
computeResult.id, | ||
]); | ||
|
||
const delResultTags = await db.get( | ||
"SELECT * FROM code_snippets_tags WHERE id = ?", | ||
[computeResultTags.id], | ||
); | ||
|
||
expect(delResult).toBeFalsy(); | ||
expect(delResultTags).toBeFalsy(); | ||
expect(mockMarkComplete).toHaveBeenCalledWith( | ||
[mockPathAndCacheKey], | ||
IndexResultType.Delete, | ||
); | ||
|
||
// AddTag test | ||
await updateIndexAndAwaitGenerator(index, "addTag", mockMarkComplete); | ||
|
||
const addTagResult = await db.get( | ||
"SELECT * FROM code_snippets WHERE path = ?", | ||
[mockPathAndCacheKey.path], | ||
); | ||
|
||
const addTagResultTags = await db.get( | ||
"SELECT * FROM code_snippets_tags WHERE snippetId = ?", | ||
[addTagResult.id], | ||
); | ||
|
||
expect(addTagResult).toBeTruthy(); | ||
expect(addTagResultTags).toBeTruthy(); | ||
expect(mockMarkComplete).toHaveBeenCalledWith( | ||
[mockPathAndCacheKey], | ||
IndexResultType.AddTag, | ||
); | ||
|
||
// RemoveTag test | ||
await updateIndexAndAwaitGenerator(index, "removeTag", mockMarkComplete); | ||
|
||
const removeTagResultTag = await db.get( | ||
"SELECT * FROM code_snippets_tags WHERE id = ?", | ||
[addTagResultTags.id], | ||
); | ||
|
||
expect(removeTagResultTag).toBeFalsy(); | ||
expect(mockMarkComplete).toHaveBeenCalledWith( | ||
[mockPathAndCacheKey], | ||
IndexResultType.RemoveTag, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.