Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(conversations): add tests for web answer rendering, balance hints, and search parsing

Steven Enamakele4b617a59bd5
diff --git a/app/src/features/conversations/components/AssistantUiToolCall.test.tsx b/app/src/features/conversations/components/AssistantUiToolCall.test.tsx
index a65308061f..3e3622d1b1 100644
--- a/app/src/features/conversations/components/AssistantUiToolCall.test.tsx
+++ b/app/src/features/conversations/components/AssistantUiToolCall.test.tsx
@@ -54,6 +54,63 @@ describe('AssistantUiToolCallCard', () => {
expect(screen.getByTestId('web-search-results')).toHaveTextContent('via Parallel');
});
+ it('renders a web answer with its text, citations and fallback note', () => {
+ render(
+ <AssistantUiToolCallCard
+ toolName="web_answer_tool"
+ args={{ query: 'who won' }}
+ result="Answer for: who won (via Gemini, after Exa)"
+ structured={{
+ kind: 'web_search',
+ query: 'who won',
+ provider: 'Gemini',
+ role: 'answer',
+ answer: 'Team A won the final.',
+ citations: [
+ { url: 'https://news.example/final', title: 'Final report' },
+ { url: 'javascript:alert(1)', title: 'Bad' },
+ ],
+ fallback_from: ['Exa'],
+ results: [],
+ }}
+ status="success"
+ />
+ );
+ expect(screen.getByTestId('web-search-answer')).toHaveTextContent('Team A won the final.');
+ const results = screen.getByTestId('web-search-results');
+ expect(results).toHaveTextContent('1 source · via Gemini, after Exa');
+ const hits = within(results).getAllByTestId('web-search-hit');
+ expect(hits).toHaveLength(1);
+ expect(hits[0]).toHaveAttribute('href', 'https://news.example/final');
+ expect(screen.getByRole('button', { name: /Asked the web/ })).toBeInTheDocument();
+ });
+
+ it('shows an insufficient-balance hint when managed search runs out of balance', () => {
+ render(
+ <AssistantUiToolCallCard
+ toolName="web_search_tool"
+ args={{ query: 'q' }}
+ result="web search failed: your TinyHumans balance is too low"
+ status="error"
+ />
+ );
+ expect(screen.getByTestId('web-search-balance-hint')).toHaveTextContent(
+ /balance is too low for included search/
+ );
+ });
+
+ it('shows no balance hint for other failures', () => {
+ render(
+ <AssistantUiToolCallCard
+ toolName="web_search_tool"
+ args={{ query: 'q' }}
+ result="timed out"
+ status="error"
+ />
+ );
+ expect(screen.queryByTestId('web-search-balance-hint')).toBeNull();
+ });
+
it('swaps the label tense as the call settles', () => {
const { rerender } = render(
<AssistantUiToolCallCard toolName="file_read" args={{ path: 'a.ts' }} status="running" />
diff --git a/app/src/features/conversations/tools/parseWebSearchResult.test.ts b/app/src/features/conversations/tools/parseWebSearchResult.test.ts
index f7ce0944ea..3923408934 100644
--- a/app/src/features/conversations/tools/parseWebSearchResult.test.ts
+++ b/app/src/features/conversations/tools/parseWebSearchResult.test.ts
@@ -1,7 +1,12 @@
import { describe, expect, it } from 'vitest';
import { extractAgentSources } from '../../../utils/toolTimelineFormatting';
-import { extractSearchProvider, parseWebSearchResult } from './parseWebSearchResult';
+import {
+ extractSearchFallbacks,
+ extractSearchProvider,
+ isSearchBalanceError,
+ parseWebSearchResult,
+} from './parseWebSearchResult';
const TEXT = [
'Search results for: rust async traits (via Exa)',
@@ -88,6 +93,119 @@ describe('parseWebSearchResult', () => {
});
});
+ it('reads the answer, citations and fallback from the structured payload', () => {
+ const parsed = parseWebSearchResult('ignored', {
+ kind: 'web_search',
+ query: 'q',
+ provider: 'Gemini',
+ role: 'answer',
+ answer: ' The answer. ',
+ citations: [
+ { url: 'https://a.dev/1', title: 'One' },
+ { url: 'https://b.dev/2', title: null },
+ { url: 'ftp://nope' },
+ ],
+ fallback_from: ['Exa', 42],
+ results: [],
+ });
+ expect(parsed).toEqual({
+ query: 'q',
+ provider: 'Gemini',
+ role: 'answer',
+ answer: 'The answer.',
+ citations: [
+ { title: 'One', url: 'https://a.dev/1', domain: 'a.dev' },
+ { title: 'b.dev', url: 'https://b.dev/2', domain: 'b.dev' },
+ ],
+ fallbackFrom: ['Exa'],
+ results: [],
+ empty: false,
+ });
+ });
+
+ it('flags an unfinished deep-research payload', () => {
+ const parsed = parseWebSearchResult(undefined, {
+ kind: 'web_search',
+ query: 'q',
+ provider: 'Gemini Deep Research',
+ role: 'answer',
+ in_progress: true,
+ results: [],
+ });
+ expect(parsed?.inProgress).toBe(true);
+ expect(parsed?.empty).toBe(true);
+ });
+
+ it('parses the plain-text answer rendering with its sources', () => {
+ const text = [
+ 'Answer for: who won the final (via Gemini, after Exa, Tavily)',
+ '',
+ 'Team A won 2-1.',
+ 'It was close.',
+ '',
+ 'Sources:',
+ '[1] Final report \u2014 https://news.example/final',
+ '[2] https://www.other.example/x',
+ ].join('\n');
+ const parsed = parseWebSearchResult(text);
+ expect(parsed?.query).toBe('who won the final');
+ expect(parsed?.provider).toBe('Gemini');
+ expect(parsed?.fallbackFrom).toEqual(['Exa', 'Tavily']);
+ expect(parsed?.role).toBe('answer');
+ expect(parsed?.answer).toBe('Team A won 2-1.\nIt was close.');
+ expect(parsed?.citations?.map(c => [c.title, c.url])).toEqual([
+ ['Final report', 'https://news.example/final'],
+ ['other.example', 'https://www.other.example/x'],
+ ]);
+ expect(parsed?.results).toEqual([]);
+ expect(parsed?.empty).toBe(false);
+ });
+
+ it('parses the markdown answer rendering with its sources', () => {
+ const md = [
+ '# Answer for: q (via Gemini)',
+ '',
+ 'The answer.',
+ '',
+ '### Sources',
+ '- [Doc](https://docs.example/a)',
+ ].join('\n');
+ const parsed = parseWebSearchResult(md);
+ expect(parsed?.query).toBe('q');
+ expect(parsed?.answer).toBe('The answer.');
+ expect(parsed?.citations?.[0]).toMatchObject({ title: 'Doc', url: 'https://docs.example/a' });
+ });
+
+ it('recognises contents and still-running research headings', () => {
+ const contents = parseWebSearchResult(
+ ['Page contents for: https://a.dev (via Exa)', '1. A page', ' https://a.dev/', ' Body'].join(
+ '\n'
+ )
+ );
+ expect(contents?.role).toBe('contents');
+ expect(contents?.results[0]?.url).toBe('https://a.dev/');
+ const running = parseWebSearchResult('Research still running for: deep q (via Gemini)');
+ expect(running?.inProgress).toBe(true);
+ expect(running?.query).toBe('deep q');
+ });
+
+ it('splits the fallback list out of the via marker', () => {
+ expect(extractSearchProvider('Answer for: q (via Gemini, after Exa)')).toBe('Gemini');
+ expect(extractSearchFallbacks('Answer for: q (via Gemini, after Exa, Brave)')).toEqual([
+ 'Exa',
+ 'Brave',
+ ]);
+ expect(extractSearchFallbacks('Search results for: q (via Exa)')).toEqual([]);
+ expect(extractSearchFallbacks(undefined)).toEqual([]);
+ });
+
+ it('detects the managed-search balance error in text or objects', () => {
+ expect(isSearchBalanceError('Your balance is too low to search')).toBe(true);
+ expect(isSearchBalanceError({ causePlain: 'Balance is too low.' })).toBe(true);
+ expect(isSearchBalanceError('timed out')).toBe(false);
+ expect(isSearchBalanceError(undefined)).toBe(false);
+ });
+
it('returns undefined for output it does not recognise', () => {
expect(parseWebSearchResult('some other text')).toBeUndefined();
expect(parseWebSearchResult(undefined)).toBeUndefined();
@@ -121,4 +239,19 @@ describe('extractAgentSources', () => {
]);
expect(sources[0].title).toBe('Async fn in traits are now stable');
});
+
+ it('lists an answer call\'s citations as sources', () => {
+ const sources = extractAgentSources([
+ {
+ id: 'a1',
+ name: 'web_answer_tool',
+ round: 1,
+ seq: 0,
+ status: 'success',
+ argsBuffer: '{"query":"q"}',
+ result: 'Answer for: q (via Gemini)\n\nYes.\n\nSources:\n[1] Doc \u2014 https://docs.example/a',
+ },
+ ]);
+ expect(sources.map(s => s.url)).toEqual(['https://docs.example/a']);
+ });
});
diff --git a/app/src/features/conversations/tools/toolPresentation.test.ts b/app/src/features/conversations/tools/toolPresentation.test.ts
index e04e88a5d7..e11af12e37 100644
--- a/app/src/features/conversations/tools/toolPresentation.test.ts
+++ b/app/src/features/conversations/tools/toolPresentation.test.ts
@@ -101,6 +101,24 @@ describe('tool labels: regressions', () => {
expect(done('brave_image_search')).toBe('Searched images');
});
+ it('covers the search role tools and provider answer tools', () => {
+ expect(done('web_answer_tool', { query: 'q' })).toBe('Asked the web');
+ expect(describeToolCall({ name: 'web_answer_tool', args: { query: 'q' } }).chip).toBe('q');
+ for (const name of ['web_answer_tool', 'gemini_agentic_search', 'exa_answer']) {
+ expect(describeToolCall({ name }).body, name).toBe('webSearch');
+ }
+ expect(done('gemini_deep_research')).toBe('Researched');
+ expect(describeToolCall({ name: 'gemini_deep_research' }).body).toBe('webSearch');
+ expect(done('web_contents_tool', { urls: ['https://a.dev/x', 'https://b.dev'] })).toBe(
+ 'Read pages'
+ );
+ expect(
+ describeToolCall({ name: 'web_contents_tool', args: { urls: ['https://a.dev/x'] } }).body
+ ).toBe('webFetch');
+ // Parallel was removed from the core, but old transcripts still render.
+ expect(done('parallel_research')).toBe('Researched');
+ });
+
it('describes the deferred-tool bridge as the tool it calls', () => {
expect(done('tool_call', { name: 'SLACK_SEND_MESSAGE', arguments: {} })).toBe('Used Slack');
expect(done('tool_call', { name: 'file_read', arguments: { path: '/a/b/c/d.ts' } })).toBe(