From aa2644befa09797496967a167f6af27781c1fed8 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Mon, 5 Oct 2026 00:56:36 +0800 Subject: [PATCH] =?UTF-8?q?test(sidechat):=20=E9=92=89=E4=BD=8F=E7=95=B8?= =?UTF-8?q?=E5=BD=A2=20assistant=20content=20=E4=B8=8D=E6=8A=9B=E9=94=99?= =?UTF-8?q?=EF=BC=88#557=20=E7=A7=BB=E6=A4=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #557 的实现部分已被主线的 src/assistant-live.ts 取代,但它新增的这条 用例有独立价值:守 src/sidechat-core.ts 的 messageTexts / resultBlocks 三道 守卫——单条畸形行(content 非数组、message 缺 content、block 非对象、text 非字符串)不得让整个 open-turn 快照变空。 按原样移植,**不**带上该 PR 同时删掉的两条回归用例(producer round-trip / LEGACY 0.1.6-wrapped),那两条在 dev 上是通过的。 Refs #557 Co-authored-by: later0day --- tests/sidechat-core.spec.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/sidechat-core.spec.ts b/tests/sidechat-core.spec.ts index ac6952ec..d7cb7edb 100644 --- a/tests/sidechat-core.spec.ts +++ b/tests/sidechat-core.spec.ts @@ -315,6 +315,27 @@ describe('buildOpenTurnSnapshot', () => { expect(snapshot).not.toBeNull() expect(snapshot).toContain('Result: legacy body') }) + + // Logs written by other producers (or by an older plugin) can carry rows the + // current shape does not describe: a non-array `content`, a message without + // one, a block that is not an object, a text block without a string. The + // guards in messageTexts/resultBlocks must skip them rather than throw — a + // single malformed row must not blank the whole open-turn snapshot. + it('skips malformed assistant content instead of throwing', () => { + const events = [ + ev('turn/start', 0, { turn: 1 }), + ev('step/start', 1, { turn: 1, step: 1 }), + ev('assistant/message', 2, { turn: 1, step: 1, message: { content: 'not-an-array' } }), + ev('assistant/message', 3, { turn: 1, step: 1 }), + ev('assistant/message', 4, { + turn: 1, + step: 1, + message: { content: [null, { type: 'text' }, { type: 'text', text: 'kept' }] }, + }), + ev('tool/call', 5, { turn: 1, step: 1, callId: 'c1', name: 'bash', arguments: '{}' }), + ] + expect(buildOpenTurnSnapshot(events)).toContain('kept') + }) }) describe('sideLabel', () => {