Files
WechatExplorer/tests/unit/query-agent-poc-cli.test.ts
T
Wxw-Gu ab3b3731b7 feat: 重构问问微信并完善知识库增量检索
统一问问微信与 Agent Hub 的查询链路
完善查询覆盖度、新鲜度和部分结果表达,避免索引滞后产生错误结论
基于会话实现真正的增量追新与历史补齐
支持后台同步、取消恢复、重启续传以及同步期间继续查询
优化知识库跨会话检索、同步状态、进度展示和侧栏布局
2026-09-11 17:44:48 +08:00

74 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { parsePocInvocation, parsePocQuestion } from '../../src/main/query-agent-poc-cli'
describe('Query Agent POC CLI 参数解析', () => {
it('移除开头的分隔符 --', () => {
expect(parsePocQuestion(['--', '我和BOBO第一次聊了什么'])).toBe('我和BOBO第一次聊了什么')
})
it('没有分隔符时保持原样', () => {
expect(parsePocQuestion(['我和BOBO第一次聊了什么'])).toBe('我和BOBO第一次聊了什么')
})
it('不删除问题正文中间的合法 --', () => {
expect(parsePocQuestion(['测试', '--', '内容'])).toBe('测试 -- 内容')
})
it('开头分隔符只移除一个,后续 -- 仍是正文', () => {
expect(parsePocQuestion(['--', '--', '内容'])).toBe('-- 内容')
expect(parsePocQuestion(['--', 'a', '--', 'b'])).toBe('a -- b')
})
it('多段参数按空格拼接,并去掉首尾空白', () => {
expect(parsePocQuestion([' ', 'BOBO', '上个月', '有没有给我发过文件 '])).toBe('BOBO 上个月 有没有给我发过文件')
})
it('只有分隔符或空参数时返回空字符串', () => {
expect(parsePocQuestion(['--'])).toBe('')
expect(parsePocQuestion([])).toBe('')
})
it('不修改传入的数组', () => {
const argv = ['--', '问题']
parsePocQuestion(argv)
expect(argv).toEqual(['--', '问题'])
})
})
describe('parsePocInvocation — 诊断模式与搜索范围', () => {
it('无 --tool 时是自然语言模式,并把 --scope 从问题里剥掉', () => {
expect(parsePocInvocation(['我和 BOBO 第一次聊了什么'])).toMatchObject({
kind: 'question',
question: '我和 BOBO 第一次聊了什么'
})
const scoped = parsePocInvocation([
'--scope',
'{"kind":"groups"}',
'最近谁聊过健身'
])
expect(scoped).toMatchObject({ kind: 'question', question: '最近谁聊过健身' })
if (scoped.kind !== 'question') throw new Error('unreachable')
expect(scoped.scope).toEqual({ kind: 'groups' })
})
it('裸工具模式把 scope 合并进工具参数(Host 注入,LLM 提供不了)', () => {
const invocation = parsePocInvocation([
'--tool',
'search_messages',
'--args',
'{"timeRange":{"kind":"all"},"query":"健身"}',
'--scope',
'{"kind":"groups"}'
])
if (invocation.kind !== 'tool') throw new Error('unreachable')
expect(invocation.toolName).toBe('search_messages')
expect(invocation.args).toMatchObject({ query: '健身', scope: { kind: 'groups' } })
})
it('非法 scope / 缺少 conversationId 会明确报错', () => {
expect(() => parsePocInvocation(['--scope', '{"kind":"nope"}', 'x'])).toThrow(/scope.kind/)
expect(() => parsePocInvocation(['--scope', '{"kind":"contact"}', 'x'])).toThrow(/conversationId/)
expect(() => parsePocInvocation(['--scope', 'not-json', 'x'])).toThrow(/合法 JSON/)
})
})