Files
llama.cpp/tools/ui/tests/unit/search-results.test.ts
T
Aleksander GrygierandGitHub 32beb244f5 ui: Agentic Content UX improvements (#25450)
* feat: Add shimmer text animation for processing state indicators

* feat: Redesign CollapsibleContentBlock component with improved UX

* feat: Add conditional setting display support with dependsOn field

* feat: Add showAgenticTurnStats setting for per-turn statistics

* feat: Update ChatMessageAgenticContent with improved UI and new features

* feat: Enhance file read tool UI/UX

* feat: Refine styling of collapsible content and code preview blocks

* feat: add terminal variant to CollapsibleContentBlock

* feat: add built-in tools UI registry

* feat: extract ChatMessageReasoningBlock and ChatMessageToolCallBlock

* refactor: simplify ChatMessageAgenticContent to use extracted blocks

* fix: correct markdown content block margin spacing

* fix: reorganize SettingsChatFields layout and reset button positioning

* fix: use direct map access in agentic store session methods

* refactor: remove reasoning preview/throttle system from CollapsibleContentBlock

* feat: add auto-scroll to reasoning block and remove showThoughtInProgress

* feat: add ChatMessageToolCallDateTime component and support for new tool types

* feat: improve auto-scroll reliability in reasoning block with RAF coalescing and MutationObserver

* feat: show MCP server favicon for tools without a built-in icon

* feat: add search-results parsing utilities and tests

* feat: add ChatMessageToolCallSearchResults component

* feat: integrate search results rendering into ChatMessageAgenticContent

* feat: display tool call input alongside output in ChatMessageToolCallBlock

* style: use muted foreground color in reasoning block content

* chore: Format

* feat: Refine reasoning block layout and make pending thoughts display configurable

* feat: Stream tool call code blocks with auto-scroll and handle partial JSON

* feat: add streaming permission gate infrastructure

* feat: wire permission gate into the agentic loop

* fix: bail out on abort and skip already-approved tool calls

* fix: clear partial tool calls on abort and savePartialResponse

* test: cover partial tool call cleanup end-to-end

* refactor: Remove streaming permission gate logic

* fix: Correct autoscroll and streaming gates for tool calls and reasoning blocks

* refactor: Chat Message Assistant componentization

* fix: Show health metadata for disabled MCP servers and promote connections on enable

* fix: Inherit global enabled state for missing MCP per-chat overrides

* refactor: Cleanup

* refactor: Split ChatMessageToolCallBlock into dedicated components

* feat: Add live streaming and auto-scroll for tool execution output

* feat: Add line numbers and change markers to file edit diffs

* chore: Formatting

* feat: Add type definitions and utilities for recommended MCP servers

* feat: Add recommended MCP servers configuration and storage key

* feat: Add McpServerCardCompact component for recommended servers

* feat: Add recommended servers section to Add New Server dialog

* feat: Update McpServerForm to support authorization requirements

* feat: Add select-none classes for text selection prevention

* feat: Add recommended MCP server icon assets

* refactor: Store dismissed MCP recommendations as a boolean flag

* feat: Render tool results as JSON or Markdown based on detected content type

* feat: UI improvement

* feat: Render search block early and update heading to show execution state

* fix: Prevent non-web-search tools from triggering the search UI block

* refactor: Cleanup

* refactor: Extract hardcoded icon size classes into shared constants

* refactor: Extract hardcoded tool result separator into a shared constant

* refactor: Tool Calls UI/logic

* refactor: Cleanup

* refactor: Cleanup

* refactor: Cleanup
2026-07-15 20:31:45 +02:00

119 lines
3.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
extractSearchResults,
extractSearchQuery,
faviconForUrl,
isWebSearchToolName
} from '$lib/utils/search-results';
describe('extractSearchResults', () => {
it('parses the Exa fixture with multiple results', () => {
const fixture = `Title: World Cup 2026 | Match schedule, fixtures
URL: https://www.fifa.com/articles/match-schedule
Published: 2026-06-22T00:01:00.000Z
Author: N/A
Highlights:
Find out the full match schedule for World Cup 2026
---
Title: 2026 FIFA World Cup match schedule
URL: https://www.espn.com/soccer/story/abc/def
Published: 2026-07-08T07:07:00.000Z
Author: ESPN
Highlights:
Round of 32 · Tuesday, July 7
---
Title: BBC
URL: https://www.bbc.co.uk/sport/football/world-cup/schedule
Published: N/A
Author: N/A
Highlights:
# FIFA World Cup Schedule
...`;
const results = extractSearchResults(fixture);
expect(results.length).toBe(3);
expect(results[0].title).toContain('World Cup 2026');
expect(results[0].url).toBe('https://www.fifa.com/articles/match-schedule');
expect(results[0].published).toBe('2026-06-22T00:01:00.000Z');
// N/A filtered out
expect(results[0].author).toBeUndefined();
expect(results[0].highlights).toContain('match schedule');
expect(results[1].author).toBe('ESPN');
expect(results[2].author).toBeUndefined(); // N/A filtered
});
it('returns empty array for empty input', () => {
expect(extractSearchResults('')).toEqual([]);
expect(extractSearchResults(undefined)).toEqual([]);
expect(extractSearchResults(null)).toEqual([]);
});
it('skips chunks missing title or url', () => {
const txt = `Title: no url here
Highlights:
foo
---
Title: foo
URL: https://x.com
---
just a paragraph
---
Title: b
URL: not a url`;
const results = extractSearchResults(txt);
// Only middle one should pass (has title + url).
expect(results.length).toBe(1);
expect(results[0].url).toBe('https://x.com');
});
it('parses a single result without separators', () => {
const txt = `Title: only one
URL: https://example.com/test
Published: 2026-01-01T00:00:00Z
Author: alice
Highlights:
a highlight`;
const results = extractSearchResults(txt);
expect(results.length).toBe(1);
expect(results[0].title).toBe('only one');
expect(results[0].author).toBe('alice');
expect(results[0].highlights).toBe('a highlight');
});
it('extracts query from JSON toolArgs', () => {
expect(extractSearchQuery('{"query":"foo"}')).toBe('foo');
expect(extractSearchQuery(' {"query":" foo "} ')).toBe('foo');
expect(extractSearchQuery('not json')).toBe('');
expect(extractSearchQuery(null)).toBe('');
expect(extractSearchQuery('{"query":123}')).toBe('');
});
it('resolves favicon URLs from origins', () => {
expect(faviconForUrl('https://example.com/path/to/page')).toBe(
'https://example.com/favicon.ico'
);
expect(faviconForUrl('http://example.com/x')).toBe('http://example.com/favicon.ico');
expect(faviconForUrl('not a url')).toBeNull();
});
});
describe('isWebSearchToolName', () => {
it('excludes tools that take the same query argument but are not web searches', () => {
expect(isWebSearchToolName('search_pull_requests')).toBe(false);
expect(isWebSearchToolName('search_code')).toBe(false);
expect(isWebSearchToolName('search_repositories')).toBe(false);
expect(isWebSearchToolName('search_issues')).toBe(false);
});
it('handles empty / missing input', () => {
expect(isWebSearchToolName(null)).toBe(false);
expect(isWebSearchToolName(undefined)).toBe(false);
expect(isWebSearchToolName('')).toBe(false);
});
it('returns false for unrelated tools', () => {
expect(isWebSearchToolName('web_fetch')).toBe(false);
expect(isWebSearchToolName('read_file')).toBe(false);
expect(isWebSearchToolName('exec_shell_command')).toBe(false);
});
});