Skip to content

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

test(api): cover zero data retention scrape and search rates (#5304)

Rakshith Ramprakash33dac7f27fd4
diff --git a/apps/api/src/lib/scrape-billing.test.ts b/apps/api/src/lib/scrape-billing.test.ts
index 8d4148e36..fd25cebc4 100644
--- a/apps/api/src/lib/scrape-billing.test.ts
+++ b/apps/api/src/lib/scrape-billing.test.ts
@@ -447,6 +447,41 @@ const successDocument = {
metadata: { statusCode: 200, proxyUsed: "basic" },
};
+describe("calculateCreditsToBeBilled — zero data retention", () => {
+ const bill = (
+ options: Record<string, unknown>,
+ zeroDataRetention: boolean,
+ flags: Record<string, unknown> = {},
+ ) =>
+ calculateCreditsToBeBilled(
+ { formats: [{ type: "markdown" }], ...options } as any,
+ { teamId: "team-id", orgId: null, zeroDataRetention },
+ { metadata: { statusCode: 200, proxyUsed: "basic" } } as any,
+ { totalCost: 0 } as any,
+ flags as any,
+ );
+
+ it("adds 1 credit per page by default", async () => {
+ expect(await bill({}, false)).toBe(1);
+ expect(await bill({}, true)).toBe(2);
+ });
+
+ it("adds the team's zdrCost when it is set", async () => {
+ expect(await bill({}, true, { zdrCost: 3 })).toBe(4);
+ expect(await bill({}, false, { zdrCost: 3 })).toBe(1);
+ });
+
+ it("stacks on format surcharges", async () => {
+ const json = { formats: [{ type: "json", schema: {} }] };
+ expect(await bill(json, false)).toBe(5);
+ expect(await bill(json, true)).toBe(6);
+ });
+
+ it("is not added on top of lockdown", async () => {
+ expect(await bill({ lockdown: true }, true)).toBe(5);
+ });
+});
+
describe("calculateThreatScanCredits", () => {
it("bills nothing for no decisions", () => {
expect(calculateThreatScanCredits([])).toBe(0);
diff --git a/apps/api/src/search/execute.test.ts b/apps/api/src/search/execute.test.ts
index 84cef2370..78217bf3c 100644
--- a/apps/api/src/search/execute.test.ts
+++ b/apps/api/src/search/execute.test.ts
@@ -207,6 +207,44 @@ describe("executeSearch safe search", () => {
});
});
+describe("executeSearch zero data retention rate", () => {
+ const results = (count: number) =>
+ Array.from({ length: count }, (_, index) => ({
+ url: `https://result${index}.example/`,
+ title: "Result",
+ description: "A result.",
+ }));
+
+ it.each([
+ { name: "a default search", enterprise: undefined, ten: 2, eleven: 4 },
+ {
+ name: "an enterprise anon search",
+ enterprise: ["anon"],
+ ten: 2,
+ eleven: 4,
+ },
+ {
+ name: "an enterprise zdr search",
+ enterprise: ["zdr"],
+ ten: 10,
+ eleven: 20,
+ },
+ ])("bills $name per ten results", async ({ enterprise, ten, eleven }) => {
+ for (const [count, credits] of [
+ [10, ten],
+ [11, eleven],
+ ]) {
+ mocks.search.mockResolvedValue({ web: results(count) });
+ const result = await executeSearch(
+ { ...options([]), limit: 20, enterprise },
+ context,
+ logger,
+ );
+ expect(result.searchCredits).toBe(credits);
+ }
+ });
+});
+
describe("executeSearch developer category", () => {
it("returns sole developer-category results in web without running SERP", async () => {
const result = await executeSearch(