refactor(fulfillment): 移除飞飞/乐玩通道,仅保留 affiliate_dash

新单只路由 affiliate_dash(未命中走 manual_dispatch);历史飞飞/乐玩任务保留只读 stub,避免订单重同步失败。同步清理 cloudtentacles 调度、Admin 写路径与相关 env。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-09-14 17:29:47 +08:00
co-authored by Cursor
parent 0cbcb89dd8
commit b3aad0044c
155 changed files with 661 additions and 23351 deletions
@@ -100,7 +100,7 @@ function stubCreatedTask(id: number, input: CreatedTaskInput): TaskRow {
} as TaskRow
}
test('syncDeliveryTasksForOrder 多账号候选时不提前固定 cloudtentacles 账号', async () => {
test('syncDeliveryTasksForOrder 为 affiliate_dash 商品创建任务上下文', async () => {
const createdInputs: CreatedTaskInput[] = []
await syncDeliveryTasksForOrderWithDeps(
@@ -113,34 +113,15 @@ test('syncDeliveryTasksForOrder 多账号候选时不提前固定 cloudtentacles
stubOrderItem({
id: 10,
order_id: 1,
sku_code: 'SKU-1',
sku_name: '荣耀勋章礼包(30个)',
sku_code: 'AFF-1001',
sku_name: '幸运币90个',
quantity: 1,
item_snapshot_json: {
cloudtentacles: {
cloudSourceKeys: ['account-a', 'account-b'],
resolvedSourceKey: 'account-a',
cloudSkuId: 74,
cloudSkuName: '荣耀勋章礼包(30个)',
deliveryItems: [
{
cloudSkuId: 74,
cloudSkuName: '荣耀勋章礼包(30个)',
quantity: 1,
},
],
},
} as JsonObject,
item_snapshot_json: buildAffiliateSnapshot('AFF-1001', '幸运币90个'),
}),
],
{
listTasksByOrderId: async () => [],
getFulfillmentProfileByKey: async () => ({
id: 9,
profile_key: 'kuaishou_ct_assisted',
profile_name: 'kuaishou-lewan 履约',
executor_key: 'kuaishou_ct_assisted',
}),
getFulfillmentProfileByKey: async () => buildAffiliateProfile(),
createTask: async (input) => {
createdInputs.push(input as CreatedTaskInput)
return stubCreatedTask(100, input as CreatedTaskInput)
@@ -151,61 +132,12 @@ test('syncDeliveryTasksForOrder 多账号候选时不提前固定 cloudtentacles
},
)
assert.equal(createdInputs[0]?.executorKey, 'affiliate_dash')
const context = JSON.parse(String(createdInputs[0]?.contextJson || '{}')) as JsonObject
const fulfillment = context.kuaishouCloudFulfillment as JsonObject
const binding = fulfillment.binding as JsonObject
assert.deepEqual(binding.cloudSourceKeys, ['account-a', 'account-b'])
assert.equal(binding.resolvedSourceKey, '')
})
test('syncDeliveryTasksForOrder 单账号候选时保留固定 cloudtentacles 账号', async () => {
const createdInputs: CreatedTaskInput[] = []
await syncDeliveryTasksForOrderWithDeps(
stubOrder({
id: 2,
pay_status: 'pending_payment',
platform_order_id: '2614900602069170',
}),
[
stubOrderItem({
id: 11,
order_id: 2,
sku_code: 'SKU-1',
sku_name: '荣耀勋章礼包(30个)',
quantity: 1,
item_snapshot_json: {
cloudtentacles: {
cloudSourceKeys: ['account-a'],
cloudSkuId: 74,
cloudSkuName: '荣耀勋章礼包(30个)',
},
} as JsonObject,
}),
],
{
listTasksByOrderId: async () => [],
getFulfillmentProfileByKey: async () => ({
id: 9,
profile_key: 'kuaishou_ct_assisted',
profile_name: 'kuaishou-lewan 履约',
executor_key: 'kuaishou_ct_assisted',
}),
createTask: async (input) => {
createdInputs.push(input as CreatedTaskInput)
return stubCreatedTask(101, input as CreatedTaskInput)
},
nowIso: () => '2026-05-29T09:05:46.658Z',
randomId: () => 'DT-test',
createTaskEvent: async () => null,
},
)
const context = JSON.parse(String(createdInputs[0]?.contextJson || '{}')) as JsonObject
const fulfillment = context.kuaishouCloudFulfillment as JsonObject
const binding = fulfillment.binding as JsonObject
assert.deepEqual(binding.cloudSourceKeys, ['account-a'])
assert.equal(binding.resolvedSourceKey, 'account-a')
const affiliateDash = context.affiliateDash as JsonObject
assert.equal(affiliateDash.sku, 'AFF-1001')
assert.equal(affiliateDash.productName, '幸运币90个')
assert.equal(affiliateDash.flowType, 'affiliate_dash')
})
test('syncDeliveryTasksForOrder 已有部分任务时按订单项补建缺失任务', async () => {
@@ -213,7 +145,7 @@ test('syncDeliveryTasksForOrder 已有部分任务时按订单项补建缺失任
orderId: 3,
orderItemId: 20,
unitIndex: 1,
executorKey: 'kuaishou_ct_assisted',
executorKey: 'affiliate_dash',
})
const createdInputs: CreatedTaskInput[] = []
const taskEvents: Array<{ taskId: number; eventType: string }> = []
@@ -225,18 +157,18 @@ test('syncDeliveryTasksForOrder 已有部分任务时按订单项补建缺失任
id: 20,
order_id: 3,
sku_code: 'SKU-existing',
item_snapshot_json: buildCloudSnapshot(74, '商品 A'),
item_snapshot_json: buildAffiliateSnapshot('AFF-A', '商品 A'),
}),
stubOrderItem({
id: 21,
order_id: 3,
sku_code: 'SKU-missing',
item_snapshot_json: buildCloudSnapshot(75, '商品 B'),
item_snapshot_json: buildAffiliateSnapshot('AFF-B', '商品 B'),
}),
],
{
listTasksByOrderId: async () => [existingTask],
getFulfillmentProfileByKey: async () => buildCloudProfile(),
getFulfillmentProfileByKey: async () => buildAffiliateProfile(),
createTask: async (input) => {
createdInputs.push(input as CreatedTaskInput)
return stubCreatedTask(202, input as CreatedTaskInput)
@@ -268,7 +200,7 @@ test('syncDeliveryTasksForOrder 数量增加时只补建缺失单元', async ()
orderId: 4,
orderItemId: 30,
unitIndex: 1,
executorKey: 'kuaishou_ct_assisted',
executorKey: 'affiliate_dash',
})
const createdInputs: CreatedTaskInput[] = []
@@ -280,12 +212,12 @@ test('syncDeliveryTasksForOrder 数量增加时只补建缺失单元', async ()
order_id: 4,
sku_code: 'SKU-quantity',
quantity: 2,
item_snapshot_json: buildCloudSnapshot(74, '商品 A'),
item_snapshot_json: buildAffiliateSnapshot('AFF-A', '商品 A'),
}),
],
{
listTasksByOrderId: async () => [existingTask],
getFulfillmentProfileByKey: async () => buildCloudProfile(),
getFulfillmentProfileByKey: async () => buildAffiliateProfile(),
createTask: async (input) => {
createdInputs.push(input as CreatedTaskInput)
return stubCreatedTask(302, input as CreatedTaskInput)
@@ -321,20 +253,18 @@ test('syncDeliveryTasksForOrder 规划失败时记录可定位的路由诊断',
item_snapshot_json: {
isConfigured: true,
fulfillmentRoute: {
selectedExecutorKey: 'kuaishou_ct_assisted',
reason: '规则指定云履约',
selectedExecutorKey: 'affiliate_dash',
reason: '规则指定 affiliate',
},
cloudtentacles: {
cloudSkuId: 74,
cloudSkuName: '商品 A',
cloudSourceKeys: [],
affiliateDash: {
skuName: '商品 A',
},
} as JsonObject,
}),
],
{
listTasksByOrderId: async () => [],
getFulfillmentProfileByKey: async () => buildCloudProfile(),
getFulfillmentProfileByKey: async () => buildAffiliateProfile(),
createTaskEvent: async () => null,
logInfo: () => null,
logWarn: (_scope, message, detail) => {
@@ -354,13 +284,13 @@ test('syncDeliveryTasksForOrder 规划失败时记录可定位的路由诊断',
assert.deepEqual(warnings[0]?.detail.missingUnitIndexes, [1])
assert.deepEqual(warnings[0]?.detail.planningDiagnostic, {
snapshotIsConfigured: true,
selectedExecutorKey: 'kuaishou_ct_assisted',
routeReason: '规则指定云履约',
selectedExecutorKey: 'affiliate_dash',
routeReason: '规则指定 affiliate',
candidateAvailability: [],
sourceItemTitle: '',
sourceSkuNick: '',
cloudSkuId: 74,
cloudSkuName: '商品 A',
cloudSkuId: 0,
cloudSkuName: '',
cloudSourceKeys: [],
feifeiProductCode: '',
affiliateDashSku: '',
@@ -372,7 +302,7 @@ test('syncDeliveryTasksForOrder 并发创建冲突时复用已落库任务', asy
orderId: 6,
orderItemId: 50,
unitIndex: 1,
executorKey: 'kuaishou_ct_assisted',
executorKey: 'affiliate_dash',
})
let listCount = 0
let eventCount = 0
@@ -384,12 +314,12 @@ test('syncDeliveryTasksForOrder 并发创建冲突时复用已落库任务', asy
id: 50,
order_id: 6,
sku_code: 'SKU-concurrent',
item_snapshot_json: buildCloudSnapshot(74, '商品 A'),
item_snapshot_json: buildAffiliateSnapshot('AFF-A', '商品 A'),
}),
],
{
listTasksByOrderId: async () => (listCount++ === 0 ? [] : [concurrentTask]),
getFulfillmentProfileByKey: async () => buildCloudProfile(),
getFulfillmentProfileByKey: async () => buildAffiliateProfile(),
createTask: async () => {
throw new Error('duplicate key value violates unique constraint')
},
@@ -411,25 +341,25 @@ test('syncDeliveryTasksForOrder 并发创建冲突时复用已落库任务', asy
assert.equal(eventCount, 0)
})
function buildCloudSnapshot(cloudSkuId: number, cloudSkuName: string): JsonObject {
function buildAffiliateSnapshot(sku: string, productName: string): JsonObject {
return {
isConfigured: true,
fulfillmentRoute: {
selectedExecutorKey: 'kuaishou_ct_assisted',
selectedExecutorKey: 'affiliate_dash',
},
cloudtentacles: {
cloudSourceKeys: ['account-a'],
cloudSkuId,
cloudSkuName,
affiliateDash: {
sku,
skuName: productName,
matchMode: 'affiliate_dash_sku_mapping',
},
}
}
function buildCloudProfile() {
function buildAffiliateProfile() {
return {
id: 9,
profile_key: 'kuaishou_ct_assisted',
profile_name: 'kuaishou-lewan 履约',
executor_key: 'kuaishou_ct_assisted',
id: 11,
profile_key: 'affiliate_dash',
profile_name: 'affiliate-dash 履约',
executor_key: 'affiliate_dash',
}
}