fix(billing): coerce COST_MULTIPLIER to a number before sandbox pricing

Merged
WA
2mo ago
+60-6

Summary

  • COST_MULTIPLIER is declared as z.number() but createEnv runs with skipValidation, so the value arrives as the raw process.env string. Every existing consumer multiplies by it, which JS coerces silently, so the type bug was invisible until createSandboxPricing (#7184) added a Number.isFinite guard — that guard rejects the string and every metered E2B/Daytona Function block fails with Sandbox pricing multiplier must be a finite nonnegative number
  • getCostMultiplier now normalizes the value through envNumber, the helper written for exactly this case. Unset, empty, non-numeric, and negative values fall back to 1 instead of leaking a string (or crashing) into billing math. This fixes all seven consumers at once
  • Regression tests exercise the real getCostMultiplier under a production NODE_ENV with a string COST_MULTIPLIER; they reproduce the exact error against the previous code

Type of Change

  • Bug fix

Testing

  • New tests fail on the previous code with the production error and pass with the fix
  • sandbox-pricing, cost-policy, providers/index, and env suites pass (84 tests)
  • bun run lint, block-registry check, check:audits, and the CI env-flag validation block pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)