:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay): tidy the spend chart and drop the dev quota scenarios (#93949)
Tue Haulunddcdf0a673dcc
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 703e8203b0e6..212673ab965f 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -8325,9 +8325,9 @@ snapshots:scenes-app-replay-vision--summarizer-overview--light:hash: v1.k794b7964.099cc1596e288a869426dec004e0d3e6ae35de1ca2ec7f0264f775911010b0d9.eTbr9P9h5LFG5AtPxCE0tZn7Hxp4GvNnGI9zYmMI86oscenes-app-replay-vision--usage-tab--dark:- hash: v1.k794b7964.9aa134e0143e1f059ee2e74c561f4bf72d3c7544a3c55f9074cc12aa7e6dc748.8olmwH0m-gjI2maBCyIaijGiHuxJa-VSX5OJ4X_Jfkw+ hash: v1.k794b7964.adcd33918c09bfe0779ee7a51b77ee173de0cdd74d66300ea01d173280068d48.ib0BfEMTsMIEACC9iavsKKP4h8jNle7YTt9dvkkw4-oscenes-app-replay-vision--usage-tab--light:- hash: v1.k794b7964.ddf3840ed0acb526be4621462a7475e33e5c7d58f0c92addc61796308743717f.cUngoOKhIwSqpS2Qe22HMpzvtPPT7eaHPrU7In5vNn4+ hash: v1.k794b7964.7b90e21b832f5814c53519accdedab8896288bc69795b4d5e1e7b1b1bfee0de4.piIPzkfkOn_qr72FuSJWIOwB8VcVKZg6ryIg44FdsoIscenes-app-saved-insights--empty-state--dark:hash: v1.k794b7964.43545664c9133c8afd354be6a6ed8f808c35b381101325d9605114632fcdc0c9.l8w9uEOEmrH6Xl1kNd9ueRtg_51cJUSjWLdjWDM0Fkoscenes-app-saved-insights--empty-state--light:diff --git a/products/replay_vision/frontend/logics/visionQuotaLogic.ts b/products/replay_vision/frontend/logics/visionQuotaLogic.tsindex 971405025ed6..4ea1760b7dad 100644--- a/products/replay_vision/frontend/logics/visionQuotaLogic.ts+++ b/products/replay_vision/frontend/logics/visionQuotaLogic.ts@@ -10,7 +10,6 @@ import { environmentVisionQuotaRetrieve } from '../generated/api'import type { VisionQuotaApi } from '../generated/api.schemas'import { billableCredits } from '../utils/credits'import { hasBillableSpend, isFreeAllocationOnly } from '../utils/quotaProjection'-import { currentQuotaScenario } from '../utils/quotaScenarios'import { applyStartupCap, startupCapCredits } from '../utils/startupCap'// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -100,10 +99,6 @@ export const visionQuotaLogic = kea<visionQuotaLogicType>([loadQuota: async (_, breakpoint) => {// Coalesce bursts of post-mutation refetches (e.g. toggling several scanners).await breakpoint(50)- const scenario = currentQuotaScenario()- if (scenario) {- return scenario.quota- }const teamId = teamLogic.values.currentTeamIdif (!teamId) {return values.quotadiff --git a/products/replay_vision/frontend/replay_scanners/components/SpendTrajectoryChart.test.tsx b/products/replay_vision/frontend/replay_scanners/components/SpendTrajectoryChart.test.tsxnew file mode 100644index 000000000000..e774bcf97262--- /dev/null+++ b/products/replay_vision/frontend/replay_scanners/components/SpendTrajectoryChart.test.tsx@@ -0,0 +1,59 @@+import { render } from '@testing-library/react'++import { dayjs } from 'lib/dayjs'++import { makeQuota } from '../../utils/quotaTestUtils'+import type { SpendSeries } from '../visionUsageLogic'+import { SpendTrajectoryChart } from './SpendTrajectoryChart'++/** Daily spend over the fixture's period, oldest first, splitting `total` evenly across `days`. */+function series(total: number, days: number, periodStart: string): SpendSeries {+ const start = dayjs.utc(periodStart)+ return Array.from({ length: days }, (_, i) => ({+ date: start.add(i, 'day').format('YYYY-MM-DD'),+ credits: Math.round(total / days),+ }))+}++describe('SpendTrajectoryChart', () => {+ const renderChart = (overrides: Parameters<typeof makeQuota>[0] = {}, spend?: SpendSeries): HTMLElement => {+ const quota = makeQuota(overrides)+ return render(+ <SpendTrajectoryChart+ quota={quota}+ dailyCredits={spend ?? series(quota.credits_used, 5, quota.period_start)}+ projectedTotal={quota.credits_used}+ capReachDate={null}+ statusVar="var(--success)"+ />+ ).container+ }++ // A free allocation this small sits on the axis, where the line reads as the axis and its label+ // lands on the period end date.+ it('hides the free-credits line when it would sit on the axis', () => {+ const container = renderChart({ credit_limit: 240_000, credits_used: 168_000, free_monthly_credits: 1_000 })+ expect(container.textContent).not.toContain('Free credits')+ })++ it('keeps the free-credits line when it clears the axis', () => {+ const container = renderChart({ credit_limit: 10_000, credits_used: 4_000, free_monthly_credits: 2_500 })+ expect(container.textContent).toContain('Free credits')+ })++ // The series and the quota are fetched together, so the series can be a moment newer. Today has to+ // read the same number the card header shows rather than the higher of the two.+ it('reports today at the quota total even when the ledger series runs ahead', () => {+ const quota = makeQuota({ credit_limit: 10_000, credits_used: 4_000 })+ const { container } = render(+ <SpendTrajectoryChart+ quota={quota}+ dailyCredits={series(4_400, 4, quota.period_start)}+ projectedTotal={4_000}+ capReachDate={null}+ statusVar="var(--success)"+ />+ )+ expect(container.textContent).toContain('Today · 4,000')+ })+})diff --git a/products/replay_vision/frontend/replay_scanners/components/SpendTrajectoryChart.tsx b/products/replay_vision/frontend/replay_scanners/components/SpendTrajectoryChart.tsxindex 32641ad71d1f..c76a7906b8d0 100644--- a/products/replay_vision/frontend/replay_scanners/components/SpendTrajectoryChart.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/SpendTrajectoryChart.tsx@@ -14,8 +14,9 @@ const PAD_X = 8const TOP = 34const BASE = HEIGHT - 20const LABEL_CLEARANCE = 12+// A reference line closer than this to the baseline reads as part of the axis.+const AXIS_CLEARANCE = 10const ABOVE = -6-const BELOW = 11interface SpendTrajectoryChartProps {quota: VisionQuotaApi@@ -70,6 +71,21 @@ function Label({)}+/** Marks a point on the line. HTML, so a stretched viewBox cannot flatten it into an ellipse. */+function Dot({ x, y, color }: { x: number; y: number; color: string }): JSX.Element {+ return (+ <span+ className="absolute size-1.5 rounded-full"+ style={{+ left: `${(x / WIDTH) * 100}%`,+ top: `${(y / HEIGHT) * 100}%`,+ transform: 'translate(-50%, -50%)',+ background: color,+ }}+ />+ )+}+/*** Cumulative spend across the period against the limit: a solid line to today, a dashed projection* to period end, and a dashed line where the limit sits. Spend pauses at the limit, so the drawn@@ -97,10 +113,14 @@ function SpendTrajectoryChartInner({const dayEnd = dayjs.utc(entry.date).diff(periodStart, 'day', true) + 1cumulative.push({ day: clamp(dayEnd, 0, todayDay), value: runningTotal })}- // The ledger only holds settled spend, so reserved in-flight credits sit on top of today's point; the- // quota total still wins when the series was fetched before the last receipts landed.- const spentTotal = Math.max(runningTotal + quota.credits_reserved, quota.credits_used)- if (cumulative.length > 0 && spentTotal > runningTotal) {+ // The card header reads `credits_used`, so today's point is that number and the ledger only gives the+ // curve its shape. The series is fetched alongside the quota and can be a moment newer, so only the+ // tail is pulled down to it: clamping every point would draw days of zero spend that never happened.+ const spentTotal = quota.credits_used+ if (cumulative.length > 0) {+ for (let i = cumulative.length - 1; i >= 0 && cumulative[i].value > spentTotal; i--) {+ cumulative[i] = { ...cumulative[i], value: spentTotal }+ }cumulative[cumulative.length - 1] = { ...cumulative[cumulative.length - 1], value: spentTotal }}@@ -154,26 +174,30 @@ function SpendTrajectoryChartInner({const projectionLabel = `${periodEnd.format('MMM D')} · ~${formatCreditNumber(endValue)}`const limitY = cap !== null ? yForCredits(cap) : nullconst freeY = drawFreeLine ? yForCredits(freeCredits) : null- // Two dotted reference lines an em apart read as one; drop the free one when they nearly touch.- const showFreeLine = freeY !== null && (limitY === null || Math.abs(freeY - limitY) >= LABEL_CLEARANCE)+ // Two dotted reference lines an em apart read as one; drop the free one when it nearly touches the+ // limit line, or when it sits so low against the limit that it merges with the axis and its date labels.+ const showFreeLine =+ freeY !== null &&+ (limitY === null || Math.abs(freeY - limitY) >= LABEL_CLEARANCE) &&+ BASE - freeY >= AXIS_CLEARANCE- // Labels prefer sitting above their anchor; flip below when a reference line runs through that spot.+ // Labels sit above their anchor. Below a point is the filled area and the rising curve, so a label+ // blocked by a reference line climbs past it instead of dropping into the fill.const referenceYs = [limitY, freeY].filter((y): y is number => y !== null)const labelY = (anchorY: number): number => {- const above = Math.max(anchorY + ABOVE, 10)- if (- referenceYs.every((y) => Math.abs(above - y) >= LABEL_CLEARANCE && Math.abs(anchorY - y) >= LABEL_CLEARANCE)- ) {- return above+ let candidate = anchorY + ABOVE+ // Lowest line first, so a label pushed past one is then tested against the next one up.+ for (const reference of [...referenceYs].sort((a, b) => b - a)) {+ if (Math.abs(candidate - reference) < LABEL_CLEARANCE) {+ candidate = reference - LABEL_CLEARANCE+ }}- return Math.min(anchorY + BELOW, BASE - 4)+ return Math.max(candidate, 10)}- // Today's label sits upper-left or lower-right; the left one is clearer, so it wins unless the point hugs the axis.+ // Today's label sits left of its dot unless the point hugs the axis, where it would run off the edge.const todayLabelLeft = today.x >= 60const todayLabelX = todayLabelLeft ? today.x - 9 : today.x + 9- const belowY = Math.min(today.y + BELOW, BASE - 4)- const rightSideY = referenceYs.every((y) => Math.abs(belowY - y) >= LABEL_CLEARANCE) ? belowY : today.y - 16- const todayLabelY = todayLabelLeft ? labelY(today.y) : rightSideY+ const todayLabelY = labelY(today.y)const endLabelY = labelY(end.y)const crossingLabelRight = crossing !== null && crossing.x + 90 <= WIDTH - PAD_X@@ -185,12 +209,18 @@ function SpendTrajectoryChartInner({return (<div className="flex flex-col gap-1">- <div className="relative">+ <div className="relative w-full">+ {/* The box stretches to the card's width at a fixed height, so the chart stays wide and short. */}<svgviewBox={`0 0 ${WIDTH} ${HEIGHT}`}- className="block h-auto w-full"+ preserveAspectRatio="none"+ className="block h-[200px] w-full"role="img"- aria-label={`Cumulative spend this period: ${formatCreditCount(spentTotal)} so far, projected ${formatCreditCount(endValue)} by ${periodEnd.format('MMMM D')}${cap !== null ? `, limit ${formatCreditCount(cap)}` : ''}`}+ aria-label={+ crossing+ ? `Cumulative spend this period: ${formatCreditCount(spentTotal)} so far, projected to reach the ${formatCreditCount(cap ?? 0)} limit around ${crossingDate}`+ : `Cumulative spend this period: ${formatCreditCount(spentTotal)} so far, projected ${formatCreditCount(endValue)} by ${periodEnd.format('MMMM D')}${cap !== null ? `, limit ${formatCreditCount(cap)}` : ''}`+ }>{yTicks.map((v) => (<line@@ -200,11 +230,20 @@ function SpendTrajectoryChartInner({x2={WIDTH - PAD_X}y2={yForCredits(v)}stroke="var(--border)"+ vectorEffect="non-scaling-stroke"strokeWidth={0.5}opacity={0.6}/>))}- <line x1={PAD_LEFT} y1={TOP - 14} x2={PAD_LEFT} y2={BASE} stroke="var(--border)" strokeWidth={1} />+ <line+ x1={PAD_LEFT}+ y1={TOP - 14}+ x2={PAD_LEFT}+ y2={BASE}+ stroke="var(--border)"+ vectorEffect="non-scaling-stroke"+ strokeWidth={1}+ />{xTicks.map((day) => (<linekey={day}@@ -213,6 +252,7 @@ function SpendTrajectoryChartInner({x2={xForDay(day)}y2={BASE + 3}stroke="var(--border)"+ vectorEffect="non-scaling-stroke"strokeWidth={1}/>))}@@ -223,6 +263,7 @@ function SpendTrajectoryChartInner({x2={WIDTH - PAD_X}y2={limitY}stroke={dangerVar}+ vectorEffect="non-scaling-stroke"strokeWidth={1}strokeDasharray="2 3"/>@@ -234,12 +275,21 @@ function SpendTrajectoryChartInner({x2={WIDTH - PAD_X}y2={freeY}stroke={mutedVar}+ vectorEffect="non-scaling-stroke"strokeWidth={1}strokeDasharray="2 3"opacity={0.7}/>)}- <line x1={PAD_LEFT} y1={BASE} x2={WIDTH - PAD_X} y2={BASE} stroke="var(--border)" strokeWidth={1} />+ <line+ x1={PAD_LEFT}+ y1={BASE}+ x2={WIDTH - PAD_X}+ y2={BASE}+ stroke="var(--border)"+ vectorEffect="non-scaling-stroke"+ strokeWidth={1}+ />{drawSpentLine && (<><polygon@@ -251,6 +301,7 @@ function SpendTrajectoryChartInner({points={pointsAttr([origin, ...spentPoints])}fill="none"stroke="currentColor"+ vectorEffect="non-scaling-stroke"strokeWidth={1.5}strokeLinecap="round"/>@@ -262,20 +313,11 @@ function SpendTrajectoryChartInner({points={pointsAttr([today, crossing])}fill="none"stroke={dangerVar}+ vectorEffect="non-scaling-stroke"strokeWidth={1.5}strokeDasharray="4 4"strokeLinecap="round"/>- <polyline- points={pointsAttr([crossing, { x: end.x, y: crossing.y }])}- fill="none"- stroke={dangerVar}- strokeWidth={1.5}- strokeDasharray="2 5"- strokeLinecap="round"- opacity={0.7}- />- <circle cx={crossing.x} cy={crossing.y} r={3} fill={dangerVar} /></>) : (<>@@ -283,16 +325,21 @@ function SpendTrajectoryChartInner({points={pointsAttr([today, end])}fill="none"stroke={pausedAtLimit ? dangerVar : statusVar}+ vectorEffect="non-scaling-stroke"strokeWidth={1.5}strokeDasharray="4 4"strokeLinecap="round"/>- <circle cx={end.x} cy={end.y} r={3} fill={pausedAtLimit ? dangerVar : statusVar} /></>)}- <circle cx={today.x} cy={today.y} r={3} fill="currentColor" /></svg><div className="absolute inset-0 pointer-events-none" aria-hidden>+ <Dot x={today.x} y={today.y} color="currentColor" />+ {crossing ? (+ <Dot x={crossing.x} y={crossing.y} color={dangerVar} />+ ) : (+ <Dot x={end.x} y={end.y} color={pausedAtLimit ? dangerVar : statusVar} />+ )}{yTicks.map((v) => (<Label key={v} x={PAD_LEFT - 4} y={yForCredits(v)} anchor="end" className="text-muted">{compactNumber(v)}@@ -318,7 +365,7 @@ function SpendTrajectoryChartInner({</Label>)}{showFreeLine && freeY !== null && (- <Label x={WIDTH - PAD_X} y={freeY + BELOW} anchor="end" className="font-semibold text-muted">+ <Label x={WIDTH - PAD_X} y={freeY - 8} anchor="end" className="font-semibold text-muted">Free credits · {formatCreditNumber(freeCredits)}</Label>)}diff --git a/products/replay_vision/frontend/replay_scanners/visionUsageLogic.ts b/products/replay_vision/frontend/replay_scanners/visionUsageLogic.tsindex 264db578ce2c..ed9acfc59151 100644--- a/products/replay_vision/frontend/replay_scanners/visionUsageLogic.ts+++ b/products/replay_vision/frontend/replay_scanners/visionUsageLogic.ts@@ -14,7 +14,6 @@ import type { VisionQuotaApi, VisionSpendSeriesApi } from '../generated/api.scheimport { refreshVisionQuota, visionQuotaLogic } from '../logics/visionQuotaLogic'import { fleetContributions } from '../utils/quotaContributions'import { hasCreditLimit } from '../utils/quotaProjection'-import { currentQuotaScenario } from '../utils/quotaScenarios'import { type SpendVerdict, spendVerdict } from '../utils/spendVerdict'import type { ReplayScanner } from './types'@@ -82,10 +81,6 @@ export const visionUsageLogic = kea<visionUsageLogicType>([null as VisionSpendSeriesApi | null,{loadSpendSeries: async (): Promise<VisionSpendSeriesApi | null> => {- const scenario = currentQuotaScenario()- if (scenario) {- return scenario.dailySpend- }const teamId = teamLogic.values.currentTeamIdreturn teamId ? await environmentVisionQuotaSpendSeriesRetrieve(String(teamId)) : null},@@ -186,11 +181,6 @@ export const visionUsageLogic = kea<visionUsageLogicType>([}),listeners(({ actions, values }) => ({loadUsageScanners: async () => {- const scenario = currentQuotaScenario()- if (scenario?.usageScanners) {- actions.loadUsageScannersSuccess(scenario.usageScanners as unknown as ReplayScanner[])- return- }const teamId = teamLogic.values.currentTeamIdif (!teamId) {actions.loadUsageScannersSuccess([])diff --git a/products/replay_vision/frontend/utils/quotaScenarios.ts b/products/replay_vision/frontend/utils/quotaScenarios.tsdeleted file mode 100644index 602c8999bd6b..000000000000--- a/products/replay_vision/frontend/utils/quotaScenarios.ts+++ /dev/null@@ -1,241 +0,0 @@-import { dayjs } from 'lib/dayjs'--import type { VisionQuotaApi, VisionSpendSeriesApi } from '../generated/api.schemas'--/**- * Dev-only fake states for every spend surface, driven by `?vision_quota_scenario=<key>`.- * Lets the quota card, landing page, and usage tab render each state of the spend UI with- * realistic data, without contorting billing or burning credits. Never active in production- * builds; the overrides are display-only and the backend still enforces the real quota.- */--export interface QuotaScenario {- key: string- quota: VisionQuotaApi | null- /** Per-scanner rows for the usage tab; null keeps the real rows. */- usageScanners: FakeUsageScanner[] | null- /** Settled credits per UTC day from the period start to today; null keeps the real series request. */- dailySpend: VisionSpendSeriesApi-}--export interface FakeUsageScanner {- id: string- name: string- enabled: boolean- credits_this_month: number- observations_this_month: number- credits_per_observation: number- sampling_rate: number- estimated_monthly_credits: number | null- estimated_at: string | null- model: string-}--const SCENARIO_PARAM = 'vision_quota_scenario'--// Hoisted so the production bundle keeps no live path into the fixtures below.-const SCENARIOS_ENABLED = process.env.NODE_ENV !== 'production'--// Scenarios run 18 days into a 30-day period, so the chart has a real spend history to draw-// regardless of today's date.-const SCENARIO_DAYS_ELAPSED = 18--function buildQuota(overrides: Partial<VisionQuotaApi>): VisionQuotaApi {- const periodStart = dayjs.utc().subtract(SCENARIO_DAYS_ELAPSED, 'day').startOf('day')- const base = {- credit_limit: 5000,- credits_used: 1850,- remaining: 3150,- exhausted: false,- period_start: periodStart.toISOString(),- period_end: periodStart.add(30, 'day').toISOString(),- projected_monthly_credits: 2400,- scanners_monthly_credits: 2100,- backfills_committed_credits: 300,- free_monthly_credits: 500,- credits_settled: 1850,- credits_reserved: 0,- }- return { ...base, ...overrides } as VisionQuotaApi-}--const FAKE_SCANNERS: FakeUsageScanner[] = [- {- id: 'scenario-checkout',- name: 'Checkout errors',- enabled: true,- credits_this_month: 820,- observations_this_month: 410,- credits_per_observation: 2,- sampling_rate: 0.25,- estimated_monthly_credits: 700,- estimated_at: '2026-01-01T00:00:00Z',- model: 'standard',- },- {- id: 'scenario-rage',- name: 'Rage click detector',- enabled: true,- credits_this_month: 520,- observations_this_month: 260,- credits_per_observation: 2,- sampling_rate: 0.1,- estimated_monthly_credits: 900,- estimated_at: '2026-01-01T00:00:00Z',- model: 'standard',- },- {- id: 'scenario-signup',- name: 'Signup friction',- enabled: true,- credits_this_month: 510,- observations_this_month: 255,- credits_per_observation: 2,- sampling_rate: 0.05,- estimated_monthly_credits: 500,- estimated_at: null,- model: 'standard',- },-]--/** Scale a scanner's period spend and monthly estimate together, so the table sums match the quota's fleet rate. */-function scaleScanners(spendFactor: number, estimateFactor: number): FakeUsageScanner[] {- return FAKE_SCANNERS.map((s) => ({- ...s,- credits_this_month: Math.round(s.credits_this_month * spendFactor),- estimated_monthly_credits:- s.estimated_monthly_credits === null ? null : Math.round(s.estimated_monthly_credits * estimateFactor),- }))-}--/**- * A believable daily burn landing on `total`: gently accelerating, dipping on weekends, with- * deterministic noise (sine-based, so every render draws the same series).- */-function rampSpend(total: number): VisionSpendSeriesApi {- const days = SCENARIO_DAYS_ELAPSED- const start = dayjs.utc().subtract(SCENARIO_DAYS_ELAPSED, 'day').startOf('day')- const weights = Array.from({ length: days }, (_, i) => {- const weekday = start.add(i, 'day').day()- const weekendDip = weekday === 0 || weekday === 6 ? 0.45 : 1- const growth = 1 + (1.2 * i) / Math.max(days - 1, 1)- const noise = 1 + 0.35 * Math.sin(i * 12.9898) * Math.sin(i * 78.233)- return weekendDip * growth * Math.max(noise, 0.2)- })- const weightTotal = weights.reduce((sum, w) => sum + w, 0)- const daily = weights.map((w) => Math.round((total * w) / weightTotal))- // Per-day rounding drifts off `total`; settle the difference on the last day so the sum is exact.- daily[daily.length - 1] += total - daily.reduce((sum, v) => sum + v, 0)- return {- period_start: start.toISOString(),- period_end: start.add(30, 'day').toISOString(),- days: daily.map((credits, i) => ({ date: start.add(i, 'day').format('YYYY-MM-DD'), credits })),- }-}--const SCENARIOS: Record<string, () => Omit<QuotaScenario, 'key'>> = {- 'on-track': () => ({- quota: buildQuota({}),- usageScanners: FAKE_SCANNERS,- dailySpend: rampSpend(1850),- }),- 'nearing-limit': () => ({- quota: buildQuota({- credits_used: 2600,- remaining: 2400,- projected_monthly_credits: 4400,- scanners_monthly_credits: 4100,- }),- usageScanners: scaleScanners(1.4, 4100 / 2100),- dailySpend: rampSpend(2600),- }),- 'limit-soon': () => ({- quota: buildQuota({- credits_used: 3900,- remaining: 1100,- projected_monthly_credits: 7800,- scanners_monthly_credits: 7500,- }),- usageScanners: scaleScanners(2.1, 7500 / 2100),- dailySpend: rampSpend(3900),- }),- paused: () => ({- quota: buildQuota({ credits_used: 5000, remaining: 0, exhausted: true }),- usageScanners: scaleScanners(2.7, 7500 / 2100),- dailySpend: rampSpend(5000),- }),- 'free-plan': () => ({- quota: buildQuota({- credit_limit: 500,- credits_used: 260,- remaining: 240,- projected_monthly_credits: 420,- scanners_monthly_credits: 420,- backfills_committed_credits: 0,- free_monthly_credits: 500,- }),- usageScanners: scaleScanners(1 / 7, 420 / 2100),- dailySpend: rampSpend(260),- }),- 'free-paused': () => ({- quota: buildQuota({- credit_limit: 500,- credits_used: 500,- remaining: 0,- exhausted: true,- free_monthly_credits: 500,- }),- usageScanners: scaleScanners(1 / 4, 420 / 2100),- dailySpend: rampSpend(500),- }),- 'zero-limit': () => ({- quota: buildQuota({- credit_limit: 0,- credits_used: 0,- remaining: 0,- exhausted: true,- projected_monthly_credits: 0,- scanners_monthly_credits: 0,- backfills_committed_credits: 0,- }),- usageScanners: FAKE_SCANNERS.map((s) => ({ ...s, credits_this_month: 0, observations_this_month: 0 })),- dailySpend: rampSpend(0),- }),- 'no-limit': () => ({- quota: buildQuota({ credit_limit: null, remaining: null }),- usageScanners: FAKE_SCANNERS,- dailySpend: rampSpend(1850),- }),- empty: () => ({- quota: buildQuota({- credits_used: 0,- remaining: 5000,- projected_monthly_credits: 0,- scanners_monthly_credits: 0,- backfills_committed_credits: 0,- }),- usageScanners: [],- dailySpend: rampSpend(0),- }),-}--function scenarioParam(name: string): string | null {- try {- return new URLSearchParams(window.location.search).get(name)- } catch {- return null- }-}--/** The active scenario, or null when none is requested (the normal case, and always in production). */-export function currentQuotaScenario(): QuotaScenario | null {- if (!SCENARIOS_ENABLED) {- return null- }- const key = scenarioParam(SCENARIO_PARAM)- const build = key && Object.hasOwn(SCENARIOS, key) ? SCENARIOS[key] : null- if (!key || !build) {- return null- }- return { key, ...build() }-}