Elffuss BraidHub

kikocis/continue public

main · 2.0 KiBRawPermalink
1import { jest } from "@jest/globals";
2
3import { IndexTag } from "../..";
4import { IContinueServerClient } from "../../continueServer/interface";
5import { ChunkCodebaseIndex } from "../chunk/ChunkCodebaseIndex";
6import { CodebaseIndex, RefreshIndexResults } from "../types";
7
8import { testIde } from "../../test/fixtures";
9import { addToTestDir, TEST_DIR } from "../../test/testDir";
10import { tagToString } from "../utils";
11
12export const mockFilename = "test.py";
13export const mockPathAndCacheKey = {
14 path: `${TEST_DIR}/${mockFilename}`,
15 cacheKey: "abc123",
16};
17
18export const mockFileContents = `\
19def main():
20 print("Hello, world!")
21
22class Foo:
23 def __init__(self, bar: str):
24 self.bar = bar
25`;
26
27export const mockTag: IndexTag = {
28 branch: "main",
29 directory: "/",
30 artifactId: "artifactId",
31};
32
33export const mockTagString = tagToString(mockTag);
34
35export const testContinueServerClient = {
36 connected: false,
37 getFromIndexCache: jest.fn(),
38} as unknown as IContinueServerClient;
39
40const mockContinueServerClient = {
41 connected: false,
42 getFromIndexCache: jest.fn(),
43} as unknown as IContinueServerClient;
44
45const mockResults: RefreshIndexResults = {
46 compute: [],
47 addTag: [],
48 removeTag: [],
49 del: [],
50};
51
52const mockMarkComplete = jest
53 .fn()
54 .mockImplementation(() => Promise.resolve()) as any;
55
56export async function insertMockChunks() {
57 const index = new ChunkCodebaseIndex(
58 testIde.readFile.bind(testIde),
59 mockContinueServerClient,
60 1000,
61 );
62
63 addToTestDir([[mockFilename, mockFileContents]]);
64
65 await updateIndexAndAwaitGenerator(index, "compute", mockMarkComplete);
66 await updateIndexAndAwaitGenerator(index, "addTag", mockMarkComplete);
67}
68
69export async function updateIndexAndAwaitGenerator(
70 index: CodebaseIndex,
71 resultType: keyof RefreshIndexResults,
72 markComplete: any,
73 tag: IndexTag = mockTag,
74) {
75 const computeGenerator = index.update(
76 tag,
77 { ...mockResults, [resultType]: [mockPathAndCacheKey] },
78 markComplete,
79 "test-repo",
80 );
81
82 while (!(await computeGenerator.next()).done) {}
83}