fix(appearance-patent): 代理缺失回填与任务前置提示
- 本地代理回填兼容旧版全局 proxy_url,补报成功后重拉服务端快照 - 创建任务前检查服务端代理,缺失时弹窗拦截并引导配置 - 商标查询失败的真实原因写入结果原因列,不再只显示查询失败
This commit is contained in:
@@ -43,3 +43,16 @@ test('test_failed_hint_marks_task_failed_and_download_later', () => {
|
||||
assert.match(body, /'FAILED'\s*\?\s*'任务已失败'/, '提示文案应按 FAILED 切换为任务已失败')
|
||||
assert.match(body, /下载按钮稍后出现/, '失败后仍提示结果文件生成后会给出下载按钮')
|
||||
})
|
||||
|
||||
// 服务端缺代理时商标维度整批失败,必须在创建任务前弹窗拦截(2026-10-25 32300/32309)。
|
||||
test('test_missing_proxy_blocks_task_creation_with_popup', () => {
|
||||
const parseBody = functionBody('parseFiles')
|
||||
const guardIdx = parseBody.indexOf('ensureBrandCheckProxyReady')
|
||||
const createIdx = parseBody.indexOf('parseAppearancePatent(')
|
||||
assert.ok(guardIdx >= 0, 'parseFiles 必须先做服务端代理检查')
|
||||
assert.ok(createIdx > guardIdx, '代理检查必须发生在创建任务之前')
|
||||
|
||||
const guardBody = functionBody('ensureBrandCheckProxyReady')
|
||||
assert.match(guardBody, /ElMessageBox\.alert/, '缺代理时应弹窗提示,不能只 console.warn')
|
||||
assert.match(guardBody, /密钥设置/, '弹窗要告诉用户去哪里补代理')
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict'
|
||||
import { http } from '../src/shared/api/http.ts'
|
||||
import {
|
||||
clearApiSecretCache,
|
||||
ensureBrandCheckProxy,
|
||||
getServerProxySnapshot,
|
||||
getStoredApiSecret,
|
||||
getStoredApiSecretSnapshot,
|
||||
@@ -191,6 +192,93 @@ test('test_secret_store_locked_proxy_aligns_local_config_once', async (t) => {
|
||||
assert.equal(saveCalls.length, 1, '本地配置已一致时不应重复写入')
|
||||
})
|
||||
|
||||
test('test_secret_store_backfills_legacy_global_proxy_to_server', async (t) => {
|
||||
setupWindow()
|
||||
clearApiSecretCache()
|
||||
const globalUrl = 'https://api.jikip.com/ip-get?num=2&key=legacy'
|
||||
const migratePayloads: Array<{ items?: Array<{ moduleKey?: string; value?: string }> }> = []
|
||||
let bundleCalls = 0
|
||||
// 老版本只把代理存在全局 proxy_url,proxy_users 里没有该用户
|
||||
attachDesktopBridge(() => ({ proxy_url: globalUrl, proxy_mode: 2 }), (patch) => patch)
|
||||
mockRequest(t, (req) => {
|
||||
if ((req.url || '').includes('/migrate')) {
|
||||
migratePayloads.push(req.data as { items?: Array<{ moduleKey?: string; value?: string }> })
|
||||
return okResponse({ migrated: 1 })
|
||||
}
|
||||
bundleCalls += 1
|
||||
return okResponse({
|
||||
items: [serverItem('appearance-patent'), serverItem('similar-asin')],
|
||||
requiredModules: ['appearance-patent', 'similar-asin'],
|
||||
complete: false,
|
||||
// 补报前无代理;补报后服务端有了代理
|
||||
proxy: bundleCalls > 1
|
||||
? { ...serverItem('proxy'), exists: true, masked: 'https://api.jikip.com' }
|
||||
: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
await loadApiSecrets({ force: true })
|
||||
|
||||
const proxyMigrate = migratePayloads
|
||||
.flatMap((payload) => payload.items || [])
|
||||
.find((item) => item.moduleKey === 'proxy')
|
||||
assert.equal(proxyMigrate?.value, globalUrl, '旧版全局代理应补报到服务端')
|
||||
assert.equal(getServerProxySnapshot()?.exists, true, '补报后应重拉服务端代理快照')
|
||||
})
|
||||
|
||||
test('test_secret_store_user_proxy_wins_over_legacy_global', async (t) => {
|
||||
setupWindow()
|
||||
clearApiSecretCache()
|
||||
const userUrl = 'https://api.jikip.com/ip-get?num=1&key=user'
|
||||
const globalUrl = 'https://api.jikip.com/ip-get?num=2&key=global'
|
||||
const migratePayloads: Array<{ items?: Array<{ moduleKey?: string; value?: string }> }> = []
|
||||
attachDesktopBridge(
|
||||
() => ({ proxy_users: { '42': { proxy_url: userUrl, proxy_mode: 1 } }, proxy_url: globalUrl, proxy_mode: 2 }),
|
||||
(patch) => patch,
|
||||
)
|
||||
mockRequest(t, (req) => {
|
||||
if ((req.url || '').includes('/migrate')) {
|
||||
migratePayloads.push(req.data as { items?: Array<{ moduleKey?: string; value?: string }> })
|
||||
return okResponse({ migrated: 1 })
|
||||
}
|
||||
return bundleResponse([serverItem('appearance-patent'), serverItem('similar-asin')])
|
||||
})
|
||||
|
||||
await loadApiSecrets({ force: true })
|
||||
|
||||
const proxyMigrate = migratePayloads
|
||||
.flatMap((payload) => payload.items || [])
|
||||
.find((item) => item.moduleKey === 'proxy')
|
||||
assert.equal(proxyMigrate?.value, userUrl, '用户自己的代理优先于旧版全局代理')
|
||||
})
|
||||
|
||||
test('test_secret_store_brand_check_proxy_missing_is_visible', async (t) => {
|
||||
setupWindow()
|
||||
clearApiSecretCache()
|
||||
mockRequest(t, () => bundleResponse([serverItem('appearance-patent'), serverItem('similar-asin')]))
|
||||
|
||||
const result = await ensureBrandCheckProxy()
|
||||
|
||||
assert.deepEqual(result, { ok: false, state: 'missing' })
|
||||
})
|
||||
|
||||
test('test_secret_store_brand_check_proxy_present_passes', async (t) => {
|
||||
setupWindow()
|
||||
clearApiSecretCache()
|
||||
mockRequest(t, () =>
|
||||
okResponse({
|
||||
items: [serverItem('appearance-patent'), serverItem('similar-asin')],
|
||||
requiredModules: ['appearance-patent', 'similar-asin'],
|
||||
complete: false,
|
||||
proxy: { ...serverItem('proxy'), exists: true, masked: 'https://api.jikip.com' },
|
||||
}),
|
||||
)
|
||||
|
||||
const result = await ensureBrandCheckProxy()
|
||||
|
||||
assert.deepEqual(result, { ok: true, state: 'server' })
|
||||
})
|
||||
|
||||
test('test_secret_store_locked_proxy_not_in_module_cards', async (t) => {
|
||||
setupWindow()
|
||||
clearApiSecretCache()
|
||||
|
||||
Reference in New Issue
Block a user