diff --git a/pm-stack/aggregator/src/saas-extract.ts b/pm-stack/aggregator/src/saas-extract.ts index 82b32d9b52..c02fb76234 100644 --- a/pm-stack/aggregator/src/saas-extract.ts +++ b/pm-stack/aggregator/src/saas-extract.ts @@ -311,14 +311,14 @@ const cloudflareMetrics: MetricExtractor = (section) => { limit: allowance(both, /([\d,.]+[kMB]?) GB-hours disk/), }), ); - const counts = /(\d+) Workers, (\d+) R2 buckets[^;]*; (\d+) D1, (\d+) KV, (\d+) Queues/.exec(usage); + const counts = /([\d,]+) Workers, ([\d,]+) R2 buckets[^;]*; ([\d,]+) D1, ([\d,]+) KV, ([\d,]+) Queues/.exec(usage); if (counts) { out.push( - metric({ id: "workers-count", label: "Workers deployed", unit: "count", used: Number(counts[1]) }), - metric({ id: "r2-buckets", label: "R2 buckets", unit: "count", used: Number(counts[2]) }), - metric({ id: "d1-count", label: "D1 databases", unit: "count", used: Number(counts[3]) }), - metric({ id: "kv-count", label: "KV namespaces", unit: "count", used: Number(counts[4]) }), - metric({ id: "queues-count", label: "Queues", unit: "count", used: Number(counts[5]) }), + metric({ id: "workers-count", label: "Workers deployed", unit: "count", used: Number(counts[1].replace(/,/g, "")) }), + metric({ id: "r2-buckets", label: "R2 buckets", unit: "count", used: Number(counts[2].replace(/,/g, "")) }), + metric({ id: "d1-count", label: "D1 databases", unit: "count", used: Number(counts[3].replace(/,/g, "")) }), + metric({ id: "kv-count", label: "KV namespaces", unit: "count", used: Number(counts[4].replace(/,/g, "")) }), + metric({ id: "queues-count", label: "Queues", unit: "count", used: Number(counts[5].replace(/,/g, "")) }), ); } return out.filter((m) => m.used != null || m.limit != null); @@ -327,14 +327,14 @@ const cloudflareMetrics: MetricExtractor = (section) => { const tursoMetrics: MetricExtractor = (section) => { const plan = bullet(section, /\*\*Plan \/ price \/ allowance:\*\*/); const usage = bullet(section, /\*\*Usage \/ dates:\*\*/); - const db = /(\d+) DB/.exec(usage); + const db = /([\d,]+) DB/.exec(usage); const zero = /0 B, 0 usage/.test(usage); return [ metric({ id: "databases", label: "Databases", unit: "count", - used: db ? Number(db[1]) : null, + used: db ? Number(db[1].replace(/,/g, "")) : null, limit: allowance(plan, /(100) DBs/), highlight: true, }), @@ -398,7 +398,7 @@ const supabaseMetrics: MetricExtractor = () => [ const githubMetrics: MetricExtractor = (section) => { const plan = bullet(section, /\*\*Plan \/ price \/ allowance:\*\*/); const usage = bullet(section, /\*\*Usage \/ dates:\*\*/); - const comped = /(\d[\d,]*) Linux \+ (\d+) macOS minutes/.exec(usage); + const comped = /([\d,]+) Linux \+ ([\d,]+) macOS minutes/.exec(usage); const out: UsageMetric[] = [ metric({ id: "actions-billable-minutes", @@ -437,7 +437,7 @@ const githubMetrics: MetricExtractor = (section) => { id: "actions-comped-minutes", label: "Actions minutes (comped, October)", unit: "minutes", - used: Number(comped[1].replace(/,/g, "")) + Number(comped[2]), + used: Number(comped[1].replace(/,/g, "")) + Number(comped[2].replace(/,/g, "")), note: "Fully comped/discounted — net $0; comped minutes do not consume the plan allowance.", }), ); diff --git a/pm-stack/aggregator/test/usage.test.ts b/pm-stack/aggregator/test/usage.test.ts index 914d97ff4f..e3db6e13c8 100644 --- a/pm-stack/aggregator/test/usage.test.ts +++ b/pm-stack/aggregator/test/usage.test.ts @@ -90,6 +90,51 @@ describe("saas extraction (Part b)", () => { expect(t.nextDate).toBe("2026-10-31 cycle end"); }); + test("cloudflare: grouped counts preserve every count", () => { + const view = VIEW.replace( + "- **Usage / pace:** Tracker: small, 3 Workers, 2 R2 buckets ~2 GB, 2 D1, 2 KV, 2 Queues; far behind, mostly unused.", + "- **Usage / pace:** Tracker: small, 1,234 Workers, 56 R2 buckets ~2 GB; 7 D1, 8 KV, 9 Queues; far behind, mostly unused.", + ); + const cloudflare = extractSaasServices(view).find((service) => service.id === "cloudflare")!; + const metrics = new Map(cloudflare.metrics.map((metric) => [metric.id, metric])); + expect(metrics.get("workers-count")?.used).toBe(1234); + expect(metrics.get("r2-buckets")?.used).toBe(56); + expect(metrics.get("d1-count")?.used).toBe(7); + expect(metrics.get("kv-count")?.used).toBe(8); + expect(metrics.get("queues-count")?.used).toBe(9); + }); + + test("cloudflare: grouped KV count keeps the whole count line", () => { + const view = VIEW.replace( + "- **Usage / pace:** Tracker: small, 3 Workers, 2 R2 buckets ~2 GB, 2 D1, 2 KV, 2 Queues; far behind, mostly unused.", + "- **Usage / pace:** Tracker: small, 3 Workers, 2 R2 buckets ~2 GB; 2 D1, 1,234 KV, 2 Queues; far behind, mostly unused.", + ); + const cloudflare = extractSaasServices(view).find((service) => service.id === "cloudflare")!; + const metrics = new Map(cloudflare.metrics.map((metric) => [metric.id, metric])); + expect(metrics.get("workers-count")?.used).toBe(3); + expect(metrics.get("r2-buckets")?.used).toBe(2); + expect(metrics.get("d1-count")?.used).toBe(2); + expect(metrics.get("kv-count")?.used).toBe(1234); + expect(metrics.get("queues-count")?.used).toBe(2); + }); + + test("turso: grouped database count is parsed whole", () => { + const view = VIEW.replace("1 DB `great-star-lord`", "1,234 DB `great-star-lord`"); + const turso = extractSaasServices(view).find((service) => service.id === "turso")!; + expect(turso.metrics.find((metric) => metric.id === "databases")?.used).toBe(1234); + }); + + test("github: grouped comped minute counts are both parsed whole", () => { + const view = `${VIEW} +### GitHub +- **Plan / price / allowance:** Pro $4/mo. +- **Usage / dates:** 5,000 Linux + 1,234 macOS minutes. +- **Last checked:** 2026-10-25. +`; + const github = extractSaasServices(view).find((service) => service.id === "github")!; + expect(github.metrics.find((metric) => metric.id === "actions-comped-minutes")?.used).toBe(6234); + }); + test("modal: not-estimable stays a note, never a number", () => { const modal = byId.get("modal")!; expect(modal.paygEstimate).toBeNull();