dsh-plugin-mesh 0.5.1 → 0.5.3
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/AGENTS.md +1 -1
- package/README.md +4 -5
- package/client/client.js +72 -1
- package/lib/_selftest-capabilities.mjs +68 -1
- package/lib/_selftest-diagnostics.mjs +92 -0
- package/lib/_selftest-osinfo.mjs +379 -0
- package/lib/_selftest-tsnet.mjs +26 -1
- package/lib/_selftest-workbench.mjs +53 -0
- package/lib/capabilities.js +197 -29
- package/lib/diagnostics.js +109 -0
- package/lib/discovery.js +27 -3
- package/lib/index.js +120 -29
- package/lib/osinfo.js +352 -0
- package/lib/scan.js +11 -10
- package/lib/tsnet/download.js +5 -1
- package/llms.txt +2 -0
- package/package.json +4 -2
package/AGENTS.md
CHANGED
|
@@ -146,7 +146,7 @@ If you must release from this machine (offline, or the pipeline is broken):
|
|
|
146
146
|
|
|
147
147
|
```bash
|
|
148
148
|
npm run check && npm test
|
|
149
|
-
|
|
149
|
+
./scripts/release-plugin.sh --publish # tarball -> GitHub release -> LAN mirror
|
|
150
150
|
npm publish # npm; publishConfig pins the public registry
|
|
151
151
|
```
|
|
152
152
|
|
package/README.md
CHANGED
|
@@ -37,7 +37,6 @@ DSH 的 Mesh 插件:**启动后自动发现同一网段的其他 DSH 实例**
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
# 进程版本 ≠ 磁盘版本 → [WARN] 新代码**没**被加载,检查 plugins 挂载
|
|
40
|
-
```
|
|
41
40
|
|
|
42
41
|
(不依赖 `node`:优先 `python3` 解 JSON,退回到正则抠 `version` 字段。)
|
|
43
42
|
|
|
@@ -402,7 +401,7 @@ VPN,换网 MAC 就变;iOS / Android / macOS 现在默认按 SSID 使用随
|
|
|
402
401
|
|
|
403
402
|
名字是人手填的,可能撞。页面会检测并告警,派发时也不会随便挑一台:
|
|
404
403
|
|
|
405
|
-
- **从 A
|
|
404
|
+
- **从 A 看**:`mesh_run` 的 `peer` 填 `winbox`,只要在 A 的上游对端里唯一就能用(自己不算)
|
|
406
405
|
- **从第三台机器看**:如果它发现有两台都叫 winbox,`mesh_run` 会**拒绝**并列出候选,
|
|
407
406
|
让你改用 `<ip>:<port>` 精确定位
|
|
408
407
|
|
|
@@ -496,7 +495,7 @@ dsh plugin add /path/to/dsh-plugin-mesh
|
|
|
496
495
|
|
|
497
496
|
### 升级已安装的插件
|
|
498
497
|
|
|
499
|
-
`release-plugin.sh --publish` 发完版会**自动同步到局域网镜像**并打印一段可直接
|
|
498
|
+
`scripts/release-plugin.sh --publish` 发完版会**自动同步到局域网镜像**并打印一段可直接
|
|
500
499
|
粘贴到对端的命令。对端(尤其是 Android,见下面的 `/tmp` 坑)执行后**必须重启 DSH**
|
|
501
500
|
才会加载新版本。
|
|
502
501
|
|
|
@@ -666,7 +665,7 @@ agent 多出四个工具:
|
|
|
666
665
|
# ── 循环限速 ──
|
|
667
666
|
maxWakesPerThread: 30 # 每窗口内最多自动唤醒几次;0 = 不限制
|
|
668
667
|
threadWindowMs: 3600000 # 窗口长度(毫秒),默认 1 小时
|
|
669
|
-
threadCooldownMs:
|
|
668
|
+
threadCooldownMs: 5000 # 两次自动唤醒的最小间隔;0 = 不限制
|
|
670
669
|
minTaskChars: 24 # 正文短于此长度只入箱不唤醒(挡 ping/ack)
|
|
671
670
|
```
|
|
672
671
|
|
|
@@ -683,7 +682,7 @@ Mesh 页面看到,不会被丢弃):
|
|
|
683
682
|
|---|---|---|
|
|
684
683
|
| `minTaskChars` | 24 | 太短的内容不开会话 |
|
|
685
684
|
| 寒暄识别 | 内置 | `ping` / `ack` / `收到` / `好的` 等整条即寒暄的,不开会话 |
|
|
686
|
-
| `threadCooldownMs` |
|
|
685
|
+
| `threadCooldownMs` | 5s | 同一 thread 不会连续秒回,管**突发** |
|
|
687
686
|
| `maxWakesPerThread` | 30 | 同一 thread 在 `threadWindowMs` 内的唤醒上限,管**持续速率** |
|
|
688
687
|
|
|
689
688
|
`maxWakesPerThread` 是**滑动窗口限速,不是终身配额**:只统计最近
|
package/client/client.js
CHANGED
|
@@ -136,6 +136,42 @@ window.__ModuleLoader__.load({
|
|
|
136
136
|
return String(os).split(/\s+/)[0];
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
/** 结构化系统身份:新对端有 osInfo,老对端只有 os 字符串,回退解析。 */
|
|
140
|
+
function osInfoLabel(peer) {
|
|
141
|
+
const info = peer && peer.osInfo;
|
|
142
|
+
if (!info) return osLabel(peer && peer.os);
|
|
143
|
+
const label = [info.name, info.version].filter(Boolean).join(" ");
|
|
144
|
+
return label || osLabel(peer && peer.os);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 一台机器上的「额外系统」(目前是 WSL 发行版)。
|
|
149
|
+
* 宿主机不在这里返回 —— 它已经由 osInfoLabel 表示了。
|
|
150
|
+
*/
|
|
151
|
+
function extraSystems(peer) {
|
|
152
|
+
const list = peer && Array.isArray(peer.systems) ? peer.systems : [];
|
|
153
|
+
return list
|
|
154
|
+
.filter((s) => s && s.kind && s.kind !== "host")
|
|
155
|
+
.map((s, i) => ({
|
|
156
|
+
key: `${s.kind}-${s.name || i}`,
|
|
157
|
+
kind: s.kind,
|
|
158
|
+
text: [s.kind === "wsl" ? "WSL" : s.kind, s.name, s.version].filter(Boolean).join(" "),
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** WSL 发行版里的运行时,压成一行;没有就返回空串。 */
|
|
163
|
+
function wslSummary(caps) {
|
|
164
|
+
const list = caps && Array.isArray(caps.wsl) ? caps.wsl : [];
|
|
165
|
+
return list
|
|
166
|
+
.map((w) => {
|
|
167
|
+
const rts = Object.entries(w.runtimes || {})
|
|
168
|
+
.map(([n, v]) => `${n} ${v}`)
|
|
169
|
+
.join("、");
|
|
170
|
+
return `${w.name}${rts ? `:${rts}` : ""}`;
|
|
171
|
+
})
|
|
172
|
+
.join(" · ");
|
|
173
|
+
}
|
|
174
|
+
|
|
139
175
|
function shortAddress(host, port) {
|
|
140
176
|
if (!host) return "地址未知";
|
|
141
177
|
return port ? `${host}:${port}` : String(host);
|
|
@@ -533,6 +569,9 @@ window.__ModuleLoader__.load({
|
|
|
533
569
|
const ts = (state && state.tsnet) || {};
|
|
534
570
|
return [
|
|
535
571
|
`Mesh ${self.version || ""}`.trim(),
|
|
572
|
+
self.diskVersion && self.diskVersion !== self.version
|
|
573
|
+
? `disk: ${self.diskVersion} (已升级,进程未重启)`
|
|
574
|
+
: "",
|
|
536
575
|
`machine: ${self.machine || ""}`,
|
|
537
576
|
`address: ${shortAddress(self.host, self.port)}`,
|
|
538
577
|
`hostname: ${self.hostname || ""}`,
|
|
@@ -2574,6 +2613,15 @@ window.__ModuleLoader__.load({
|
|
|
2574
2613
|
: null,
|
|
2575
2614
|
!runtimes.length ? h("span", { className: "mesh-chip is-muted" }, "未探到运行时") : null,
|
|
2576
2615
|
),
|
|
2616
|
+
// WSL 发行版里的运行时单独一行:Windows 上的 Python 和 WSL 里的 Python
|
|
2617
|
+
// 是两个环境,混进同一排 chip 会让人以为"装过了",从而把任务派到没有它的地方。
|
|
2618
|
+
wslSummary(caps)
|
|
2619
|
+
? h(
|
|
2620
|
+
"div",
|
|
2621
|
+
{ className: "mesh-chips", style: { marginTop: 6 } },
|
|
2622
|
+
h("span", { className: "mesh-chip is-muted" }, `WSL · ${wslSummary(caps)}`),
|
|
2623
|
+
)
|
|
2624
|
+
: null,
|
|
2577
2625
|
runtimes.length > 6
|
|
2578
2626
|
? h(
|
|
2579
2627
|
"button",
|
|
@@ -2904,10 +2952,22 @@ window.__ModuleLoader__.load({
|
|
|
2904
2952
|
"div",
|
|
2905
2953
|
{ className: "mesh-meta" },
|
|
2906
2954
|
h(Status, { kind: online ? "ok" : "idle" }, isSelf ? "运行中" : online ? "在线" : "离线"),
|
|
2955
|
+
h("span", null, osInfoLabel(peer)),
|
|
2907
2956
|
h("span", { className: "mesh-address" }, address),
|
|
2908
2957
|
isSelf ? null : h("span", null, `最后心跳 ${ago(peer.lastSeen, now)}`),
|
|
2909
2958
|
peer.capabilitiesStale ? h(Badge, { kind: "warn" }, "能力可能过期") : null,
|
|
2910
2959
|
),
|
|
2960
|
+
// 同一台机器上的其它系统(WSL)。分开显示:Windows 上的 Python 和
|
|
2961
|
+
// WSL 里的 Python 是两个环境,混成一行会让 Placement 判断错。
|
|
2962
|
+
extraSystems(peer).length
|
|
2963
|
+
? h(
|
|
2964
|
+
"div",
|
|
2965
|
+
{ className: "mesh-meta" },
|
|
2966
|
+
extraSystems(peer).map((sys) =>
|
|
2967
|
+
h("span", { key: sys.key, className: "mesh-chip" }, h("span", { className: "mesh-chip-label" }, sys.text)),
|
|
2968
|
+
),
|
|
2969
|
+
)
|
|
2970
|
+
: null,
|
|
2911
2971
|
),
|
|
2912
2972
|
h(
|
|
2913
2973
|
"div",
|
|
@@ -4392,9 +4452,19 @@ window.__ModuleLoader__.load({
|
|
|
4392
4452
|
h("dt", null, "端口"), h("dd", null, String(self.port || "—")),
|
|
4393
4453
|
h("dt", null, "主机名"), h("dd", null, self.hostname || "—"),
|
|
4394
4454
|
h("dt", null, "MAC"), h("dd", null, self.mac || "—"),
|
|
4395
|
-
h("dt", null, "
|
|
4455
|
+
h("dt", null, "版本(进程)"), h("dd", null, self.version || "—"),
|
|
4456
|
+
// 进程版本 ≠ 磁盘版本 = 升级了没重启。光看一个版本号永远发现不了,
|
|
4457
|
+
// 于是用户会拿旧行为当新版本的 bug 报上来(真踩过)。
|
|
4458
|
+
h("dt", null, "版本(磁盘)"), h("dd", null, self.diskVersion || "—"),
|
|
4396
4459
|
h("dt", null, "对端"), h("dd", null, `${peers.length} 台,在线 ${peers.filter((p) => p && p.online).length} 台`),
|
|
4397
4460
|
),
|
|
4461
|
+
self.versionDrift
|
|
4462
|
+
? h(
|
|
4463
|
+
"div",
|
|
4464
|
+
{ className: "mesh-notice", role: "status" },
|
|
4465
|
+
`磁盘上是 ${self.diskVersion},当前进程还在跑 ${self.version}:重启 DSH 后新版本才生效。`,
|
|
4466
|
+
)
|
|
4467
|
+
: null,
|
|
4398
4468
|
h(
|
|
4399
4469
|
"div",
|
|
4400
4470
|
{ className: "mesh-actions-row" },
|
|
@@ -6567,6 +6637,7 @@ window.__ModuleLoader__.load({
|
|
|
6567
6637
|
TaskRow,
|
|
6568
6638
|
TaskDetail,
|
|
6569
6639
|
SettingsView,
|
|
6640
|
+
Diagnostics,
|
|
6570
6641
|
Composer,
|
|
6571
6642
|
TopBar,
|
|
6572
6643
|
TransferLayer,
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* node lib/_selftest-capabilities.mjs
|
|
8
8
|
*/
|
|
9
9
|
import { strict as assert } from "node:assert";
|
|
10
|
-
import { homedir } from "node:os";
|
|
10
|
+
import { homedir, tmpdir } from "node:os";
|
|
11
|
+
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
11
12
|
import { join } from "node:path";
|
|
12
13
|
import {
|
|
13
14
|
augmentedPath,
|
|
@@ -35,6 +36,8 @@ import {
|
|
|
35
36
|
__storeAliasDir,
|
|
36
37
|
__hasUncertainProbe,
|
|
37
38
|
__probeFailCount,
|
|
39
|
+
__isUncertain,
|
|
40
|
+
__gpuProbeSpecs,
|
|
38
41
|
} from "./capabilities.js";
|
|
39
42
|
import { MeshDiscovery, APP_TAG } from "./discovery.js";
|
|
40
43
|
|
|
@@ -105,6 +108,30 @@ test("parseWindowsGpu 取第一行(多显卡时)", () => {
|
|
|
105
108
|
assert.equal(g.name, "Intel(R) UHD Graphics");
|
|
106
109
|
});
|
|
107
110
|
|
|
111
|
+
test("parseWindowsGpu 取第一条**真卡**(虚拟适配器排在前面时)", () => {
|
|
112
|
+
// 现场复现(真机):MuMu / GameViewer / Parsec 这类虚拟显示驱动常常排在
|
|
113
|
+
// 真卡前面,原实现"取第一行"于是把 3060 的机器报成 MuMuVMM。
|
|
114
|
+
const g = parseWindowsGpu("MuMuVMM Display Adapter\r\nNVIDIA GeForce RTX 3060");
|
|
115
|
+
assert.equal(g.name, "NVIDIA GeForce RTX 3060");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("parseWindowsGpu 全是虚拟适配器时退回第一行,而不是说「没有 GPU」", () => {
|
|
119
|
+
// 「只有虚拟显卡」是一台真机器的真实状态;报 null 等于"我们不知道",
|
|
120
|
+
// 会让 Placement 把一台能用的机器当成没探过。退回第一行至少是真话。
|
|
121
|
+
const g = parseWindowsGpu("Parsec Virtual Display Adapter\r\nBasic Display Adapter");
|
|
122
|
+
assert.equal(g.present, true);
|
|
123
|
+
assert.equal(g.name, "Parsec Virtual Display Adapter");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("GPU 探测候选链:Windows 先问 nvidia-smi,再退回 powershell", () => {
|
|
127
|
+
const win = __gpuProbeSpecs("win32");
|
|
128
|
+
assert.equal(win.length, 2, "Windows 应该有两个候选");
|
|
129
|
+
assert.equal(win[0].cmd, "nvidia-smi", "先问最可信的 nvidia-smi(只报真 N 卡)");
|
|
130
|
+
assert.equal(win[1].cmd, "powershell");
|
|
131
|
+
assert.equal(__gpuProbeSpecs("darwin").length, 1);
|
|
132
|
+
assert.equal(__gpuProbeSpecs("plan9").length, 0, "不认识的平台不该凭空造命令");
|
|
133
|
+
});
|
|
134
|
+
|
|
108
135
|
test("传入非字符串(对象)→ 返回 null「未知」,不是「确定没有」也不是乱码", () => {
|
|
109
136
|
// ⚠️ 这就是真实踩到的回归:runProbe 的返回值从 string 改成 {output,error}
|
|
110
137
|
// 之后 collectGpu 漏改,把**对象**交给了解析函数。旧实现里 String(对象) 变成
|
|
@@ -413,6 +440,28 @@ test("Store 别名目录(WindowsApps)不算「补全真的生效」的证据
|
|
|
413
440
|
assert.ok(!__storeAliasDir.test(String.raw`C:\tools\WindowsApps\extra`), "只排除该目录本身,不误伤子目录");
|
|
414
441
|
});
|
|
415
442
|
|
|
443
|
+
test("探测 PATH 不再前置 WindowsApps(0 字节 Store 存根不能遮住真实运行时)", () => {
|
|
444
|
+
// 构造一个只存在 WindowsApps 的 LOCALAPPDATA。修复前 extraPathDirs() 会把它
|
|
445
|
+
// 加进候选;修复后必须为空 —— 否则它会排在真实 python/node 前面。
|
|
446
|
+
const tmp = mkdtempSync(join(tmpdir(), "mesh-path-"));
|
|
447
|
+
try {
|
|
448
|
+
mkdirSync(join(tmp, "Microsoft", "WindowsApps"), { recursive: true });
|
|
449
|
+
const dirs = __extraPathDirs("win32", { LOCALAPPDATA: tmp });
|
|
450
|
+
assert.ok(
|
|
451
|
+
!dirs.some((d) => __storeAliasDir.test(d)),
|
|
452
|
+
`不该把 WindowsApps 补进探测 PATH:${dirs.join(", ")}`,
|
|
453
|
+
);
|
|
454
|
+
} finally {
|
|
455
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
test("exit-9009(Store 存根)算「不确定」,不能当「没装」", () => {
|
|
460
|
+
assert.equal(__isUncertain("exit-9009"), true);
|
|
461
|
+
assert.equal(__isUncertain("ENOENT"), false);
|
|
462
|
+
assert.equal(__isUncertain("timeout"), true);
|
|
463
|
+
});
|
|
464
|
+
|
|
416
465
|
test("对端 Android:6 项 ENOENT 确实都没装(它自查 command -v 确认)", () => {
|
|
417
466
|
// 对端跑过 command -v:go/docker/rustc/java/ffmpeg/adb **全部 absent**,
|
|
418
467
|
// 所以它那台**没有缺陷**。这条用例记的是"它曾经被误判成活反例"这件事:
|
|
@@ -628,6 +677,24 @@ test("探测没探准 → 标出来,并说明不能据此断定「没有」",
|
|
|
628
677
|
assert.ok(s.includes("不能据此断定"), s);
|
|
629
678
|
});
|
|
630
679
|
|
|
680
|
+
test("sanitizeCapabilities:保留并清洗 WSL 运行时", () => {
|
|
681
|
+
const caps = sanitizeCapabilities({
|
|
682
|
+
runtimes: { node: "20.19" },
|
|
683
|
+
wsl: [
|
|
684
|
+
{ name: "Ubuntu", runtimes: { node: "22.1", python: "3.12" }, error: "" },
|
|
685
|
+
{ name: "", runtimes: { node: "1.0" } },
|
|
686
|
+
{ name: "Debian", runtimes: { git: "2.43" }, error: "x".repeat(100) },
|
|
687
|
+
],
|
|
688
|
+
});
|
|
689
|
+
assert.equal(caps.wsl.length, 2, "空名字的项应被丢掉");
|
|
690
|
+
assert.equal(caps.wsl[0].name, "Ubuntu");
|
|
691
|
+
assert.equal(caps.wsl[0].runtimes.node, "22.1");
|
|
692
|
+
assert.equal(caps.wsl[1].runtimes.git, "2.43");
|
|
693
|
+
assert.ok(caps.wsl[1].error.length <= 80);
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
console.log("\n── 指纹认领的边界:同机多实例不该互相顶掉 ──");
|
|
697
|
+
|
|
631
698
|
console.log("\n── 指纹认领的边界:同机多实例不该互相顶掉 ──");
|
|
632
699
|
|
|
633
700
|
test("同指纹 + 同名(重装场景)→ 认领,旧记录被顶掉", () => {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 诊断块自测(`lib/diagnostics.js`)。
|
|
3
|
+
*
|
|
4
|
+
* 这组断言盯着一个反复踩的坑:**"进程版本 ≠ 磁盘版本"肉眼看不出来**。
|
|
5
|
+
* 磁盘已经升到 0.5.3、宿主进程还在跑 0.5.2 时,界面必须能自己说清楚,
|
|
6
|
+
* 否则用户会把旧行为当成新版本的 bug 报上来。
|
|
7
|
+
*
|
|
8
|
+
* node lib/_selftest-diagnostics.mjs
|
|
9
|
+
*/
|
|
10
|
+
import { strict as assert } from "node:assert";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import { buildDiagnostics, entryInfo, readPackageVersion } from "./diagnostics.js";
|
|
14
|
+
|
|
15
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const ENTRY = new URL("index.js", new URL(`file://${HERE}/`)).href;
|
|
17
|
+
|
|
18
|
+
let passed = 0;
|
|
19
|
+
let failed = 0;
|
|
20
|
+
function test(name, fn) {
|
|
21
|
+
try {
|
|
22
|
+
fn();
|
|
23
|
+
passed += 1;
|
|
24
|
+
console.log(` ✓ ${name}`);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
failed += 1;
|
|
27
|
+
console.log(` ✗ ${name}`);
|
|
28
|
+
console.log(` ${err?.message ?? err}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log("\n── 版本漂移:进程 vs 磁盘 ──");
|
|
33
|
+
|
|
34
|
+
test("版本一致时 versionMatches=true,且不报磁盘更新", () => {
|
|
35
|
+
const d = buildDiagnostics({ version: "0.5.3", packageVersion: "0.5.3", entryMtimeMs: 0, startedAt: Date.now() });
|
|
36
|
+
assert.equal(d.versionMatches, true);
|
|
37
|
+
assert.equal(d.diskNewerThanProcess, false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("升级了没重启:versionMatches=false,能看出磁盘比进程新", () => {
|
|
41
|
+
const startedAt = Date.now() - 60_000;
|
|
42
|
+
const d = buildDiagnostics({ version: "0.5.2", packageVersion: "0.5.3", entryMtimeMs: Date.now(), startedAt });
|
|
43
|
+
assert.equal(d.versionMatches, false);
|
|
44
|
+
assert.equal(d.diskNewerThanProcess, true, "入口文件比进程启动还新 → 就是没重启");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("入口 mtime 拿不到时不能诬告「磁盘更新」", () => {
|
|
48
|
+
const d = buildDiagnostics({ version: "0.5.3", packageVersion: "0.5.3", entryMtimeMs: 0, startedAt: Date.now() });
|
|
49
|
+
assert.equal(d.diskNewerThanProcess, false, "mtime 未知 ≠ 磁盘更新");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("空版本号不算匹配(宁可说不知道)", () => {
|
|
53
|
+
const d = buildDiagnostics({ version: "", packageVersion: "0.5.3" });
|
|
54
|
+
assert.equal(d.versionMatches, false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
console.log("\n── 不泄露密钥 ──");
|
|
58
|
+
|
|
59
|
+
test("config 只挑安全字段,tsnetAuthKey / secret 一律不出现", () => {
|
|
60
|
+
const d = buildDiagnostics({
|
|
61
|
+
version: "0.5.3",
|
|
62
|
+
packageVersion: "0.5.3",
|
|
63
|
+
config: { port: 45917, requirePairing: true, tsnetAuthKey: "tskey-auth-SECRET", secret: "s2", apiToken: "tok" },
|
|
64
|
+
});
|
|
65
|
+
assert.equal(d.config.port, 45917);
|
|
66
|
+
assert.equal(d.config.requirePairing, true);
|
|
67
|
+
const text = JSON.stringify(d);
|
|
68
|
+
assert.ok(!text.includes("SECRET"), "tsnet 授权码泄进了诊断块");
|
|
69
|
+
assert.ok(!text.includes("\"tok\""), "apiToken 泄进了诊断块");
|
|
70
|
+
assert.ok(!("secret" in d.config));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
console.log("\n── 真实磁盘读取 ──");
|
|
74
|
+
|
|
75
|
+
test("readPackageVersion 读得到本仓库版本号", () => {
|
|
76
|
+
const v = readPackageVersion(ENTRY);
|
|
77
|
+
assert.match(v, /^\d+\.\d+\.\d+/, `读到的版本号是 ${JSON.stringify(v)}`);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("entryInfo 给出真实路径与 mtime", () => {
|
|
81
|
+
const info = entryInfo(ENTRY);
|
|
82
|
+
assert.ok(info.path.endsWith(join("lib", "index.js")), info.path);
|
|
83
|
+
assert.ok(info.mtimeMs > 0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("入口 URL 是垃圾时安静返回空,不抛", () => {
|
|
87
|
+
assert.equal(readPackageVersion("not-a-url"), "");
|
|
88
|
+
assert.deepEqual(entryInfo("not-a-url"), { path: "", mtimeMs: 0 });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
console.log(`\n结果:${passed} 通过,${failed} 失败`);
|
|
92
|
+
if (failed > 0) process.exit(1);
|