← back to Dw Photo Capture
test: cover nmfr + brandRe normalizers (cycle 22)
25e953207a520eaaf4dfd4ebbf587c065dbc14c9 · 2026-06-26 09:28:34 -0700 · Steve Abrams
Two untested load-bearing normalizers:
- nmfr (mfr dedup key: strips ONE trailing T, uppercases, trims so WOS3467T == WOS3467).
A regression here would defeat dedup and let duplicate products be created. 5 guards:
trailing-T strip, no-T-unchanged, trim+upper+strip, only-one-T-removed, null→'' no-throw.
- brandRe (vendor name → flexible OCR-detection regex source). 5 guards: multiword →
\s*-joined caps, single ≥4-char word kept, single <4-char → null, 2-char word dropped,
no-alpha → null.
Behavior verified empirically before asserting. 61→71 tests, lint clean. $0 (local).
Files touched
M OVERNIGHT_LEDGER.mdM test-analyze-ocr.js
Diff
commit 25e953207a520eaaf4dfd4ebbf587c065dbc14c9
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Fri Jun 26 09:28:34 2026 -0700
test: cover nmfr + brandRe normalizers (cycle 22)
Two untested load-bearing normalizers:
- nmfr (mfr dedup key: strips ONE trailing T, uppercases, trims so WOS3467T == WOS3467).
A regression here would defeat dedup and let duplicate products be created. 5 guards:
trailing-T strip, no-T-unchanged, trim+upper+strip, only-one-T-removed, null→'' no-throw.
- brandRe (vendor name → flexible OCR-detection regex source). 5 guards: multiword →
\s*-joined caps, single ≥4-char word kept, single <4-char → null, 2-char word dropped,
no-alpha → null.
Behavior verified empirically before asserting. 61→71 tests, lint clean. $0 (local).
---
OVERNIGHT_LEDGER.md | 1 +
test-analyze-ocr.js | 26 ++++++++++++++++++++++++--
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/OVERNIGHT_LEDGER.md b/OVERNIGHT_LEDGER.md
index ee83ebc..27ee7de 100644
--- a/OVERNIGHT_LEDGER.md
+++ b/OVERNIGHT_LEDGER.md
@@ -68,3 +68,4 @@ the single highest-value safe one, the officer executes it, and the loop resched
| 19 | investigate O/0 (real, backlogged) + ship /api/stats | O/0/I/1 ambiguity CONFIRMED real (122 of 1033 codes have letter-O, 47 have both O+0) but touches hot resolve path w/ untestable false-match risk → BACKLOGGED w/ evidence; shipped additive /api/stats (version, vendors, fingerprinted, learn total, last-learn, model) — read-only, auth-gated, zero hot-path risk | df 27G; stats 200 + 401 no-creds; lint+51 tests; selfcheck implied | $0 |
| 20 | collision gate → REJECT O/0 fallback + lock verbatim contract | checked 225,846 real codes: 14 collision groups where different products are pure O/0 or I/1 variants (RI5112≠R15112) → O/0 auto-fallback would mis-resolve → REJECTED w/ evidence; locked the safe behavior (analyzeOcr preserves codes verbatim, no silent O↔0/I↔1) with 3 tests | df 34G; 51→54 tests; lint clean | $0 |
| 21 | test-coverage (untested core helper) | mfrToHouseSku (scanned vendor code → DW house SKU) was UNTESTED despite real logic; added 7 guards via an injected MFR_INDEX fixture: exact/normalized match, case+dash+space stripping, <4-char→null, no-match→null, ±1-trailing-char fuzzy (WDW23107→WDW2310), 5-char fuzzy length-guard. Behavior verified empirically first (my initial guesses were wrong — code is correct) | df 34G; 54→61 tests; lint clean | $0 |
+| 22 | test-coverage (untested normalizers) | covered nmfr (mfr dedup: WOS3467T==WOS3467; a regression would let duplicate products be created) + brandRe (vendor name → OCR-detection regex source). Behavior verified empirically first; 10 guards: trailing-T strip/trim/upper/null, single-T-only, multiword \s*-join, single-<4-char→null, 2-char-word-drop, no-alpha→null | df 32G; 61→71 tests; lint clean | $0 |
diff --git a/test-analyze-ocr.js b/test-analyze-ocr.js
index 0d3b40f..f6f4ac7 100644
--- a/test-analyze-ocr.js
+++ b/test-analyze-ocr.js
@@ -43,9 +43,11 @@ const moduleSrc = [
sliceFn('fingerprintVendor'),
sliceConst('escapeRe'),
sliceFn('profileToLex'),
- 'return { parseOcrRows, analyzeOcr, fuzzyVendor, fingerprintVendor, profileToLex, VENDOR_LEX };',
+ sliceConst('nmfr'),
+ sliceFn('brandRe'),
+ 'return { parseOcrRows, analyzeOcr, fuzzyVendor, fingerprintVendor, profileToLex, nmfr, brandRe, VENDOR_LEX };',
].join('\n\n');
-const { parseOcrRows, analyzeOcr, fuzzyVendor, fingerprintVendor, profileToLex } =
+const { parseOcrRows, analyzeOcr, fuzzyVendor, fingerprintVendor, profileToLex, nmfr, brandRe } =
new Function('VENDOR_PROFILES', moduleSrc)(VENDOR_PROFILES);
// --- tiny assert harness ---
@@ -243,5 +245,25 @@ const bc = (payload, sym = 'Code128') => `BC\t${payload}\t${sym}`;
eq(mfrMod('WDW23'), null, 'mfr: 5-char code does not fuzzy-match (length guard)');
}
+// ── nmfr: mfr dedup normalizer (cycle 22, was untested) ──
+// Used to dedup so a scanned WOS3467T doesn't create a duplicate of WOS3467 — a regression
+// here would let duplicate products be created. Strips ONE trailing T, uppercases, trims.
+{
+ eq(nmfr('WOS3467T'), 'WOS3467', 'nmfr: single trailing T stripped');
+ eq(nmfr('WOS3467'), 'WOS3467', 'nmfr: no trailing T → unchanged');
+ eq(nmfr(' wos3467t '), 'WOS3467', 'nmfr: trims + uppercases + strips T');
+ eq(nmfr('ABCTT'), 'ABCT', 'nmfr: only ONE trailing T removed');
+ eq(nmfr(null), '', 'nmfr: null → empty string (no throw)');
+}
+
+// ── brandRe: vendor name → OCR-detection regex source (cycle 22, was untested) ──
+{
+ eq(brandRe('Winfield Thybony'), 'WINFIELD\\s*THYBONY', 'brandRe: multiword → \\s*-joined caps');
+ eq(brandRe('Romo'), 'ROMO', 'brandRe: single ≥4-char word kept');
+ eq(brandRe('Abc'), null, 'brandRe: single <4-char word → null (too noisy)');
+ eq(brandRe('AS Creation'), 'CREATION', 'brandRe: 2-char word dropped, ≥3-char kept');
+ eq(brandRe('123'), null, 'brandRe: no alpha words → null');
+}
+
console.log(`\nanalyzeOcr/vendor tests: ${pass} passed, ${fail} failed`);
process.exit(fail ? 1 : 0);
← 2e6d31c test: cover mfrToHouseSku resolver (cycle 21)
·
back to Dw Photo Capture
·
test: lock parseOcrRows barcode branches + overnight wind-do 6407d11 →