fix(后管): 状态列认得新分的 check_code,不再一律掉回「无法判定」

现网证据:uid=1 的 proxy 行库里已是 channel_busy(15:51 用户自己点检测写的),
后管却显示「无法判定」——数据对、界面不认识这个码。今天后端把青果检测从"无条件
假通过"改成真提取分档后,码集扩到 ok/channel_busy/invalid_key/forbidden/rate_limited/
insufficient_balance/tunnel_unverified/provider_error/网络超时族,前端只认旧几档就会
把"等一会儿就好"和"密钥坏了"混成同一个黄标。

档位:channel_busy→待释放(青,可重试族);rate_limited/timeout/network_error/
server_error→各自青档;insufficient_balance→欠费(现网 21 行原本吊在 failed 上,
改成按码认);tunnel_unverified→链接缺账密;invalid_key/forbidden/bad_request/
provider_error→红;**「无法判定」只留给空码/未知码**,unknown 留「未检测」
(那是后端 upsert 初值=从没问过,不是问不出)。句子一律取后端 check_message 原文,
前端不再按码自己拼措辞。行级汇总同样分族:逐格全属可重试才叫「可重试」。

判据:单元 9→19 支(含逐码档位表)+新增 mount 10 支;变异验证删掉 channel_busy
一行→单元 4 红+挂载 2 红。本面 node --test 1872/0、vitest 12 文件 68/0、tsc rc=0。
source-pin 台账按该尺子自带开关重生成(只多这一支文件)。
This commit is contained in:
2026-11-02 16:20:08 +08:00
parent 2cbd99ed4f
commit e26a157037
5 changed files with 653 additions and 55 deletions
@@ -1,10 +1,10 @@
{
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
"totals": {
"files": 252,
"cases": 1753,
"pins": 456,
"reads": 651
"files": 253,
"cases": 1772,
"pins": 457,
"reads": 652
},
"files": {
"admin-scaffold.test.ts": {
@@ -1266,6 +1266,11 @@
"cases": 4,
"pins": 0,
"reads": 1
},
"密钥货源标签与代理脱敏.test.ts": {
"cases": 19,
"pins": 1,
"reads": 1
}
}
}
@@ -0,0 +1,262 @@
/**
* 密钥管理列表页「检测结果分档」的界面侧判据(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('部分配置本次无法判定')
})
})
@@ -1,20 +1,31 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import {
DEFAULT_PROXY_PROVIDER,
INDETERMINATE_BAND,
NOT_CHECKED_BAND,
PASSED_BAND,
UNKNOWN_SOURCE_LABEL,
buildProxyEntryPayload,
checkCodeBand,
emptyProxyEntryDraft,
isRetryBand,
llmSourceLabel,
moduleStatusBand,
proxyDisplayText,
proxySourceLabel,
rowDetailLines,
rowStatusBand,
validateProxyEntry,
} from '../src/pages/account/user-secret-model.ts'
import { QINGGUO_EXTRACT_URL, composeQingguoLink } from '../src/shared/utils/qingguo-link.ts'
// 密钥管理页(后管)两条收口的判据(2026-11-02):
// 密钥管理页(后管)三条收口的判据(2026-11-02):
// ① 货源标签按模块分字典——代理列只认供应商,LLM 渠道名不许出现在代理行上;
// ② 代理列只显示后端脱敏值(masked),界面既不回落原文、也没有可预填的整条链接。
// ② 代理列只显示后端脱敏值(masked),界面既不回落原文、也没有可预填的整条链接;
// ③ 检测结果按 `check_code` 分档——后端今天把青果检测分成一族供应商码,界面只认
// `check_status` 三档就会把「通道被自己占着」和「密钥坏了」「欠费」挤成同一句「无法判定」。
// 夹具里的 key/pwd 全是假值(fakekey/fakepwd),本仓有尺子按长度+高熵认凭据。
test('代理列只认供应商:LLM 渠道值在代理列认不出', () => {
@@ -100,3 +111,168 @@ test('载荷带上这一单的供应商:channel 缺失会被后端按域名识
assert.equal(buildProxyEntryPayload({ provider: 'qingguo', authkey: 'fakekey', authpwd: 'fakepwd', link: '' })?.channel, 'qingguo')
assert.equal(buildProxyEntryPayload({ provider: 'jikip', authkey: '', authpwd: '', link: 'https://api.example.test/ip-get' })?.channel, 'jikip')
})
/* ------------------------------------------------------------------ *
* ③ 检测结果按 check_code 分档(2026-11-02)
*
* 码集与状态取自后端 `UserApiSecretCheckService` 的 `CODE_*`/`STATUS_*`(逐条对着源码抄):
* `channel_busy`、`tunnel_unverified`、`rate_limited`、`timeout`、`network_error`、`server_error`
* 落 `error`;`insufficient_balance`、`invalid_key`、`forbidden`、`bad_request`、`provider_error`、
* `network_error`(提取接口不可达那一支)落 `failed`;`ok` 落 `passed`。
* 界面只看 `check_status` 的话,前一半全被挤成「无法判定」——现网 uid=1 的 proxy 行就是这么花的。
* ------------------------------------------------------------------ */
/** 后端 2026-11-02 那一版实际会下发的码全集(新增码时这张清单要一起长)。 */
const BACKEND_CHECK_CODES = [
'ok',
'channel_busy',
'invalid_key',
'forbidden',
'bad_request',
'rate_limited',
'server_error',
'network_error',
'timeout',
'provider_error',
'insufficient_balance',
'tunnel_unverified',
]
/** 已配置的一格(默认 error + 空码:那是「问了问不出」的形状,不是任何一档码)。 */
function checkedModule(over: Record<string, unknown> = {}) {
return { exists: true, moduleLabel: '代理设置', checkStatus: 'error', checkCode: '', checkMessage: '', ...over }
}
test('后端分出的每一档码都不许掉进「无法判定」(逐码扫全集)', () => {
const offenders: string[] = []
for (const code of BACKEND_CHECK_CODES) {
// 同一个码在 error/failed 两个状态下都扫一遍:`network_error` 后端就两支都用
for (const status of ['error', 'failed']) {
const band = moduleStatusBand(checkedModule({ checkCode: code, checkStatus: status }))
if (band.label === INDETERMINATE_BAND.label) offenders.push(`${status}/${code}`)
}
}
assert.deepEqual(offenders, [], '这些码又被当成「无法判定」渲染:' + offenders.join(', '))
})
test('逐码档位表:档名与配色都登记在案(可重试那一族既不正红也不黄)', () => {
const table: Array<[string, string, string]> = [
['ok', '通过', 'is-allowed'],
['channel_busy', '待释放', 'is-retry'],
['rate_limited', '限流重试', 'is-retry'],
['timeout', '超时重试', 'is-retry'],
['network_error', '网络重试', 'is-retry'],
['server_error', '上游重试', 'is-retry'],
['insufficient_balance', '欠费', 'is-warn'],
['tunnel_unverified', '链接缺账密', 'is-warn'],
['invalid_key', '密钥失效', 'is-blocked'],
['forbidden', '鉴权被拒', 'is-blocked'],
['bad_request', '参数被拒', 'is-blocked'],
['provider_error', '供应商报错', 'is-blocked'],
]
assert.deepEqual(table.map((row) => row[0]).sort(), [...BACKEND_CHECK_CODES].sort(), '这张表与码集不同步:漏档就红')
for (const [code, label, tone] of table) {
const band = moduleStatusBand(checkedModule({ checkCode: code }))
assert.equal(band.label, label, `码 ${code} 的档名变了`)
assert.equal(band.tone, tone, `码 ${code} 的配色变了`)
assert.ok(band.label.length <= 5, `档名「${band.label}」超过 5 字:状态列 130px 会把药丸裁掉`)
}
})
test('变异钉子:把 channel_busy 改回「不认识」立刻红', () => {
const busy = moduleStatusBand(checkedModule({ checkCode: 'channel_busy' }))
const blank = moduleStatusBand(checkedModule({ checkCode: '' }))
// 这一条就是今天的线上形状:认不出码 ⇒ 与空码同档 ⇒ 显示「无法判定」
assert.notDeepEqual(busy, blank, 'channel_busy 与空码同档=又回到「error 一律无法判定」')
assert.ok(isRetryBand(busy), 'channel_busy 必须落在可重试那一族')
assert.equal(busy.tone, 'is-retry')
assert.notEqual(busy.tone, INDETERMINATE_BAND.tone, '可重试与查不出必须是两种配色')
})
test('欠费(现网 21 行)有自己的一档,且不再吊在 check_status=failed 上', () => {
const broke = checkedModule({ checkCode: 'insufficient_balance' })
assert.deepEqual(moduleStatusBand(broke), { label: '欠费', tone: 'is-warn' })
// 后端哪天把欠费落成 error,界面仍然说欠费(按码判档,不看状态脸色)
assert.deepEqual(moduleStatusBand({ ...broke, checkStatus: 'error' }), { label: '欠费', tone: 'is-warn' })
assert.notEqual(moduleStatusBand(broke).label, INDETERMINATE_BAND.label)
})
test('「无法判定」只留给真没结论:空码与未知码才落这一档', () => {
assert.deepEqual(moduleStatusBand(checkedModule({ checkCode: '' })), INDETERMINATE_BAND)
assert.deepEqual(moduleStatusBand(checkedModule({ checkCode: ' ' })), INDETERMINATE_BAND)
assert.deepEqual(moduleStatusBand(checkedModule({ checkCode: 'a_code_backend_has_not_invented_yet' })), INDETERMINATE_BAND)
// 没问过的格子不是「问不出」:后端 upsert 后 check_status=unknown,这里留「未检测」
assert.deepEqual(moduleStatusBand(checkedModule({ checkStatus: 'unknown' })), NOT_CHECKED_BAND)
assert.deepEqual(moduleStatusBand(checkedModule({ checkStatus: '' })), NOT_CHECKED_BAND)
assert.notDeepEqual(NOT_CHECKED_BAND, INDETERMINATE_BAND, '「未检测」与「无法判定」是两件事,不许并档')
// 未配置优先于一切状态
assert.deepEqual(moduleStatusBand(checkedModule({ exists: false, checkCode: 'channel_busy' })), { label: '未配置', tone: 'is-unknown' })
assert.deepEqual(moduleStatusBand(undefined), { label: '未配置', tone: 'is-unknown' })
// 后端新增一档状态而前端没登记:failed 兜底成「失败」,不把坏说成查不出
assert.equal(moduleStatusBand(checkedModule({ checkStatus: 'failed', checkCode: 'brand_new_code' })).tone, 'is-blocked')
})
test('passed 状态一律「通过」:码位上留着旧值也不许翻档', () => {
assert.deepEqual(moduleStatusBand(checkedModule({ checkStatus: 'passed', checkCode: 'ok' })), PASSED_BAND)
// 后端 applyCheckOutcome 状态与码是同一条 UPDATE,留旧码属异常;此时以状态为准,不给管理员一个假红灯
assert.deepEqual(moduleStatusBand(checkedModule({ checkStatus: 'passed', checkCode: 'timeout' })), PASSED_BAND)
})
test('码名归一:大小写与首尾空格不改变档位', () => {
assert.deepEqual(checkCodeBand(' CHANNEL_BUSY '), checkCodeBand('channel_busy'))
assert.deepEqual(checkCodeBand('Insufficient_Balance')?.label, '欠费')
assert.equal(checkCodeBand(null), null)
assert.equal(checkCodeBand(undefined), null)
assert.equal(checkCodeBand(''), null)
})
test('行级状态:整行只剩可重试那一族时补成「可重试」,混进别的就还「无法判定」', () => {
const busyRow = {
status: 'error',
similarAsin: checkedModule({ moduleLabel: '货源查询密钥', checkStatus: 'passed', checkCode: 'ok' }),
appearancePatent: checkedModule({ moduleLabel: '外观专利密钥', checkStatus: 'passed', checkCode: 'ok' }),
proxy: checkedModule({ checkStatus: 'error', checkCode: 'channel_busy' }),
}
assert.deepEqual(rowStatusBand(busyRow), { label: '可重试', tone: 'is-retry' })
// 另一格是「链接缺账密」:那一格不会自己好,把整行说成可重试等于让管理员一直等
assert.deepEqual(rowStatusBand({ ...busyRow, appearancePatent: checkedModule({ checkCode: 'tunnel_unverified' }) }), INDETERMINATE_BAND)
// 后端行级聚合的其余取值原样保留(优先级是后端的,界面不重排)
assert.deepEqual(rowStatusBand({ status: 'passed' }), { label: '检测通过', tone: 'is-allowed' })
assert.deepEqual(rowStatusBand({ status: 'failed' }), { label: '检测失败', tone: 'is-blocked' })
assert.deepEqual(rowStatusBand({ status: 'incomplete' }), { label: '未配齐', tone: 'is-warn' })
assert.deepEqual(rowStatusBand({ status: 'unknown' }), NOT_CHECKED_BAND)
assert.deepEqual(rowStatusBand({ status: 'error' }), INDETERMINATE_BAND, '行级 error 但一格码都认不出时仍是「无法判定」')
assert.deepEqual(rowStatusBand(null), NOT_CHECKED_BAND)
})
test('行级明细逐字搬后端 check_message:前端不改写、不另拼句子', () => {
const busyMessage = '后端原话:通道被占,等约 3 分钟再点'
const lines = rowDetailLines({
status: 'error',
similarAsin: checkedModule({ moduleLabel: '货源查询密钥', checkStatus: 'passed', checkCode: 'ok', checkMessage: '连通正常' }),
appearancePatent: checkedModule({ moduleLabel: '外观专利密钥', exists: false, checkMessage: '' }),
proxy: checkedModule({ checkStatus: 'error', checkCode: 'channel_busy', checkMessage: busyMessage }),
})
assert.deepEqual(lines, ['货源查询密钥:连通正常', `代理设置:${busyMessage}`])
assert.ok(lines[1].endsWith(busyMessage), `后端那句被改写了:${lines[1]}`)
// 没有 message 的格子不占位(否则 tooltip 里一串空段,运维读不到重点)
assert.deepEqual(rowDetailLines({ proxy: checkedModule({ checkMessage: ' ' }) }), [])
})
test('页面只有一张码表:不留旧 switch、tooltip 取后端 checkMessage、is-retry 真有条配色', () => {
const page = readSource('src/pages/account/UserSecretsPage.vue')
// ① 页面不得自带第二张表:两处各判各的,后端加分档时界面只会漏(今天漏的就是 channel_busy)
for (const code of BACKEND_CHECK_CODES) {
// 'ok' 这种两字母串当子串查必然误报(token/lock 里就有),它也不是会漏进旧 switch 的那族
if (code.length < 4) continue
assert.ok(!page.includes(code), `页面里又写了一遍码名 ${code}`)
}
assert.ok(!/case 'error':/.test(page), "页面里还留着按状态硬分档的旧 switch('error' 一律「无法判定」)")
assert.match(page, /moduleStatusBand\(/, '单格药丸必须走模型那一档')
assert.match(page, /rowStatusBand\(row\)/, '行级药丸必须吃整行:后端只剩一个 error,逐格码才说得清')
// ② 悬停那句必须是后端原文,且不许开回 `full` 那条旁路
assert.match(page, /module\.checkMessage/, 'tooltip 要的是后端那句人话(运维判欠费还是被自己占着就靠它)')
assert.ok(!/module\.full/.test(page), '不得读 full:后台侧恒空,读它等于把脱敏前的行为留在界面里')
// ③ 新档位得真有条样式,否则 is-retry 渲染出来是无框无底的裸文本
assert.match(page, /\.wh-pill\.is-retry\s*\{[^}]*background/, '页面没有 .is-retry 这一档配色')
})