来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
120 lines
4.3 KiB
TypeScript
120 lines
4.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { TenantContext } from '../src/services/tenantScope';
|
|
import { executeCapability, listCapabilities } from '../src/capabilities/registry';
|
|
import { registerBuiltinCapabilities } from '../src/capabilities/registerBuiltins';
|
|
import { routeModules } from '../src/capabilities/routeModules';
|
|
import { SYSTEM_PROMPT } from '../src/mcp/orderEntryAgentHost';
|
|
|
|
registerBuiltinCapabilities();
|
|
|
|
const superAdmin: TenantContext = {
|
|
userId: 'u1',
|
|
roles: ['super_admin'],
|
|
permissions: [],
|
|
branchCode: 'BR001',
|
|
supplierCode: null,
|
|
purchaserCode: null,
|
|
isSuperAdmin: true,
|
|
isBranchAdmin: false,
|
|
isInternalStaff: true,
|
|
isSupplierAccount: false,
|
|
};
|
|
|
|
describe('explain simple pages', () => {
|
|
it('navigates trace / quality-reports / units without write tools', async () => {
|
|
const pages = [
|
|
{ path: '/trace', label: '商品溯源' },
|
|
{ path: '/purchase/quality-reports', label: '检验报告' },
|
|
{ path: '/products/units', label: '单位管理' },
|
|
];
|
|
const trace = await executeCapability('explain_product_trace', {
|
|
userId: 'u1',
|
|
ctx: superAdmin,
|
|
args: { sync_page: true },
|
|
surface: 'web',
|
|
visiblePages: pages,
|
|
});
|
|
expect(trace.ok).toBe(true);
|
|
if (trace.ok) {
|
|
const data = trace.data as { path: string; how_to: string; ui: Array<{ path?: string }> };
|
|
expect(data.path).toBe('/trace');
|
|
expect(data.how_to).toMatch(/入库日/);
|
|
expect(data.ui.some((row) => row.path === '/trace')).toBe(true);
|
|
}
|
|
|
|
const reports = await executeCapability('explain_quality_reports', {
|
|
userId: 'u1',
|
|
ctx: superAdmin,
|
|
args: {},
|
|
surface: 'web',
|
|
visiblePages: pages,
|
|
});
|
|
expect(reports.ok).toBe(true);
|
|
if (reports.ok) {
|
|
const data = reports.data as { path: string };
|
|
expect(data.path).toBe('/purchase/quality-reports');
|
|
}
|
|
|
|
const units = await executeCapability('explain_units', {
|
|
userId: 'u1',
|
|
ctx: superAdmin,
|
|
args: {},
|
|
surface: 'web',
|
|
visiblePages: pages,
|
|
});
|
|
expect(units.ok).toBe(true);
|
|
if (units.ok) {
|
|
const data = units.data as { path: string };
|
|
expect(data.path).toBe('/products/units');
|
|
}
|
|
|
|
expect(listCapabilities({ ctx: superAdmin, surface: 'web', modules: ['product-trace'] }).map((c) => c.name)).toEqual([
|
|
'explain_product_trace',
|
|
]);
|
|
expect(listCapabilities({ ctx: superAdmin, surface: 'web', modules: ['quality-reports'] }).every((c) => c.effect === 'read')).toBe(
|
|
true
|
|
);
|
|
expect(listCapabilities({ ctx: superAdmin, surface: 'web', modules: ['unit-dictionary'] }).map((c) => c.name)).toEqual([
|
|
'explain_units',
|
|
]);
|
|
});
|
|
|
|
it('does not name explain tools in SYSTEM_PROMPT', () => {
|
|
expect(SYSTEM_PROMPT).not.toContain('explain_product_trace');
|
|
expect(SYSTEM_PROMPT).not.toContain('explain_quality_reports');
|
|
expect(SYSTEM_PROMPT).not.toContain('explain_units');
|
|
});
|
|
|
|
it('routes 商品溯源 / 检验报告 / 单位管理, not potato order-entry or sku-catalog', () => {
|
|
const visible = [
|
|
'navigate',
|
|
'order-entry',
|
|
'sku-catalog',
|
|
'category-catalog',
|
|
'product-trace',
|
|
'quality-reports',
|
|
'unit-dictionary',
|
|
];
|
|
const trace = routeModules({ text: '商品溯源怎么用', visibleModuleIds: visible });
|
|
expect(trace.modules).toContain('product-trace');
|
|
expect(trace.modules).not.toContain('order-entry');
|
|
|
|
const reports = routeModules({ text: '检验报告在哪', visibleModuleIds: visible });
|
|
expect(reports.modules).toContain('quality-reports');
|
|
expect(reports.modules).not.toContain('order-entry');
|
|
|
|
const units = routeModules({ text: '打开单位管理', visibleModuleIds: visible });
|
|
expect(units.modules).toContain('unit-dictionary');
|
|
expect(units.modules).not.toContain('sku-catalog');
|
|
expect(units.modules).not.toContain('order-entry');
|
|
|
|
const sku = routeModules({ text: '打开商品管理', visibleModuleIds: visible });
|
|
expect(sku.modules).toContain('sku-catalog');
|
|
expect(sku.modules).not.toContain('unit-dictionary');
|
|
|
|
const potato = routeModules({ text: '给某客户录土豆', visibleModuleIds: visible });
|
|
expect(potato.modules).toContain('order-entry');
|
|
expect(potato.modules).not.toContain('product-trace');
|
|
});
|
|
});
|