| 1 | // /** |
| 2 | // * @jest-environment jsdom |
| 3 | // */ |
| 4 | // import { ConfigHandler } from "../../config/ConfigHandler.js"; |
| 5 | // import { SiteIndexingConfig } from "../../index.js"; |
| 6 | // import { LLMLogger } from "../../llm/logger.js"; |
| 7 | // import FileSystemIde from "../../util/filesystem.js"; |
| 8 | // import { editConfigJson } from "../../util/paths.js"; |
| 9 | |
| 10 | // import DocsService from "./DocsService.js"; |
| 11 | // import preIndexedDocs from "./preIndexedDocs.js"; |
| 12 | |
| 13 | // describe.skip("DocsService Integration Tests", () => { |
| 14 | // let ide: FileSystemIde; |
| 15 | // let configHandler: ConfigHandler; |
| 16 | // let docsService: DocsService; |
| 17 | |
| 18 | // const mockSiteConfig: SiteIndexingConfig = { |
| 19 | // startUrl: "https://amplified.dev/", |
| 20 | // title: "Test repo", |
| 21 | // faviconUrl: "https://github.com/favicon.ico", |
| 22 | // }; |
| 23 | |
| 24 | // /** |
| 25 | // * We need to reload config explicitly to handle the scenario where the |
| 26 | // * config file update listeners are not called before we attempt to |
| 27 | // * use the new config |
| 28 | // */ |
| 29 | // async function getReloadedConfig() { |
| 30 | // await configHandler.reloadConfig(); |
| 31 | // const latestConfig = await configHandler.loadConfig(); |
| 32 | |
| 33 | // return latestConfig; |
| 34 | // } |
| 35 | |
| 36 | // beforeEach(async () => { |
| 37 | // ide = new FileSystemIde(process.cwd()); |
| 38 | |
| 39 | // const ideSettingsPromise = Promise.resolve({ |
| 40 | // remoteConfigSyncPeriod: 60, |
| 41 | // userToken: "", |
| 42 | // continueTestEnvironment: "none" as const, |
| 43 | // pauseCodebaseIndexOnStart: false, |
| 44 | // ideSettings: {} as any, |
| 45 | // enableDebugLogs: false, |
| 46 | // remoteConfigServerUrl: "", |
| 47 | // }); |
| 48 | // configHandler = new ConfigHandler( |
| 49 | // ide, |
| 50 | // ideSettingsPromise, |
| 51 | // new LLMLogger(), |
| 52 | // Promise.resolve(undefined), |
| 53 | // ); |
| 54 | |
| 55 | // docsService = DocsService.createSingleton(configHandler, ide); |
| 56 | |
| 57 | // await docsService.isInitialized; |
| 58 | // }); |
| 59 | |
| 60 | // test("Indexing, retrieval, and deletion of a new documentation site", async () => { |
| 61 | // await docsService.indexAndAdd(mockSiteConfig); |
| 62 | |
| 63 | // let latestConfig = await getReloadedConfig(); |
| 64 | |
| 65 | // // Sqlite check |
| 66 | // expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(true); |
| 67 | |
| 68 | // // config.json check |
| 69 | // expect(latestConfig.config!.docs).toContainEqual(mockSiteConfig); |
| 70 | |
| 71 | // // Lance DB check |
| 72 | // let retrievedChunks = await docsService.retrieveChunksFromQuery( |
| 73 | // "test", |
| 74 | // mockSiteConfig.startUrl, |
| 75 | // 5, |
| 76 | // ); |
| 77 | |
| 78 | // expect(retrievedChunks.length).toBeGreaterThan(0); |
| 79 | |
| 80 | // await docsService.delete(mockSiteConfig.startUrl); |
| 81 | |
| 82 | // // Sqlite check |
| 83 | // expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(false); |
| 84 | |
| 85 | // // config.json check |
| 86 | // latestConfig = await getReloadedConfig(); |
| 87 | // expect(latestConfig.config!.docs).not.toContainEqual( |
| 88 | // expect.objectContaining(mockSiteConfig), |
| 89 | // ); |
| 90 | |
| 91 | // // LanceDB check |
| 92 | // retrievedChunks = await docsService.retrieveChunksFromQuery( |
| 93 | // "test", |
| 94 | // mockSiteConfig.startUrl, |
| 95 | // 5, |
| 96 | // ); |
| 97 | // expect(retrievedChunks.length).toBe(0); |
| 98 | // }); |
| 99 | |
| 100 | // // test("Reindexes when changing embeddings provider", async () => { |
| 101 | // // const originalEmbeddingsProvider = |
| 102 | // // await docsService.getEmbeddingsProvider(); |
| 103 | |
| 104 | // // TODO removed this test when free trial provider was removed |
| 105 | // // }); |
| 106 | |
| 107 | // test("Handles pulling down and adding pre-indexed docs", async () => { |
| 108 | // const preIndexedDoc = Object.values(preIndexedDocs)[0]; |
| 109 | // await docsService.indexAndAdd(preIndexedDoc); |
| 110 | // }); |
| 111 | |
| 112 | // test("Config synchronization with SQLite", async () => { |
| 113 | // await docsService.indexAndAdd(mockSiteConfig); |
| 114 | |
| 115 | // await getReloadedConfig(); |
| 116 | |
| 117 | // expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(true); |
| 118 | |
| 119 | // editConfigJson((config) => { |
| 120 | // const { docs, ...restConfig } = config; |
| 121 | // return restConfig; |
| 122 | // }); |
| 123 | |
| 124 | // await getReloadedConfig(); |
| 125 | |
| 126 | // const startTime = Date.now(); |
| 127 | // const maxWaitTimeMs = 10_000; |
| 128 | |
| 129 | // while (docsService.isSyncing) { |
| 130 | // if (Date.now() - startTime > maxWaitTimeMs) { |
| 131 | // throw new Error( |
| 132 | // `Timeout: docsService.isSyncing did not complete within within ${maxWaitTimeMs}ms`, |
| 133 | // ); |
| 134 | // } |
| 135 | // await new Promise((resolve) => setTimeout(resolve, 100)); |
| 136 | // } |
| 137 | |
| 138 | // expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(false); |
| 139 | // }); |
| 140 | // }); |