@@ -62,6 +62,95 @@ describe("custodian panel toggle", () => {
6262 } ) ;
6363} ) ;
6464
65+ describe ( "session workspace artifacts" , ( ) => {
66+ function createArtifactHost ( params : { data : string ; mimeType : string ; title ?: string } ) {
67+ const handleOpenSidebar = vi . fn ( ) ;
68+ const request = vi . fn ( ) . mockResolvedValue ( {
69+ artifact : {
70+ id : "artifact-1" ,
71+ mimeType : params . mimeType ,
72+ title : params . title ?? "Unicode artifact" ,
73+ } ,
74+ data : params . data ,
75+ encoding : "base64" ,
76+ } ) ;
77+ const state = {
78+ client : { request } ,
79+ connected : true ,
80+ handleOpenSidebar,
81+ hello : gatewayHello ( [ ] ) ,
82+ sessionKey : "agent:main:current" ,
83+ sessions : { } ,
84+ } as unknown as SessionWorkspaceHost ;
85+ return { handleOpenSidebar, request, state } ;
86+ }
87+
88+ it . each ( [
89+ {
90+ content : "Résumé 東京 🦀" ,
91+ fence : "```" ,
92+ mimeType : "text/plain" ,
93+ } ,
94+ {
95+ content : JSON . stringify ( { message : "Résumé 東京 🦀" } ) ,
96+ fence : "```json" ,
97+ mimeType : "application/json" ,
98+ } ,
99+ ] ) (
100+ "decodes UTF-8 $mimeType artifacts without corrupting visible or raw text" ,
101+ async ( testCase ) => {
102+ const data = btoa ( String . fromCharCode ( ...new TextEncoder ( ) . encode ( testCase . content ) ) ) ;
103+ const { handleOpenSidebar, state } = createArtifactHost ( {
104+ data,
105+ mimeType : testCase . mimeType ,
106+ } ) ;
107+
108+ createSessionWorkspaceProps ( state ) . onOpenArtifact ( "artifact-1" ) ;
109+
110+ await vi . waitFor ( ( ) => expect ( handleOpenSidebar ) . toHaveBeenCalledOnce ( ) ) ;
111+ expect ( handleOpenSidebar . mock . calls [ 0 ] ?. [ 0 ] ) . toEqual ( {
112+ kind : "markdown" ,
113+ content : `# Unicode artifact\n\n${ testCase . fence } \n${ testCase . content } \n\`\`\`` ,
114+ rawText : testCase . content ,
115+ } ) ;
116+ } ,
117+ ) ;
118+
119+ it ( "preserves inline image artifacts as their original base64 data URLs" , async ( ) => {
120+ const data = "iVBORw0KGgo=" ;
121+ const { handleOpenSidebar, state } = createArtifactHost ( {
122+ data,
123+ mimeType : "image/png" ,
124+ title : "preview.png" ,
125+ } ) ;
126+
127+ createSessionWorkspaceProps ( state ) . onOpenArtifact ( "artifact-1" ) ;
128+
129+ await vi . waitFor ( ( ) => expect ( handleOpenSidebar ) . toHaveBeenCalledOnce ( ) ) ;
130+ expect ( handleOpenSidebar . mock . calls [ 0 ] ?. [ 0 ] ) . toEqual ( {
131+ kind : "image" ,
132+ mimeType : "image/png" ,
133+ rawText : null ,
134+ src : `data:image/png;base64,${ data } ` ,
135+ title : "preview.png" ,
136+ } ) ;
137+ } ) ;
138+
139+ it ( "reports malformed base64 artifact data as a visible workspace error" , async ( ) => {
140+ const { handleOpenSidebar, state } = createArtifactHost ( {
141+ data : "not-base64!" ,
142+ mimeType : "text/plain" ,
143+ } ) ;
144+
145+ createSessionWorkspaceProps ( state ) . onOpenArtifact ( "artifact-1" ) ;
146+
147+ await vi . waitFor ( ( ) =>
148+ expect ( createSessionWorkspaceProps ( state ) . error ) . toMatch ( / I n v a l i d C h a r a c t e r E r r o r | i n v a l i d / i) ,
149+ ) ;
150+ expect ( handleOpenSidebar ) . not . toHaveBeenCalled ( ) ;
151+ } ) ;
152+ } ) ;
153+
65154describe ( "openSessionWorkspaceFile" , ( ) => {
66155 it ( "opens Markdown with a canonical Gateway- and pane-scoped draft identity" , async ( ) => {
67156 const handleOpenSidebar = vi . fn ( ) ;
0 commit comments