fix(vehicle): calculate VIN check digit - #3954
Conversation
✅ Deploy Preview for fakerjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #3954 +/- ##
=======================================
Coverage 98.91% 98.91%
=======================================
Files 924 924
Lines 3224 3233 +9
Branches 585 569 -16
=======================================
+ Hits 3189 3198 +9
Misses 31 31
Partials 4 4
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request fixes vehicle.vin() to generate ISO 3779 / North American–compliant VINs by computing and inserting the proper check digit at position 9, while keeping the existing random generation sequence intact (only the completed VIN’s 9th character is replaced).
Changes:
- Add VIN transliteration + weight tables and a local
vinCheckDigit()helper to compute the ISO 3779 modulo-11 check digit (with10 -> 'X'). - Update
VehicleModule.vin()to splice the computed check digit into position 9 of the already-generated VIN. - Add test coverage validating the check digit (including the
'X'case) and update affected seeded snapshots.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/modules/vehicle/module.ts |
Computes and inserts the VIN check digit into position 9 without changing RNG draw count. |
test/modules/vehicle.spec.ts |
Adds a check-digit validator and asserts generated VINs have a correct position-9 check digit. |
test/modules/__snapshots__/vehicle.spec.ts.snap |
Updates seeded VIN snapshots to reflect the corrected check digit. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // NHTSA 49 CFR § 565.15(c), Tables III and IV define the transliteration | ||
| // values and position weights used here: | ||
| // https://www.govinfo.gov/content/pkg/CFR-2025-title49-vol6/pdf/CFR-2025-title49-vol6-sec565-15.pdf |
There was a problem hiding this comment.
I might be stupid, but this link does not lead to any valid PDF for me 🤷♀️
Summary
Xmodulo-11 case, and update the affected seeded snapshotsRoot cause
vehicle.vin()generated the ninth character as an unconstrained alphanumeric value. That position is the VIN check digit in the North American VIN standard, so generated values commonly failed validation or contained an invalid letter there.The calculation uses the standard transliteration table and positional weights. Its zero weight for position 9 means the existing generated VIN can be used as input, preserving the random sequence while replacing only the check digit.
Fixes #3952.
Validation
corepack pnpm@10.34.4 run buildcorepack pnpm@10.34.4 exec vitest run test/modules/vehicle.spec.tscorepack pnpm@10.34.4 exec eslint src/modules/vehicle/module.ts test/modules/vehicle.spec.tscorepack pnpm@10.34.4 exec prettier --check src/modules/vehicle/module.ts test/modules/vehicle.spec.tscorepack pnpm@10.34.4 run ts-checkcorepack pnpm@10.34.4 run test(54,317 passing; one existing docs-version-links failure intest/docs/versions.spec.ts, unrelated to this change)git diff --check