refactor: modularize portal server and harden session recovery

This commit is contained in:
john
2026-07-24 18:39:24 +08:00
parent 1d291fd528
commit 785731d98d
109 changed files with 29185 additions and 5836 deletions
+32
View File
@@ -75,3 +75,35 @@ test('consumeSessionEventsUntilFinish records a successful raster generate_image
assert.equal(result.toolEvidence.generateImage.succeeded, true);
assert.equal(result.toolEvidence.generateImage.jobId, 'job-1');
});
test('consumeSessionEventsUntilFinish surfaces provider tool history errors before Finish', async () => {
const frames = [
`data: ${JSON.stringify({
type: 'Message',
request_id: 'req-1',
message: {
role: 'assistant',
content: [{
type: 'text',
text: "Ran into this error: Request failed: Bad request (400): An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. (insufficient tool messages following tool_calls message).\n\nPlease retry if you think this is a transient or recoverable error.",
}],
},
})}\n\n`,
'data: {"type":"Finish","request_id":"req-1"}\n\n',
];
const stream = new ReadableStream({
start(controller) {
for (const frame of frames) controller.enqueue(new TextEncoder().encode(frame));
controller.close();
},
});
await assert.rejects(
consumeSessionEventsUntilFinish(stream, { requestId: 'req-1', timeoutMs: 5000 }),
(error) => {
assert.equal(error.code, 'SESSION_TOOL_HISTORY_POISONED');
assert.match(error.message, /tool_calls/);
return true;
},
);
});