import test from 'node:test' import assert from 'node:assert/strict' import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const here = path.dirname(fileURLToPath(import.meta.url)) const source = fs.readFileSync(path.join(here, 'order-inbound-status-fixtures.mjs'), 'utf8') test('为头程订单列表八个真实状态分别创建独立样本', () => { for (const status of ['DRAFT', 'SUBMITTED', 'REJECTED', 'APPROVED', 'ACCEPTED', 'PROCESSING', 'COMPLETED', 'CANCELLED']) { assert.match(source, new RegExp(`\\['${status}', \\[`)) assert.match(source, new RegExp(`result\\.orders\\[target\\]`)) } assert.match(source, /status=\$\{status\}/) assert.match(source, /筛选结果包含人工样本/) }) test('所有写入均走订单生命周期 HTTP API 且不清理保留数据', () => { assert.match(source, /\/api\/merchant\/v1\/orders\/first-leg/) assert.match(source, /\/api\/platform\/v1\/orders\/first-leg/) assert.match(source, /'Idempotency-Key': key\(context,/) assert.doesNotMatch(source, /\b(?:INSERT|UPDATE|DELETE|TRUNCATE)\b/i) assert.doesNotMatch(source, /cleanup|remove|unlink/i) }) test('状态矩阵复用订单共享的逐仓真实报价选择,不假设首仓或首税制', () => { assert.match(source, /findPricedOrderRouteAcrossOrigins/) assert.match(source, /loadChannels: \(receiving\)/) assert.match(source, /pricing\/estimate/) assert.doesNotMatch(source, /rows\(.*domestic.*\)\[0\]/) assert.doesNotMatch(source, /pricingTaxModes\[0\]/) assert.match(source, /pricingTaxMode: priced\.priced\.pricingTaxMode/) }) test('入库通过真实订单测量链保留测量态并最终进入 WAIT_SPLIT', () => { assert.match(source, /result\.inbounds\.WAIT_MEASURE/) assert.match(source, /processStatus: 'WAIT_MEASURE'/) for (const status of ['MEASURING', 'MEASURE_PENDING', 'MEASURE_REJECTED', 'WAIT_SPLIT']) { assert.match(source, new RegExp(`'${status}'`)) } assert.match(source, /\.\/inbound-measurement\.mjs/) assert.match(source, /`\/api\/platform\/v1\/inbounds\/\$\{query\(inboundId\)\}\/measurements\/reject\?tenantId=\$\{query\(tenantId\)\}`/) assert.doesNotMatch(source, /path\.replace\('\/measurement\/submit', '\/measurements\/reject'\)/) }) test('FBA 状态样本为订单头和每条货物行提供四个必填标识', () => { assert.match(source, /const shipmentId = `MANUAL-/) assert.match(source, /const referenceId = `STATUS-/) assert.match(source, /const upcNo =/) assert.match(source, /upcNo, shipmentId, referenceId/) }) test('测量状态截停发生在正确的 HTTP 边界', () => { assert.match(source, /includes\(summary\.mainStatus\)/) assert.doesNotMatch(source, /includes\(summary\.processStatus\)/) assert.match(source, /target === 'MEASURING'/) assert.match(source, /\.\/inbound-weight-ocr\.mjs/) assert.match(source, /await weightOcr\.run\(context\)/) assert.match(source, /target !== 'MEASURING'/) assert.doesNotMatch(source, /target === 'MEASURING' && ok\(response\)/) assert.match(source, /target === 'MEASURE_PENDING' && isSubmit/) assert.match(source, /target === 'MEASURE_REJECTED' && isSubmit/) assert.match(source, /measurements\/reject/) assert.match(source, /expectedVersion: version/) }) test('入库不可独立保留状态显式阻断', () => { for (const status of ['WAIT_PRICING', 'FEE_CONFIRMING', 'INBOUNDING', 'VOIDED']) { assert.match(source, new RegExp(`${status}:`)) } assert.match(source, /AutomaticInboundCompletionService 在同一调用内立即从 INBOUNDING 推进 WAIT_SPLIT/) assert.match(source, /processStatus=WAIT_SPLIT/) assert.match(source, /查询存量 WAIT_SPLIT 样本/) assert.match(source, /没有作废入库单 API/) assert.match(source, /recordCoverageGap\(context, `入库列表保留 \$\{status\}`/) assert.match(source, /context\.addCoverageGap\?\./) }) test('统一订单声明合法可达状态并显式阻断废弃或无 API 状态', () => { assert.match(source, /result\.unifiedOrders\.PENDING_REVIEW/) assert.match(source, /result\.unifiedOrders\.WAIT_MEASURE/) for (const status of ['WAIT_SPLIT', 'LOADING', 'LOADED', 'DELIVERED']) { assert.match(source, new RegExp(`'${status}'`)) } assert.doesNotMatch(source, /WAIT_SPLIT 标记为历史废弃状态/) assert.match(source, /没有完成派送并写 DELIVERED 的公开业务 API/) }) test('按总门禁格式写入 matrix.pages 的 requiredStatuses 和 fixtures', () => { assert.match(source, /run\(context, matrix = context\.createdResources\.manualStateMatrix\)/) for (const page of ['firstLegOrders', 'inbounds', 'unifiedOrders']) { assert.match(source, new RegExp(`matrix\\.pages\\.${page} = \\{ requiredStatuses:`)) } assert.match(source, /detailPath: `\/orders\/\$\{orderId\}`/) })