Files
SupplierSystem/server/tests/promptRegistryRender.test.ts
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库: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 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

73 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { renderTemplate } from '../src/services/promptRegistryService';
import {
getPromptDefault,
getPromptUsageRank,
PROMPT_DEFAULTS,
RETIRED_PROMPT_KEYS,
} from '../src/prompts/defaults';
describe('promptRegistry render + defaults', () => {
it('replaces {{var}} placeholders', () => {
expect(renderTemplate('hello {{name}}', { name: 'world' })).toBe('hello world');
expect(renderTemplate('a={{a}} b={{ missing }}', { a: 1 })).toBe('a=1 b=');
});
it('registers all catalog prompts as wired', () => {
expect(PROMPT_DEFAULTS.length).toBeGreaterThanOrEqual(14);
expect(PROMPT_DEFAULTS.every((d) => d.wired)).toBe(true);
expect(getPromptDefault('order.parse.text')?.wired).toBe(true);
expect(getPromptDefault('order.parse.text')?.systemTemplate).toContain('{{category_list}}');
expect(getPromptDefault('order.parse.text')?.systemTemplate).toContain('打字、粘贴');
expect(getPromptDefault('order.parse.image')?.wired).toBe(true);
expect(getPromptDefault('order.parse.image')?.modality).toBe('image');
expect(getPromptDefault('order.parse.image')?.systemTemplate).toContain('一行两品');
expect(getPromptDefault('order.parse.image')?.systemTemplate).toContain('禁止认成数字');
expect(getPromptDefault('cost.free.voucher_amount')?.wired).toBe(true);
expect(getPromptDefault('cost.free.voucher_amount')?.modality).toBe('image');
expect(getPromptDefault('cost.free.voucher_amount')?.systemTemplate).toContain('document_kind');
expect(getPromptDefault('market.auto_configure')?.wired).toBe(true);
});
it('已退休提示词不再出现在代码清单里(设计 20260914-ai-prompt-retire-unused)', () => {
expect(RETIRED_PROMPT_KEYS).toEqual([
'order.parse.image_alt',
'order.parse.miss_supplement',
'order.parse.qty_verify',
'order.parse.image_ocr',
'order.parse.audio',
'weigh.recognize.catalog',
]);
for (const key of RETIRED_PROMPT_KEYS) {
expect(getPromptDefault(key)).toBeNull();
expect(PROMPT_DEFAULTS.some((d) => d.featureKey === key)).toBe(false);
}
// 同一 key 不得同时出现在「在用清单」与「已退休清单」,否则归档与种子互相打架
const live = new Set(PROMPT_DEFAULTS.map((d) => d.featureKey));
expect(RETIRED_PROMPT_KEYS.filter((k) => live.has(k))).toEqual([]);
expect(new Set(RETIRED_PROMPT_KEYS).size).toBe(RETIRED_PROMPT_KEYS.length);
});
it('renders category_list into the order parse prompts', () => {
for (const key of ['order.parse.text', 'order.parse.image'] as const) {
const tpl = getPromptDefault(key)!.systemTemplate;
expect(renderTemplate(tpl, { category_list: '干杂(CAT_DRY)' })).toContain('干杂(CAT_DRY)');
expect(tpl).toContain('"分类"');
expect(tpl).toContain('下方列表完全空白');
}
});
it('renders free-cost type placeholders', () => {
const tpl = getPromptDefault('cost.free.categorize')!.systemTemplate;
expect(renderTemplate(tpl, { type_lines: '- a(A)', type_codes: 'a|b' })).toContain('- a(A)');
});
it('ranks order parse ahead of invoice ocr', () => {
expect(getPromptUsageRank('order.parse.image')).toBeLessThan(getPromptUsageRank('order.parse.text'));
expect(getPromptUsageRank('order.parse.text')).toBeLessThan(getPromptUsageRank('invoice.ocr'));
expect(getPromptUsageRank('inspection.quality.photo')).toBeLessThan(
getPromptUsageRank('menu.group.icon_svg')
);
});
});