Read the source and its declared rule
The original import checks NFC-equivalent spellings but must retain every original label. Composed é and e plus combining accent share one NFC key. The supplied collision rule holds a key containing more than one distinct original spelling; an exact repeated spelling is retained without that collision classification.
| Record | Input JSON |
|---|---|
| Base input | {"labels":["é","é"]} |
Compare the actual paths
Good output retains both originals and identifies key é. It neither overwrites a spelling nor silently establishes that two business records represent the same entity.
| Path | Output JSON |
|---|---|
| Misleading path | {"accepted":true,"labels":["é"]} |
| Corrected path | {"accepted":false,"originals":["é","é"],"collisions":[{"key":"é","originals":["é","é"]}]} |
import {DatabaseSync} from 'node:sqlite';
import {TextDecoder} from 'node:util';
import {inflateSync} from 'node:zlib';
import {posix} from 'node:path';
import {createHash} from 'node:crypto';
const rows=(db,sql)=>db.prepare(sql).all().map(r=>({...r}));
const failed=(action)=>{try{action();return null;}catch(e){return {code:e.errcode??e.code??e.name};}};
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
const groups=new Map();for(const source of i.labels){const key=source.normalize('NFC');if(!groups.has(key))groups.set(key,[]);groups.get(key).push(source);}
if(!corrected)return {accepted:true,labels:[...groups.keys()]};
const collisions=[...groups].filter(([,originals])=>new Set(originals).size>1).map(([key,originals])=>({key,originals}));
return {accepted:collisions.length===0,originals:[...i.labels],collisions};
};
const cases=[{"label":"misleading base","input":{"labels":["é","é"]},"expected":{"accepted":true,"labels":["é"]},"corrected":false},{"label":"corrected base","input":{"labels":["é","é"]},"expected":{"accepted":false,"originals":["é","é"],"collisions":[{"key":"é","originals":["é","é"]}]},"corrected":true},{"label":"repeated identical spelling","input":{"labels":["é","é"]},"expected":{"accepted":true,"originals":["é","é"],"collisions":[]},"corrected":true},{"label":"two distinct normal forms","input":{"labels":["A","B"]},"expected":{"accepted":true,"originals":["A","B"],"collisions":[]},"corrected":true}];
for(const test of cases){
const actual=run(test.input,test.corrected);
assert.deepEqual(actual,test.expected,test.label);
console.log(test.label,actual);
}
Check boundaries before the next load
Two exact é spellings remain two originals with no distinct-spelling collision. A/B form separate keys.
| Case | Input JSON | Expected output JSON |
|---|---|---|
| Repeated exact spelling | {"labels":["é","é"]} | {"accepted":true,"originals":["é","é"],"collisions":[]} |
| Distinct canonical keys | {"labels":["A","B"]} | {"accepted":true,"originals":["A","B"],"collisions":[]} |
Should the two source spellings be replaced by one stored é?
Show the worked answer
No. The supplied rule is compare-and-hold, with both originals retained. The NFC key is evidence for review, not a replacement record.