← Back to Pull requests

feat(parser): add opt-in GTIN check-digit validation #42

Closed
unknown closed this pull request without merging on Oct 13, 2026 21:31 UTC
View on GitHub
unknown unknown commented on Oct 09, 2026 23:01 UTC
Author

Summary

Add opt-in GTIN check-digit validation for AI 01 and AI 02, including supported bare GTIN and retail-carrier inputs. Go callers can set ParseOptions.ValidateCheckDigits, the CLI accepts -check-digits, and WASM accepts validateCheckDigits.

Default parsing stays lenient. The existing -strict / strict options continue to validate associations only, and both checks can be enabled independently. Barcode.Validate() now runs association checks followed by GTIN checks against its current elements. The ADR documents error priority and UPC-E / stripped ITF check-digit handling.

Closes #6. This covers the check-digit validation paths while preserving the existing association-only strict options; it does not adopt the same strict flag proposed in that issue.

Specification reference

The GS1 Syntax Dictionary, release 2026-01-27, AI 01 (GTIN) and AI 02 (CONTENT) entries, specifies N14 with the csum constraint. This change reuses the package's existing ValidateGTIN implementation.

Validation

  • make all, make race, GOMAXPROCS=4 make fuzz (30 seconds), make bench, make build, and make wasm pass.

  • node wasm/check-digits.test.mjs passes against the built WASM module, including all four combinations of the two validation options.

  • BenchmarkParseInto remains at 0 B/op and 0 allocs/op.

  • Validated with Go 1.27.2 and Node 24.21.0; the minimum supported Go 1.23 was not tested locally.
  • Checklist

  • make all passes (vet, lint, tests)

  • New parsing paths have table-driven tests and, where applicable, fuzz seeds

  • Exported identifiers have godoc comments

  • No new external dependencies

  • CHANGELOG.md updated under Unreleased
  • Diff: 225 lines (+168 / -57) across 2 files Reviewer: Boulea7 Review duration: 5670m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.37) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 225 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.324
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #42"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.9% (MEDIUM) · Higher = larger blast radius
    36.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.0% · Safe to merge
    16.0%