上一轮我把皮肤交付做成了「另建一套执行器 + 独立领取接口 + 只提交账号就结束」, 跟买家实际要走的过程不一致(真正的完成信号是「扫码绑定后的 UID == 买家填的 UID」), 而且核销还触发了老通知逻辑,给买家**又发了一条 /redeem** —— 买家收到两条链接。 本次按用户要求改回**完全复用仓库现成的 affiliate_dash 通道**(= 旧的快手皮肤自动发货)。 **删掉** - 执行器 `douyin_mashida_skin`(含 registry/types/planner/bootstrap/路由白名单注册) - `services/claim/claim-skin-service.ts`、`routes/claim-skin.ts`、`/api/v1/claim-skin` 挂载 - 迁移 096 的 `claim_submission_json` 全链路(task-repo / rows / inputs / task-detail / admin-read-service 的 claimSubmission),并新增 **097 兜底迁移**把该列 DROP 掉 - 顺带清掉上一轮专为已删接口加的死代码(utils/http.ts 的 buildMessageSuccessPayload 等) **改回复用** - `resolveOrderItemClaimLink`:通用解析(只看订单项、不看执行器)→ `buildConfiguredClaimUrl(claimLinkBase, token)`;多履约单元取 task id 最小并告警; **绝不回退** hash 形态的 `buildClaimUrl` - `cert_link` 与付款后那条**唯一**消息共用同一个解析结果 - **核销后不再给抖音买家发第二条消息**(`shouldNotifyBuyerAfterVerify` 只放行非抖音 provider) - 买家侧走既有流程:输 UID → 二维码 → 扫码绑定 → 比对 UID → delivered/REDEEMED; 在 delivered 分支 best-effort 核销平台券(幂等、失败只 warn,不拖慢买家响应) - 后台回显链接改按 **order.provider** 判断(抖音用 `claimLinkBase`) **SQL 守卫**:允许「删除历史迁移」,但强制要求「同时新增兜底迁移」配对 (修改历史迁移仍禁止),并把改动来源换成 `git status --porcelain`(否则未跟踪的新迁移看不见) `npm run check`:tests 671 / pass 668 / fail 0 / skipped 3(含新增的物品图回退用例)
276 lines
9.4 KiB
TypeScript
276 lines
9.4 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import {
|
|
normalizeFulfillmentRoutingConfig,
|
|
resolveFulfillmentRoute,
|
|
} from './routing-config-service.js'
|
|
|
|
test('normalizeFulfillmentRoutingConfig drops retired executors and keeps affiliate_dash default', () => {
|
|
const config = normalizeFulfillmentRoutingConfig({
|
|
defaultExecutorPriority: ['kuaishou_ct_assisted', 'kuaishou_feifei'],
|
|
})
|
|
|
|
assert.deepEqual(config.defaultExecutorPriority, ['affiliate_dash'])
|
|
assert.deepEqual(Object.keys(config.executors).sort(), ['affiliate_dash', 'manual_dispatch'])
|
|
assert.equal(config.unmatchedExecutorKey, 'manual_dispatch')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 总开关关闭后不再回退默认配置,返回未选中', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '测试商品',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({
|
|
enabled: false,
|
|
}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, '')
|
|
assert.equal(result.reason, '履约路由未启用,自动发货已停止')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 默认选择 affiliate_dash', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '测试商品',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'affiliate_dash')
|
|
assert.equal(result.reason, '按全局优先级命中')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute affiliate 不可用时回退人工', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '测试商品',
|
|
candidates: [
|
|
{ executorKey: 'affiliate_dash', available: false, reason: '未命中 affiliate-dash sku 映射' },
|
|
],
|
|
config: normalizeFulfillmentRoutingConfig({}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'manual_dispatch')
|
|
assert.equal(result.reason, '未命中自动履约通道,进入人工履约')
|
|
assert.deepEqual(result.skipped[0], {
|
|
executorKey: 'affiliate_dash',
|
|
reason: '未命中 affiliate-dash sku 映射',
|
|
})
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 商品规则可以强制走 affiliate_dash', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '荣耀套装',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({
|
|
rules: [
|
|
{
|
|
enabled: true,
|
|
productName: '荣耀套装',
|
|
executorKey: 'affiliate_dash',
|
|
priority: 200,
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'affiliate_dash')
|
|
assert.equal(result.selectedRuleId, '荣耀套装:affiliate_dash')
|
|
assert.equal(result.reason, '命中商品路由规则')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 商品规则目标不可用时不再静默改通道', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '套装-糯粉咩咩',
|
|
candidates: [
|
|
{ executorKey: 'affiliate_dash', available: false, reason: '未命中 affiliate-dash sku 映射' },
|
|
],
|
|
config: normalizeFulfillmentRoutingConfig({
|
|
rules: [
|
|
{
|
|
enabled: true,
|
|
productName: '套装-糯粉咩咩',
|
|
executorKey: 'affiliate_dash',
|
|
priority: 200,
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, '')
|
|
assert.equal(result.reason, '商品路由规则目标通道不可用,且未命中其他履约通道')
|
|
assert.deepEqual(result.skipped[0], {
|
|
executorKey: 'affiliate_dash',
|
|
reason: '未命中 affiliate-dash sku 映射',
|
|
})
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 商品规则可以强制转人工', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '临时停用商品',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({
|
|
rules: [
|
|
{
|
|
enabled: true,
|
|
productName: '临时停用',
|
|
matchType: 'contains',
|
|
executorKey: 'manual_dispatch',
|
|
priority: 300,
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'manual_dispatch')
|
|
assert.equal(result.reason, '命中商品路由规则')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 指定匹配(显式映射)最高优先', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '幸运币90个',
|
|
preferredExecutorKey: 'affiliate_dash',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'affiliate_dash')
|
|
assert.equal(result.reason, '命中指定匹配(显式映射),优先选择')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 指定匹配命中但通道停用时回退人工', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '幸运币90个',
|
|
preferredExecutorKey: 'affiliate_dash',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({
|
|
executors: {
|
|
affiliate_dash: { enabled: false },
|
|
},
|
|
}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'manual_dispatch')
|
|
assert.ok(result.skipped.some((item) => item.executorKey === 'affiliate_dash'))
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 指定匹配命中但商品不可用时回退人工', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '幸运币90个',
|
|
preferredExecutorKey: 'affiliate_dash',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: false, reason: '未命中 sku 映射' }],
|
|
config: normalizeFulfillmentRoutingConfig({}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'manual_dispatch')
|
|
assert.ok(result.skipped.some((item) => item.executorKey === 'affiliate_dash'))
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 无指定匹配时按全局优先级选择', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '幸运币90个',
|
|
preferredExecutorKey: '',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'affiliate_dash')
|
|
assert.equal(result.reason, '按全局优先级命中')
|
|
})
|
|
|
|
test('normalizeFulfillmentRoutingConfig 支持按内部 SKU 的规则维度', () => {
|
|
const config = normalizeFulfillmentRoutingConfig({
|
|
rules: [
|
|
{
|
|
internalSku: '幸运币2个',
|
|
executorKey: 'affiliate_dash',
|
|
priority: 500,
|
|
},
|
|
],
|
|
})
|
|
|
|
assert.equal(config.rules.length, 1)
|
|
const rule = config.rules[0]
|
|
assert.ok(rule)
|
|
assert.equal(rule.matchField, 'internal_sku')
|
|
// 展示字段沿用 productName(值为内部 SKU),但商品名匹配键留空,避免被商品名规则误命中
|
|
assert.equal(rule.productName, '幸运币2个')
|
|
assert.equal(rule.normalizedProductName, '')
|
|
assert.equal(rule.internalSku, '幸运币2个')
|
|
assert.equal(rule.normalizedInternalSku, '幸运币2个')
|
|
assert.equal(rule.id, '幸运币2个:affiliate_dash')
|
|
})
|
|
|
|
test('旧商品名规则归一化后带 matchField=product_name,语义不变', () => {
|
|
const config = normalizeFulfillmentRoutingConfig({
|
|
rules: [{ productName: '荣耀套装', executorKey: 'affiliate_dash', priority: 200 }],
|
|
})
|
|
|
|
const rule = config.rules[0]
|
|
assert.ok(rule)
|
|
assert.equal(rule.matchField, 'product_name')
|
|
assert.equal(rule.normalizedProductName, '荣耀套装')
|
|
assert.equal(rule.internalSku, '')
|
|
assert.equal(rule.id, '荣耀套装:affiliate_dash')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 命中内部 SKU 规则', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '【测试专用】和平精英皮肤小店入口',
|
|
internalSku: '幸运币2个',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({
|
|
rules: [{ internalSku: '幸运币2个', executorKey: 'affiliate_dash', priority: 500 }],
|
|
}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'affiliate_dash')
|
|
assert.equal(result.reason, '命中商品路由规则')
|
|
assert.equal(result.matchedRule?.productName, '幸运币2个')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 内部 SKU 规则支持归一化与 contains', () => {
|
|
const config = normalizeFulfillmentRoutingConfig({
|
|
rules: [
|
|
{
|
|
internalSku: '幸运币',
|
|
matchType: 'contains',
|
|
executorKey: 'affiliate_dash',
|
|
priority: 500,
|
|
},
|
|
],
|
|
})
|
|
|
|
const exactFullWidth = resolveFulfillmentRoute({
|
|
productName: '',
|
|
internalSku: ' 幸运币2个 ',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config,
|
|
})
|
|
assert.equal(exactFullWidth.selectedExecutorKey, 'affiliate_dash')
|
|
|
|
const miss = resolveFulfillmentRoute({
|
|
productName: '',
|
|
internalSku: '荣耀勋章2个',
|
|
candidates: [],
|
|
config,
|
|
})
|
|
assert.equal(miss.selectedExecutorKey, 'manual_dispatch')
|
|
})
|
|
|
|
test('resolveFulfillmentRoute 未命中内部 SKU 规则时商品名规则仍然优先生效', () => {
|
|
const result = resolveFulfillmentRoute({
|
|
productName: '荣耀套装',
|
|
internalSku: '荣耀勋章2个',
|
|
candidates: [{ executorKey: 'affiliate_dash', available: true }],
|
|
config: normalizeFulfillmentRoutingConfig({
|
|
rules: [
|
|
{ productName: '荣耀套装', executorKey: 'affiliate_dash', priority: 200 },
|
|
{ internalSku: '幸运币2个', executorKey: 'affiliate_dash', priority: 900 },
|
|
],
|
|
}),
|
|
})
|
|
|
|
assert.equal(result.selectedExecutorKey, 'affiliate_dash')
|
|
assert.equal(result.matchedRule?.productName, '荣耀套装')
|
|
})
|