import { readFileSync } from 'node:fs'; import path from 'path'; import { describe, expect, it } from 'vitest'; import { getPromptDefault } from '../src/prompts/defaults'; describe('安卓入库非斤单位不入重量', () => { it('提示词登记进统一 registry,且包含数量识别规则', () => { const catalog = getPromptDefault('weigh.recognize.open'); expect(catalog).toBeTruthy(); expect(catalog!.wired).toBe(true); expect(catalog!.systemTemplate).toContain('"qty":数字或null'); expect(catalog!.systemTemplate).toContain('"unit":"单位或null"'); expect(catalog!.systemTemplate).toContain('计数单位'); expect(catalog!.systemTemplate).toContain('禁止编造'); const inbound = getPromptDefault('weigh.recognize.catalog_inbound'); expect(inbound).toBeTruthy(); expect(inbound!.wired).toBe(true); }); it('weighStationService 走 resolvePrompt,无硬编码提示词,响应透传 suggested_qty/unit', () => { const src = readFileSync( path.join(__dirname, '../src/services/weighStationService.ts'), 'utf8' ); expect(src).toContain("resolvePrompt('weigh.recognize.open'"); expect(src).toContain("resolvePrompt('weigh.recognize.catalog_inbound'"); expect(src).toContain('suggested_qty'); expect(src).toContain('suggested_unit'); // 不再残留硬编码长提示词 expect(src).not.toContain('你是生鲜称重台商品识别与质量验收助手'); expect(src).not.toContain('你是生鲜仓库独立入库识别与质量验收助手'); }); it('/inspection/complete 接可选 actual_weight;小程序不传则为 null', () => { const route = readFileSync( path.join(__dirname, '../src/routes/mobile/mobileWarehouseRoutes.ts'), 'utf8' ); expect(route).toContain('actual_weight'); // 可选解析:undefined/null/'' → null expect(route).toContain("actualWeightRaw === undefined"); // 仅 >0 才传给 service expect(route).toContain('actualWeight as number) > 0'); const svc = readFileSync( path.join(__dirname, '../src/services/inspectionComplianceService.ts'), 'utf8' ); expect(svc).toContain('actual_weight?: number | null'); expect(svc).toContain('actual_weight = $17'); // actual_weight 不参与校验/金额:落库为 NULL 或正数 expect(svc).toContain('Number(input.actual_weight) > 0'); }); it('inspections 迁移:actual_weight 可空列', () => { const mig = readFileSync( path.join(__dirname, '../../migrations/20260829_inspection_actual_weight.sql'), 'utf8' ); expect(mig).toContain('ADD COLUMN IF NOT EXISTS actual_weight'); expect(mig).not.toContain('NOT NULL'); }); it('安卓端:非斤禁自动提交 + 弹窗确认件数 + actualWeight 双参数', () => { const api = readFileSync( path.join( __dirname, '../../android-weigh-terminal/app/src/main/java/com/canteen/weigh/api/InspectionApi.java' ), 'utf8' ); expect(api).toContain('double actualWeight'); expect(api).toContain('if (actualWeight > 0)'); expect(api).toContain('body.put("actual_weight", actualWeight)'); const act = readFileSync( path.join( __dirname, '../../android-weigh-terminal/app/src/main/java/com/canteen/weigh/ui/InspectionWeighActivity.java' ), 'utf8' ); // 非斤禁自动提交 expect(act).toContain('if (!WeighStationMatcher.isWeightUnit(item.unit)) return;'); // 非斤弹窗 expect(act).toContain('confirmSubmitCounting'); expect(act).toContain('秤上参考重量'); // 非斤单位提交按钮无需秤重也可点(弹窗确认件数) expect(act).toContain('countingUnit || settlement > 0'); // 换商品/入库完成时清空 AI 数量,避免串单 expect(act).toContain('lastSuggestedQty = null;'); // doSubmit 双参数:actualQty + actualWeightJin expect(act).toContain('doSubmit(final InspectionTask task, String quality, final double actualQty, final double actualWeightJin'); // AI 识别数量字段 expect(act).toContain('lastSuggestedQty'); expect(act).toContain('suggested_qty'); }); });