@@ -1749,109 +1749,155 @@ describe("chat transcript rendering", () => {
17491749 ) ;
17501750 } ) ;
17511751
1752- it ( "announces named attachment failures in ordinary and completed-run assistant rows" , ( ) => {
1753- const transcript = createTestTranscript ( ) ;
1754- const container = document . createElement ( "div" ) ;
1755- const existing = {
1756- testVirtualRow : true ,
1757- testVirtualKey : "assistant-existing" ,
1758- testVirtualRole : "assistant" ,
1759- role : "assistant" ,
1760- content : "Existing answer" ,
1761- } ;
1762- const renderMessages = ( messages : unknown [ ] ) =>
1763- renderChatInto ( container , { transcript, messages } ) ;
1764-
1765- renderMessages ( [ existing ] ) ;
1766- const attachmentOnly = {
1767- testVirtualRow : true ,
1768- testVirtualKey : "assistant-missing-attachment" ,
1769- testVirtualRole : "assistant" ,
1770- role : "assistant" ,
1771- content : [
1772- {
1773- type : "attachment_error" ,
1774- attachment : { code : "file-not-found" , kind : "document" , label : "missing.pdf" } ,
1775- } ,
1776- ] ,
1777- } ;
1778- renderMessages ( [ existing , attachmentOnly ] ) ;
1779- expect ( container . querySelector ( ".chat-transcript-announcement" ) ?. textContent ) . toBe (
1780- "missing.pdf: Not sent. File not found. Check the path and try again." ,
1781- ) ;
1752+ it . each ( [ "ordinary" , "active" , "completed" ] ) (
1753+ "announces named attachment failures within the cap in %s assistant rows" ,
1754+ ( flow ) => {
1755+ const transcript = createTestTranscript ( ) ;
1756+ const container = document . createElement ( "div" ) ;
1757+ const existing = {
1758+ testVirtualRow : true ,
1759+ testVirtualKey : "assistant-existing" ,
1760+ testVirtualRole : "assistant" ,
1761+ role : "assistant" ,
1762+ content : "Existing answer" ,
1763+ } ;
1764+ const renderMessages = ( messages : unknown [ ] ) =>
1765+ renderChatInto ( container , { transcript, messages } ) ;
1766+
1767+ renderMessages ( [ existing ] ) ;
1768+ expect ( container . querySelector ( ".chat-transcript-announcement" ) ?. textContent ) . toBe ( "" ) ;
1769+ const attachmentOnly = {
1770+ testVirtualRow : true ,
1771+ testVirtualKey : "assistant-missing-attachment" ,
1772+ testVirtualRole : "assistant" ,
1773+ role : "assistant" ,
1774+ content : [
1775+ {
1776+ type : "attachment_error" ,
1777+ attachment : { code : "file-not-found" , kind : "document" , label : "missing.pdf" } ,
1778+ } ,
1779+ ] ,
1780+ } ;
1781+ renderMessages ( [ existing , attachmentOnly ] ) ;
1782+ expect ( container . querySelector ( ".chat-transcript-announcement" ) ?. textContent ) . toBe (
1783+ "missing.pdf: Not sent. File not found. Check the path and try again." ,
1784+ ) ;
17821785
1783- const mixed = {
1784- testVirtualRow : true ,
1785- testVirtualKey : "assistant-mixed-attachments" ,
1786- testVirtualRole : "assistant" ,
1787- role : "assistant" ,
1788- content : [
1789- { type : "text" , text : "Partial result" } ,
1790- {
1791- type : "attachment_error" ,
1792- attachment : {
1793- code : "unsupported-format" ,
1794- kind : "document" ,
1795- label : "settings.toml" ,
1786+ const mixed = {
1787+ testVirtualRow : true ,
1788+ testVirtualKey : "assistant-mixed-attachments" ,
1789+ testVirtualRole : "assistant" ,
1790+ role : "assistant" ,
1791+ content : [
1792+ { type : "text" , text : "Partial result" } ,
1793+ {
1794+ type : "attachment_error" ,
1795+ attachment : {
1796+ code : "unsupported-format" ,
1797+ kind : "document" ,
1798+ label : "settings.toml" ,
1799+ } ,
17961800 } ,
1797- } ,
1798- ] ,
1799- } ;
1800- renderMessages ( [ existing , attachmentOnly , mixed ] ) ;
1801- expect ( container . querySelector ( ".chat-transcript-announcement" ) ?. textContent ) . toBe (
1802- "Partial result settings.toml: Not sent. Rejected by the local attachment allowlist. Send a supported file type." ,
1803- ) ;
1801+ ] ,
1802+ } ;
1803+ renderMessages ( [ existing , attachmentOnly , mixed ] ) ;
1804+ const mixedAnnouncement = container . querySelector (
1805+ ".chat-transcript-announcement" ,
1806+ ) ?. textContent ;
18041807
1805- const runBoundary = {
1806- kind : "group" as const ,
1807- key : "group:user:attachment-run" ,
1808- role : "user" as const ,
1809- messages : [
1810- {
1811- key : "user:attachment-run" ,
1812- message : {
1813- role : "user" ,
1814- content : "Send the attachment" ,
1815- __openclaw : {
1816- id : "user:attachment-run" ,
1817- idempotencyKey : "attachment-run:user" ,
1808+ const runBoundary = {
1809+ kind : "group" as const ,
1810+ key : "group:user:attachment-run" ,
1811+ role : "user" as const ,
1812+ messages : [
1813+ {
1814+ key : "user:attachment-run" ,
1815+ message : {
1816+ role : "user" ,
1817+ content : "Send the attachment" ,
1818+ __openclaw : {
1819+ id : "user:attachment-run" ,
1820+ idempotencyKey : "attachment-run:user" ,
1821+ } ,
18181822 } ,
18191823 } ,
1820- } ,
1821- ] ,
1822- timestamp : 1 ,
1823- isStreaming : false ,
1824- } ;
1825- const completedFailure = {
1826- kind : "group" as const ,
1827- key : "group: assistant:attachment-run" ,
1828- role : "assistant" as const ,
1829- messages : [
1830- {
1831- key : "assistant:attachment-run" ,
1832- message : {
1833- role : "assistant" ,
1834- content : attachmentOnly . content ,
1835- runId : "attachment-run" ,
1824+ ] ,
1825+ timestamp : 1 ,
1826+ isStreaming : false ,
1827+ } ;
1828+ const completedFailure = {
1829+ kind : "group" as const ,
1830+ key : "group:assistant:attachment-run" ,
1831+ role : "assistant" as const ,
1832+ messages : [
1833+ {
1834+ key : "assistant:attachment-run" ,
1835+ message : {
1836+ role : "assistant" ,
1837+ content : attachmentOnly . content ,
1838+ runId : "attachment-run" ,
1839+ } ,
18361840 } ,
1837- } ,
1838- ] ,
1839- timestamp : 2 ,
1840- isStreaming : false ,
1841- runId : "attachment-run" ,
1842- } ;
1843- vi . mocked ( chatThread . buildCachedChatItems ) . mockReturnValue ( [
1844- runBoundary ,
1845- completedFailure ,
1846- ] as ReturnType < typeof chatThread . buildCachedChatItems > ) ;
1847- renderChatInto ( container , {
1848- transcript,
1849- messages : [ runBoundary , completedFailure ] ,
1850- } ) ;
1851- expect ( container . querySelector ( ".chat-transcript-announcement" ) ?. textContent ) . toBe (
1852- "missing.pdf: Not sent. File not found. Check the path and try again." ,
1853- ) ;
1854- } ) ;
1841+ ] ,
1842+ timestamp : 2 ,
1843+ isStreaming : false ,
1844+ runId : "attachment-run" ,
1845+ } ;
1846+ vi . mocked ( chatThread . buildCachedChatItems ) . mockReturnValue ( [
1847+ runBoundary ,
1848+ completedFailure ,
1849+ ] as ReturnType < typeof chatThread . buildCachedChatItems > ) ;
1850+ renderChatInto ( container , {
1851+ transcript,
1852+ messages : [ runBoundary , completedFailure ] ,
1853+ } ) ;
1854+ expect ( container . querySelector ( ".chat-transcript-announcement" ) ?. textContent ) . toBe (
1855+ "missing.pdf: Not sent. File not found. Check the path and try again." ,
1856+ ) ;
1857+
1858+ for ( const [ index , prose ] of [
1859+ "Here is the requested summary. " . repeat ( 25 ) ,
1860+ `${ "x" . repeat ( 430 ) } 🦞${ "y" . repeat ( 100 ) } ` ,
1861+ ] . entries ( ) ) {
1862+ const message = {
1863+ role : "assistant" ,
1864+ content : [ { type : "text" , text : prose } , ...attachmentOnly . content ] ,
1865+ runId : "attachment-run" ,
1866+ } ;
1867+ const reply = {
1868+ ...completedFailure ,
1869+ key : `group:assistant:long-${ index } ` ,
1870+ messages : [ { key : `assistant:long-${ index } ` , message } ] ,
1871+ isStreaming : flow === "active" ,
1872+ } ;
1873+ const items = flow === "ordinary" ? [ reply ] : [ runBoundary , reply ] ;
1874+ vi . mocked ( chatThread . buildCachedChatItems ) . mockReturnValue ( items ) ;
1875+ renderChatInto ( container , { transcript, messages : items } ) ;
1876+ const announcement = expectDefined (
1877+ container . querySelector ( ".chat-transcript-announcement" ) ?. textContent ,
1878+ "attachment failure announcement" ,
1879+ ) ;
1880+ expect ( announcement ) . toContain (
1881+ "missing.pdf: Not sent. File not found. Check the path and try again." ,
1882+ ) ;
1883+ expect ( announcement ) . toContain ( prose . slice ( 0 , 30 ) ) ;
1884+ expect ( announcement . length ) . toBe ( index === 0 ? 500 : 499 ) ;
1885+ expect ( announcement ) . not . toMatch ( / [ \uD800 - \uDFFF ] / u) ;
1886+
1887+ vi . mocked ( chatThread . buildCachedChatItems ) . mockReturnValue ( [
1888+ ...items . slice ( 0 , - 1 ) ,
1889+ { ...reply , messages : [ { key : `assistant:long-${ index } ` , message : mixed } ] } ,
1890+ ] ) ;
1891+ renderChatInto ( container , { transcript, messages : [ mixed ] } ) ;
1892+ expect ( container . querySelector ( ".chat-transcript-announcement" ) ?. textContent ) . toBe (
1893+ announcement ,
1894+ ) ;
1895+ }
1896+ expect ( mixedAnnouncement ) . toBe (
1897+ "settings.toml: Not sent. Rejected by the local attachment allowlist. Send a supported file type. Partial result" ,
1898+ ) ;
1899+ } ,
1900+ ) ;
18551901
18561902 it ( "announces a run preamble and its later terminal answer separately" , ( ) => {
18571903 const transcript = createTestTranscript ( ) ;
0 commit comments