docs crawling testing is back
This commit is contained in:
parent
f0b26d9cf0
commit
2ea3f3581f
10 changed files with 201 additions and 158 deletions
|
|
@ -1,146 +0,0 @@
|
|||
import os from "os";
|
||||
|
||||
// import { pathToFileUrl } from "path";
|
||||
import { ContinueConfig } from "../..";
|
||||
import { testConfigHandler } from "../../test/fixtures";
|
||||
import FileSystemIde from "../../util/filesystem";
|
||||
|
||||
import DocsCrawler, {
|
||||
ChromiumInstaller,
|
||||
DocsCrawlerType,
|
||||
type PageData,
|
||||
} from "./DocsCrawler";
|
||||
|
||||
// Temporary workaround until we have better caching of Chromium
|
||||
// download between test runs
|
||||
const TIMEOUT_MS = 1_000_000_000;
|
||||
|
||||
// Overwrite the Chromium download path to `os.tmpdir()`
|
||||
// so that we don't delete the Chromium install between tests
|
||||
ChromiumInstaller.PCR_CONFIG = { downloadPath: os.tmpdir() };
|
||||
|
||||
// Skipped until we have a better way to cache Chromium installs
|
||||
// between tests and in CI
|
||||
describe("DocsCrawler", () => {
|
||||
const NUM_PAGES_TO_CRAWL = 5;
|
||||
|
||||
let config: ContinueConfig;
|
||||
let mockIde: FileSystemIde;
|
||||
let docsCrawler: DocsCrawler;
|
||||
|
||||
beforeAll(async () => {
|
||||
const result = await testConfigHandler.loadConfig();
|
||||
if (!result.config) {
|
||||
throw new Error("Failed to load config");
|
||||
}
|
||||
config = result.config;
|
||||
mockIde = new FileSystemIde(process.cwd());
|
||||
// docsCrawler = new DocsCrawler(mockIde, config, 5, 5, false);
|
||||
// chromiumInstaller = new ChromiumInstaller(mockIde, config);
|
||||
|
||||
// Make sure we have Chromium pulled down before beginning tests
|
||||
// await chromiumInstaller.install();
|
||||
}, TIMEOUT_MS);
|
||||
|
||||
// async function crawlTest(
|
||||
// url: string,
|
||||
// numPagesToCrawl: number = NUM_PAGES_TO_CRAWL,
|
||||
// expectedCrawlerUsed: DocsCrawlerType,
|
||||
// ) {
|
||||
// const crawlResults: PageData[] = [];
|
||||
// it(
|
||||
// `Crawl ${url}`,
|
||||
// async () => {
|
||||
// const generator = docsCrawler.crawl(new URL(url));
|
||||
// let done = false;
|
||||
// while (!done) {
|
||||
// const result = await generator.next();
|
||||
// if (result.done) {
|
||||
// done = true;
|
||||
// expect(result.value).toEqual(expectedCrawlerUsed);
|
||||
// } else {
|
||||
// crawlResults.push(result.value);
|
||||
// }
|
||||
// }
|
||||
|
||||
// expect(crawlResults.length).toBeGreaterThanOrEqual(numPagesToCrawl);
|
||||
// },
|
||||
// TIMEOUT_MS,
|
||||
// );
|
||||
// return crawlResults;
|
||||
// }
|
||||
|
||||
// describe("GitHub Crawler", async () => {
|
||||
// docsCrawler = new DocsCrawler(mockIde, config, 5, 5, false);
|
||||
|
||||
// const repoUrl =
|
||||
// "https://github.com/Patrick-Erichsen/test-github-repo-for-crawling";
|
||||
|
||||
// const crawlResults = await crawlTest(repoUrl, 1, "github");
|
||||
// // test("finds expected markdown files", async () => {
|
||||
// expect(crawlResults.some((page) => page.path.endsWith("README.md"))).toBe(
|
||||
// true,
|
||||
// );
|
||||
|
||||
// expect(
|
||||
// crawlResults.some((page) => page.path.endsWith("docs-depth-1.md")),
|
||||
// ).toBe(true);
|
||||
// // });
|
||||
|
||||
// // test("html includes the correct content", async () => {
|
||||
// const doc = crawlResults.find((page) =>
|
||||
// page.path.endsWith("docs-depth-1.md"),
|
||||
// );
|
||||
|
||||
// expect(doc?.content.includes("Test body")).toBe(true);
|
||||
// expect(doc?.content.includes("Test H2 Header")).toBe(true);
|
||||
// // });
|
||||
|
||||
// // test("ignores non-markdown files, e.g. `test.js` at the root", async () => {
|
||||
// expect(crawlResults.some((page) => page.path.endsWith("test.js"))).toBe(
|
||||
// false,
|
||||
// );
|
||||
// // });
|
||||
// });
|
||||
|
||||
// describe("Chromium Crawler", () => {
|
||||
// let shouldUseChromiumSpy: any;
|
||||
|
||||
// beforeAll(() => {
|
||||
// shouldUseChromiumSpy = jest
|
||||
// .spyOn(docsCrawler as any, "shouldUseChromium")
|
||||
// .mockReturnValue(true);
|
||||
// });
|
||||
|
||||
// afterAll(() => {
|
||||
// shouldUseChromiumSpy.mockRestore();
|
||||
// });
|
||||
|
||||
// describe("Pre-indexed Docs", () => {
|
||||
// crawlTest(Object.keys(preIndexedDocs));
|
||||
// });
|
||||
|
||||
// describe("Running list of common sites", () => {
|
||||
// crawlTest([
|
||||
// "https://docs.nestjs.com/",
|
||||
// "https://go.dev/doc/",
|
||||
// "https://clickhouse.com/docs",
|
||||
// "https://www.tensorflow.org/api_docs",
|
||||
// // "https://www.rust-lang.org/learn", TODO: This is failing
|
||||
// "https://docs.anthropic.com/en/docs",
|
||||
// ]);
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe("Default Crawler", () => {
|
||||
// docsCrawler = new DocsCrawler(mockIde, config, 5, 5, true);
|
||||
|
||||
// crawlTest("https://amplified.dev/", 1, "default");
|
||||
// });
|
||||
|
||||
describe("Cheerio Crawler", () => {
|
||||
docsCrawler = new DocsCrawler(mockIde, config, 5, 5, true);
|
||||
|
||||
// crawlTest("https://amplified.dev/", 1, "cheerio");
|
||||
});
|
||||
});
|
||||
|
|
@ -30,7 +30,7 @@ import {
|
|||
htmlPageToArticleWithChunks,
|
||||
markdownPageToArticleWithChunks,
|
||||
} from "./article";
|
||||
import DocsCrawler, { DocsCrawlerType, PageData } from "./DocsCrawler";
|
||||
import DocsCrawler, { DocsCrawlerType, PageData } from "./crawlers/DocsCrawler";
|
||||
import { ConfigResult } from "@continuedev/config-yaml";
|
||||
import { runLanceMigrations, runSqliteMigrations } from "./migrations";
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { JSDOM } from "jsdom";
|
|||
import { Chunk } from "../../";
|
||||
import { cleanFragment, cleanHeader, markdownChunker } from "../chunk/markdown";
|
||||
|
||||
import { type PageData } from "./DocsCrawler";
|
||||
import { type PageData } from "./crawlers/DocsCrawler";
|
||||
|
||||
export type ArticleComponent = {
|
||||
title: string;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { URL } from "node:url";
|
|||
|
||||
import * as cheerio from "cheerio";
|
||||
|
||||
import { PageData } from "../DocsCrawler";
|
||||
import { PageData } from "./DocsCrawler";
|
||||
|
||||
export default class CheerioCrawler {
|
||||
private readonly IGNORE_PATHS_ENDING_IN = [
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {
|
|||
getChromiumPath,
|
||||
getContinueUtilsPath,
|
||||
} from "../../../util/paths";
|
||||
import { PageData } from "../DocsCrawler";
|
||||
import { PageData } from "./DocsCrawler";
|
||||
|
||||
export class ChromiumCrawler {
|
||||
private readonly LINK_GROUP_SIZE = 2;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { URL } from "node:url";
|
|||
|
||||
import { getHeaders } from "../../../continueServer/stubs/headers";
|
||||
import { TRIAL_PROXY_URL } from "../../../control-plane/client";
|
||||
import { PageData } from "../DocsCrawler";
|
||||
import { PageData } from "./DocsCrawler";
|
||||
|
||||
export class DefaultCrawler {
|
||||
constructor(
|
||||
|
|
|
|||
177
core/indexing/docs/crawlers/DocsCrawler.test.ts
Normal file
177
core/indexing/docs/crawlers/DocsCrawler.test.ts
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
import os from "os";
|
||||
|
||||
import { ContinueConfig } from "../../..";
|
||||
import { testConfigHandler } from "../../../test/fixtures";
|
||||
import FileSystemIde from "../../../util/filesystem";
|
||||
|
||||
import DocsCrawler, {
|
||||
ChromiumInstaller,
|
||||
DocsCrawlerType,
|
||||
type PageData,
|
||||
} from "./DocsCrawler";
|
||||
import { commonDocsSites } from "./crawl-test-cases";
|
||||
|
||||
// Temporary workaround until we have better caching of Chromium
|
||||
// download between test runs
|
||||
const TIMEOUT_MS = 1_000_000_000;
|
||||
|
||||
// Overwrite the Chromium download path to `os.tmpdir()`
|
||||
// so that we don't delete the Chromium install between tests
|
||||
ChromiumInstaller.PCR_CONFIG = { downloadPath: os.tmpdir() };
|
||||
|
||||
describe("DocsCrawler", () => {
|
||||
let config: ContinueConfig;
|
||||
let mockIde: FileSystemIde;
|
||||
let chromiumInstaller: ChromiumInstaller;
|
||||
let docsCrawler: DocsCrawler;
|
||||
|
||||
beforeAll(async () => {
|
||||
const result = await testConfigHandler.loadConfig();
|
||||
config = result.config!;
|
||||
mockIde = new FileSystemIde(process.cwd());
|
||||
chromiumInstaller = new ChromiumInstaller(mockIde, config);
|
||||
docsCrawler = new DocsCrawler(mockIde, config);
|
||||
}, TIMEOUT_MS);
|
||||
|
||||
async function runCrawl(url: string) {
|
||||
const pages: PageData[] = [];
|
||||
const generator = docsCrawler.crawl(new URL(url));
|
||||
let done = false;
|
||||
let crawler: DocsCrawlerType = "default";
|
||||
while (!done) {
|
||||
const result = await generator.next();
|
||||
if (result.done) {
|
||||
done = true;
|
||||
crawler = result.value;
|
||||
} else {
|
||||
pages.push(result.value);
|
||||
}
|
||||
}
|
||||
return {
|
||||
pages,
|
||||
crawler,
|
||||
};
|
||||
}
|
||||
|
||||
describe("GitHub Crawler", () => {
|
||||
const repoUrl =
|
||||
"https://github.com/Patrick-Erichsen/test-github-repo-for-crawling";
|
||||
|
||||
let crawlResults: PageData[];
|
||||
let crawlerUsed: DocsCrawlerType;
|
||||
|
||||
beforeAll(async () => {
|
||||
docsCrawler = new DocsCrawler(mockIde, config, 5, 5, false);
|
||||
const { pages, crawler } = await runCrawl(repoUrl);
|
||||
crawlerUsed = crawler;
|
||||
crawlResults = pages;
|
||||
}, TIMEOUT_MS);
|
||||
|
||||
test(
|
||||
"finds expected markdown files",
|
||||
async () => {
|
||||
expect(
|
||||
crawlResults.some((page) => page.path.endsWith("README.md")),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
crawlResults.some((page) => page.path.endsWith("docs-depth-1.md")),
|
||||
).toBe(true);
|
||||
},
|
||||
TIMEOUT_MS,
|
||||
);
|
||||
|
||||
test(
|
||||
"html includes the correct content",
|
||||
async () => {
|
||||
const doc = crawlResults.find((page) =>
|
||||
page.path.endsWith("docs-depth-1.md"),
|
||||
);
|
||||
|
||||
expect(doc?.content.includes("Test body")).toBe(true);
|
||||
expect(doc?.content.includes("Test H2 Header")).toBe(true);
|
||||
},
|
||||
TIMEOUT_MS,
|
||||
);
|
||||
|
||||
test(
|
||||
"ignores non-markdown files, e.g. `test.js` at the root",
|
||||
async () => {
|
||||
expect(crawlResults.some((page) => page.path.endsWith("test.js"))).toBe(
|
||||
false,
|
||||
);
|
||||
},
|
||||
TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
|
||||
// Skipped until we have a better way to cache Chromium installs
|
||||
// between tests and in CI
|
||||
// Run this periodically to make sure it's still working
|
||||
describe.skip("Chromium Crawler", () => {
|
||||
let shouldUseChromiumSpy: any;
|
||||
|
||||
beforeAll(async () => {
|
||||
docsCrawler = new DocsCrawler(mockIde, config, 5, 5, true);
|
||||
await chromiumInstaller.install();
|
||||
shouldUseChromiumSpy = jest
|
||||
.spyOn(docsCrawler as any, "shouldUseChromium")
|
||||
.mockReturnValue(true);
|
||||
}, TIMEOUT_MS);
|
||||
|
||||
afterAll(() => {
|
||||
shouldUseChromiumSpy.mockRestore();
|
||||
}, TIMEOUT_MS);
|
||||
|
||||
commonDocsSites.forEach((url) => {
|
||||
test(
|
||||
`Chromium crawler common site: ${url}`,
|
||||
async () => {
|
||||
const { pages, crawler } = await runCrawl(url);
|
||||
expect(pages.length).toBeGreaterThanOrEqual(1);
|
||||
expect(crawler).toEqual("chromium");
|
||||
},
|
||||
TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Default Crawler", () => {
|
||||
beforeAll(() => {
|
||||
docsCrawler = new DocsCrawler(mockIde, config, 2, 2, false);
|
||||
});
|
||||
|
||||
test(
|
||||
"works on static site",
|
||||
async () => {
|
||||
const { pages, crawler } = await runCrawl("https://amplified.dev/");
|
||||
expect(pages.length).toBeGreaterThanOrEqual(1);
|
||||
expect(crawler).toEqual("default");
|
||||
},
|
||||
TIMEOUT_MS,
|
||||
);
|
||||
|
||||
commonDocsSites.forEach((url) => {
|
||||
test(`Default crawler common site: ${url}`, async () => {
|
||||
const { pages, crawler } = await runCrawl(url);
|
||||
expect(pages.length).toBeGreaterThanOrEqual(1);
|
||||
expect(crawler).toEqual("default");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Cheerio Crawler", () => {
|
||||
beforeAll(() => {
|
||||
docsCrawler = new DocsCrawler(mockIde, config, 2, 2, true);
|
||||
});
|
||||
test(
|
||||
"works on static site",
|
||||
async () => {
|
||||
const { pages, crawler } = await runCrawl("https://amplified.dev/");
|
||||
expect(pages.length).toBeGreaterThanOrEqual(1);
|
||||
expect(crawler).toEqual("cheerio");
|
||||
},
|
||||
TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
import { URL } from "node:url";
|
||||
|
||||
import { ContinueConfig, IDE } from "../..";
|
||||
import { ContinueConfig, IDE } from "../../..";
|
||||
|
||||
import CheerioCrawler from "./crawlers/CheerioCrawler";
|
||||
import { ChromiumCrawler, ChromiumInstaller } from "./crawlers/ChromiumCrawler";
|
||||
import { DefaultCrawler } from "./crawlers/DefaultCrawler";
|
||||
import GitHubCrawler from "./crawlers/GitHubCrawler";
|
||||
import CheerioCrawler from "./CheerioCrawler";
|
||||
import { ChromiumCrawler, ChromiumInstaller } from "./ChromiumCrawler";
|
||||
import { DefaultCrawler } from "./DefaultCrawler";
|
||||
import GitHubCrawler from "./GitHubCrawler";
|
||||
|
||||
export type PageData = {
|
||||
url: string;
|
||||
|
|
@ -2,7 +2,7 @@ import { URL } from "node:url";
|
|||
|
||||
import { Octokit } from "@octokit/rest";
|
||||
|
||||
import { PageData } from "../DocsCrawler";
|
||||
import { PageData } from "./DocsCrawler";
|
||||
|
||||
class GitHubCrawler {
|
||||
private readonly markdownRegex = new RegExp(/\.(md|mdx)$/);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export const githubTestRepos: string[] = [
|
||||
export const commonDocsRepos: string[] = [
|
||||
// "https://github.com/freeCodeCamp/freeCodeCamp",
|
||||
"https://github.com/996icu/996.ICU",
|
||||
// "https://github.com/vuejs/vue",
|
||||
|
|
@ -50,3 +50,15 @@ export const githubTestRepos: string[] = [
|
|||
// "https://github.com/RocketChat/Rocket.Chat",
|
||||
// "https://github.com/open-source-labs/reactime",
|
||||
];
|
||||
|
||||
export const commonDocsSites = [
|
||||
"https://docs.nestjs.com/",
|
||||
"https://go.dev/doc/",
|
||||
"https://clickhouse.com/docs",
|
||||
];
|
||||
|
||||
export const failingDocsSites = [
|
||||
"https://www.tensorflow.org/api_docs",
|
||||
"https://docs.anthropic.com/en/docs",
|
||||
"https://www.rust-lang.org/learn",
|
||||
];
|
||||
Loading…
Add table
Reference in a new issue