来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
import { beforeEach, describe, expect, it } from 'vitest';
|
|
import { compactToolResultForModel, runOrderEntryAgentBrowse, showQueryFromList } from '../src/mcp/orderEntryAgentHost';
|
|
import {
|
|
assertPendingBrowse,
|
|
isLinkyValue,
|
|
mergeBrowsePatch,
|
|
sanitizeQueryRow,
|
|
} from '../src/mcp/queryBrowse';
|
|
import { resetAssistantSessionsForTests, writeAssistantSession } from '../src/services/assistantSessionStore';
|
|
|
|
describe('query browse', () => {
|
|
beforeEach(() => {
|
|
resetAssistantSessionsForTests();
|
|
});
|
|
|
|
it('strips image urls from query rows', () => {
|
|
expect(isLinkyValue('https://oss.example/a.jpg')).toBe(true);
|
|
expect(sanitizeQueryRow({ order_code: 'O1', photo_url: 'https://x/a.jpg', signed_url: 'https://x/b' })).toEqual({
|
|
order_code: 'O1',
|
|
});
|
|
});
|
|
|
|
it('compact tool result still previews 8 rows', () => {
|
|
const orders = Array.from({ length: 25 }, (_, i) => ({ order_code: `O${i}`, photo_url: 'https://x/a.jpg' }));
|
|
const compact = compactToolResultForModel('list_orders', {
|
|
ok: true,
|
|
data: { count: 37, orders },
|
|
}) as { orders: unknown[] };
|
|
expect(compact.orders).toHaveLength(8);
|
|
expect(JSON.stringify(compact.orders)).not.toContain('https://');
|
|
});
|
|
|
|
it('rejects a stale browse_id', () => {
|
|
expect(() => assertPendingBrowse({ browse_id: 'b1', capability: 'list_orders', args: {} }, 'other')).toThrow(
|
|
/查询已失效/
|
|
);
|
|
});
|
|
|
|
it('keeps frozen args when only page changes', () => {
|
|
const next = mergeBrowsePatch(
|
|
{
|
|
browse_id: 'b1',
|
|
capability: 'list_orders',
|
|
args: { date_from: '2026-09-17', date_to: '2026-09-23', search: '大安', page: 1 },
|
|
},
|
|
{ page: 2 }
|
|
);
|
|
expect(next.page).toBe(2);
|
|
expect(next.date_from).toBe('2026-09-17');
|
|
expect(next.search).toBe('大安');
|
|
expect(next.sync_page).toBeUndefined();
|
|
});
|
|
|
|
it('browse mismatch when session has no pendingBrowse', async () => {
|
|
await writeAssistantSession('u1', 's1', {
|
|
lastModule: 'order-management',
|
|
lastUser: '近七天订单',
|
|
lastReply: '37条',
|
|
traces: [],
|
|
});
|
|
await expect(
|
|
runOrderEntryAgentBrowse({
|
|
userId: 'u1',
|
|
ctx: { userId: 'u1', branchCode: 'BR002', roles: [], permissions: [], isSuperAdmin: false } as never,
|
|
sessionId: 's1',
|
|
browseId: 'missing',
|
|
})
|
|
).rejects.toMatchObject({ code: 'browse_mismatch' });
|
|
const card = showQueryFromList('list_orders', {
|
|
count: 2,
|
|
orders: [
|
|
{ order_code: 'A', image: 'https://x/a.png' },
|
|
{ order_code: 'B' },
|
|
],
|
|
});
|
|
expect(card?.type).toBe('show_query');
|
|
if (card?.type === 'show_query') {
|
|
expect(card.payload.rows.every((row) => !('image' in row))).toBe(true);
|
|
}
|
|
});
|
|
});
|