Set the decision and its input
The fictional capture grammar ends a frame with ENTER and expects a three-character code. A12 ENTER B34 ENTER supplies two frames. Concatenating all characters instead creates A12B34. One ENTER after that combined string supplies one oversized frame requiring review, not two proven scans.
| Case | Input JSON |
|---|---|
| Base test | {"keys":["A","1","2","ENTER","B","3","4","ENTER"]} |
Run the supplied comparison
The state machine closes frames only on the stated terminator. Frame admission is separate from catalogue lookup; these characters never create a stock movement.
| Path | Output JSON |
|---|---|
| Faulty path | {"frames":["A12B34"],"pending":"","requiresReview":false} |
| Required path | {"frames":["A12","B34"],"pending":"","requiresReview":false} |
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
const frames=[];let pending='';for(const key of i.keys){if(key==='ENTER'){if(corrected){frames.push(pending);pending='';}}else pending+=key;}
if(!corrected&&pending){frames.push(pending);pending='';}
return {frames,pending,requiresReview:corrected&&(pending!==''||frames.some(f=>f.length!==3))};
};
const cases=[{"input":{"keys":["A","1","2","ENTER","B","3","4","ENTER"]},"corrected":false,"expected":{"frames":["A12B34"],"pending":"","requiresReview":false}},{"input":{"keys":["A","1","2","ENTER","B","3","4","ENTER"]},"corrected":true,"expected":{"frames":["A12","B34"],"pending":"","requiresReview":false}},{"input":{"keys":["A","1","2","B","3","4","ENTER"]},"corrected":true,"expected":{"frames":["A12B34"],"pending":"","requiresReview":true}},{"input":{"keys":["A","1","2"]},"corrected":true,"expected":{"frames":[],"pending":"A12","requiresReview":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Choose from the boundary evidence
Unterminated A12 stays pending. A six-character frame is retained whole with review required.
- Collect the pending characters
- Close on the declared terminator
- Check frame length before lookup
Do not invent a terminator from a familiar code shape.
| Condition | Input JSON | Expected output JSON |
|---|---|---|
| one combined frame | {"keys":["A","1","2","B","3","4","ENTER"]} | {"frames":["A12B34"],"pending":"","requiresReview":true} |
| unterminated tail | {"keys":["A","1","2"]} | {"frames":[],"pending":"A12","requiresReview":true} |
Can the combined frame be split automatically into A12 and B34?
Show the worked answer
No. Only one terminator exists. Retain A12B34 as one unresolved frame and obtain the missing framing evidence.