Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions src/api/tools/commonTools.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { describe, it, expect } from "vitest";
import { enforceToolNameLengthLimit, LIMIT } from "./commonTools";
import { afterEach, describe, it, expect, vi } from "vitest";
import {
enforceToolNameLengthLimit,
LIMIT,
searchRepositoryDocumentationAutoRag,
} from "./commonTools";
import { generateServerName } from "../../shared/nameUtils";

describe("enforceToolNameLengthLimit", () => {
Expand Down Expand Up @@ -38,3 +42,57 @@ describe("enforceToolNameLengthLimit", () => {
expect(toolName).toBe("search_docs");
});
});

describe("searchRepositoryDocumentationAutoRag", () => {
afterEach(() => {
vi.unstubAllGlobals();
});

it("points source follow-ups to the registered generic URL tool", async () => {
vi.stubGlobal("caches", {
default: {
match: vi.fn().mockResolvedValue(undefined),
put: vi.fn().mockResolvedValue(undefined),
},
});
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue(
new Response(JSON.stringify({ default_branch: "main" }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
),
);

const search = vi.fn().mockResolvedValue({
search_query: "configured name",
data: [
{
filename: "owner/repo/docs/guide.md",
score: 0.9,
content: [{ text: "A matching documentation excerpt" }],
},
],
});
const env = {
AI: { autorag: vi.fn().mockReturnValue({ search }) },
} as unknown as CloudflareEnvironment;

const result = await searchRepositoryDocumentationAutoRag({
repoData: {
owner: "owner",
repo: "repo",
host: "gitmcp.io",
urlType: "github",
},
query: "configured name",
env,
ctx: { waitUntil: vi.fn() },
autoragPipeline: "test-docs-rag",
});

expect(result.content[0].text).toContain("fetch_generic_url_content");
expect(result.content[0].text).not.toContain("fetch_url_content");
});
});
2 changes: 1 addition & 1 deletion src/api/tools/commonTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export async function searchRepositoryDocumentationAutoRag({

if (filteredData.length > 0) {
responseText +=
"### Sources:\nImportant: you can fetch the full content of any source using the fetch_url_content tool\n";
"### Sources:\nImportant: you can fetch the full content of any source using the fetch_generic_url_content tool\n";
const defaultBranch = await getRepoBranch(
repoData.owner,
repoData.repo,
Expand Down