Skip to content

fix: review findings, ~20x faster solver, and Portuguese receipt fixes - #5

Merged
rsoaresdev merged 20 commits into
mainfrom
fix/review-findings
Nov 27, 2026
Merged

rsoaresdev merged 20 commits into
mainfrom
fix/review-findings

Conversation

@rsoaresdev

@rsoaresdev rsoaresdev commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Fixes and cleanup from a full review of src/. One concern per commit.

Fixes

  • otherFills sources pointed at the internally joined rows instead of the caller's lines when a row was split by the recogniser. Highlights for a second fill landed on the wrong line. Test added in rows.test.ts.

  • gal matched inside words (Portugal, Galp, Legal), so the US tenth-of-a-cent repair turned 12.50 9 into 12.509. Now only a whole word gal/gals/gallon(s)/ppg triggers it; 11.482GAL still does.

  • Bulgaria has used the euro since 1 January 2026: country: "BG" now maps to EUR. Lev receipts (лв.) still read as BGN.

  • Currency precedence: an explicit context.currency now settles an ambiguous symbol ahead of the currency implied by country, matching how extract.ts already picks its fallback.

  • Other fills tolerance now uses the receipt's fallback currency instead of always the euro cent (only matters on lines with no currency mark).

  • Alternates were unbounded: lines were capped at 500 × 1500 chars but each line's alternates were not, and every number keeps a copy of its line, so memory grows with the square of the length. 50 alternates of 100k chars ran Node out of memory. Now the first 3, cut to 1500 chars. Test added in resilience.test.ts (fails without the fix).

  • Total IVA 11,22 taken as the total when the sum cannot close (litres not read): it tied with TOTAL 60,00 and won by coming first. A total whose label names a tax now ranks lower unless it says the tax is included (c/IVA, inkl, TTC, …). Tests for Total IVA, Valor IVA and Total s/IVA … Total c/IVA.

  • Miles & More 123456 read as odometer (123456 mi). Loyalty labels are now skipped by the odometer reader. Test added.

  • Fuel not named when printed on its own number line: GASOLEO 40,00 L x 1,600 EUR/L 64,00 gave fuelTypeId: null, and a line with no currency gave the whole line as the label. The product is now also read from the text before the first decimal number. Tests for three layouts.

Added

  • Gasóleo Evologic and Óptima Diesel as additised diesel; Alves Bandeira as a station. (Names taken from the brands' ranges, not from receipts — worth confirming against real paper.)
  • Mobi.E Taxa OPC / Taxa EGME as fees, so a charging receipt printing them can close. Test added.

Speed

  • ~20× faster on a typical receipt (42 lines: 114 ms → 5.6 ms on an M-series Mac). The solver called namesFuelAmount(contextFor(...)) for every total inside the quantity × price loop (~8000 lexicon scans); it is now asked once per total.

CI

  • Release job runs npm ci --ignore-scripts, since it holds id-token: write. Checked locally that lint, typecheck, coverage, build, publint, attw and smoke all work after a scripts-free install.

Cleanup

  • README: documents the alternates bound and that currency settles an ambiguous symbol.
  • Doc comment for contextFor moved back onto it.
  • currencyOf computed once; unit-kind regexes compiled once instead of per call.
  • Removed src/units.ts and decimalInput / localNumber / localReceiptNumber from src/format.ts: not exported, not used by the library.

Checks

biome check, tsc --noEmit, vitest run --coverage (278 tests) publint, attw and npm run smoke pass locally. CHANGELOG has an Unreleased section.

@rsoaresdev rsoaresdev changed the title fix: review findings (otherFills sources, gal lines, Bulgaria, currency precedence) and cleanup fix: review findings, ~20x faster solver, and Portuguese receipt fixes Nov 26, 2026
@rsoaresdev
rsoaresdev merged commit 0a05d8f into main Nov 27, 2026
6 checks passed
@rsoaresdev
rsoaresdev deleted the fix/review-findings branch November 27, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant