Skip to content

Commit 2c1bedd

Browse files
fix(frontend): single-layer tool summary escaping and registry tests
1 parent 05b9f40 commit 2c1bedd

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

static/js/render/registry.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('TOOL_USE_RENDERERS', () => {
4141
expect(html).toContain('<script>');
4242
});
4343

44-
it('renderReadUse escapes file path in body', () => {
44+
it('renderReadUse escapes file path in body and summary', () => {
4545
const html = renderToolUse({
4646
name: 'Read',
4747
input: { file_path: 'C:\\tmp\\<evil>.txt' },
@@ -81,8 +81,8 @@ describe('getToolSummary', () => {
8181
expect(getToolSummary('Bash', { command: 'ls -la' })).toContain('ls -la');
8282
});
8383

84-
it('formats Read summary with escaped path', () => {
85-
expect(getToolSummary('Read', { file_path: 'a<b' })).toContain('&lt;b');
84+
it('formats Read summary as plain text (escaping deferred to wrapToolUse)', () => {
85+
expect(getToolSummary('Read', { file_path: 'a<b' })).toBe('Read: a<b');
8686
});
8787
});
8888

@@ -147,4 +147,11 @@ describe('renderToolResult fallback', () => {
147147
expect(html).toContain('Tool result (custom_type)');
148148
expect(html).toContain('tool-result');
149149
});
150+
151+
it('uses fallback when result_type is an inherited property (e.g. constructor)', () => {
152+
const html = renderToolResult({ result_type: 'constructor' });
153+
expect(html).toContain('Tool result (constructor)');
154+
expect(html).toContain('tool-result');
155+
expect(Object.prototype.hasOwnProperty.call(TOOL_RESULT_RENDERERS, 'constructor')).toBe(false);
156+
});
150157
});

static/js/render/tool_use/summary.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { esc, truncate } from '../../shared/utils.js';
1+
import { truncate } from '../../shared/utils.js';
22

3+
/** Plain-text summaries; HTML escaping happens in wrapToolUse / finishToolResult. */
34
export function getToolSummary(name, inp) {
45
if (name === 'Bash') return `Bash: ${truncate(inp.command || '', 80)}`;
5-
if (name === 'Read') return `Read: ${esc(inp.file_path || '')}`;
6-
if (name === 'Write') return `Write: ${esc(inp.file_path || '')}`;
7-
if (name === 'Edit') return `Edit: ${esc(inp.file_path || '')}`;
8-
if (name === 'Glob') return `Glob: ${esc(inp.pattern || '')}`;
9-
if (name === 'Grep') return `Grep: /${esc(inp.pattern || '')}/` + (inp.path ? ` in ${esc(inp.path)}` : '');
6+
if (name === 'Read') return `Read: ${inp.file_path || ''}`;
7+
if (name === 'Write') return `Write: ${inp.file_path || ''}`;
8+
if (name === 'Edit') return `Edit: ${inp.file_path || ''}`;
9+
if (name === 'Glob') return `Glob: ${inp.pattern || ''}`;
10+
if (name === 'Grep') return `Grep: /${inp.pattern || ''}/` + (inp.path ? ` in ${inp.path}` : '');
1011
if (name === 'WebFetch') return `Fetch: ${truncate(inp.url || '', 80)}`;
1112
if (name === 'WebSearch') return `Search: ${truncate(inp.query || '', 80)}`;
12-
if (name === 'Task') return `Task: ${esc(inp.subagent_type || '')} - ${esc(inp.description || '')}`;
13+
if (name === 'Task') return `Task: ${inp.subagent_type || ''} - ${inp.description || ''}`;
1314
if (name === 'TodoWrite') return 'TodoWrite';
1415
if (name === 'AskUserQuestion') return 'AskUserQuestion';
1516
return name;

0 commit comments

Comments
 (0)