6d46506726
安全 - /api/ziniao/** 五个匿名接口加管理员鉴权(此前可匿名换取任意员工店铺登录令牌) - 删除 Flask 遗留后门:默认密码建超管 + 每次启动写生产 users 表(服务端与客户端各一份) - 进度/详情接口归属过滤:新增 TaskProgressOwnershipSupport,11 模块 progress/light 与 /tasks/batch 接入,DTO 补 userId,前端 13 个查询封装补传(未传时后端不过滤,兼容旧端) - 代理提取链接(含账密)不再明文入日志(新增 common/util/SecretMasking) - 全局异常兜底不再回传原始异常信息;内部令牌比较改常量时间 - 登录加失败计数与锁定(10 次锁 15 分钟);品牌源文件下载加 SSRF 防护 - AdminApiGuardFilter 覆盖前缀从 2 扩到 15(开关默认 false,行为不变,为收紧做准备) - 生产关闭 springdoc/knife4j(/doc.html 匿名可读全部接口定义) 正确性 - 40901/40902 拆分:锁竞争不再被伪装成 success=true(此前客户端停止重试、分片静默丢失) - 假成功收敛:集采明细批量写失败改为抛出、去重 worker 异常标失败、4 个 worker 改判 success 字段、publish 空 ASIN 行参与批次 flush、巡店删除全失败带 error 上报 - 客户端心跳 discard 移入 finally(7 模块,失败路径不再留僵尸 RUNNING 任务) - 状态机条件更新:跟价停止循环、集采 activate/fail、imagevideo 归档回填、店铺匹配提交 性能 - 前端入口包 JS 1.05MB→204KB、CSS 355KB→10.7KB(Element Plus 改按需 + el-config-provider) - 载荷引用计数按指针里的 taskId 收敛(原 JSON 列 IN 全表扫且逐行调用) - 店铺明细多值批量 INSERT;快照 upsert 预载缓存;结果文件列改单条 UPDATE - 新增迁移 V120(补 3 个缺失索引)/V121(删 4 个被覆盖的冗余索引)/V122(URL 前缀索引) 稳定性 - 新增 common/util/ThreadPools 有界线程池替换 5 处无界队列(防堆积 OOM) - Redis 锁释放改 Lua 原子校验(原裸 delete 会误删他人已过期的锁) - imagevideo 加死节点接管;锁续期失败重试;调度池 4→16;openStream 全部加超时 - 事务内远程对象删除移到提交后;启动恢复锁按实例命名 客户端 - 不再 taskkill /f /im chrome.exe(改为按调试端口精准回收,不杀用户自己的浏览器) - 密码检测不再无条件杀紫鸟进程;品牌检测加全局互斥(代理池不再互相覆盖) - base_dir 统一到 exe 目录(原被 os.getcwd() 覆盖,日志/缓存会分裂两个目录) - 缓存加定时清理;图片下载加超时;mkstemp 句柄托管 测试 - 同步更新受影响的契约测试(构造器签名/条件更新/方法改名/新增接口方法等) - 修复 FaultInjectionTest 等 3 处 mock 未 stub 流式 read 导致的读循环 OOM - mvn test 2795 个测试全绿
273 lines
12 KiB
TypeScript
273 lines
12 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { http } from '../src/shared/api/http.ts'
|
|
import {
|
|
listProductRiskCandidates,
|
|
addProductRiskCandidate,
|
|
deleteProductRiskCandidate,
|
|
getProductRiskCountryPreference,
|
|
putProductRiskCountryPreference,
|
|
matchProductRiskShops,
|
|
getProductRiskDashboard,
|
|
getProductRiskHistory,
|
|
deleteProductRiskHistory,
|
|
createProductRiskTask,
|
|
deleteProductRiskTask,
|
|
deletePendingProductRiskShopResult,
|
|
getProductRiskTasksBatch,
|
|
getProductRiskResultDownloadUrl,
|
|
getProductRiskTaskProgressBatch,
|
|
listShopMatchCandidates,
|
|
addShopMatchCandidate,
|
|
deleteShopMatchCandidate,
|
|
getShopMatchCountryPreference,
|
|
putShopMatchCountryPreference,
|
|
matchShopMatchShops,
|
|
getShopMatchDashboard,
|
|
getShopMatchHistory,
|
|
deleteShopMatchHistory,
|
|
createShopMatchTask,
|
|
deleteShopMatchTask,
|
|
activateShopMatchTask,
|
|
completeShopMatchTaskStage,
|
|
getShopMatchTasksBatch,
|
|
getShopMatchResultDownloadUrl,
|
|
getShopMatchTaskSkipAsinsPaginated,
|
|
getShopMatchTaskProgressBatch,
|
|
} from '../src/shared/api/types/modules/shop-match.ts'
|
|
import {
|
|
type ShopMatchCreateTaskItem,
|
|
} from '../src/shared/api/types/modules/shop-match.ts'
|
|
|
|
function setupWindow() {
|
|
;(globalThis as Record<string, unknown>).window = {
|
|
localStorage: { getItem: () => '42' },
|
|
location: { origin: 'http://localhost' },
|
|
}
|
|
}
|
|
|
|
function mockRequest(
|
|
t: Parameters<typeof test>[1] extends (t: infer T) => unknown ? T : never,
|
|
impl: (config: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown; timeout?: number }) => Promise<unknown>,
|
|
) {
|
|
t.mock.method(http, 'request', impl as never)
|
|
}
|
|
|
|
const okResponse = (data: unknown) => Promise.resolve({ data: { success: true, message: 'ok', data } })
|
|
|
|
test('test_product_risk_candidates_crud', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ id: 1, shop_name: 's1' })
|
|
})
|
|
await listProductRiskCandidates()
|
|
await addProductRiskCandidate('店铺A')
|
|
await deleteProductRiskCandidate(3)
|
|
assert.equal(calls[0].url, '/newApi/api/product-risk-resolve/candidates')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/product-risk-resolve/candidates')
|
|
assert.equal(calls[1].method, 'POST')
|
|
assert.deepEqual(calls[1].data, { user_id: 42, shop_name: '店铺A' })
|
|
assert.equal(calls[2].url, '/newApi/api/product-risk-resolve/candidates/3')
|
|
assert.deepEqual(calls[2].params, { user_id: 42 })
|
|
assert.equal(calls[2].method, 'DELETE')
|
|
})
|
|
|
|
test('test_product_risk_preference_match', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ country_codes: ['US'] })
|
|
})
|
|
await getProductRiskCountryPreference()
|
|
await putProductRiskCountryPreference(['US'])
|
|
await matchProductRiskShops(['店铺A'])
|
|
assert.equal(calls[0].url, '/newApi/api/product-risk-resolve/country-preference')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/product-risk-resolve/country-preference')
|
|
assert.equal(calls[1].method, 'PUT')
|
|
assert.deepEqual(calls[1].data, { user_id: 42, country_codes: ['US'] })
|
|
assert.equal(calls[2].url, '/newApi/api/product-risk-resolve/match-shops')
|
|
assert.deepEqual(calls[2].data, { user_id: 42, shop_names: ['店铺A'] })
|
|
})
|
|
|
|
test('test_product_risk_task_apis', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ taskId: 1, items: [] })
|
|
})
|
|
await createProductRiskTask([{ shopName: '店铺A', matched: true }])
|
|
await deleteProductRiskTask(7)
|
|
await deletePendingProductRiskShopResult('店铺A')
|
|
await getProductRiskTasksBatch([5, 3])
|
|
assert.equal(calls[0].url, '/newApi/api/product-risk-resolve/tasks')
|
|
assert.deepEqual(calls[0].data, { user_id: 42, items: [{ shopName: '店铺A', matched: true }] })
|
|
assert.equal(calls[1].url, '/newApi/api/product-risk-resolve/tasks/7')
|
|
assert.equal(calls[1].method, 'DELETE')
|
|
assert.deepEqual(calls[1].params, { user_id: 42 })
|
|
assert.equal(calls[2].url, '/newApi/api/product-risk-resolve/pending-shop-result')
|
|
assert.deepEqual(calls[2].params, { user_id: 42, shop_name: '店铺A' })
|
|
assert.equal(calls[3].url, '/newApi/api/product-risk-resolve/tasks/batch')
|
|
assert.deepEqual(calls[3].data, { taskIds: [5, 3], userId: 42 })
|
|
})
|
|
|
|
test('test_product_risk_dashboard_history_download', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown> }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ candidateCount: 0, processedTaskCount: 0, successTaskCount: 1, failedTaskCount: 0 })
|
|
})
|
|
await getProductRiskDashboard()
|
|
await getProductRiskHistory()
|
|
await deleteProductRiskHistory(9)
|
|
assert.equal(calls[0].url, '/newApi/api/product-risk-resolve/dashboard')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/product-risk-resolve/history')
|
|
assert.deepEqual(calls[1].params, { user_id: 42 })
|
|
assert.equal(calls[2].url, '/newApi/api/product-risk-resolve/history/9')
|
|
assert.equal(calls[2].method, 'DELETE')
|
|
assert.equal(
|
|
getProductRiskResultDownloadUrl(7),
|
|
'http://localhost/newApi/api/product-risk-resolve/results/7/download?user_id=42',
|
|
)
|
|
})
|
|
|
|
test('test_shop_match_candidates_crud', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ id: 1, shop_name: 's1' })
|
|
})
|
|
await listShopMatchCandidates()
|
|
await addShopMatchCandidate('店铺A')
|
|
await deleteShopMatchCandidate(3)
|
|
assert.equal(calls[0].url, '/newApi/api/shop-match/candidates')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/shop-match/candidates')
|
|
assert.equal(calls[1].method, 'POST')
|
|
assert.deepEqual(calls[1].data, { user_id: 42, shop_name: '店铺A' })
|
|
assert.equal(calls[2].url, '/newApi/api/shop-match/candidates/3')
|
|
assert.equal(calls[2].method, 'DELETE')
|
|
})
|
|
|
|
test('test_shop_match_preference_match', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ country_codes: ['US'] })
|
|
})
|
|
await getShopMatchCountryPreference()
|
|
await putShopMatchCountryPreference(['US'])
|
|
await matchShopMatchShops(['店铺A'])
|
|
assert.equal(calls[0].url, '/newApi/api/shop-match/country-preference')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/shop-match/country-preference')
|
|
assert.equal(calls[1].method, 'PUT')
|
|
assert.deepEqual(calls[1].data, { user_id: 42, country_codes: ['US'] })
|
|
assert.equal(calls[2].url, '/newApi/api/shop-match/match-shops')
|
|
assert.deepEqual(calls[2].data, { user_id: 42, shop_names: ['店铺A'] })
|
|
})
|
|
|
|
test('test_shop_match_task_apis', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ taskId: 1, items: [] })
|
|
})
|
|
const item: ShopMatchCreateTaskItem = { shopName: '店铺A', matched: true }
|
|
await createShopMatchTask([item], ['US'], ['2026-09-01 10:00'])
|
|
await deleteShopMatchTask(7)
|
|
await activateShopMatchTask(7, 1)
|
|
await completeShopMatchTaskStage(7, 1)
|
|
await getShopMatchTasksBatch([5, 3])
|
|
assert.equal(calls[0].url, '/newApi/api/shop-match/tasks')
|
|
assert.equal(calls[0].method, 'POST')
|
|
assert.deepEqual(calls[0].data, { user_id: 42, items: [item], country_codes: ['US'], schedule_times: ['2026-09-01 10:00'] })
|
|
assert.equal(calls[1].url, '/newApi/api/shop-match/tasks/7')
|
|
assert.equal(calls[1].method, 'DELETE')
|
|
assert.equal(calls[2].url, '/newApi/api/shop-match/tasks/7/activate?user_id=42&stage_index=1')
|
|
assert.equal(calls[2].method, 'POST')
|
|
assert.equal(calls[3].url, '/newApi/api/shop-match/tasks/7/stage-finished?user_id=42')
|
|
assert.deepEqual(calls[3].data, { stage_index: 1 })
|
|
assert.equal(calls[4].url, '/newApi/api/shop-match/tasks/batch')
|
|
assert.deepEqual(calls[4].data, { taskIds: [5, 3], userId: 42 })
|
|
})
|
|
|
|
test('test_shop_match_dashboard_history_skip_asins', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown> }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ candidateCount: 0, processedTaskCount: 0, successTaskCount: 1, failedTaskCount: 0 })
|
|
})
|
|
await getShopMatchDashboard()
|
|
await getShopMatchHistory()
|
|
await deleteShopMatchHistory(9)
|
|
await getShopMatchTaskSkipAsinsPaginated(7, 1, 1000, { shopName: '店铺A' })
|
|
assert.equal(calls[0].url, '/newApi/api/shop-match/dashboard')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/shop-match/history')
|
|
assert.equal(calls[2].url, '/newApi/api/shop-match/history/9')
|
|
assert.equal(calls[2].method, 'DELETE')
|
|
assert.equal(calls[3].url, '/newApi/api/shop-match/tasks/7/skip-asins/paginated')
|
|
assert.deepEqual(calls[3].params, { page: 1, page_size: 1000, shop_name: '店铺A' })
|
|
assert.equal(
|
|
getShopMatchResultDownloadUrl(7),
|
|
'http://localhost/newApi/api/shop-match/results/7/download?user_id=42',
|
|
)
|
|
})
|
|
|
|
test('test_shop_match_product_risk_progress_batch', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; data?: unknown; timeout?: number }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ items: [], missingTaskIds: [] })
|
|
})
|
|
const shopMatch = await getShopMatchTaskProgressBatch([5, 3])
|
|
const productRisk = await getProductRiskTaskProgressBatch([5, 3])
|
|
assert.equal(calls[0].url, '/newApi/api/shop-match/tasks/progress/batch')
|
|
assert.deepEqual(calls[0].data, { taskIds: [3, 5], userId: 42 })
|
|
assert.equal(calls[0].timeout, 10000)
|
|
assert.equal(calls[1].url, '/newApi/api/product-risk-resolve/tasks/progress/batch')
|
|
assert.deepEqual(calls[1].data, { taskIds: [3, 5], userId: 42 })
|
|
assert.equal(calls[1].timeout, 10000)
|
|
assert.deepEqual(shopMatch, { items: [], missingTaskIds: [] })
|
|
assert.deepEqual(productRisk, { items: [], missingTaskIds: [] })
|
|
})
|
|
|
|
test('test_shop_match_product_risk_export_compat', async (t) => {
|
|
setupWindow()
|
|
const fromJavaModules = await import('../src/shared/api/java-modules.ts')
|
|
const fromShopMatch = await import('../src/shared/api/types/modules/shop-match.ts')
|
|
const productRiskNames = [
|
|
'listProductRiskCandidates', 'addProductRiskCandidate', 'deleteProductRiskCandidate',
|
|
'getProductRiskCountryPreference', 'putProductRiskCountryPreference', 'matchProductRiskShops',
|
|
'getProductRiskDashboard', 'getProductRiskHistory', 'deleteProductRiskHistory',
|
|
'createProductRiskTask', 'deleteProductRiskTask', 'deletePendingProductRiskShopResult',
|
|
'getProductRiskTasksBatch', 'getProductRiskResultDownloadUrl', 'getProductRiskTaskProgressBatch',
|
|
]
|
|
const shopMatchNames = [
|
|
'listShopMatchCandidates', 'addShopMatchCandidate', 'deleteShopMatchCandidate',
|
|
'getShopMatchCountryPreference', 'putShopMatchCountryPreference', 'matchShopMatchShops',
|
|
'getShopMatchDashboard', 'getShopMatchHistory', 'deleteShopMatchHistory',
|
|
'createShopMatchTask', 'deleteShopMatchTask', 'activateShopMatchTask',
|
|
'completeShopMatchTaskStage', 'getShopMatchTasksBatch', 'getShopMatchResultDownloadUrl',
|
|
'getShopMatchTaskSkipAsinsPaginated', 'getShopMatchTaskProgressBatch',
|
|
]
|
|
for (const name of [...productRiskNames, ...shopMatchNames]) {
|
|
assert.equal(fromJavaModules[name], fromShopMatch[name], `${name} 应为同一引用`)
|
|
}
|
|
const candidate = { id: 1, shop_name: 's1' }
|
|
assert.equal(candidate.shop_name, 's1')
|
|
})
|