import { readFileSync } from 'node:fs'; import path from 'path'; import { describe, expect, it } from 'vitest'; describe('待补录实收补录口(隔离闸门)', () => { it('补录服务:仅校验订单存在(待补录闸门已取消),免拍/跳过质检闸/跳过履约推进,合单不分拣邻居', () => { const src = readFileSync( path.join(__dirname, '../src/services/pendingBackfillQtyService.ts'), 'utf8' ); // 「待补录」中间态已取消(用户 2026-09-15):闸门改为仅校验订单存在且未删除。 // 见 docs/design/20260915-remove-pending-backfill-state.md expect(src).not.toContain('isPendingBackfillDelivering'); expect(src).toContain('订单不存在或已删除'); expect(src).toContain('skipQualityReportGate: true'); expect(src).toContain('skipFulfillmentAdvance: true'); expect(src).toContain('allowMissingPhotos: true'); expect(src).toContain('confirm_over_qty: true'); expect(src).toContain('countUnfinishedBackfillPickingItems'); const pickStart = src.indexOf('export async function countUnfinishedBackfillPickingItems'); const pickNext = src.indexOf('async function assertPendingBackfillOrder'); const pickBody = src.slice(pickStart, pickNext > pickStart ? pickNext : pickStart + 1800); expect(pickBody).toContain('COALESCE(oi.is_returned, false) = false'); expect(pickBody).toContain('pi.order_item_id IS NOT NULL AND oi.id = pi.order_item_id'); expect(pickBody).toContain('pi.order_item_id IS NULL AND pi.sku_code IS NOT DISTINCT FROM oi.sku_code'); // 保存实收不再推进分拣完成/订单状态(设计 20260829-save-received-qty-merge) expect(src).not.toContain('confirmPickingComplete'); expect(src).toContain('applyWarehouseInboundQty'); expect(src).toContain('adjustInboundInspectionQty'); expect(src).toContain('ensureBackfillInboundOnConfirm'); expect(src).toContain('reconcileOrderPurchaseFromLatestInspections'); expect(src).toContain('fillPickingForOrder'); const adjust = readFileSync( path.join(__dirname, '../src/services/inspectionInboundQtyAdjust.ts'), 'utf8' ); expect(adjust).toContain('export async function adjustInboundInspectionQty'); }); it('submitInspectionCompliance 选项不默认跳过闸门', () => { const src = readFileSync( path.join(__dirname, '../src/services/inspectionComplianceService.ts'), 'utf8' ); expect(src).toContain('skipQualityReportGate'); expect(src).toContain('skipFulfillmentAdvance'); expect(src).toContain('!options?.skipQualityReportGate'); expect(src).toContain('!options?.skipFulfillmentAdvance'); expect(src).not.toContain('isPendingBackfillDelivering'); const auto = src.slice(src.indexOf('const AUTO_COMPLETE_OPTIONS')); expect(auto.slice(0, 250)).not.toContain('skipQualityReportGate'); }); it('自采/备货仅待补录不新建待验;直送 skip_inbound 仍在前', () => { const purchase = readFileSync( path.join(__dirname, '../src/services/inspectionComplianceService.ts'), 'utf8' ); const ensureStart = purchase.indexOf('export async function ensurePurchaseInspectionForCompletedPurchase'); const ensure = purchase.slice(ensureStart, ensureStart + 4500); // 「待补录」窄路径已移除:不再有“只回写待验、不新建入库卡片”的分支 expect(ensure).not.toContain('isPendingBackfillDelivering'); expect(ensure).not.toContain('不新建入库卡片'); expect(ensure).toContain('原供应商验收入库不能当成新自采已覆盖'); const reject = readFileSync( path.join(__dirname, '../src/services/inspectionRejectFulfillmentService.ts'), 'utf8' ); const createStart = reject.indexOf('export async function createSupplierInspectionIfNeeded'); const create = reject.slice(createStart, createStart + 2800); // 拒收创建路径不再受待补录闸门影响;直送免入库闸门保留 expect(create).toContain('isSupplierSkipInbound'); expect(create).not.toContain('isPendingBackfillDelivering'); }); it('路由与 Web:backfill-received-qty 并入保存按钮;强推仍排除 UNASSIGNED', () => { const routes = readFileSync( path.join(__dirname, '../src/modules/workflow/routes/deliveryRoutes.ts'), 'utf8' ); expect(routes).toContain("router.post('/orders/backfill-received-qty'"); expect(routes).toContain('savePendingBackfillReceivedQty'); const web = readFileSync( path.join(__dirname, '../../src/pages/orders/orderManagement/OrderManagementPage.tsx'), 'utf8' ); expect(web).toContain('savePendingBackfillReceivedQtyApi'); expect(web).not.toContain('保存实收'); expect(web).toContain('collectDirtyReceivedQtyLines'); expect(web).toContain('isBackfillQtyOrder'); const panel = readFileSync( path.join(__dirname, '../../src/components/order/OrderDetailDeliveryNotePanel.tsx'), 'utf8' ); expect(panel).toContain('canEditReceivedQty'); const advance = readFileSync( path.join(__dirname, '../src/services/orderAutoAdvanceService.ts'), 'utf8' ); // 2026-09-16 更新:强推的「未分配」判定原先只判 UNASSIGNED,漏了 INTERNAL(自采盖章值)。 // 全仓 isUnassignedSupplier / orderAllocationService / orderStatusDisplayService // 以及 marginQueryService 的财务分桶都把 NULL/''/UNASSIGNED/INTERNAL 视为同义, // 故补成 IN ('UNASSIGNED','INTERNAL')(见 §1.2.1 缺陷③)。本断言随之更新, // 语义不变且更严:仍然「排除未分配行」,只是把自采盖章行也算进未分配。 expect(advance).toContain("UPPER(TRIM(oi.supplier_code)) IN ('UNASSIGNED', 'INTERNAL')"); // 两个扫描口径(定时 / 手动「立即执行一次」)都必须带上 expect(advance.match(/UPPER\(TRIM\(oi\.supplier_code\)\) IN \('UNASSIGNED', 'INTERNAL'\)/g)?.length).toBe(2); }); it('独立入库同样受「不合格不得入库」硬门槛约束,直送闸门源码仍在', () => { const insp = readFileSync( path.join(__dirname, '../src/services/inspectionComplianceService.ts'), 'utf8' ); expect(insp).toContain('reject_fulfillment'); expect(insp).toContain('inspection_fail_cannot_inbound'); expect(insp).toContain('independent_inbound_returned'); expect(insp).not.toContain('independent_inbound_no_reject'); const skip = readFileSync( path.join(__dirname, '../src/services/supplierSkipInbound.ts'), 'utf8' ); expect(skip).toContain('skip_inbound'); }); });