修复(半自动履约): 收口虎牙确认恢复与任务切换
This commit is contained in:
@@ -310,10 +310,27 @@ test(
|
||||
reauthorized.events.some((event) => event.eventType === 'customer_reauth_requested'),
|
||||
)
|
||||
|
||||
const missingVersionEventId = randomUUID()
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: missingVersionEventId,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
bindingStatus: 'not_started',
|
||||
},
|
||||
{ eventId: missingVersionEventId, eventType: 'semi_auto.task_state' },
|
||||
),
|
||||
'semi_auto_snapshot_state_version_required',
|
||||
)
|
||||
|
||||
const snapshotEventId = randomUUID()
|
||||
const snapshot = await applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: snapshotEventId,
|
||||
stateVersion: 2,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
@@ -337,6 +354,7 @@ test(
|
||||
applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: reusedUidEventId,
|
||||
stateVersion: 3,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
@@ -353,6 +371,7 @@ test(
|
||||
const duplicateSnapshot = await applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: snapshotEventId,
|
||||
stateVersion: 2,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
@@ -387,6 +406,7 @@ test(
|
||||
await applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: staleConfirmEventId,
|
||||
stateVersion: 3,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
@@ -415,6 +435,37 @@ test(
|
||||
execution_status: 'waiting_customer',
|
||||
binding_flow_state: 'rebind_required',
|
||||
})
|
||||
const outOfOrderEventId = randomUUID()
|
||||
const outOfOrder = await applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: outOfOrderEventId,
|
||||
stateVersion: 2,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
bindingStatus: 'confirmed',
|
||||
huyaUid: `it-huya-${suffix}`,
|
||||
bindGameAccount: '集成测试虎牙账号',
|
||||
bindGameRole: '集成测试角色',
|
||||
bindGameRoleToken: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
bindGameChannel: '安卓(android) · 微信',
|
||||
isBindAccount: true,
|
||||
isBindRole: true,
|
||||
roleIdentitySource: 'huya_outer_current',
|
||||
verificationBasis: 'role_name_zone',
|
||||
},
|
||||
{ eventId: outOfOrderEventId, eventType: 'semi_auto.task_state' },
|
||||
)
|
||||
assert.equal(outOfOrder.applied, false)
|
||||
assert.equal(outOfOrder.stale, true)
|
||||
const afterOutOfOrder = await query<{ binding_flow_state: string; execution_status: string }>(
|
||||
`SELECT binding_flow_state, execution_status FROM semi_auto_tasks WHERE id = $1`,
|
||||
[taskId],
|
||||
)
|
||||
assert.deepEqual(afterOutOfOrder.rows[0], {
|
||||
binding_flow_state: 'rebind_required',
|
||||
execution_status: 'waiting_customer',
|
||||
})
|
||||
} finally {
|
||||
if (orderId > 0) {
|
||||
await query('DELETE FROM order_source_snapshots WHERE order_id = $1', [orderId])
|
||||
@@ -542,8 +593,18 @@ test(
|
||||
UPDATE semi_auto_tasks
|
||||
SET credential_id = $2,
|
||||
login_status = 'authenticated',
|
||||
binding_status = 'not_started',
|
||||
binding_status = 'confirmed',
|
||||
binding_flow_state = 'confirmed',
|
||||
execution_status = 'waiting_operator',
|
||||
customer_game_role_name = '半自动原子性角色',
|
||||
customer_game_role_id = '1192083858',
|
||||
customer_game_server_zone = '安卓V区',
|
||||
bind_game_role = '半自动原子性角色',
|
||||
bind_game_role_token = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
bind_game_channel = '安卓(android) · 微信',
|
||||
is_bind_account = TRUE,
|
||||
is_bind_role = TRUE,
|
||||
bound_at = NOW(),
|
||||
authenticated_at = NOW(),
|
||||
updated_at = NOW()
|
||||
WHERE id = $1
|
||||
@@ -677,6 +738,183 @@ test(
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'人工配置切换半自动平台会终止旧任务并创建新的活动任务',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
async () => {
|
||||
process.env.DATABASE_URL = TEST_DATABASE_URL
|
||||
process.env.ENABLE_DEV_MOCK = '1'
|
||||
const { closeDb, query } = await import('../../db/client.js')
|
||||
const { createSemiAutoMock } = await import('../dev-mock/dev-mock-service.js')
|
||||
const { reconcileSemiAutoTasksForManualConfig } = await import('./semi-auto-task-service.js')
|
||||
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}`
|
||||
const orderNo = `IT-SEMI-AUTO-PLATFORM-SWITCH-${suffix}`
|
||||
let orderId = 0
|
||||
let configId = 0
|
||||
try {
|
||||
const result = await createSemiAutoMock({
|
||||
orderNo,
|
||||
skuName: `半自动平台切换-${suffix}`,
|
||||
quantity: 1,
|
||||
connectorMode: 'embedded',
|
||||
})
|
||||
orderId = result.orderId
|
||||
configId = result.configId
|
||||
await query(
|
||||
`UPDATE manual_fulfillment_configs
|
||||
SET semi_auto_platform = 'weibo', updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
[configId],
|
||||
)
|
||||
const reconciled = await reconcileSemiAutoTasksForManualConfig(configId)
|
||||
assert.equal(reconciled.createdIds.length, 1)
|
||||
|
||||
const tasks = await query<{
|
||||
id: number
|
||||
platform: string
|
||||
execution_status: string
|
||||
last_error: string
|
||||
}>(
|
||||
`SELECT id, platform, execution_status, last_error
|
||||
FROM semi_auto_tasks
|
||||
WHERE order_id = $1
|
||||
ORDER BY id`,
|
||||
[orderId],
|
||||
)
|
||||
assert.equal(tasks.rows.length, 2)
|
||||
assert.equal(tasks.rows[0]?.platform, 'huya')
|
||||
assert.equal(tasks.rows[0]?.execution_status, 'cancelled')
|
||||
assert.match(tasks.rows[0]?.last_error || '', /切换半自动平台/)
|
||||
assert.equal(tasks.rows[1]?.platform, 'weibo')
|
||||
assert.equal(tasks.rows[1]?.execution_status, 'waiting_customer')
|
||||
|
||||
await query(
|
||||
`UPDATE manual_fulfillment_configs
|
||||
SET semi_auto_enabled = FALSE, updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
[configId],
|
||||
)
|
||||
await reconcileSemiAutoTasksForManualConfig(configId)
|
||||
const disabled = await query<{ platform: string; execution_status: string }>(
|
||||
`SELECT platform, execution_status
|
||||
FROM semi_auto_tasks
|
||||
WHERE order_id = $1
|
||||
ORDER BY id`,
|
||||
[orderId],
|
||||
)
|
||||
assert.deepEqual(disabled.rows, [
|
||||
{ platform: 'huya', execution_status: 'cancelled' },
|
||||
{ platform: 'weibo', execution_status: 'cancelled' },
|
||||
])
|
||||
} finally {
|
||||
if (orderId > 0) await query('DELETE FROM orders WHERE id = $1', [orderId])
|
||||
if (configId > 0) {
|
||||
await query('DELETE FROM manual_fulfillment_configs WHERE id = $1', [configId])
|
||||
}
|
||||
delete process.env.ENABLE_DEV_MOCK
|
||||
await closeDb()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'虎牙确认状态可从数据库恢复并在回查角色一致后收敛为已确认',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
async () => {
|
||||
process.env.DATABASE_URL = TEST_DATABASE_URL
|
||||
process.env.ENABLE_DEV_MOCK = '1'
|
||||
const { closeDb, query, withTransaction } = await import('../../db/client.js')
|
||||
const { createSemiAutoMock } = await import('../dev-mock/dev-mock-service.js')
|
||||
const { loadTask, updateBindingTaskWithClient } = await import('./semi-auto-task-core.js')
|
||||
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}`
|
||||
const orderNo = `IT-HUYA-CONFIRM-RECOVERY-${suffix}`
|
||||
const targetRoleToken = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
|
||||
let orderId = 0
|
||||
let configId = 0
|
||||
try {
|
||||
const result = await createSemiAutoMock({
|
||||
orderNo,
|
||||
skuName: `虎牙确认恢复-${suffix}`,
|
||||
quantity: 1,
|
||||
connectorMode: 'embedded',
|
||||
})
|
||||
orderId = result.orderId
|
||||
configId = result.configId
|
||||
await query(
|
||||
`
|
||||
UPDATE semi_auto_tasks
|
||||
SET login_status = 'authenticated',
|
||||
customer_game_role_name = '恢复目标角色',
|
||||
customer_game_role_id = '1192083858',
|
||||
customer_game_server_zone = '安卓V区',
|
||||
binding_status = 'scanned',
|
||||
bind_game_role = '旧角色',
|
||||
bind_game_role_token = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
bind_game_channel = '安卓(android) · 微信',
|
||||
is_bind_account = TRUE,
|
||||
is_bind_role = TRUE,
|
||||
pending_bind_game_role = '恢复目标角色',
|
||||
pending_bind_game_role_token = $2,
|
||||
pending_bind_game_channel = '安卓(android) · 微信',
|
||||
bind_confirm_state = 'accepted',
|
||||
binding_effect_deadline_at = NOW() + INTERVAL '1 minute',
|
||||
execution_status = 'waiting_customer',
|
||||
updated_at = NOW()
|
||||
WHERE id = $1
|
||||
`,
|
||||
[result.taskId, targetRoleToken],
|
||||
)
|
||||
const task = await loadTask(result.taskId)
|
||||
await withTransaction((client) =>
|
||||
updateBindingTaskWithClient(
|
||||
client,
|
||||
task.id,
|
||||
{
|
||||
sessionId: task.connector_session_id,
|
||||
status: 'role_ready',
|
||||
qrImage: '',
|
||||
qrExpiresAt: '',
|
||||
qrUrl: '',
|
||||
bindGameAccount: '恢复目标账号',
|
||||
bindGameRole: '恢复目标角色',
|
||||
bindGameRoleId: targetRoleToken,
|
||||
bindGameRoleToken: targetRoleToken,
|
||||
bindGameChannel: '安卓(android) · 微信',
|
||||
currentRole: {
|
||||
isBindAccount: true,
|
||||
isBindRole: true,
|
||||
roleName: '恢复目标角色',
|
||||
roleToken: targetRoleToken,
|
||||
channel: '安卓(android) · 微信',
|
||||
changeBindTime: 0,
|
||||
changeBindDay: 7,
|
||||
},
|
||||
pendingRole: null,
|
||||
hasExistingBinding: true,
|
||||
rebindRequested: false,
|
||||
message: '平台角色已生效',
|
||||
},
|
||||
'connector',
|
||||
),
|
||||
)
|
||||
const recovered = await loadTask(result.taskId)
|
||||
assert.equal(recovered.binding_status, 'confirmed')
|
||||
assert.equal(recovered.binding_flow_state, 'confirmed')
|
||||
assert.equal(recovered.execution_status, 'waiting_operator')
|
||||
assert.equal(recovered.bind_confirm_state, 'idle')
|
||||
assert.equal(recovered.pending_bind_game_role, '')
|
||||
assert.ok(recovered.bound_at)
|
||||
} finally {
|
||||
if (orderId > 0) await query('DELETE FROM orders WHERE id = $1', [orderId])
|
||||
if (configId > 0) {
|
||||
await query('DELETE FROM manual_fulfillment_configs WHERE id = $1', [configId])
|
||||
}
|
||||
delete process.env.ENABLE_DEV_MOCK
|
||||
await closeDb()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'微博账号 CK 以账号级 Cookie JSON 保存并可加载',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
@@ -1011,7 +1249,8 @@ test(
|
||||
)
|
||||
|
||||
assert.equal(binding.status, 'confirmed')
|
||||
assert.equal(binding.comparison.verdict, 'match')
|
||||
assert.equal(binding.comparison.verdict, 'unknown')
|
||||
assert.equal(binding.comparison.message, '当前不是虎牙绑定任务')
|
||||
const stored = await query<{
|
||||
binding_status: string
|
||||
execution_status: string
|
||||
|
||||
Reference in New Issue
Block a user