来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { parseVisionInspectionJson } from '../src/services/inspectionAiService';
|
|
|
|
describe('parseVisionInspectionJson', () => {
|
|
it('keeps model B when basis says no local rot (negation must not downgrade)', () => {
|
|
const result = parseVisionInspectionJson({
|
|
grade: 'B',
|
|
score: 90,
|
|
damage_types: [],
|
|
issues: [],
|
|
basis: ['两颗白菜整体色泽鲜绿润白,表皮完整,无局部变色、软烂、发黑'],
|
|
conclusion: '本次验收的白菜整体新鲜度良好,无明显坏损,符合B级生鲜标准',
|
|
suggestion: '可正常入库,按常规生鲜流程存储销售即可',
|
|
confidence: 93,
|
|
});
|
|
expect(result.grade).toBe('B');
|
|
expect(result.score).toBe(90);
|
|
expect(result.damage_types).toEqual([]);
|
|
expect(result.issues.join('')).not.toContain('可见尾部');
|
|
expect(result.conclusion).toContain('B级');
|
|
});
|
|
|
|
it('keeps model D and original conclusion without regex rewrite', () => {
|
|
const result = parseVisionInspectionJson({
|
|
grade: 'D',
|
|
score: 60,
|
|
damage_types: ['腐烂'],
|
|
issues: ['尾部约3cm区域发软变色'],
|
|
basis: ['可见局部尾部发黑'],
|
|
conclusion: '不合格,建议退供处理',
|
|
suggestion: '建议退供并记录供应商考核',
|
|
});
|
|
expect(result.grade).toBe('D');
|
|
expect(result.score).toBe(60);
|
|
expect(result.damage_types).toEqual(['腐烂']);
|
|
expect(result.conclusion).toBe('不合格,建议退供处理');
|
|
});
|
|
|
|
it('does not force rotten type or lower score from damage words in text', () => {
|
|
const result = parseVisionInspectionJson({
|
|
grade: 'B',
|
|
score: 88,
|
|
damage_types: [],
|
|
issues: ['表皮局部霉斑未确认,整体可入库'],
|
|
basis: [],
|
|
conclusion: '合格验收,建议正常入库',
|
|
});
|
|
expect(result.grade).toBe('B');
|
|
expect(result.score).toBe(88);
|
|
expect(result.damage_types).toEqual([]);
|
|
});
|
|
|
|
it('falls back to score band when grade is missing', () => {
|
|
const result = parseVisionInspectionJson({
|
|
score: 90,
|
|
conclusion: '合格验收,建议正常入库',
|
|
});
|
|
expect(result.grade).toBe('B');
|
|
expect(result.score).toBe(90);
|
|
});
|
|
});
|