cc22600a07
按拍板:数据源=实时查上游不落库(⇒ 本窗零 Flyway、零 Schema);列形态=拆两列,不是一列两行—— 两张货源字典本就互不相通(LLM 行为渠道 longtaitou/t8star,代理行为供应商 qingguo/jikip),合成一格 就是 11-02 那次"代理行贴出龙抬头"的串档形状重来一遍(铁律 25)。不加 v-if="isSuperAdmin":主管必须 能解释组员任务为什么挂欠费,鉴权维持 requireAdmin + DataReadScope。 - src/api/user-secrets.ts:fetchAdminSecretBalances(userIds, companyId?),POST /api/admin/user-secrets/balances, 超时放宽到 30s(服务端整请求预算 10s,客户端必须比它长,否则拿到的是本地掐断而不是"上游未应答")。 - user-secret-model.ts:llmBalanceLines/proxyBalanceLine 纯函数——**两张字典各查各的**、跨域一律 —、 未知渠道只出 — 不出钱;available=false 时把 message 挂进 title 而不是画成 0;同一账号两个模块归到 同一个渠道名下只列一次钱。保持零 @/ 别名以便 node --test 直测。 - UserSecretsPage.vue:两个 <th>(LLM 余额 170px/代理余量 160px,放「更新时间」前),两个 <td> 首屏画 —/查询中, 列表返回后异步填(不阻塞首屏);colspan 由 isSuperAdmin ? 10 : 9 改成 12 : 11(两处同改,892d88ed 的提交信息 专门写过这句);表格 min-width 相应 +240px;「刷新余额」按钮按 BALANCE_BATCH=20 分批请求。 - 已核对 ops-cell-must-wrap.test.ts:它的 opsColDecl() 正则锚在表头文字「操作」上,新增 <th> 排在它之前不影响 UserSecretsPage: 314 下限 ⇒ 那张表不改(实测绿)。 - mock-admin-server.mjs 补两列夹具(一条有数、一条全查不到)供 dev/e2e。 测试:tests/密钥余额列读数.test.ts 12 例(跨域不认、坏值不画 0)+ tests/mount/user-secret-balance-columns.mount.test.ts 9 例——按表头文字定位不靠列序数,并钉 <th> 数=<td> 数= 空行 colspan(超管与非超管两种形状各一遍),把"加列忘改 colspan"直接钉死。既有 status-band 挂载格的夹具 mock 补一个 fetchAdminSecretBalances 函数名(页面挂载即取余额,缺它整个模块 mock 会炸),不是判据改动。 刻意不新增 readSource 钉 ⇒ 不动 tests/baselines/source-pin-ledger.json。vue-tsc rc=0、node --test 1890 例、vitest 77 例。
264 lines
13 KiB
TypeScript
264 lines
13 KiB
TypeScript
/**
|
||
* 密钥管理列表页「检测结果分档」的界面侧判据(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(),
|
||
fetchAdminSecretBalances: 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('部分配置本次无法判定')
|
||
})
|
||
})
|