Files
crawler-plugin/frontend-vue/tests/青果账密拼提取链接.test.ts
T
huangzd1997 7c7712e7f3 feat(密钥面板): 青果下架——供应商单选不再出现,存量青果配置照常回显
2026-11-08 用户拍板「先屏蔽掉,代码留着」:api-secret-channel.ts 加 QINGGUO_ENABLED=false+SELECTABLE_PROXY_PROVIDER_OPTIONS 过滤列表,面板 radiogroup 只渲染过滤后列表;拼链/检测/保存/标签回显(composeQingguoLink、proxyCheckValue、proxyProviderLabel)全量保留,存量已存青果账密仍按本机/服务端值回显可检测,翻回 true 即整体恢复。判据:tests/青果账密拼提取链接.test.ts 钉可选列表只剩极客+标签字典仍全量;mount 测试钉单选区只剩极客+存量配置回显。
2026-11-08 23:30:48 +08:00

101 lines
5.0 KiB
TypeScript
Raw Permalink 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.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { composeQingguoLink, QINGGUO_EXTRACT_URL } from '../src/shared/utils/qingguo-link.ts'
import {
PROXY_PROVIDER_OPTIONS,
QINGGUO_ENABLED,
SELECTABLE_PROXY_PROVIDER_OPTIONS,
moduleSourceLabel,
proxyProviderLabel,
proxyCheckValue,
} from '../src/shared/utils/api-secret-channel.ts'
/**
* 青果没有「提取链接」可填,用户只给 key(Authkey)/ pwd(Authpwd),链接必须由前端拼
* (2026-10-31 用户拍板;官方口径 `https://overseas.proxy.qg.net/get?key=…&pwd=…`)。
* 拼不出来或拼错,用户就会在「填了账密」之后仍被商标检测的前置检查判成「未配置代理」。
*/
test('青果按密码鉴权拼出 key+pwd 的提取链接', () => {
assert.equal(composeQingguoLink('40F79A90', 'S3cret'),
`${QINGGUO_EXTRACT_URL}?key=40F79A90&pwd=S3cret`)
})
test('只有 key 时也拼得出来(不猜白名单档,缺 pwd 就只带 key)', () => {
assert.equal(composeQingguoLink(' 40F79A90 ', ''), `${QINGGUO_EXTRACT_URL}?key=40F79A90`)
})
test('没填 key 就不拼链接(空串=没配置,不许拼一条必然失败的链接)', () => {
assert.equal(composeQingguoLink('', 'pwd'), '')
assert.equal(composeQingguoLink(' ', 'pwd'), '')
})
test('key/pwd 里的特殊字符要编码,不能把查询串拼坏', () => {
const link = composeQingguoLink('a&b=c', 'p@ss:1')
assert.ok(link.endsWith('?key=a%26b%3Dc&pwd=p%40ss%3A1'), link)
})
/**
* 「点检测」送出去的链接必须走同一条拼装出处(2026-11-02 放开青果检测)。
* 检测按钮过去被 `proxyProvider === 'qingguo'` 直接 disabled,用户只能"保存了再猜";
* 现在未保存也要能检,就必须送现拼的链接——若这里另写一遍 URL,就会出现
* 「检的是一条、存的是另一条」(AGENTS.md 铁律 27 的同源边界)。
*/
test('检测未保存的青果账密时送现拼链接(与保存路径同一出处)', () => {
const sent = proxyCheckValue({
provider: 'qingguo', url: '', dirty: true, account: 'fakekey', password: 'fakepwd',
})
assert.equal(sent, composeQingguoLink('fakekey', 'fakepwd'), '送检值必须逐字节等于拼装出处的输出')
assert.ok(sent?.includes('fakekey'), '账密没进来就等于白检一次')
})
test('没改动时不送链接:让服务端用它库里存的那条(后端已不下发链接原文)', () => {
assert.equal(
proxyCheckValue({ provider: 'qingguo', url: '', dirty: false, account: 'fakekey', password: 'fakepwd' }),
undefined,
'已保存态送 undefined,前端手里没有库里的值可送')
assert.equal(
proxyCheckValue({ provider: 'jikip', url: 'http://1.2.3.4:8080', dirty: false, account: '', password: '' }),
undefined,
)
})
test('极客的检测送地址框里的原文(青果才需要拼)', () => {
assert.equal(
proxyCheckValue({ provider: 'jikip', url: ' http://1.2.3.4:8080 ', dirty: true, account: '', password: '' }),
'http://1.2.3.4:8080',
)
})
test('草稿拼不出链接时返回空串:调用方必须拦住,不能拿空串冒充"检测输入值"', () => {
assert.equal(
proxyCheckValue({ provider: 'qingguo', url: '', dirty: true, account: '', password: 'fakepwd' }),
'',
'空串与 undefined 语义不同:前者是"没配出来",后者才是"用库里的"')
})
/**
* 卡片标签:代理卡的货源是供应商(青果/极客),不能进 LLM 渠道字典——
* `normalizeLlmChannel('qingguo')` 会静默落到 LLM 默认值,界面就成了「代理卡标着渠道名」
* (2026-11-02 后端核实的那个错标)。
*/
test('代理卡按供应商标货源,LLM 卡仍按渠道字典', () => {
assert.equal(moduleSourceLabel('proxy', 'qingguo'), '青果')
assert.equal(moduleSourceLabel('proxy', 'jikip'), '极客')
assert.equal(moduleSourceLabel('appearance-patent', 'longtaitou'), '龙抬头')
assert.equal(moduleSourceLabel('similar-asin', 't8star'), '贞贞')
assert.notEqual(moduleSourceLabel('proxy', 'qingguo'), '龙抬头', '供应商 key 不许被当成 LLM 渠道回显')
})
/**
* 青果下架(2026-11-08 用户拍板「先屏蔽掉,代码留着」):单选里不再出现青果,
* 但**只屏蔽入口不拆链路**——存量青果配置的标签回显(`moduleSourceLabel`/`proxyProviderLabel`)
* 与拼链/检测(上面的用例)必须原样可用,翻回 true 即整体恢复。
* 面板渲染只认 `SELECTABLE_PROXY_PROVIDER_OPTIONS`,不许绕过开关自己过滤。
*/
test('青果下架:可选列表只剩极客,标签字典仍全量(存量青果配置照常回显)', () => {
assert.equal(QINGGUO_ENABLED, false, '拍板口径就是屏蔽;要恢复青果先翻这个开关并过一遍本文件全部用例')
assert.deepEqual(SELECTABLE_PROXY_PROVIDER_OPTIONS.map((option) => option.key), ['jikip'])
assert.deepEqual(PROXY_PROVIDER_OPTIONS.map((option) => option.key), ['jikip', 'qingguo'])
assert.equal(proxyProviderLabel('qingguo'), '青果', '存量配置的货源标签不许退化成裸 key')
})