Define the local evaluation task
A synthetic local stream carries text chunks and an explicit ended Boolean. Concatenate chunks in the supplied order but parse JSON only after ended is true. A parseable prefix without the end marker remains incomplete. Once ended, malformed JSON returns a parse error; no partial object is invented.
- Join supplied chunks in order
- Wait for explicit end state
- Parse the final text or retain error
Incomplete streams stay pending; ended parse failures need raw-output review.
Use the filled cases
| Case | Supplied input | Expected structured output | Decision and reason |
|---|---|---|---|
| Parseable prefix without end marker | {"chunks":["{\"x\":","1}"],"ended":false} | {"status":"incomplete"} | The explicit completion channel is still false. |
| Ended complete object | {"chunks":["{\"x\":","1}"],"ended":true} | {"status":"parsed","value":{"x":1}} | Both the end state and final parsed structure are available. |
| A stream chunk is numeric | {"chunks":[1],"ended":true} | {"status":"invalid-text-chunks"} | The text channel must not coerce numeric 1 into a parseable JSON string. |
| Ended malformed payload | {"chunks":["{\"x\":"],"ended":true} | {"status":"parse-error"} | An end marker does not repair invalid JSON. |
Work the ended-broken-json case. Which output is required, and why?
Show the worked answer
{"status":"parse-error"} — An end marker does not repair invalid JSON.
Run the self-contained evaluator
import assert from 'node:assert/strict';
function evaluate(x){
if(!Array.isArray(x.chunks)||x.chunks.some(chunk=>typeof chunk!=='string'))return {status:'invalid-text-chunks'};
if(typeof x.ended!=='boolean')return {status:'invalid-end-state'};if(!x.ended)return {status:'incomplete'};
try{return {status:'parsed',value:JSON.parse(x.chunks.join(''))};}catch{return {status:'parse-error'};}
}
const cases = [
{
"id": "valid-prefix-not-ended",
"input": {
"chunks": [
"{\"x\":",
"1}"
],
"ended": false
},
"expected": {
"status": "incomplete"
}
},
{
"id": "ended-valid-object",
"input": {
"chunks": [
"{\"x\":",
"1}"
],
"ended": true
},
"expected": {
"status": "parsed",
"value": {
"x": 1
}
}
},
{
"id": "nontext-stream-chunk",
"input": {
"chunks": [
1
],
"ended": true
},
"expected": {
"status": "invalid-text-chunks"
}
},
{
"id": "ended-broken-json",
"input": {
"chunks": [
"{\"x\":"
],
"ended": true
},
"expected": {
"status": "parse-error"
}
}
];
for (const c of cases) assert.deepEqual(evaluate(c.input), c.expected, c.id);
console.log(JSON.stringify({checked:cases.length,caseIds:cases.map(c=>c.id)}));
Retain the raw chunks and finalisation state. This bounded example receives no live stream and performs no external action; a parsed object still needs its own acceptance rules.