Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(search): prefer the upstream title for developer results

Karan Lokchandania898af984f55
diff --git a/apps/api/src/search/developer.test.ts b/apps/api/src/search/developer.test.ts
index 3035c04e1..3a8b94281 100644
--- a/apps/api/src/search/developer.test.ts
+++ b/apps/api/src/search/developer.test.ts
@@ -65,6 +65,7 @@ describe("searchDeveloperCategory", () => {
id: "abc",
type: "issue",
url: "https://github.com/a/b/issues/1",
+ title: "Retries drop the backoff",
passages: [{ text: "first passage" }],
},
{ id: "def", type: "readme", url: "", passages: [] },
@@ -80,7 +81,7 @@ describe("searchDeveloperCategory", () => {
expect(results).toEqual([
{
url: "https://github.com/a/b/issues/1",
- title: "https://github.com/a/b/issues/1",
+ title: "Retries drop the backoff",
description: "first passage",
position: 1,
category: "developer",
@@ -88,6 +89,38 @@ describe("searchDeveloperCategory", () => {
]);
});
+ it("falls back to the url when the upstream sends no usable title", async () => {
+ fetchMock.mockResolvedValue(
+ upstreamOk({
+ results: [
+ {
+ id: "abc",
+ type: "pull_request",
+ url: "https://github.com/a/b/pull/1",
+ passages: [{ text: "first passage" }],
+ },
+ {
+ id: "def",
+ type: "pull_request",
+ url: "https://github.com/a/b/pull/2",
+ title: " ",
+ passages: [],
+ },
+ ],
+ }),
+ );
+
+ const results = await searchDeveloperCategory(
+ { query: "retries", limit: 5, teamId: "t1", timeout: 500 },
+ logger,
+ );
+
+ expect(results.map(result => result.title)).toEqual([
+ "https://github.com/a/b/pull/1",
+ "https://github.com/a/b/pull/2",
+ ]);
+ });
+
it("returns no results and drains the body when the upstream fails", async () => {
const cancel = vi.fn(async () => {});
fetchMock.mockResolvedValue({
diff --git a/apps/api/src/search/developer.ts b/apps/api/src/search/developer.ts
index 77918239d..fac7ceef7 100644
--- a/apps/api/src/search/developer.ts
+++ b/apps/api/src/search/developer.ts
@@ -42,7 +42,12 @@ export async function searchDeveloperCategory(
.slice(0, options.limit)
.map((result, index) => ({
url: typeof result?.url === "string" ? result.url : "",
- title: typeof result?.url === "string" ? result.url : "",
+ title:
+ typeof result?.title === "string" && result.title.trim().length > 0
+ ? result.title
+ : typeof result?.url === "string"
+ ? result.url
+ : "",
description:
typeof result?.passages?.[0]?.text === "string"
? result.passages[0].text