perf(bridge): 商品检索改用短关键词并恢复分阶段计时

This commit is contained in:
wangliang
2026-10-23 16:32:03 +08:00
parent a0d386b752
commit 0959777048
6 changed files with 174 additions and 12 deletions
+12
View File
@@ -91,6 +91,18 @@ test('search_products: maps RPC items and caps results', async () => {
assert.equal(rpc.calls[0].method, '/product/list');
});
test('search_products: sends cleaned short keyword to catalog RPC for long queries', async () => {
const rpc = fakeRpc(() => ({ data: { list: [{ spuName: 'Steel Ring', minPriceWithCurrency: '€2,50', spuId: 1 }] } }));
const tools = createTools(baseCfg, { rpc, twenty: fakeTwenty() });
const tool = tools.find((t) => t.name === 'search_products');
const out = await tool.handler({ query: 'We need 500 stainless steel rings wholesale under 10 dollars', limit: 3 }, { verified: false });
const cmd = rpc.calls[0].params[0];
assert.equal(cmd.keyword, 'stainless steel rings');
assert.equal(out.query_used, 'stainless steel rings');
// 给客户看的兜底搜索链接仍用原话
assert.match(out.search_url, /500%20stainless%20steel%20rings/);
});
test('search_products: falls back to site map when catalog returns empty', async () => {
const tools = createTools(baseCfg, {
rpc: fakeRpc(() => []),