The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): cover opaque carrier and decodable envelope hydration together
Brooklyn Nicholson38732f7fe2a9
diff --git a/apps/desktop/src/lib/chat-messages/hydration.ts b/apps/desktop/src/lib/chat-messages/hydration.tsindex 7c7c8cfd9f6..f845e8b2520 100644--- a/apps/desktop/src/lib/chat-messages/hydration.ts+++ b/apps/desktop/src/lib/chat-messages/hydration.ts@@ -455,9 +455,7 @@ export function toChatMessages(messages: SessionMessage[]): ChatMessage[] {const commentary = codexText?.commentary ?? []const rawReasoning =- message.reasoning ||- message.reasoning_content ||- reasoningTextFromDetails(message.reasoning_details)+ message.reasoning || message.reasoning_content || reasoningTextFromDetails(message.reasoning_details)const reasoning = message.display_reasoning !== undefined ? message.display_reasoning : rawReasoningdiff --git a/apps/desktop/src/lib/chat-messages/parts.ts b/apps/desktop/src/lib/chat-messages/parts.tsindex c2214029faa..4290759a8c1 100644--- a/apps/desktop/src/lib/chat-messages/parts.ts+++ b/apps/desktop/src/lib/chat-messages/parts.ts@@ -33,11 +33,15 @@ export function reasoningTextFromDetails(details: unknown): string {const text: string[] = []const push = (value: unknown) => {- if (typeof value !== 'string') return+ if (typeof value !== 'string') {+ return+ }const prose = value.trim()- if (prose && !text.includes(prose)) text.push(prose)+ if (prose && !text.includes(prose)) {+ text.push(prose)+ }}// Nested carrier internals: only genuinely readable reasoning kinds. A@@ -46,11 +50,16 @@ export function reasoningTextFromDetails(details: unknown): string {// reasoning, and signatures/projections/data are opaque replay fields.const walkNested = (node: unknown): void => {if (Array.isArray(node)) {- for (const item of node) walkNested(item)+ for (const item of node) {+ walkNested(item)+ }+return}- if (!node || typeof node !== 'object') return+ if (!node || typeof node !== 'object') {+ return+ }const record = node as Record<string, unknown>const kind = typeof record.type === 'string' ? record.type : ''@@ -64,23 +73,31 @@ export function reasoningTextFromDetails(details: unknown): string {}for (const [key, value] of Object.entries(record)) {- if (key === 'signature' || key === 'projection' || key === 'data' || key === 'type') continue+ if (key === 'signature' || key === 'projection' || key === 'data' || key === 'type') {+ continue+ }- if (value && typeof value === 'object') walkNested(value)+ if (value && typeof value === 'object') {+ walkNested(value)+ }}}for (const block of Array.isArray(blocks) ? blocks : [blocks]) {if (typeof block === 'string') {push(block)+continue}- if (!block || typeof block !== 'object') continue+ if (!block || typeof block !== 'object') {+ continue+ }// Top-level blocks are provider reasoning-detail entries; recognized// prose fields (summary, thinking, content, text) are display text.const record = block as Record<string, unknown>+const value = [record.summary, record.thinking, record.content, record.text].find(candidate => typeof candidate === 'string' && candidate.trim())diff --git a/apps/desktop/src/lib/chat-messages/reasoning-details.test.ts b/apps/desktop/src/lib/chat-messages/reasoning-details.test.tsindex 04b3acdf850..3616419a863 100644--- a/apps/desktop/src/lib/chat-messages/reasoning-details.test.ts+++ b/apps/desktop/src/lib/chat-messages/reasoning-details.test.ts@@ -44,4 +44,38 @@ describe('reasoning-details display text', () => {})).toEqual(['Canonical reasoning.'])})++ it('hydrates an opaque carrier and a decodable envelope side by side without leaking either', () => {+ const reasoningParts = (message: Partial<SessionMessage>): string[] =>+ toChatMessages([{ role: 'assistant', content: 'Answer.', ...message } as SessionMessage])+ .flatMap(item => item.parts)+ .filter(part => part.type === 'reasoning')+ .map(part => (part as { text: string }).text)++ // The #126588 DirectSDK carrier: signed thinking with empty plaintext,+ // native text blocks and a projection that repeat the public answer.+ const carrier = JSON.stringify([+ {+ type: 'claude-subscription-directsdk-experimental.native_assistant',+ version: 1,+ messages: [+ {+ content: [+ { type: 'thinking', thinking: '', signature: 'sigside' },+ { type: 'text', text: 'Answer A' }+ ]+ }+ ],+ projection: { content: 'Answer A', tool_calls: [] }+ }+ ])++ const envelope = JSON.stringify([+ { type: 'reasoning.summary', summary: 'Checked the lock.' },+ { type: 'reasoning.text', text: 'Return the result.' }+ ])++ expect(reasoningParts({ reasoning_details: carrier })).toEqual([])+ expect(reasoningParts({ reasoning_details: envelope })).toEqual(['Checked the lock.\n\nReturn the result.'])+ })})