Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
self-audit: scope the shared-loopback row check to the zero-credit regression signature
Karan Lokchandani78a2a42892c8
diff --git a/apps/api/src/__tests__/snips/v2/research.test.ts b/apps/api/src/__tests__/snips/v2/research.test.tsindex 11b71814e..57f6022b3 100644--- a/apps/api/src/__tests__/snips/v2/research.test.ts+++ b/apps/api/src/__tests__/snips/v2/research.test.ts@@ -124,15 +124,22 @@ async function keylessUsageRowsAfter(ip: string,afterId: number,): Promise<number> {+ // With the proxy secret the IP is an isolated RFC 5737 bucket, so ANY new+ // row is a regression. Without it the IP is the shared loopback: a+ // concurrently running keyless snip can legitimately land a *billable* row+ // for the same IP inside our window, so only zero-credit rows — the actual+ // regression signature of the log-only contract — count against us there.+ const conditions = [+ eq(schema.keyless_credit_usage.ip, ip),+ gt(schema.keyless_credit_usage.id, afterId),+ ];+ if (!KEYLESS_PROXY_SECRET) {+ conditions.push(eq(schema.keyless_credit_usage.credits_used, 0));+ }const rows = await db.select({ id: schema.keyless_credit_usage.id }).from(schema.keyless_credit_usage)- .where(- and(- eq(schema.keyless_credit_usage.ip, ip),- gt(schema.keyless_credit_usage.id, afterId),- ),- );+ .where(and(...conditions));return rows.length;}