Skip to content

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

fix(api): don't drop the first sitemap URL in /map (#4337) (#4338)

nosssuri215fa7c9610a
diff --git a/apps/api/src/__tests__/snips/mocks/map-sitemap-all-urls.json b/apps/api/src/__tests__/snips/mocks/map-sitemap-all-urls.json
new file mode 100644
index 000000000..fe00dc295
--- /dev/null
+++ b/apps/api/src/__tests__/snips/mocks/map-sitemap-all-urls.json
@@ -0,0 +1,18 @@
+[
+ {
+ "time": 1740000000000,
+ "options": {
+ "url": "https://www.hfea.gov.uk/sitemap.xml",
+ "method": "GET",
+ "ignoreResponse": false,
+ "ignoreFailure": false,
+ "tryCount": 1
+ },
+ "result": {
+ "url": "https://www.hfea.gov.uk/sitemap.xml",
+ "body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n <url><loc>https://www.hfea.gov.uk/first-page</loc></url>\n <url><loc>https://www.hfea.gov.uk/second-page</loc></url>\n <url><loc>https://www.hfea.gov.uk/third-page</loc></url>\n</urlset>\n",
+ "status": 200,
+ "headers": [["content-type", "text/xml; charset=utf-8"]]
+ }
+ }
+]
diff --git a/apps/api/src/__tests__/snips/v2/map.test.ts b/apps/api/src/__tests__/snips/v2/map.test.ts
index 07bc33abd..21fe0676c 100644
--- a/apps/api/src/__tests__/snips/v2/map.test.ts
+++ b/apps/api/src/__tests__/snips/v2/map.test.ts
@@ -78,6 +78,53 @@ describe("Map tests", () => {
60000,
);
+ it.concurrent(
+ "sitemap=only returns every URL of the sitemap",
+ async () => {
+ const response = await map(
+ {
+ url: "https://www.hfea.gov.uk",
+ sitemap: "only",
+ useMock: "map-sitemap-all-urls",
+ ignoreCache: true,
+ },
+ identity,
+ );
+
+ expect(response.statusCode).toBe(200);
+ expect(response.body.success).toBe(true);
+
+ // The first URL the sitemap yields used to be discarded, so
+ // /first-page never made it into the response.
+ const urls = response.body.links.map(x => x.url);
+ expect(urls).toContain("https://www.hfea.gov.uk/first-page");
+ expect(urls).toContain("https://www.hfea.gov.uk/second-page");
+ expect(urls).toContain("https://www.hfea.gov.uk/third-page");
+ },
+ 60000,
+ );
+
+ it.concurrent(
+ "sitemap=only still respects a limit smaller than the sitemap",
+ async () => {
+ const response = await map(
+ {
+ url: "https://www.hfea.gov.uk",
+ sitemap: "only",
+ useMock: "map-sitemap-all-urls",
+ ignoreCache: true,
+ limit: 2,
+ },
+ identity,
+ );
+
+ expect(response.statusCode).toBe(200);
+ expect(response.body.success).toBe(true);
+ expect(response.body.links.length).toBe(2);
+ },
+ 60000,
+ );
+
concurrentIf(ALLOW_TEST_SUITE_WEBSITE)(
"sitemap=only respects limit",
async () => {
diff --git a/apps/api/src/lib/map-utils.ts b/apps/api/src/lib/map-utils.ts
index 056d4a7cc..43d6fb66f 100644
--- a/apps/api/src/lib/map-utils.ts
+++ b/apps/api/src/lib/map-utils.ts
@@ -181,7 +181,6 @@ export async function getMapResults({
if (sitemap > 0) {
mapResults = mapResults
- .slice(1)
.map(x => {
try {
return {