fix(bridge): 商品链接兜底与强制检索

This commit is contained in:
wangliang
2026-10-23 13:15:37 +08:00
parent 4d7b89492b
commit 22d96edee6
9 changed files with 414 additions and 3 deletions
+40
View File
@@ -140,3 +140,43 @@ test('guard: rewrites unsupported price but keeps product name', () => {
assert.doesNotMatch(r.content, /fake-a/);
assert.match(r.content, /价格以商品页为准/);
});
test('guard: drops dangling CTA text when a hallucinated product link is removed', () => {
const r = guardReply({
content: '<p>🔹 <strong>Stainless Steel Ring Set</strong> — $2.88<br>✅ 库存:充足<br>→ 查看详情:https://www.yehwang.com/stainless-steel-ring-set-12-pcs</p>',
toolResults: [],
toolCalls: [],
lang: 'zh',
});
assert.equal(r.blocked, true);
assert.ok(r.reasons.includes('stock_price_without_tool'));
assert.deepEqual(r.removed_urls, ['https://www.yehwang.com/stainless-steel-ring-set-12-pcs']);
assert.doesNotMatch(r.content, /查看详情/);
assert.doesNotMatch(r.content, /stainless-steel-ring-set-12-pcs/);
assert.match(r.content, /价格以商品页为准/);
});
test('guard: generic CTA label is removed together with the unverified URL', () => {
const r = guardReply({
content: '商品A — [查看详情](https://www.yehwang.com/fake-a)',
toolResults: [{ products: [{ name: '商品A' }] }],
toolCalls: [{ name: 'search_products', ok: true }],
lang: 'zh',
});
assert.equal(r.blocked, true);
assert.deepEqual(r.removed_urls, ['https://www.yehwang.com/fake-a']);
assert.doesNotMatch(r.content, /查看详情/);
assert.match(r.content, /商品A/);
});
test('guard: keeps meaningful anchor text when the URL is removed', () => {
const r = guardReply({
content: 'You can read [the product care guide](https://www.yehwang.com/fake-guide) for details.',
toolResults: [],
toolCalls: [],
lang: 'en',
});
assert.equal(r.blocked, true);
assert.doesNotMatch(r.content, /fake-guide/);
assert.match(r.content, /the product care guide/);
});