Files
Enterprise-Knowledge-Base/frontend/src/utils/agent-tool-display.test.mjs
T
wizardchen 45eab4a95f fix(quick-qa): distinguish web and knowledge base retrieval in pipeline UI
Emit search_source metadata from RAG progress events so quick-answer steps,
summaries, and IM labels no longer mislabel web-only results as knowledge base search.
2026-07-08 00:26:34 +08:00

79 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict'
import test from 'node:test'
import { getAgentToolIconName } from './agent-tool-icons.ts'
import {
getKnowledgeSearchSummaryHtml,
getQueryText,
getRagPipelineStepTitle,
getWikiPageText,
} from './agent-tool-display.ts'
const t = (key, params) => {
if (key === 'agentStream.search.foundResultsFromFiles') {
return `found ${params?.count} from ${params?.files} files`
}
if (key === 'agentStream.ragPipeline.searchingWithQuery') {
return `searching ${params?.query}`
}
return key
}
test('getAgentToolIconName maps rag pipeline tools', () => {
assert.equal(getAgentToolIconName('query_understand'), 'ai-search')
assert.equal(getAgentToolIconName('knowledge_search'), 'data-search')
})
test('getAgentToolIconName maps Wiki tools to semantic search and reading icons', () => {
assert.equal(getAgentToolIconName('wiki_search'), 'search')
assert.equal(getAgentToolIconName('wiki_read_page'), 'file-search')
assert.equal(getAgentToolIconName('wiki_read_source_doc'), 'file-search')
})
test('getQueryText joins unique query strings', () => {
assert.equal(getQueryText({ query: 'foo', queries: ['foo', 'bar'] }), 'foo,bar')
})
test('getQueryText parses JSON-encoded queries string', () => {
assert.equal(
getQueryText({
queries: '["合力天胜游泳俱乐部介绍", "合力天胜游泳训练机构", "合力天胜游泳队"]',
}),
'合力天胜游泳俱乐部介绍,合力天胜游泳训练机构,合力天胜游泳队',
)
})
test('getWikiPageText supports persisted slugs arrays', () => {
assert.equal(
getWikiPageText({ slugs: ['entity/知识助理', 'concept/API管理'] }),
'entity/知识助理、concept/API管理',
)
assert.equal(getWikiPageText('{"slug":"index"}'), 'index')
})
test('getKnowledgeSearchSummaryHtml includes file count when present', () => {
const html = getKnowledgeSearchSummaryHtml(t, {
results: [{}, {}],
kb_counts: { a: 1, b: 2 },
})
assert.match(html, /found <strong>2<\/strong> from <strong>2<\/strong> files/)
})
test('getRagPipelineStepTitle uses query-aware search labels', () => {
const title = getRagPipelineStepTitle(t, {
tool_name: 'knowledge_search',
pending: true,
arguments: { query: '讯飞开放平台' },
})
assert.equal(title, 'searching 讯飞开放平台')
})
test('getRagPipelineStepTitle uses web labels when search_source is web', () => {
const title = getRagPipelineStepTitle(t, {
tool_name: 'knowledge_search',
pending: false,
success: true,
arguments: { search_source: 'web' },
})
assert.equal(title, 'agentStream.toolStatus.webSearch')
})