dsh-napcat-keeper 2.8.2 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +45 -59
- package/lib/client.js +61 -105
- package/lib/index.js +529 -708
- package/package.json +5 -5
- package/scripts/selftest-companion.mjs +25 -6
- package/scripts/selftest-qrpanel.mjs +260 -0
- package/scripts/smoke-client.mjs +61 -59
- package/scripts/selftest-setup.mjs +0 -210
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-napcat-keeper",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "发现没有能够随着dsh打开自动启动napcat的插件,遂使用大肥鱼制作此插件,建议搭配Yuuyuko-uu的dsh-qq-
|
|
3
|
+
"version": "2.9.2",
|
|
4
|
+
"description": "发现没有能够随着dsh打开自动启动napcat的插件,遂使用大肥鱼制作此插件,建议搭配Yuuyuko-uu的dsh-qq-link使用~",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"selftest:save": "node scripts/selftest-save.mjs",
|
|
28
28
|
"selftest:probe": "node scripts/selftest-probe.mjs",
|
|
29
29
|
"selftest:companion": "node scripts/selftest-companion.mjs",
|
|
30
|
-
"selftest:setup": "node scripts/selftest-setup.mjs",
|
|
31
30
|
"selftest:layout": "node scripts/selftest-layout.mjs",
|
|
32
|
-
"
|
|
31
|
+
"selftest:qrpanel": "node scripts/selftest-qrpanel.mjs",
|
|
32
|
+
"test": "node scripts/check-manifest.mjs && node scripts/check-privacy.mjs && node scripts/smoke-client.mjs && node scripts/selftest-scan.mjs && node scripts/selftest-save.mjs && node scripts/selftest-probe.mjs && node scripts/selftest-companion.mjs && node scripts/selftest-layout.mjs && node scripts/selftest-qrpanel.mjs"
|
|
33
33
|
},
|
|
34
34
|
"keywords": [
|
|
35
35
|
"deepseek-harness",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"onebot",
|
|
39
39
|
"qq",
|
|
40
40
|
"watchdog",
|
|
41
|
-
"dsh-qq-
|
|
41
|
+
"dsh-qq-link"
|
|
42
42
|
],
|
|
43
43
|
"author": "熙的大肥鱼",
|
|
44
44
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@ const {
|
|
|
42
42
|
probe,
|
|
43
43
|
normalizeConfig,
|
|
44
44
|
COMPANION_DEFAULTS,
|
|
45
|
-
// dsh-qq-
|
|
45
|
+
// dsh-qq-link 那一套
|
|
46
46
|
detectBridge,
|
|
47
47
|
bridgePublic,
|
|
48
48
|
bridgeCheck,
|
|
@@ -50,6 +50,8 @@ const {
|
|
|
50
50
|
urlPort,
|
|
51
51
|
BRIDGE_DEFAULTS,
|
|
52
52
|
BRIDGE_PACKAGE,
|
|
53
|
+
BRIDGE_PACKAGES,
|
|
54
|
+
bridgeHits,
|
|
53
55
|
profileHits,
|
|
54
56
|
} = await loadInternals()
|
|
55
57
|
|
|
@@ -364,8 +366,8 @@ console.log('\n5b) 跟随开关:装没装 / 启没启用 决定显不显示、
|
|
|
364
366
|
setStored({})
|
|
365
367
|
}
|
|
366
368
|
|
|
367
|
-
/* 6. dsh-qq-
|
|
368
|
-
console.log('\n6) dsh-qq-
|
|
369
|
+
/* 6. dsh-qq-link 也认得出 -------------------------------------------- */
|
|
370
|
+
console.log('\n6) dsh-qq-link:装没装、挂没挂、桥接指向哪')
|
|
369
371
|
{
|
|
370
372
|
// 清场:前面几组造的 profile 全删掉,这一组只看自己造的
|
|
371
373
|
for (const name of ['alpha', 'beta', 'gamma', 'delta', 'desktop']) {
|
|
@@ -386,8 +388,8 @@ console.log('\n6) dsh-qq-bridge:装没装、挂没挂、桥接指向哪')
|
|
|
386
388
|
|
|
387
389
|
// 6b. 装了 + 在 bundles 里 + 配置文件齐全
|
|
388
390
|
mkProfile('desktop', {
|
|
389
|
-
deps: { 'dsh-qq-
|
|
390
|
-
bundles: ['dsh-napcat-keeper', 'dsh-qq-
|
|
391
|
+
deps: { 'dsh-qq-link': '^1.0.7' },
|
|
392
|
+
bundles: ['dsh-napcat-keeper', 'dsh-qq-link'],
|
|
391
393
|
patch: 'plugins: []\n',
|
|
392
394
|
})
|
|
393
395
|
dropPkg('desktop', BRIDGE_PACKAGE, '1.0.7')
|
|
@@ -398,6 +400,8 @@ console.log('\n6) dsh-qq-bridge:装没装、挂没挂、桥接指向哪')
|
|
|
398
400
|
b = detectBridge({ force: true })
|
|
399
401
|
ok(b.found === true && b.mounted === true, '装了且在 bundles 里 → 已挂载', JSON.stringify({ found: b.found, mounted: b.mounted }))
|
|
400
402
|
ok(b.packageVersion === '1.0.7', '读到它的版本号', String(b.packageVersion))
|
|
403
|
+
ok(b.packageName === 'dsh-qq-link', '报的是新包名 dsh-qq-link', String(b.packageName))
|
|
404
|
+
ok(bridgePublic(b).packageName === 'dsh-qq-link', '对外也带 packageName(界面照着显示)', String(bridgePublic(b).packageName))
|
|
401
405
|
ok(readBridgeConfig().known === true, '读得到 ~/.dsh/qq-bridge-config.json(摊在根上,不在 profile 里)')
|
|
402
406
|
ok(b.napcatPort === 4000, '桥接指向 4000', String(b.napcatPort))
|
|
403
407
|
ok(b.enabled === true && b.dryRun === false, '总开关开、试运行关', JSON.stringify({ enabled: b.enabled, dryRun: b.dryRun }))
|
|
@@ -435,7 +439,7 @@ console.log('\n6) dsh-qq-bridge:装没装、挂没挂、桥接指向哪')
|
|
|
435
439
|
ok(bridgeCheck({ mode: 'http', portUsed: 3000 }, b).state === 'dry-run', '试运行 → dry-run')
|
|
436
440
|
|
|
437
441
|
// 6h. 装了但没挂进 profile:先报没挂,别先去怪端口
|
|
438
|
-
mkProfile('beta', { deps: { 'dsh-qq-
|
|
442
|
+
mkProfile('beta', { deps: { 'dsh-qq-link': '^1.0.7' }, bundles: ['dsh-napcat-keeper'], patch: 'plugins: []\n' })
|
|
439
443
|
dropPkg('beta', BRIDGE_PACKAGE, '1.0.7')
|
|
440
444
|
fs.rmSync(path.join(HOME, 'profiles', 'desktop'), { recursive: true, force: true })
|
|
441
445
|
b = detectBridge({ force: true })
|
|
@@ -481,6 +485,21 @@ console.log('\n6) dsh-qq-bridge:装没装、挂没挂、桥接指向哪')
|
|
|
481
485
|
)
|
|
482
486
|
ok(Boolean(health.bridge && health.bridge.note), '而且带一句人话提示')
|
|
483
487
|
await srv2.close()
|
|
488
|
+
|
|
489
|
+
// 6k. 老包名 dsh-qq-bridge(还没升级的机器)照样认得出
|
|
490
|
+
// 上游 2026-11 才改名,真实机器上很可能还躺着老包;认不到就等于「说得像没装」。
|
|
491
|
+
fs.rmSync(path.join(HOME, 'profiles', 'beta'), { recursive: true, force: true })
|
|
492
|
+
mkProfile('gamma', {
|
|
493
|
+
deps: { 'dsh-qq-bridge': '^1.0.7' },
|
|
494
|
+
bundles: ['dsh-napcat-keeper', 'dsh-qq-bridge'],
|
|
495
|
+
patch: 'plugins: []\n',
|
|
496
|
+
})
|
|
497
|
+
dropPkg('gamma', 'dsh-qq-bridge', '1.0.7')
|
|
498
|
+
const legacy = detectBridge({ force: true })
|
|
499
|
+
ok(legacy.found === true && legacy.mounted === true, '只装了老包 → 仍认得出且算已挂载', JSON.stringify({ found: legacy.found, mounted: legacy.mounted }))
|
|
500
|
+
ok(legacy.packageName === 'dsh-qq-bridge', '这时 packageName 如实报老名', String(legacy.packageName))
|
|
501
|
+
ok(BRIDGE_PACKAGES[0] === 'dsh-qq-link' && BRIDGE_PACKAGES.includes('dsh-qq-bridge'), '两个包名都在候选里、新名优先', JSON.stringify(BRIDGE_PACKAGES))
|
|
502
|
+
ok(bridgeHits().some((h) => h.pkg === 'dsh-qq-bridge'), 'bridgeHits 把老包也扫进来了', JSON.stringify(bridgeHits().map((h) => h.pkg)))
|
|
484
503
|
}
|
|
485
504
|
|
|
486
505
|
fs.rmSync(HOME, { recursive: true, force: true })
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「扫码页」回归自检。
|
|
3
|
+
*
|
|
4
|
+
* 守的是这几个坑:
|
|
5
|
+
* 1. DSH 的 webServer 对外部浏览器一律 403(Browser access is disabled),
|
|
6
|
+
* 所以扫码页必须另有自己的小端口 —— 只挂 DSH 路由等于点不开。
|
|
7
|
+
* 2. 页面里的 qr.png / qr-state / qr-restart 用相对路径,
|
|
8
|
+
* 在 / 下和在 /dsh-napcat-keeper/qr 下都得指对地方。
|
|
9
|
+
* 3. 关掉开关 / 换端口之后,旧 server 必须关掉(不然端口越占越多)。
|
|
10
|
+
*
|
|
11
|
+
* 全程在本机环回、临时 DSH_HOME 上跑,不碰真配置、不碰真 NapCat。
|
|
12
|
+
* node scripts/selftest-qrpanel.mjs
|
|
13
|
+
*/
|
|
14
|
+
import http from 'node:http'
|
|
15
|
+
import net from 'node:net'
|
|
16
|
+
import os from 'node:os'
|
|
17
|
+
import path from 'node:path'
|
|
18
|
+
import fs from 'node:fs'
|
|
19
|
+
|
|
20
|
+
let pass = 0
|
|
21
|
+
let fail = 0
|
|
22
|
+
const ok = (cond, name, extra = '') => {
|
|
23
|
+
if (cond) {
|
|
24
|
+
pass += 1
|
|
25
|
+
console.log(` ✓ ${name}`)
|
|
26
|
+
} else {
|
|
27
|
+
fail += 1
|
|
28
|
+
console.log(` ✗ ${name}${extra ? ' — ' + extra : ''}`)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 临时家目录:所有写操作都落在这里,不碰真实 DSH_HOME */
|
|
33
|
+
const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'napcat-keeper-qrpanel-'))
|
|
34
|
+
process.env.DSH_HOME = tmpHome
|
|
35
|
+
|
|
36
|
+
const mod = await import('../lib/index.js?t=' + Date.now())
|
|
37
|
+
const I = mod.__internals
|
|
38
|
+
|
|
39
|
+
const freePort = () =>
|
|
40
|
+
new Promise((resolve) => {
|
|
41
|
+
const srv = net.createServer()
|
|
42
|
+
srv.listen(0, '127.0.0.1', () => {
|
|
43
|
+
const port = srv.address().port
|
|
44
|
+
srv.close(() => resolve(port))
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const get = (url, { raw = false } = {}) =>
|
|
49
|
+
new Promise((resolve, reject) => {
|
|
50
|
+
const req = http.get(url, { timeout: 8000 }, (res) => {
|
|
51
|
+
const chunks = []
|
|
52
|
+
res.on('data', (c) => chunks.push(c))
|
|
53
|
+
res.on('end', () => {
|
|
54
|
+
const body = Buffer.concat(chunks)
|
|
55
|
+
if (raw) return resolve({ status: res.statusCode, headers: res.headers, body })
|
|
56
|
+
let json = null
|
|
57
|
+
try {
|
|
58
|
+
json = JSON.parse(body.toString('utf8'))
|
|
59
|
+
} catch {}
|
|
60
|
+
resolve({ status: res.statusCode, headers: res.headers, text: body.toString('utf8'), json })
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
req.on('error', reject)
|
|
64
|
+
req.on('timeout', () => {
|
|
65
|
+
req.destroy(new Error('timeout'))
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const waitListening = async (port, ms = 4000) => {
|
|
70
|
+
const deadline = Date.now() + ms
|
|
71
|
+
while (Date.now() < deadline) {
|
|
72
|
+
const okNow = await new Promise((resolve) => {
|
|
73
|
+
const s = net.connect(port, '127.0.0.1')
|
|
74
|
+
s.on('connect', () => {
|
|
75
|
+
s.destroy()
|
|
76
|
+
resolve(true)
|
|
77
|
+
})
|
|
78
|
+
s.on('error', () => resolve(false))
|
|
79
|
+
})
|
|
80
|
+
if (okNow) return true
|
|
81
|
+
await new Promise((r) => setTimeout(r, 60))
|
|
82
|
+
}
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log('扫码页自检')
|
|
87
|
+
|
|
88
|
+
/* 1. 配置项默认值 + 归一化 ------------------------------------------------ */
|
|
89
|
+
{
|
|
90
|
+
const d = I.resolveConfig({})
|
|
91
|
+
ok(d.qrPanelEnabled === true, '默认开着扫码页')
|
|
92
|
+
ok(d.qrPanelPort === 8899, '默认端口 8899', String(d.qrPanelPort))
|
|
93
|
+
|
|
94
|
+
const c = I.normalizeConfig({ qrPanelEnabled: false, qrPanelPort: 70000 })
|
|
95
|
+
ok(c.qrPanelEnabled === false, 'qrPanelEnabled=false 能关掉')
|
|
96
|
+
ok(c.qrPanelPort === 65535, '越界端口被夹到合法上界', String(c.qrPanelPort))
|
|
97
|
+
ok(I.normalizeConfig({ qrPanelPort: 80 }).qrPanelPort === 1024, '小于 1024 的端口被夹到 1024')
|
|
98
|
+
|
|
99
|
+
const c2 = I.normalizeConfig({ qrPanelEnabled: 'false', qrPanelPort: 9123 })
|
|
100
|
+
ok(c2.qrPanelEnabled === false, '字符串 "false" 也认作关')
|
|
101
|
+
ok(c2.qrPanelPort === 9123, '合法端口原样保留', String(c2.qrPanelPort))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* 2. 起服务 → 页面 / 状态 / 图片 / 未知路径 ------------------------------- */
|
|
105
|
+
const port = await freePort()
|
|
106
|
+
const cfg = { ...I.resolveConfig({}), qrPanelEnabled: true, qrPanelPort: port, enabled: false }
|
|
107
|
+
I.state.cfg = cfg
|
|
108
|
+
|
|
109
|
+
{
|
|
110
|
+
const started = I.startQrPanel(cfg)
|
|
111
|
+
ok(started.ok === true, 'startQrPanel 返回 ok')
|
|
112
|
+
ok(await waitListening(port), `127.0.0.1:${port} 真的在听`)
|
|
113
|
+
|
|
114
|
+
const pub = I.qrPanelPublic(cfg)
|
|
115
|
+
ok(pub.running === true, 'qrPanelPublic.running = true')
|
|
116
|
+
ok(pub.url === `http://127.0.0.1:${port}/`, '给出的地址带端口', pub.url)
|
|
117
|
+
ok(I.qrPanelUrl(cfg) === pub.url, 'qrPanelUrl 与 qrPanelPublic 一致')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
{
|
|
121
|
+
const r = await get(`http://127.0.0.1:${port}/`)
|
|
122
|
+
ok(r.status === 200, 'GET / → 200', String(r.status))
|
|
123
|
+
ok(/text\/html/.test(String(r.headers['content-type'] || '')), '/ 是 HTML')
|
|
124
|
+
ok(r.text.includes('扫码'), '页面里有「扫码」字样')
|
|
125
|
+
ok(r.text.includes('qr.png'), '页面用相对路径引 qr.png')
|
|
126
|
+
ok(!/src="\/qr\.png/.test(r.text), '页面没有写死绝对路径(子路径下也能用)')
|
|
127
|
+
ok(r.text.includes('smsbox'), '页面留了短信验证提示的位置')
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
{
|
|
131
|
+
const r = await get(`http://127.0.0.1:${port}/qr-state`)
|
|
132
|
+
ok(r.status === 200, 'GET /qr-state → 200', String(r.status))
|
|
133
|
+
ok(r.json && r.json.ok === true, '/qr-state 返回 ok:true')
|
|
134
|
+
ok(r.json && typeof r.json.qrTtlSec === 'number', '/qr-state 带 qrTtlSec')
|
|
135
|
+
ok(r.json && r.json.panel && r.json.panel.port === port, '/qr-state 里带 panel.port', JSON.stringify(r.json && r.json.panel))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
{
|
|
139
|
+
const r = await get(`http://127.0.0.1:${port}/qr.png`, { raw: true })
|
|
140
|
+
// 临时家里没有二维码,正常就该是 404;真出过码时是 200 + image/png
|
|
141
|
+
const fine = r.status === 404 || (r.status === 200 && /image\/png/.test(String(r.headers['content-type'] || '')))
|
|
142
|
+
ok(fine, '/qr.png 只会是 404 或 image/png', String(r.status))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
{
|
|
146
|
+
const r = await get(`http://127.0.0.1:${port}/nope`)
|
|
147
|
+
ok(r.status === 404, '不认识的路径 → 404', String(r.status))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
{
|
|
151
|
+
// DSH 路由那条是 /dsh-napcat-keeper/qr,靠 serveQrPage 剥前缀,这里用小服务复现
|
|
152
|
+
const r = await get(`http://127.0.0.1:${port}/dsh-napcat-keeper/qr`)
|
|
153
|
+
ok(r.status === 200 && r.text.includes('扫码'), '带 ROUTE 前缀的路径也能出页面', String(r.status))
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* 3. 端口被占时给的是人话 ------------------------------------------------ */
|
|
157
|
+
{
|
|
158
|
+
const busy = net.createServer()
|
|
159
|
+
await new Promise((r) => busy.listen(0, '127.0.0.1', r))
|
|
160
|
+
const busyPort = busy.address().port
|
|
161
|
+
const cfg2 = { ...cfg, qrPanelPort: busyPort }
|
|
162
|
+
I.startQrPanel(cfg2)
|
|
163
|
+
await new Promise((r) => setTimeout(r, 250))
|
|
164
|
+
const pub = I.qrPanelPublic(cfg2)
|
|
165
|
+
ok(pub.running === false, '端口被占时 running=false')
|
|
166
|
+
ok(/被占/.test(pub.note) || /被占/.test(pub.error), '提示里说了端口被占', pub.note || pub.error)
|
|
167
|
+
await new Promise((r) => busy.close(r))
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* 4. 关掉开关 → 端口立刻释放 -------------------------------------------- */
|
|
171
|
+
{
|
|
172
|
+
const cfg3 = { ...cfg, qrPanelEnabled: false }
|
|
173
|
+
I.startQrPanel(cfg3)
|
|
174
|
+
const still = await new Promise((resolve) => {
|
|
175
|
+
const s = net.connect(port, '127.0.0.1')
|
|
176
|
+
s.on('connect', () => {
|
|
177
|
+
s.destroy()
|
|
178
|
+
resolve(true)
|
|
179
|
+
})
|
|
180
|
+
s.on('error', () => resolve(false))
|
|
181
|
+
})
|
|
182
|
+
ok(still === false, '关掉后端口不再接受连接')
|
|
183
|
+
ok(I.qrPanelPublic(cfg3).enabled === false, 'qrPanelPublic.enabled = false')
|
|
184
|
+
ok(I.qrPanelUrl(cfg3) === '', '关掉后不给地址')
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* 5. 换端口:旧的就该关掉 ---------------------------------------------- */
|
|
188
|
+
{
|
|
189
|
+
const p2 = await freePort()
|
|
190
|
+
I.startQrPanel({ ...cfg, qrPanelPort: port })
|
|
191
|
+
ok(await waitListening(port), '重新打开原端口')
|
|
192
|
+
I.startQrPanel({ ...cfg, qrPanelPort: p2 })
|
|
193
|
+
ok(await waitListening(p2), `换到 ${p2} 后新端口在听`)
|
|
194
|
+
const oldStill = await new Promise((resolve) => {
|
|
195
|
+
const s = net.connect(port, '127.0.0.1')
|
|
196
|
+
s.on('connect', () => {
|
|
197
|
+
s.destroy()
|
|
198
|
+
resolve(true)
|
|
199
|
+
})
|
|
200
|
+
s.on('error', () => resolve(false))
|
|
201
|
+
})
|
|
202
|
+
ok(oldStill === false, '换端口后旧端口已释放')
|
|
203
|
+
I.stopQrPanel(cfg, '自检收尾')
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* 6. 状态里带 qrPanel(设置页要用) ------------------------------------ */
|
|
207
|
+
{
|
|
208
|
+
const st = await I.qrPageState({ ...cfg, qrPanelPort: port })
|
|
209
|
+
ok(st && st.panel && typeof st.panel.enabled === 'boolean', 'qrPageState 带 panel.enabled')
|
|
210
|
+
ok(st && st.sms && typeof st.sms === 'object', 'qrPageState 带 sms')
|
|
211
|
+
ok(st && st.sms && st.sms.url === '', '临时家里没有运行日志时 sms.url 是空串')
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* 7. 短信验证:从假日志里抠 ErrCode / proofWaterUrl --------------------- */
|
|
215
|
+
{
|
|
216
|
+
const shell = path.join(tmpHome, 'fake-napcat')
|
|
217
|
+
fs.mkdirSync(shell, { recursive: true })
|
|
218
|
+
fs.writeFileSync(
|
|
219
|
+
path.join(shell, '_run.log'),
|
|
220
|
+
'01-01 00:00:01 [INFO] start\n01-01 00:00:02 [ERROR] ErrCode: 46\n' +
|
|
221
|
+
'proofWaterUrl: https://tn.qq.com/proof?x=1\n01-01 00:00:03 Login Success\n',
|
|
222
|
+
'latin1',
|
|
223
|
+
)
|
|
224
|
+
const cfg4 = { ...cfg, shellDir: shell.replace(/\\/g, '/'), qrPanelPort: port }
|
|
225
|
+
const st = await I.qrPageState(cfg4)
|
|
226
|
+
ok(st.sms.code === 46, '能抠到 ErrCode', String(st.sms.code))
|
|
227
|
+
ok(st.sms.url === 'https://tn.qq.com/proof?x=1', '能抠到 proofWaterUrl', st.sms.url)
|
|
228
|
+
ok(st.sms.success === true, '能认出「登录成功」')
|
|
229
|
+
ok(st.sms.needSms === false, '登录成功之后的老 ErrCode 不算「这次要验证」')
|
|
230
|
+
ok(st.sms.file.includes('_run.log'), '记录读的是哪个文件', st.sms.file)
|
|
231
|
+
|
|
232
|
+
/* 登录成功之后又冒出 ErrCode = 这次真的要短信验证(时间戳用「现在」,否则会被判成过期) */
|
|
233
|
+
const now2 = new Date()
|
|
234
|
+
const p2 = (n) => String(n).padStart(2, '0')
|
|
235
|
+
const stamp = `${p2(now2.getMonth() + 1)}-${p2(now2.getDate())} ${p2(now2.getHours())}:${p2(now2.getMinutes())}:${p2(now2.getSeconds())}`
|
|
236
|
+
fs.writeFileSync(
|
|
237
|
+
path.join(shell, '_run.log'),
|
|
238
|
+
`${stamp} Login Success\n${stamp} [error] ErrCode: 46\n${stamp} [info] 需要验证码, proofWaterUrl: https://tn.qq.com/proof?x=2\n`,
|
|
239
|
+
'latin1',
|
|
240
|
+
)
|
|
241
|
+
const st2 = await I.qrPageState(cfg4)
|
|
242
|
+
ok(st2.sms.needSms === true, '登录后又掉线 → 判定要短信验证')
|
|
243
|
+
ok(st2.sms.url === 'https://tn.qq.com/proof?x=2', '拿到新的验证链接', st2.sms.url)
|
|
244
|
+
|
|
245
|
+
/* 很老的验证链接就别拿出来让人点了 */
|
|
246
|
+
fs.writeFileSync(
|
|
247
|
+
path.join(shell, '_run.log'),
|
|
248
|
+
`01-01 00:10:00 [error] ErrCode: 46\n01-01 00:10:00 [info] 需要验证码, proofWaterUrl: https://tn.qq.com/proof?old=1\n`,
|
|
249
|
+
'latin1',
|
|
250
|
+
)
|
|
251
|
+
const st3 = await I.qrPageState(cfg4)
|
|
252
|
+
ok(st3.sms.url === '', '过期(>30 分钟)的验证链接被丢掉')
|
|
253
|
+
ok(st3.sms.urlStale === true, '并且标了 urlStale')
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
fs.rmSync(tmpHome, { recursive: true, force: true })
|
|
257
|
+
|
|
258
|
+
console.log('')
|
|
259
|
+
console.log(`扫码页:${pass} 过 / ${fail} 挂`)
|
|
260
|
+
if (fail) process.exitCode = 1
|
package/scripts/smoke-client.mjs
CHANGED
|
@@ -43,12 +43,19 @@ function collect(tree) {
|
|
|
43
43
|
const boxes = [];
|
|
44
44
|
const selects = [];
|
|
45
45
|
const texts = [];
|
|
46
|
+
const links = [];
|
|
46
47
|
(function walk(n) {
|
|
47
48
|
if (n === null || n === undefined || n === false) return;
|
|
48
49
|
if (typeof n === 'string' || typeof n === 'number') { texts.push(String(n)); return; }
|
|
49
50
|
if (Array.isArray(n)) { n.forEach(walk); return; }
|
|
50
51
|
if (n.__el) {
|
|
51
52
|
if (n.type === 'button') buttons.push(n.children.filter((c) => typeof c === 'string').join(''));
|
|
53
|
+
if (n.type === 'a') {
|
|
54
|
+
links.push({
|
|
55
|
+
text: n.children.filter((c) => typeof c === 'string').join(''),
|
|
56
|
+
href: String((n.props && n.props.href) || ''),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
52
59
|
if (n.type === 'input' && n.props && n.props.type === 'checkbox') {
|
|
53
60
|
boxes.push({ name: String(n.props.name || ''), checked: Boolean(n.props.checked), disabled: Boolean(n.props.disabled) });
|
|
54
61
|
}
|
|
@@ -61,7 +68,7 @@ function collect(tree) {
|
|
|
61
68
|
n.children.forEach(walk);
|
|
62
69
|
}
|
|
63
70
|
})(tree);
|
|
64
|
-
return { buttons, boxes, selects, text: texts.join(' ') };
|
|
71
|
+
return { buttons, boxes, selects, links, text: texts.join(' ') };
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
render(); // 第一次:态=null 的 loading 分支
|
|
@@ -84,33 +91,6 @@ states[0] = {
|
|
|
84
91
|
},
|
|
85
92
|
scan: { running: false, found: [], drives: ['C:'], visited: 0, elapsedMs: 0, limitHit: false, cancelled: false },
|
|
86
93
|
drives: ['C:', 'D:', 'E:'],
|
|
87
|
-
setup: {
|
|
88
|
-
dir: 'C:/Users/x/.dsh/dsh-napcat-keeper/setup',
|
|
89
|
-
cmdPath: 'C:/Users/x/.dsh/dsh-napcat-keeper/setup/apply-admin.cmd',
|
|
90
|
-
ps1Path: 'C:/Users/x/.dsh/dsh-napcat-keeper/setup/apply.ps1',
|
|
91
|
-
undoCmdPath: 'C:/Users/x/.dsh/dsh-napcat-keeper/setup/undo-admin.cmd',
|
|
92
|
-
exists: true,
|
|
93
|
-
needs: [
|
|
94
|
-
{ id: 'launcher', label: '自动启动脚本', hint: '补一个 napcat.quick.auto.bat', ready: true, why: '', needAdmin: false },
|
|
95
|
-
{ id: 'envbat', label: '中间层(密码)', hint: '写中间层 bat', ready: true, why: '', needAdmin: false },
|
|
96
|
-
{ id: 'task', label: '计划任务', hint: '建计划任务', ready: true, why: '', needAdmin: false },
|
|
97
|
-
{ id: 'firewall', label: '防火墙放行', hint: '放行 OneBot 端口', ready: false, why: '端口没填', needAdmin: true },
|
|
98
|
-
],
|
|
99
|
-
plan: {
|
|
100
|
-
createdAt: '2026-10-27T00:12:00.000Z',
|
|
101
|
-
needAdmin: true,
|
|
102
|
-
steps: [{ id: 'a', label: '建计划任务' }, { id: 'b', label: '放行防火墙' }],
|
|
103
|
-
},
|
|
104
|
-
lastRun: {
|
|
105
|
-
mode: 'apply',
|
|
106
|
-
ok: false,
|
|
107
|
-
elevated: true,
|
|
108
|
-
results: [
|
|
109
|
-
{ id: 'a', label: '建计划任务', ok: true, skipped: false, message: '好了' },
|
|
110
|
-
{ id: 'b', label: '放行防火墙', ok: false, skipped: false, message: '没权限' },
|
|
111
|
-
],
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
94
|
log: ['line1'],
|
|
115
95
|
};
|
|
116
96
|
|
|
@@ -140,6 +120,38 @@ const rev = collect(render());
|
|
|
140
120
|
check('反向 WS 时状态条说「反向 WS 已连接」', rev.text.includes('反向 WS 已连接'));
|
|
141
121
|
check('反向 WS 时显示客户端数', /客户端 2/.test(rev.text));
|
|
142
122
|
check('反向 WS 时显示探测方式与 HTTP 状态', rev.text.includes('反向 WebSocket') && rev.text.includes('HTTP 426'));
|
|
123
|
+
// 扫码页:要扫码时顶上得冒黄横幅,链接指向插件自己的小端口(DSH 路由对外 403,只能当兜底)
|
|
124
|
+
{
|
|
125
|
+
states[0].runtime.online = true;
|
|
126
|
+
states[0].runtime.phase = 'online';
|
|
127
|
+
states[0].qrPanel = { enabled: true, port: 8899, running: true, url: 'http://127.0.0.1:8899/', path: '/dsh-napcat-keeper/qr', note: '', error: '' };
|
|
128
|
+
const calm = collect(render());
|
|
129
|
+
check('没要扫码时不画扫码横幅', !calm.text.includes('要手机扫码登录'));
|
|
130
|
+
check('平时也有「打开扫码页」链接', calm.links.some((l) => l.text.includes('打开扫码页')));
|
|
131
|
+
|
|
132
|
+
states[0].runtime.online = false;
|
|
133
|
+
states[0].runtime.phase = 'need-scan';
|
|
134
|
+
states[0].runtime.qr = { file: 'q.png', ageSec: 20, copy: '' };
|
|
135
|
+
const scan = collect(render());
|
|
136
|
+
check('要扫码时顶上出黄横幅', scan.text.includes('要手机扫码登录'));
|
|
137
|
+
check('横幅里有「点开扫码页」', scan.links.some((l) => l.text.includes('点开扫码页')));
|
|
138
|
+
check('扫码页链接走小端口而不是 DSH 路由',
|
|
139
|
+
scan.links.filter((l) => l.text.includes('扫码页')).every((l) => l.href === 'http://127.0.0.1:8899/'),
|
|
140
|
+
JSON.stringify(scan.links));
|
|
141
|
+
|
|
142
|
+
states[0].qrPanel = { enabled: true, port: 8899, running: false, url: '', path: '/dsh-napcat-keeper/qr', note: '端口 8899 被占了(改一个 qrPanelPort,或关掉占它的程序)', error: '' };
|
|
143
|
+
const fallback = collect(render());
|
|
144
|
+
check('小端口没起来时退回 DSH 路由',
|
|
145
|
+
fallback.links.filter((l) => l.text.includes('扫码页')).every((l) => l.href === '/dsh-napcat-keeper/qr'),
|
|
146
|
+
JSON.stringify(fallback.links));
|
|
147
|
+
check('小端口没起来时把 note 写出来', fallback.text.includes('被占了'));
|
|
148
|
+
|
|
149
|
+
states[0].runtime.online = true;
|
|
150
|
+
states[0].runtime.phase = 'online';
|
|
151
|
+
delete states[0].runtime.qr;
|
|
152
|
+
states[0].qrPanel = { enabled: true, port: 8899, running: true, url: 'http://127.0.0.1:8899/', path: '/dsh-napcat-keeper/qr', note: '', error: '' };
|
|
153
|
+
}
|
|
154
|
+
|
|
143
155
|
states[0].runtime.mode = 'auth';
|
|
144
156
|
states[0].runtime.online = false;
|
|
145
157
|
states[0].runtime.portStatus = 401;
|
|
@@ -178,10 +190,10 @@ delete states[0].runtime.companion;
|
|
|
178
190
|
delete states[0].runtime.companionReady;
|
|
179
191
|
delete states[0].runtime.companionTokenMatch;
|
|
180
192
|
|
|
181
|
-
// 和 dsh-qq-
|
|
193
|
+
// 和 dsh-qq-link 共存:它是「客户端」,要能看出装没装、挂没挂、连的端口对不对
|
|
182
194
|
const noBridge = collect(render());
|
|
183
195
|
check('没装桥接时也有「桥接插件」那行', noBridge.text.includes('桥接插件'));
|
|
184
|
-
check('没装时写「没检测到 dsh-qq-
|
|
196
|
+
check('没装时写「没检测到 dsh-qq-link」', noBridge.text.includes('没检测到 dsh-qq-link'));
|
|
185
197
|
states[0].runtime.bridgePlugin = {
|
|
186
198
|
version: '1.0.7',
|
|
187
199
|
profile: 'desktop',
|
|
@@ -194,10 +206,10 @@ states[0].runtime.bridgePlugin = {
|
|
|
194
206
|
bindings: 0,
|
|
195
207
|
configKnown: true,
|
|
196
208
|
check: 'bridge-hits-reverse',
|
|
197
|
-
note: 'dsh-qq-
|
|
209
|
+
note: 'dsh-qq-link 连的是 http://127.0.0.1:8643,而那个端口现在是反向 WebSocket',
|
|
198
210
|
};
|
|
199
211
|
const withBridge = collect(render());
|
|
200
|
-
check('装了会说版本与状态', withBridge.text.includes('dsh-qq-
|
|
212
|
+
check('装了会说版本与状态', withBridge.text.includes('dsh-qq-link 1.0.7') && withBridge.text.includes('已启用'));
|
|
201
213
|
check('在发 / 试运行 要分得清', withBridge.text.includes('在发'));
|
|
202
214
|
check('连的是反向 WS 端口要标出来', withBridge.text.includes('连的是反向 WS 端口'));
|
|
203
215
|
check('提示文案单独一行给出来', withBridge.text.includes('桥接提示:') && withBridge.text.includes('反向 WebSocket'));
|
|
@@ -259,34 +271,24 @@ const legacyOut = collect(render());
|
|
|
259
271
|
check('老后端不给判定时不误标壳模板', !legacyOut.text.includes('多半是 OneKey 装完留下的壳模板'));
|
|
260
272
|
check('老后端时提示要重启 DSH', legacyOut.text.includes('重启 DSH'));
|
|
261
273
|
|
|
262
|
-
//
|
|
274
|
+
// 2.9.1:提权交接(生成脚本那份)整块删了 —— 面板里不该再有它的按钮/勾选框,
|
|
275
|
+
// 服务端旧状态里还带着 setup 字段时也不能炸。
|
|
263
276
|
states[0].scan = { running: false, found: [], drives: ['C:'], visited: 0, elapsedMs: 0, limitHit: false, cancelled: false };
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
check('
|
|
272
|
-
check('
|
|
273
|
-
|
|
274
|
-
check('
|
|
275
|
-
|
|
276
|
-
check('
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const keepSetup = states[0].setup;
|
|
280
|
-
states[0].setup = { ...keepSetup, plan: null, lastRun: null };
|
|
281
|
-
const emptyOut = collect(render());
|
|
282
|
-
check('没生成过时提示', emptyOut.text.includes('还没生成过脚本'));
|
|
283
|
-
states[0].setup = keepSetup;
|
|
284
|
-
|
|
285
|
-
// 没有 setup 字段也不炸
|
|
286
|
-
states[0].setup = undefined;
|
|
287
|
-
const noSetup = collect(render());
|
|
288
|
-
check('缺 setup 字段时降级提示', noSetup.text.includes('读不到脚本状态'));
|
|
289
|
-
states[0].setup = keepSetup;
|
|
277
|
+
states[0].setup = {
|
|
278
|
+
dir: 'C:/Users/x/.dsh/dsh-napcat-keeper/setup',
|
|
279
|
+
needs: [{ id: 'launcher', label: '自动启动脚本', ready: true }],
|
|
280
|
+
plan: { steps: [{ id: 'a', label: '建计划任务' }] },
|
|
281
|
+
lastRun: { mode: 'apply', ok: true, elevated: false, results: [] },
|
|
282
|
+
};
|
|
283
|
+
const setupGone = collect(render());
|
|
284
|
+
check('不再有「生成脚本并打开文件夹」', !setupGone.buttons.includes('生成脚本并打开文件夹'));
|
|
285
|
+
check('不再有「打开文件夹」「读结果」',
|
|
286
|
+
!setupGone.buttons.includes('打开文件夹') && !setupGone.buttons.includes('读结果'));
|
|
287
|
+
check('不再有 need 勾选框', setupGone.boxes.filter((b) => b.name.startsWith('npk-need-')).length === 0,
|
|
288
|
+
String(setupGone.boxes.length));
|
|
289
|
+
check('不再出现「需要你点一下的脚本」这一组', !setupGone.text.includes('需要你点一下的脚本'));
|
|
290
|
+
check('旧状态里带 setup 字段也不炸', setupGone.text.includes('napcat桥') || setupGone.text.length > 200);
|
|
291
|
+
delete states[0].setup;
|
|
290
292
|
|
|
291
293
|
// 「进程」那行:按安装形态换词(boot 恒 0 不代表没进程)
|
|
292
294
|
const keepRuntime = states[0].runtime;
|