feat(units): weight math audit — new @packrat/units package with NIST constants and 174 tests#2388
Conversation
- Create packages/units with NIST-exact avoirdupois constants (1 oz = 28.349523125 g, 1 lb = 453.59237 g — single source of truth) - Expose normalize, fromGrams, convert, displayWeight, isWeightUnit, parseWeightUnit; 174 tests including cross-validation vs convert-units v3 - Migrate all call sites: apps/expo weight utils, computePackWeights, computePackTemplateWeights, computeCategories, lib/utils/compute-pack, packages/api weight utils and compute-pack - Fix convertToGrams/convertFromGrams which were NOT inverses of each other (used 28.3495 vs 28.35 — silent drift of ~0.016 oz per 100 oz) - Fix computeCategories percentage bug: was mixing pack.totalWeight (in preferred unit) with convertToGrams, giving wrong % for non-gram users - Update all test suites to NIST values; 730 tests passing (0 failures) - Add convert-units 3.0.0-beta.8 as devDependency for cross-validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add @media (prefers-reduced-motion: reduce) to landing app globals.css to satisfy WCAG 2.3.3 accessibility requirement (fixes react-doctor check) - Bump 8 expo packages to SDK-54 required patch versions: expo ^54.0.33→~54.0.34, expo-dev-client/file-system/glass-effect/ image-picker/linking/updates/web-browser each +0.0.1 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Satisfies the no-raw-typeof custom lint rule enforced by the pre-push hook.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (22)
Warning
|
Coverage Report for Expo Unit Tests Coverage (./apps/expo)
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Coverage Report for API Unit Tests Coverage (./packages/api)
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR introduces a shared @packrat/units package to centralize weight-unit conversion/normalization using exact NIST avoirdupois constants, then refactors existing API + Expo weight utilities to consume that shared implementation (reducing duplicated conversion math). It also includes small dependency updates (Expo) and a landing-page accessibility improvement for reduced-motion users.
Changes:
- Added new
@packrat/unitspackage with weight conversion helpers (normalize,fromGrams,convert,displayWeight, parsing/guards) and comprehensive tests. - Refactored API and Expo weight computations (base/total/category summaries, grams helpers) to use
@packrat/unitsinstead of bespoke conversion logic. - Updated Expo-related dependencies and added
prefers-reduced-motionCSS handling on the landing site.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/units/vitest.config.ts | Adds Vitest config for the new @packrat/units package with strict coverage thresholds. |
| packages/units/src/index.ts | Implements canonical unit conversion/parsing/formatting helpers and exported types/constants. |
| packages/units/src/index.test.ts | Adds extensive unit tests and cross-validation against convert-units. |
| packages/units/package.json | Declares the new workspace package and its test/dev dependencies. |
| packages/api/src/utils/weight.ts | Replaces ad-hoc conversions with @packrat/units and keeps legacy helpers via re-exports/wrappers. |
| packages/api/src/utils/compute-pack.ts | Refactors pack base/total weight computation to normalize to grams via @packrat/units and use displayWeight. |
| packages/api/src/utils/tests/weight.test.ts | Updates assertions to reflect exact NIST constants and new conversion behavior. |
| packages/api/package.json | Adds @packrat/units workspace dependency. |
| bun.lock | Records new workspace package and dependency updates (including Expo version bumps). |
| biome.json | Adds packages/units/src/index.ts to the existing override list (rule exceptions). |
| apps/landing/app/globals.css | Adds prefers-reduced-motion styles to reduce animation/transition effects. |
| apps/expo/vitest.config.ts | Adds Vitest aliases for @packrat/units (and @packrat/guards) to point at source during unit tests. |
| apps/expo/utils/weight.ts | Refactors Expo app weight utilities to use @packrat/units. |
| apps/expo/utils/tests/weight.test.ts | Updates Expo-side weight util tests to align with exact constants/behavior. |
| apps/expo/package.json | Adds @packrat/units dependency and bumps Expo-related versions. |
| apps/expo/lib/utils/compute-pack.ts | Refactors Expo pack weight computation to normalize via @packrat/units and format via displayWeight. |
| apps/expo/features/packs/utils/convertToGrams.ts | Replaces local conversion switch with normalize(..., parseWeightUnit(...)). |
| apps/expo/features/packs/utils/convertFromGrams.ts | Replaces local conversion switch with fromGrams(...). |
| apps/expo/features/packs/utils/computePackWeights.ts | Refactors feature-level pack weight computation to use @packrat/units. |
| apps/expo/features/packs/utils/computeCategories.ts | Refactors category aggregation to compute percentages from grams and display using @packrat/units. |
| apps/expo/features/packs/utils/tests/convertToGrams.test.ts | Updates tests for NIST exact values and new behavior. |
| apps/expo/features/packs/utils/tests/convertFromGrams.test.ts | Updates tests for NIST exact values and new behavior. |
| apps/expo/features/pack-templates/utils/computePacktemplateWeight.ts | Refactors template weight computation to normalize via @packrat/units and format via displayWeight. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| oz: 28.349523125, | ||
| lb: 453.59237, | ||
| } as const; | ||
|
|
||
| export const WEIGHT_UNITS = Object.freeze(['g', 'kg', 'oz', 'lb'] as const); | ||
|
|
||
| export type WeightUnit = keyof typeof TO_GRAMS; | ||
|
|
feat(units): weight math audit — new @packrat/units package with NIST constants and 174 tests
Summary
Key changes
Testing
Post-Deploy Monitoring & Validation
No additional operational monitoring required: pure refactor of math utilities with no behavior change for users, no DB writes, no API surface changes.