1- import { expect } from 'vitest' ;
2- import { renderToolUse , renderToolResult } from './registry.js' ;
1+ import { describe , expect , it } from 'vitest' ;
2+ import { renderToolResult } from './registry.js' ;
33
44/** Common XSS payloads for renderer escaping assertions. */
55export const XSS_SCRIPT = '<script>alert(1)</script>' ;
66export const XSS_IMG = '<img onerror=alert(1)>' ;
77
8- /**
9- * Render a tool-use card via the registry and return the HTML string.
10- */
11- export function mountToolUse ( tool ) {
12- return renderToolUse ( tool ) ;
13- }
14-
15- /**
16- * Render a tool-result card via the registry and return the HTML string.
17- */
18- export function mountToolResult ( parsed ) {
19- return renderToolResult ( parsed ) ;
20- }
21-
228/**
239 * Assert raw HTML fragments are escaped (not present verbatim).
2410 */
@@ -34,3 +20,33 @@ export function expectNoRawHtml(html, rawFragments) {
3420export function expectEscaped ( html , escapedFragment ) {
3521 expect ( html ) . toContain ( escapedFragment ) ;
3622}
23+
24+ /**
25+ * Shared behavioral tests for summary-only tool_result renderers (Edited/Plan/Wrote).
26+ */
27+ export function describeSummaryOnlyResult (
28+ render ,
29+ { suiteName, resultType, label, samplePath } ,
30+ ) {
31+ describe ( suiteName , ( ) => {
32+ it ( `renders ${ label . toLowerCase ( ) } file path in summary` , ( ) => {
33+ const html = render ( { result_type : resultType , file_path : samplePath } ) ;
34+ expect ( html ) . toContain ( `${ label } : ${ samplePath } ` ) ;
35+ expect ( html ) . toContain ( 'tool-result' ) ;
36+ } ) ;
37+
38+ it ( 'handles missing file path' , ( ) => {
39+ const html = render ( { result_type : resultType } ) ;
40+ expect ( html ) . toContain ( `${ label } :` ) ;
41+ expect ( html ) . not . toContain ( 'undefined' ) ;
42+ } ) ;
43+
44+ it ( 'escapes HTML in file path via registry' , ( ) => {
45+ const html = renderToolResult ( {
46+ result_type : resultType ,
47+ file_path : XSS_SCRIPT ,
48+ } ) ;
49+ expectNoRawHtml ( html , [ XSS_SCRIPT ] ) ;
50+ } ) ;
51+ } ) ;
52+ }
0 commit comments