Read the source and its declared rule
This original destination contract permits ASCII code points 0..127 only. It is a synthetic repertoire test, not a full legacy-codec adapter. Replacing 你 with ? loses the source meaning; corrected admission retains the original and rejects the loss.
| Record | Input JSON |
|---|---|
| Base input | {"text":"你"} |
Compare the actual paths
The bad path announces ? as accepted. The correction holds 你 with not-representable; choosing another destination encoding is a separate confirmed mapping decision.
| Path | Output JSON |
|---|---|
| Misleading path | {"accepted":true,"text":"?","source":"你"} |
| Corrected path | {"accepted":false,"error":"not-representable","source":"你"} |
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 supported=Array.from(i.text).every(c=>c.codePointAt(0)<=127);
if(corrected&&!supported)return {accepted:false,error:'not-representable',source:i.text};
return {accepted:true,text:Array.from(i.text,c=>c.codePointAt(0)<=127?c:'?').join(''),source:i.text};
};
const cases=[{"label":"misleading base","input":{"text":"你"},"expected":{"accepted":true,"text":"?","source":"你"},"corrected":false},{"label":"corrected base","input":{"text":"你"},"expected":{"accepted":false,"error":"not-representable","source":"你"},"corrected":true},{"label":"representable source","input":{"text":"Ada"},"expected":{"accepted":true,"text":"Ada","source":"Ada"},"corrected":true},{"label":"empty representable source","input":{"text":""},"expected":{"accepted":true,"text":"","source":""},"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
Ada and the empty string are representable under the supplied contract and remain unchanged.
| Case | Input JSON | Expected output JSON |
|---|---|---|
| Representable ASCII label | {"text":"Ada"} | {"accepted":true,"text":"Ada","source":"Ada"} |
| Empty representable text | {"text":""} | {"accepted":true,"text":"","source":""} |
Can ? stand in for the original Chinese label here?
Show the worked answer
No. That would accept a lossy replacement. Hold the original 你; the ASCII Ada boundary can proceed.