Files
crawler-plugin/admin-frontend-vue/tests/mount/user-secret-status-band.mount.test.ts
T
huangzd1997 0114a5b7a7 fix(文案): NO_AVAILABLE_CHANNEL 不再断言"是你自己的采集占着",三成因一次说全
现网实测把这句文案证伪了:零并发单发 overseas.proxy.qg.net/get(就这把平台 key)仍回
NO_AVAILABLE_CHANNEL,而两台机器本小时都没有一条青果提取记录(vc 槽空闲、maixiang 走的是
极客且本小时只确立 17 次租约)。所以"等约 3 分钟释放"是一个**猜出来的单一成因**,
它会把人引去反复点、等一个根本不会来的释放。

供应商这个码至少三种成因,文案一次给全并给出去哪查:同账号其他提取占着(约 3 分钟)、
这把 key 的套餐到期/无余量、后台把鉴权切成 IP 白名单档(我们只做账密档,切了就一直拿不到
通道——铁律 25 那条口径)。后管档位名同步从「待释放」改成「无可用通道」,用户端面板提示
补"隔几分钟仍报同一句就别再等,去青果控制台核对通道数与有效期"。

判据跟着反转:原来那条测试把"正被你自己的采集占着"当事实钉住,现在改成
doesNotContain 那句 + 必须含「没有可用的空闲通道」「IP 白名单」——谁改回单一成因即红。

顺带清掉 B73-14:UserSecretModule.defaultChannel() 的注释写"代理=青果(10-29 拍板)",
而代码取 ProxyProvider.DEFAULT=JIKIP(10-30 拍板改回极客)——注释与代码相反,下一个人照
注释判断"没写 channel 就是青果"会做错事;改成只跟着 DEFAULT 取值并写明来历。

后端整量 5187/0 失败/19 skipped;用户端 994+55、后管 1872+68、tsc 两面 rc=0、
ops 可读性棘轮 10 绿。
2026-11-02 17:09:08 +08:00

263 lines
13 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 密钥管理列表页「检测结果分档」的界面侧判据(2026-11-02)。
*
* 现网证据:库里 uid=1 的 proxy 行是 `check_status=error / check_code=channel_busy`,
* 数据是对的、界面不认识这个码,于是渲染成「无法判定」——管理员分不清
* 「被自己的采集占着(等 3 分钟再点)」「密钥坏了」「欠费」这三种完全不同的处置。
*
* 这一支跑真组件+真 pinia store,API 用假数据顶掉,逐档核对:
* ① 药丸文字与配色类名(`is-retry` 是新档,既不红也不黄);
* ② 悬停详情里能看到后端 `check_message` 原文(措辞权威在后端,界面只搬运);
* ③ 一格上的两颗药丸分别取 `channel`(货源)与 `check_status`/`check_code`(状态)——
* 把状态当渠道渲染(或反过来)会在这里红。
*
* 夹具里的凭据一律假值(fakekey/fakepwd/sk-fake),本仓有尺子按长度+高熵认凭据。
*
* 跑法:`npx vitest run tests/mount/user-secret-status-band.mount.test.ts`
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import UserSecretsPage from '@/pages/account/UserSecretsPage.vue'
import { useAdminSessionStore } from '@/stores/admin-session'
import { useCompanyTabStore } from '@/stores/company-tab'
const secretsApi = vi.hoisted(() => ({
fetchUserSecretList: vi.fn(),
checkUserSecret: vi.fn(),
deleteUserSecret: vi.fn(),
saveUserSecretModule: vi.fn(),
clearUserSecretModule: vi.fn(),
}))
vi.mock('@/api/user-secrets', () => secretsApi)
/** 后端那句人话(CHANNEL_BUSY_MESSAGE 的形状):措辞权威在后端,界面只原样透出。 */
const BUSY_MESSAGE = '通道正被你自己的采集占着,等约 3 分钟释放后再点检测'
const BALANCE_MESSAGE = '代理服务商余额不足,请充值后重试'
const MASKED_PROXY = 'https://overseas.proxy.qg.net'
function moduleCell(moduleKey: string, over: Record<string, unknown> = {}) {
return {
moduleKey,
moduleLabel: moduleKey,
channel: null,
masked: 'sk-f****9BgQ',
full: '',
exists: true,
locked: false,
checkStatus: 'passed',
checkCode: 'ok',
checkMessage: '连通正常',
checkLatencyMs: 12,
checkedAt: '2026-11-02T15:51:07',
updatedAt: '2026-11-02T15:51:07',
...over,
}
}
function row(over: Record<string, unknown> = {}) {
return {
userId: 7,
username: 'alice',
groups: [],
leaderUsername: '',
similarAsin: moduleCell('similar-asin', { moduleLabel: '货源查询密钥', channel: 'longtaitou' }),
appearancePatent: moduleCell('appearance-patent', { moduleLabel: '外观专利密钥', channel: 't8star' }),
proxy: moduleCell('proxy', { moduleLabel: '代理设置', channel: 'qingguo', masked: MASKED_PROXY }),
status: 'passed',
statusMessage: '三项均检测通过',
createdAt: '2026-11-01T09:00:00',
updatedAt: '2026-11-02T15:51:07',
...over,
}
}
/** 表头文字定位列(不靠列序数:加列就会全体错位),返回该格里的药丸。 */
function pills(wrapper: VueWrapper<Element>, header: string) {
const headers = wrapper.findAll('thead th').map((th) => th.text().trim())
const index = headers.findIndex((label) => label.includes(header))
expect(index, `表头里找不到「${header}」`).toBeGreaterThanOrEqual(0)
return wrapper.findAll('tbody tr')[0].findAll('td')[index].findAll('.wh-pill').map((pill) => ({
text: pill.text().trim(),
classes: pill.classes(),
title: pill.attributes('title') ?? '',
}))
}
function cellText(wrapper: VueWrapper<Element>, header: string): string {
const headers = wrapper.findAll('thead th').map((th) => th.text().trim())
const index = headers.findIndex((label) => label.includes(header))
return wrapper.findAll('tbody tr')[0].findAll('td')[index].text()
}
describe('密钥管理页:检测结果按 check_code 分档渲染', () => {
let pinia: Pinia
beforeEach(() => {
vi.clearAllMocks()
pinia = createPinia()
setActivePinia(pinia)
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
useCompanyTabStore().setActiveId(1)
})
async function mountWith(rowValue: Record<string, unknown>) {
secretsApi.fetchUserSecretList.mockResolvedValue({ items: [rowValue], total: 1, page: 1, pageSize: 15, groupOptions: [] })
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia] } })
await flushPromises()
return wrapper
}
/** 现网 uid=1 那一行的形状:error + channel_busy。 */
function busyRow() {
return row({
status: 'error',
statusMessage: '存在无法判定的检测结果',
proxy: moduleCell('proxy', {
moduleLabel: '代理设置',
channel: 'qingguo',
masked: MASKED_PROXY,
checkStatus: 'error',
checkCode: 'channel_busy',
checkMessage: BUSY_MESSAGE,
}),
})
}
it('channel_busy 渲染成「无可用通道」+独立配色,不再掉进「无法判定」', async () => {
const wrapper = await mountWith(busyRow())
const proxyPills = pills(wrapper, '代理设置')
const statusPill = proxyPills[proxyPills.length - 1]
expect(statusPill.text).toBe('无可用通道')
expect(statusPill.classes).toContain('is-retry')
expect(cellText(wrapper, '代理设置')).not.toContain('无法判定')
// 供应商那颗药丸还在原位:改的是状态档,不是把货源档挤掉
expect(proxyPills[0].text).toBe('青果')
expect(proxyPills[0].classes).toContain('is-source')
})
it('整行只剩「等一等」那一族时,行级状态列补成「可重试」', async () => {
const wrapper = await mountWith(busyRow())
const rowPill = pills(wrapper, '状态')[0]
expect(rowPill.text).toBe('可重试')
expect(rowPill.classes).toContain('is-retry')
expect(rowPill.text).not.toBe('无法判定')
})
it('混进一格「不会自己好」的问题时,行级不许谎报可重试', async () => {
const wrapper = await mountWith({
...busyRow(),
appearancePatent: moduleCell('appearance-patent', {
moduleLabel: '外观专利密钥',
channel: 't8star',
checkStatus: 'error',
checkCode: 'tunnel_unverified',
checkMessage: '这条链接里没有可用于隧道验连的账密,请重新填写',
}),
})
expect(pills(wrapper, '状态')[0].text).toBe('无法判定')
expect(pills(wrapper, '外观专利密钥').at(-1)!.text).toBe('链接缺账密')
})
it('悬停能看到后端 check_message 原文:单格与行级 tooltip 都带上', async () => {
const wrapper = await mountWith(busyRow())
const proxyStatusTitle = pills(wrapper, '代理设置').at(-1)!.title
expect(proxyStatusTitle).toContain(BUSY_MESSAGE)
expect(proxyStatusTitle).toContain(MASKED_PROXY, '脱敏值仍然在同一条 tooltip 里')
const rowTitle = pills(wrapper, '状态')[0].title
expect(rowTitle).toContain('存在无法判定的检测结果', '后端行级摘要不动')
expect(rowTitle).toContain(`代理设置:${BUSY_MESSAGE}`, '运维判「是欠费还是被自己占着」就靠这句')
})
it('欠费(现网 21 行)保留自己那一档,不被新码表挤去「无法判定」', async () => {
const wrapper = await mountWith(row({
status: 'failed',
statusMessage: '存在检测失败的配置',
proxy: moduleCell('proxy', {
moduleLabel: '代理设置',
channel: 'qingguo',
masked: MASKED_PROXY,
checkStatus: 'failed',
checkCode: 'insufficient_balance',
checkMessage: BALANCE_MESSAGE,
}),
}))
const balancePill = pills(wrapper, '代理设置').at(-1)!
expect(balancePill.text).toBe('欠费')
expect(balancePill.classes).toContain('is-warn')
expect(pills(wrapper, '状态')[0].text).toBe('检测失败', '行级优先级是后端的:failed 永远压过 error')
expect(pills(wrapper, '代理设置').at(-1)!.title).toContain(BALANCE_MESSAGE)
})
it('密钥坏了与查不出是两档:invalid_key 红、空码/未知码才是「无法判定」', async () => {
const wrapper = await mountWith(row({
status: 'error',
similarAsin: moduleCell('similar-asin', { moduleLabel: '货源查询密钥', channel: 'longtaitou', checkStatus: 'failed', checkCode: 'invalid_key', checkMessage: '密钥无效(401)' }),
appearancePatent: moduleCell('appearance-patent', { moduleLabel: '外观专利密钥', channel: 't8star', checkStatus: 'error', checkCode: '', checkMessage: '' }),
proxy: moduleCell('proxy', { moduleLabel: '代理设置', channel: 'qingguo', masked: MASKED_PROXY, checkStatus: 'error', checkCode: 'a_code_not_registered', checkMessage: '' }),
}))
expect(pills(wrapper, '货源查询密钥').at(-1)!.text).toBe('密钥失效')
expect(pills(wrapper, '货源查询密钥').at(-1)!.classes).toContain('is-blocked')
expect(pills(wrapper, '外观专利密钥').at(-1)!.text).toBe('无法判定')
expect(pills(wrapper, '代理设置').at(-1)!.text).toBe('无法判定')
})
it('没配与没检测不许冒充「无法判定」', async () => {
const wrapper = await mountWith(row({
status: 'unknown',
statusMessage: '存在尚未检测的配置',
similarAsin: moduleCell('similar-asin', { moduleLabel: '货源查询密钥', exists: false, checkStatus: 'unknown', checkCode: '', checkMessage: '' }),
appearancePatent: moduleCell('appearance-patent', { moduleLabel: '外观专利密钥', channel: 't8star', checkStatus: 'unknown', checkCode: '', checkMessage: '' }),
}))
expect(pills(wrapper, '货源查询密钥').at(-1)!.text).toBe('未配置')
expect(cellText(wrapper, '货源查询密钥')).toContain('未配置')
expect(pills(wrapper, '外观专利密钥').at(-1)!.text).toBe('未检测')
expect(pills(wrapper, '状态')[0].text).toBe('未检测')
})
it('一格上的两颗药丸不同源:货源取 channel、状态取 check_status/check_code', async () => {
// 把代理供应商值塞进 LLM 行的 channel:货源那颗药丸必须认不出(走「—」),
// 状态那颗仍按 check_code 出「鉴权被拒」——两值互不串门,才是「不同源」的正证。
const wrapper = await mountWith(row({
status: 'failed',
similarAsin: moduleCell('similar-asin', { moduleLabel: '货源查询密钥', channel: 'qingguo', checkStatus: 'failed', checkCode: 'forbidden', checkMessage: '密钥被拒绝(403)' }),
appearancePatent: moduleCell('appearance-patent', { moduleLabel: '外观专利密钥', channel: 't8star', checkStatus: 'passed', checkCode: 'ok' }),
}))
const similarPills = pills(wrapper, '货源查询密钥')
expect(similarPills[0].text).toBe('—')
expect(similarPills[1].text).toBe('鉴权被拒')
// 反向:把状态词塞进渠道位也不会被认成货源
const llmPills = pills(wrapper, '外观专利密钥')
expect(llmPills[0].text).toBe('贞贞')
expect(llmPills[1].text).toBe('通过')
expect(llmPills[0].classes).toContain('is-source')
expect(llmPills[1].classes).toContain('is-allowed')
})
it('筛选项把 error 这一档的两个可能读法都点名(选了要能筛到无可用通道的行)', async () => {
const wrapper = await mountWith(busyRow())
const options = wrapper.findAll('.secrets-filter-row select')[0].findAll('option').map((option) => option.text().trim())
expect(options).toContain('无法判定/可重试')
expect(options).not.toContain('无法判定')
})
it('立即检测的 toast 用后端那句原文,不再硬写「无法判定」', async () => {
secretsApi.fetchUserSecretList.mockResolvedValue({ items: [busyRow()], total: 1, page: 1, pageSize: 15, groupOptions: [] })
secretsApi.checkUserSecret.mockResolvedValue([
{ moduleKey: 'proxy', checkStatus: 'error', checkCode: 'channel_busy', checkMessage: BUSY_MESSAGE, checkLatencyMs: 30, checkedAt: '2026-11-02T15:51:07', viaProxy: false },
])
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia] } })
await flushPromises()
const checkButton = wrapper.findAll('button').find((button) => button.text().trim() === '立即检测')
expect(checkButton, '行内应有「立即检测」入口').toBeDefined()
await checkButton!.trigger('click')
await flushPromises()
// ElMessage 真渲染进 body:读的是那一句后端原文,不是界面自己拼的「部分配置本次无法判定」
const shown = document.body.textContent ?? ''
expect(shown).toContain(BUSY_MESSAGE)
expect(shown).not.toContain('部分配置本次无法判定')
})
})