dsh-plugin-mesh 0.5.0 → 0.5.1
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/README.md +3 -2
- package/client/client.js +6410 -893
- package/cordis.patch.yml +3 -2
- package/lib/_rehearsal-peer.mjs +2 -1
- package/lib/_selftest-capabilities.mjs +3 -1
- package/lib/_selftest-client.mjs +6 -389
- package/lib/_selftest-layout.mjs +112 -0
- package/lib/_selftest-prompt.mjs +67 -1
- package/lib/_selftest-reply-route.mjs +12 -1
- package/lib/_selftest-workbench.mjs +728 -0
- package/lib/discovery.js +33 -3
- package/lib/index.js +246 -27
- package/lib/layout.js +128 -0
- package/lib/persist.js +4 -0
- package/lib/prompt.js +25 -7
- package/package.json +4 -3
- package/scripts/_selftest-release-plan.mjs +33 -2
- package/scripts/release-plan.mjs +19 -1
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mesh 工作台(client.js)的渲染自测。
|
|
3
|
+
*
|
|
4
|
+
* 与旧的 _selftest-client.mjs 不同:这一版不依赖具体组件的旧名字,
|
|
5
|
+
* 而是直接拿 __test 导出的新组件,用最小 react stub 渲染成元素树,
|
|
6
|
+
* 断言“用户能看到的文案”和“坏数据不崩”。
|
|
7
|
+
*
|
|
8
|
+
* node lib/_selftest-workbench.mjs
|
|
9
|
+
*/
|
|
10
|
+
import { strict as assert } from "node:assert";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
|
|
15
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const BUNDLE = join(HERE, "..", "client", "client.js");
|
|
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
|
+
async function testAsync(name, fn) {
|
|
33
|
+
try {
|
|
34
|
+
await fn();
|
|
35
|
+
passed += 1;
|
|
36
|
+
console.log(` ✓ ${name}`);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
failed += 1;
|
|
39
|
+
console.log(` ✗ ${name}`);
|
|
40
|
+
console.log(` ${err?.message ?? err}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const react = {
|
|
45
|
+
createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }),
|
|
46
|
+
useState: (v) => [typeof v === "function" ? v() : v, () => {}],
|
|
47
|
+
useEffect: () => {},
|
|
48
|
+
useMemo: (f) => f(),
|
|
49
|
+
useCallback: (f) => f,
|
|
50
|
+
useRef: (v) => ({ current: v }),
|
|
51
|
+
Fragment: Symbol("Fragment"),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** 真实 react 会把第三个参数塞进 props.children;stub 里要手动补上。 */
|
|
55
|
+
function propsFor(node) {
|
|
56
|
+
const kids = node.children && node.children.length ? (node.children.length === 1 ? node.children[0] : node.children) : undefined;
|
|
57
|
+
return kids === undefined ? node.props : { ...node.props, children: kids };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function textOf(node, out = []) {
|
|
61
|
+
if (node === null || node === undefined || node === false || node === true) return out;
|
|
62
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
63
|
+
out.push(String(node));
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(node)) {
|
|
67
|
+
for (const c of node) textOf(c, out);
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
if (typeof node === "object") {
|
|
71
|
+
if (typeof node.type === "function") {
|
|
72
|
+
textOf(node.type(propsFor(node)), out);
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
// Collapsed sections are still mounted for the height animation, but their
|
|
76
|
+
// text is not user-visible; the assertions describe visible content.
|
|
77
|
+
if (
|
|
78
|
+
node.props &&
|
|
79
|
+
node.props["aria-hidden"] === true &&
|
|
80
|
+
String(node.props.className || "").includes("mesh-collapse")
|
|
81
|
+
) {
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
textOf(node.children, out);
|
|
85
|
+
const kids = node.props && node.props.children;
|
|
86
|
+
if (kids !== undefined) textOf(kids, out);
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function walk(node, fn) {
|
|
93
|
+
if (!node || typeof node !== "object") return;
|
|
94
|
+
if (Array.isArray(node)) return node.forEach((n) => walk(n, fn));
|
|
95
|
+
if (typeof node.type === "function") return walk(node.type(propsFor(node)), fn);
|
|
96
|
+
fn(node);
|
|
97
|
+
walk(node.children, fn);
|
|
98
|
+
if (node.props && node.props.children !== undefined) walk(node.props.children, fn);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let captured = null;
|
|
102
|
+
globalThis.window = {
|
|
103
|
+
__ModuleLoader__: {
|
|
104
|
+
load: (entry) => {
|
|
105
|
+
captured = entry;
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const source = readFileSync(BUNDLE, "utf8");
|
|
111
|
+
new Function("window", `${source}\n`)(globalThis.window);
|
|
112
|
+
const mod = captured.factory((name) => {
|
|
113
|
+
if (name === "react") return react;
|
|
114
|
+
throw new Error(`未预期的依赖:${name}`);
|
|
115
|
+
});
|
|
116
|
+
const {
|
|
117
|
+
MeshApp,
|
|
118
|
+
HomeView,
|
|
119
|
+
HomeBoard,
|
|
120
|
+
DeviceDetail,
|
|
121
|
+
DeviceRow,
|
|
122
|
+
CapabilityChips,
|
|
123
|
+
TaskRow,
|
|
124
|
+
TaskDetail,
|
|
125
|
+
SettingsView,
|
|
126
|
+
Composer,
|
|
127
|
+
DispatchPanel,
|
|
128
|
+
DeviceList,
|
|
129
|
+
TasksView,
|
|
130
|
+
TopBar,
|
|
131
|
+
TransferComposer,
|
|
132
|
+
TransferLog,
|
|
133
|
+
deriveAnchor,
|
|
134
|
+
snapshotFor,
|
|
135
|
+
anchorLabel,
|
|
136
|
+
transferPrompt,
|
|
137
|
+
transferMarkdown,
|
|
138
|
+
currentSessionId,
|
|
139
|
+
sendToAgent,
|
|
140
|
+
PairingBody,
|
|
141
|
+
TsnetBody,
|
|
142
|
+
} = mod.__test;
|
|
143
|
+
|
|
144
|
+
const noop = () => {};
|
|
145
|
+
const now = Date.now();
|
|
146
|
+
const peer = {
|
|
147
|
+
id: "p1",
|
|
148
|
+
machine: "winbox",
|
|
149
|
+
online: true,
|
|
150
|
+
host: "192.168.1.9",
|
|
151
|
+
port: 45917,
|
|
152
|
+
hostname: "winbox-host",
|
|
153
|
+
mac: "aa:bb",
|
|
154
|
+
os: "win32 10.0",
|
|
155
|
+
user: "u",
|
|
156
|
+
profile: "desktop",
|
|
157
|
+
version: "0.3.33",
|
|
158
|
+
lastSeen: now,
|
|
159
|
+
transport: "lan",
|
|
160
|
+
endpoints: [{ transport: "lan", host: "192.168.1.9", port: 45917, verified: true, okCount: 10, failCount: 0, rttMs: 8 }],
|
|
161
|
+
capabilities: { runtimes: { go: "1.25", python: "3.12" }, cpuCores: 8, memMb: 16384, arch: "amd64", gpu: { present: true, name: "RTX 3060", vramMb: 12288 } },
|
|
162
|
+
capabilitiesStale: false,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
console.log("\n── bundle 能被加载 ──");
|
|
166
|
+
test("bundle 的 id 是包名,apply 注册两个槽位", () => {
|
|
167
|
+
assert.equal(captured.id, "dsh-plugin-mesh");
|
|
168
|
+
const regs = [];
|
|
169
|
+
mod.apply({
|
|
170
|
+
slots: {
|
|
171
|
+
inject: (name, cb) => {
|
|
172
|
+
cb();
|
|
173
|
+
regs.push(name);
|
|
174
|
+
},
|
|
175
|
+
register: (spec) => regs.push(spec),
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
assert.ok(regs.includes("sidebar.panellist"));
|
|
179
|
+
assert.ok(regs.includes("main"));
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
console.log("\n── 设备行 / 详情:离线与缺地址 ──");
|
|
183
|
+
test("设备行显示名字、在线状态与系统", () => {
|
|
184
|
+
const txt = textOf(DeviceRow({ peer, active: true, onSelect: noop, now })).join(" ");
|
|
185
|
+
assert.ok(txt.includes("winbox"), txt);
|
|
186
|
+
assert.ok(txt.includes("在线"), txt);
|
|
187
|
+
assert.ok(txt.includes("Windows"), txt);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("离线 + host 为空 + 有 endpoint 时,用 endpoint 地址,不显示 ?:? / :0", () => {
|
|
191
|
+
const offline = { ...peer, online: false, host: "", port: 0, transport: null };
|
|
192
|
+
const txt = textOf(DeviceDetail({ peer: offline, now, onCompose: noop, onProbe: noop, onBack: noop })).join(" ");
|
|
193
|
+
assert.ok(txt.includes("离线"), txt);
|
|
194
|
+
assert.ok(txt.includes("192.168.1.9:45917"), txt);
|
|
195
|
+
assert.ok(!txt.includes("?:?"), txt);
|
|
196
|
+
assert.ok(!txt.includes(":0"), txt);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("完全没地址时显示“地址未知”,而不是空白或问号", () => {
|
|
200
|
+
const offline = { ...peer, online: false, host: "", port: 0, endpoints: [], capabilities: null };
|
|
201
|
+
const txt = textOf(DeviceDetail({ peer: offline, now, onCompose: noop, onProbe: noop, onBack: noop })).join(" ");
|
|
202
|
+
assert.ok(txt.includes("地址未知"), txt);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
console.log("\n── 能力:三种“不知道”分开 ──");
|
|
206
|
+
test("有运行时 → 徽章;没上报 → 说明“还没有上报能力”", () => {
|
|
207
|
+
const has = textOf(CapabilityChips({ caps: peer.capabilities })).join(" ");
|
|
208
|
+
assert.ok(has.includes("python"), has);
|
|
209
|
+
assert.ok(has.includes("3.12"), has);
|
|
210
|
+
assert.ok(has.includes("RTX 3060"), has);
|
|
211
|
+
assert.ok(has.includes("8 核"), has);
|
|
212
|
+
|
|
213
|
+
const unknown = textOf(DeviceDetail({ peer: { ...peer, capabilities: null }, now, onCompose: noop, onProbe: noop, onBack: noop })).join(" ");
|
|
214
|
+
assert.ok(unknown.includes("对端还没有上报能力"), unknown);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("上报了但确实没有运行时 → 说“未探到运行时”", () => {
|
|
218
|
+
const txt = textOf(CapabilityChips({ caps: { runtimes: {} } })).join(" ");
|
|
219
|
+
assert.ok(txt.includes("未探到运行时"), txt);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test("能力过期 / 探测未探准 → 显示可见提示(不只 hover)", () => {
|
|
223
|
+
const stale = textOf(DeviceDetail({ peer: { ...peer, capabilitiesStale: true }, now, onCompose: noop, onProbe: noop, onBack: noop })).join(" ");
|
|
224
|
+
assert.ok(stale.includes("能力可能过期") || stale.includes("数据可能已过期"), stale);
|
|
225
|
+
const incomplete = textOf(DeviceDetail({ peer: { ...peer, capabilities: { ...peer.capabilities, runtimesIncomplete: true } }, now, onCompose: noop, onProbe: noop, onBack: noop })).join(" ");
|
|
226
|
+
assert.ok(incomplete.includes("不能当结论"), incomplete);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("坏数据不崩", () => {
|
|
230
|
+
for (const junk of ["python", 42, [], undefined, { runtimes: "nope" }]) {
|
|
231
|
+
const el = DeviceDetail({ peer: { ...peer, capabilities: junk }, now, onCompose: noop, onProbe: noop, onBack: noop });
|
|
232
|
+
assert.ok(el);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
console.log("\n── 任务:状态与详情 ──");
|
|
237
|
+
test("任务行把英文状态翻成中文", () => {
|
|
238
|
+
const task = { key: "k", dir: "in", id: "t1", peer: "winbox", at: now, text: "跑一下构建", thread: "", status: "noted-only", raw: {} };
|
|
239
|
+
const txt = textOf(TaskRow({ task, active: true, onSelect: noop, now })).join(" ");
|
|
240
|
+
assert.ok(txt.includes("仅记录"), txt);
|
|
241
|
+
assert.ok(!txt.includes("noted-only"), txt);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("失败的发出任务能看到原因与重试", () => {
|
|
245
|
+
const task = { key: "k", dir: "out", id: "t2", peer: "winbox", at: now, text: "构建", thread: "", status: "failed", raw: { ok: false, status: 500, error: "boom" } };
|
|
246
|
+
const txt = textOf(TaskDetail({ task, now, onCopy: noop, onRetry: noop, onBack: noop })).join(" ");
|
|
247
|
+
assert.ok(txt.includes("失败原因:boom"), txt);
|
|
248
|
+
assert.ok(txt.includes("重试"), txt);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
console.log("\n── 连接:配对码 / Tailscale ──");
|
|
252
|
+
test("配对关闭时给出“启用配对码”,不是让人改 YAML", () => {
|
|
253
|
+
const txt = textOf(PairingBody({ self: { secret: "x".repeat(32) }, cfg: { requirePairing: false }, push: noop, reload: async () => {} })).join(" ");
|
|
254
|
+
assert.ok(txt.includes("启用配对码"), txt);
|
|
255
|
+
assert.ok(!txt.includes("改 YAML"), txt);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("配对开启时给出“停用配对码”", () => {
|
|
259
|
+
const txt = textOf(PairingBody({ self: { secret: "x".repeat(32) }, cfg: { requirePairing: true }, push: noop, reload: async () => {} })).join(" ");
|
|
260
|
+
assert.ok(txt.includes("停用配对码"), txt);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("Tailscale 未启用时,授权地址是可见文本,并说明 Reusable", () => {
|
|
264
|
+
const tsnet = { enabled: false, authKeySaved: false, controlUrl: "", node: null, recentEvents: [] };
|
|
265
|
+
const el = TsnetBody({ tsnet, push: noop, reload: async () => {} });
|
|
266
|
+
const txt = textOf(el).join(" ");
|
|
267
|
+
assert.ok(txt.includes("https://console.tailscale.com/admin/settings/keys"), txt.slice(0, 300));
|
|
268
|
+
assert.ok(txt.includes("Reusable"), txt);
|
|
269
|
+
assert.ok(txt.includes("授权码"), txt);
|
|
270
|
+
let disabled = false;
|
|
271
|
+
walk(el, (n) => {
|
|
272
|
+
if (n.type === "button" && n.props && n.props.disabled === true) disabled = true;
|
|
273
|
+
});
|
|
274
|
+
assert.ok(disabled, "没有授权码时,连接按钮应禁用");
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
console.log("\n── 外壳 / 设置 / 派发 sheet ──");
|
|
278
|
+
test("无 state 时 MeshApp 渲染加载态与顶栏,不崩", () => {
|
|
279
|
+
const txt = textOf(MeshApp({})).join(" ");
|
|
280
|
+
assert.ok(txt.includes("Mesh"), txt);
|
|
281
|
+
assert.ok(txt.includes("正在读取 Mesh 状态"), txt);
|
|
282
|
+
assert.ok(txt.includes("设备"), txt);
|
|
283
|
+
assert.ok(txt.includes("任务"), txt);
|
|
284
|
+
assert.ok(txt.includes("连接"), txt);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const state = {
|
|
288
|
+
ok: true,
|
|
289
|
+
self: { machine: "Rosmontis喵", host: "10.30.191.107", port: 45917, hostname: "Rosmontis", mac: "ac:f2", platform: "win32", version: "0.3.33", addresses: ["10.30.191.107"], capabilities: peer.capabilities, secret: "x".repeat(32), needsName: false },
|
|
290
|
+
config: { requirePairing: false, scanIntervalMs: 60000, pingIntervalMs: 10000, useMulticast: true },
|
|
291
|
+
tsnet: { enabled: false, authKeySaved: false, controlUrl: "", node: null, recentEvents: [] },
|
|
292
|
+
peers: [peer],
|
|
293
|
+
inbound: [],
|
|
294
|
+
outbound: [],
|
|
295
|
+
throttled: [],
|
|
296
|
+
duplicateNames: [],
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
test("主页默认卡片:概览/设备/任务/配对/联网,诊断默认隐藏", () => {
|
|
300
|
+
const txt = textOf(HomeView({
|
|
301
|
+
state,
|
|
302
|
+
self: state.self,
|
|
303
|
+
peers: [peer],
|
|
304
|
+
tasks: [],
|
|
305
|
+
now,
|
|
306
|
+
lastOk: now,
|
|
307
|
+
focus: false,
|
|
308
|
+
layout: ["overview", "devices", "tasks", "pairing", "tsnet"],
|
|
309
|
+
onLayoutChange: noop,
|
|
310
|
+
onFocusChange: noop,
|
|
311
|
+
onReset: noop,
|
|
312
|
+
onDevices: noop,
|
|
313
|
+
onTasks: noop,
|
|
314
|
+
onConnect: noop,
|
|
315
|
+
onScan: noop,
|
|
316
|
+
scanning: false,
|
|
317
|
+
firstRun: null,
|
|
318
|
+
})).join(" ");
|
|
319
|
+
assert.ok(txt.includes("主页"), txt);
|
|
320
|
+
assert.ok(txt.includes("概览"), txt);
|
|
321
|
+
assert.ok(txt.includes("设备"), txt);
|
|
322
|
+
assert.ok(txt.includes("最近任务"), txt);
|
|
323
|
+
assert.ok(txt.includes("配对码"), txt);
|
|
324
|
+
assert.ok(txt.includes("互联网组网"), txt);
|
|
325
|
+
assert.ok(!txt.includes("诊断"), "诊断默认隐藏在自定义里");
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("专注模式在主页可见", () => {
|
|
329
|
+
const txt = textOf(HomeView({
|
|
330
|
+
state,
|
|
331
|
+
self: state.self,
|
|
332
|
+
peers: [peer],
|
|
333
|
+
tasks: [],
|
|
334
|
+
now,
|
|
335
|
+
lastOk: now,
|
|
336
|
+
focus: true,
|
|
337
|
+
layout: ["overview"],
|
|
338
|
+
onLayoutChange: noop,
|
|
339
|
+
onFocusChange: noop,
|
|
340
|
+
onReset: noop,
|
|
341
|
+
onDevices: noop,
|
|
342
|
+
onTasks: noop,
|
|
343
|
+
onConnect: noop,
|
|
344
|
+
onScan: noop,
|
|
345
|
+
scanning: false,
|
|
346
|
+
firstRun: null,
|
|
347
|
+
})).join(" ");
|
|
348
|
+
assert.ok(txt.includes("专注模式"), txt);
|
|
349
|
+
assert.ok(txt.includes("每 15 秒刷新"), txt);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test("主页把派发任务面板放在最底下(卡片之后)", () => {
|
|
353
|
+
const txt = textOf(HomeBoard({
|
|
354
|
+
state,
|
|
355
|
+
self: state.self,
|
|
356
|
+
peers: [peer],
|
|
357
|
+
tasks: [],
|
|
358
|
+
now,
|
|
359
|
+
lastOk: now,
|
|
360
|
+
focus: false,
|
|
361
|
+
layout: [],
|
|
362
|
+
sizes: {},
|
|
363
|
+
customCards: [],
|
|
364
|
+
density: "comfortable",
|
|
365
|
+
onLayoutChange: noop,
|
|
366
|
+
onFocusChange: noop,
|
|
367
|
+
onSizesChange: noop,
|
|
368
|
+
onCustomCardsChange: noop,
|
|
369
|
+
onDensityChange: noop,
|
|
370
|
+
onReset: noop,
|
|
371
|
+
onDevices: noop,
|
|
372
|
+
onTasks: noop,
|
|
373
|
+
onConnect: noop,
|
|
374
|
+
onScan: noop,
|
|
375
|
+
scanning: false,
|
|
376
|
+
hostDown: false,
|
|
377
|
+
onDispatched: noop,
|
|
378
|
+
firstRun: null,
|
|
379
|
+
})).join(" ");
|
|
380
|
+
assert.ok(txt.includes("派发任务"), txt);
|
|
381
|
+
assert.ok(txt.includes("要对方做什么"), txt);
|
|
382
|
+
const cardTail = txt.indexOf("主页上的卡片都收起来了");
|
|
383
|
+
const dispatch = txt.indexOf("派发任务");
|
|
384
|
+
assert.ok(cardTail >= 0 && dispatch > cardTail, "派发面板应在卡片区之后");
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
console.log("\n── 视图里不再重复 tab 名 ──");
|
|
388
|
+
|
|
389
|
+
/** 收集某个 class 上的可见文字,用来钉住「标题写了什么」。 */
|
|
390
|
+
function textsOfClass(el, className) {
|
|
391
|
+
const out = [];
|
|
392
|
+
walk(el, (n) => {
|
|
393
|
+
if (n.props && n.props.className === className) out.push(textOf(n).join("").trim());
|
|
394
|
+
});
|
|
395
|
+
return out;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
test("主页不再重复写「主页」标题(tab 上已经有)", () => {
|
|
399
|
+
const el = HomeBoard({
|
|
400
|
+
state, self: state.self, peers: [peer], tasks: [], now, lastOk: now, focus: false,
|
|
401
|
+
layout: [], sizes: {}, customCards: [], density: "comfortable",
|
|
402
|
+
onLayoutChange: noop, onFocusChange: noop, onSizesChange: noop, onCustomCardsChange: noop,
|
|
403
|
+
onDensityChange: noop, onReset: noop, onDevices: noop, onTasks: noop, onConnect: noop,
|
|
404
|
+
onScan: noop, scanning: false, hostDown: false, onDispatched: noop, firstRun: null,
|
|
405
|
+
});
|
|
406
|
+
assert.deepEqual(textsOfClass(el, "mesh-home-title"), [], "不该再有 mesh-home-title 这种重复标题");
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test("设备页左栏只写台数,不重复「设备」", () => {
|
|
410
|
+
const titles = textsOfClass(DeviceList({ selfPeer: state.self, peers: [peer], selectedId: null, onSelect: noop, now, lastOk: now, onScan: noop, scanning: false }), "mesh-pane-title");
|
|
411
|
+
assert.deepEqual(titles, ["1 台设备"]);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test("任务页左栏只写条数,不重复「任务」", () => {
|
|
415
|
+
const el = TasksView({ state, filter: "all", onFilter: noop, selectedKey: null, onSelect: noop, pane: "list", onBack: noop, onRetry: noop, onCopy: noop, push: noop, reload: async () => {}, now, onGoDevices: noop });
|
|
416
|
+
const titles = textsOfClass(el, "mesh-pane-title");
|
|
417
|
+
assert.equal(titles.length, 1, titles.join("|"));
|
|
418
|
+
assert.ok(/条任务$/.test(titles[0]), titles[0]);
|
|
419
|
+
assert.notEqual(titles[0], "任务");
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
test("连接页不再重复写「连接」大标题", () => {
|
|
423
|
+
const el = SettingsView({ state, open: null, onOpen: noop, onSaveName: async () => true, nameBusy: false, push: noop, reload: async () => {} });
|
|
424
|
+
let h1 = 0;
|
|
425
|
+
walk(el, (n) => {
|
|
426
|
+
if (n.type === "h1") h1 += 1;
|
|
427
|
+
});
|
|
428
|
+
assert.equal(h1, 0, "tab 已经叫「连接」,正文不必再来一个 h1");
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
console.log("\n── 图标:网段探测 vs 单机探测 ──");
|
|
432
|
+
|
|
433
|
+
/** 收集组件树里所有按钮/图标按钮的 icon 名(含函数组件展开)。 */
|
|
434
|
+
function iconsIn(node, out = []) {
|
|
435
|
+
if (!node || typeof node !== "object") return out;
|
|
436
|
+
if (Array.isArray(node)) {
|
|
437
|
+
for (const c of node) iconsIn(c, out);
|
|
438
|
+
return out;
|
|
439
|
+
}
|
|
440
|
+
const props = node.props || {};
|
|
441
|
+
if (typeof props.icon === "string") out.push(props.icon);
|
|
442
|
+
if (typeof node.type === "function") {
|
|
443
|
+
iconsIn(node.type(propsFor(node)), out);
|
|
444
|
+
return out;
|
|
445
|
+
}
|
|
446
|
+
iconsIn(node.children, out);
|
|
447
|
+
if (props.children !== undefined) iconsIn(props.children, out);
|
|
448
|
+
return out;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
test("设备详情的「探测」用准星图标,不再复用网段扫描那个", () => {
|
|
452
|
+
const icons = iconsIn(DeviceDetail({ peer, now, onCompose: noop, onProbe: noop, onBack: noop, onRename: noop }));
|
|
453
|
+
assert.ok(icons.includes("probe"), `探测按钮应使用 probe 图标:${icons.join(",")}`);
|
|
454
|
+
assert.ok(!icons.includes("scan"), `设备详情里不该再出现网段扫描图标:${icons.join(",")}`);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
test("网段探测的入口按钮统一显示「局域网探测」", () => {
|
|
458
|
+
const empty = textOf(DeviceList({ selfPeer: state.self, peers: [], selectedId: null, onSelect: noop, now, lastOk: now, onScan: noop, scanning: false })).join(" ");
|
|
459
|
+
assert.ok(empty.includes("局域网探测"), empty);
|
|
460
|
+
assert.ok(!empty.includes("扫描"), `设备页左栏不该再说「扫描」:${empty}`);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
test("自定义卡片能渲染便签内容", () => {
|
|
464
|
+
const custom = [{
|
|
465
|
+
id: "custom-test",
|
|
466
|
+
custom: true,
|
|
467
|
+
type: "note",
|
|
468
|
+
title: "构建便签",
|
|
469
|
+
icon: "note",
|
|
470
|
+
text: "部署前先跑测试",
|
|
471
|
+
metric: "online",
|
|
472
|
+
filter: "all",
|
|
473
|
+
}];
|
|
474
|
+
const txt = textOf(HomeBoard({
|
|
475
|
+
state,
|
|
476
|
+
self: state.self,
|
|
477
|
+
peers: [peer],
|
|
478
|
+
tasks: [],
|
|
479
|
+
now,
|
|
480
|
+
lastOk: now,
|
|
481
|
+
focus: false,
|
|
482
|
+
layout: ["overview", "custom-test"],
|
|
483
|
+
sizes: {},
|
|
484
|
+
customCards: custom,
|
|
485
|
+
density: "comfortable",
|
|
486
|
+
onLayoutChange: noop,
|
|
487
|
+
onFocusChange: noop,
|
|
488
|
+
onSizesChange: noop,
|
|
489
|
+
onCustomCardsChange: noop,
|
|
490
|
+
onDensityChange: noop,
|
|
491
|
+
onReset: noop,
|
|
492
|
+
onDevices: noop,
|
|
493
|
+
onTasks: noop,
|
|
494
|
+
onConnect: noop,
|
|
495
|
+
onScan: noop,
|
|
496
|
+
scanning: false,
|
|
497
|
+
firstRun: null,
|
|
498
|
+
})).join(" ");
|
|
499
|
+
assert.ok(txt.includes("构建便签"), txt);
|
|
500
|
+
assert.ok(txt.includes("部署前先跑测试"), txt);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
test("设置页有四个入口,且默认全部收起", () => {
|
|
504
|
+
const txt = textOf(SettingsView({ state, open: null, onOpen: noop, onSaveName: async () => true, nameBusy: false, push: noop, reload: async () => {} })).join(" ");
|
|
505
|
+
assert.ok(txt.includes("本机"), txt);
|
|
506
|
+
assert.ok(txt.includes("配对码"), txt);
|
|
507
|
+
assert.ok(txt.includes("互联网组网"), txt);
|
|
508
|
+
assert.ok(txt.includes("诊断"), txt);
|
|
509
|
+
assert.ok(!txt.includes("Generate auth key"), "收起时不该出现 Tailscale 教程");
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
test("派发 sheet 显示目标与输入框,空任务时发送禁用", () => {
|
|
513
|
+
const el = Composer({ target: peer, open: true, onClose: noop, onSent: noop, hostDown: false });
|
|
514
|
+
const txt = textOf(el).join(" ");
|
|
515
|
+
assert.ok(txt.includes("派发任务"), txt);
|
|
516
|
+
assert.ok(txt.includes("winbox"), txt);
|
|
517
|
+
let sendDisabled = false;
|
|
518
|
+
walk(el, (n) => {
|
|
519
|
+
if (n.type === "button" && n.props && n.props.disabled === true && textOf(n).join("").includes("发送")) sendDisabled = true;
|
|
520
|
+
});
|
|
521
|
+
assert.ok(sendDisabled, "空任务时发送按钮应禁用");
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
console.log("\n── 主页 · 派发任务面板 ──");
|
|
525
|
+
|
|
526
|
+
test("派发面板列出在线设备,空任务时发送禁用", () => {
|
|
527
|
+
const el = DispatchPanel({ peers: [peer], hostDown: false, onScan: noop, scanning: false });
|
|
528
|
+
const txt = textOf(el).join(" ");
|
|
529
|
+
assert.ok(txt.includes("派发任务"), txt);
|
|
530
|
+
assert.ok(txt.includes("winbox"), "目标下拉里应有设备名");
|
|
531
|
+
assert.ok(txt.includes("1 / 1 台在线"), txt);
|
|
532
|
+
let options = 0;
|
|
533
|
+
let sendDisabled = false;
|
|
534
|
+
walk(el, (n) => {
|
|
535
|
+
if (n.type === "option" && n.props && n.props.value === "p1") options += 1;
|
|
536
|
+
if (n.type === "button" && n.props && n.props.disabled === true && textOf(n).join("").includes("发送")) sendDisabled = true;
|
|
537
|
+
});
|
|
538
|
+
assert.equal(options, 1, "每台设备一个 option");
|
|
539
|
+
assert.ok(sendDisabled, "没写内容时不该能发");
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
test("没有设备时给局域网探测入口,而不是一个空的下拉", () => {
|
|
543
|
+
const el = DispatchPanel({ peers: [], hostDown: false, onScan: noop, scanning: false });
|
|
544
|
+
const txt = textOf(el).join(" ");
|
|
545
|
+
assert.ok(txt.includes("还没有发现其他设备"), txt);
|
|
546
|
+
assert.ok(txt.includes("局域网探测"), "应引导用户去探测局域网");
|
|
547
|
+
let disabled = false;
|
|
548
|
+
walk(el, (n) => {
|
|
549
|
+
if (n.type === "select" && n.props && n.props.disabled === true) disabled = true;
|
|
550
|
+
});
|
|
551
|
+
assert.ok(disabled, "没有设备时下拉应禁用");
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
test("目标离线时说清原因,不静默失败", () => {
|
|
555
|
+
const offline = { ...peer, online: false };
|
|
556
|
+
const txt = textOf(DispatchPanel({ peers: [offline], hostDown: false, onScan: noop, scanning: false })).join(" ");
|
|
557
|
+
assert.ok(txt.includes("离线"), txt);
|
|
558
|
+
assert.ok(txt.includes("当前离线"), txt);
|
|
559
|
+
assert.ok(txt.includes("winbox(离线)"), "下拉项要标出离线");
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
test("与主机失联时派发按钮禁用并说明原因", () => {
|
|
563
|
+
const el = DispatchPanel({ peers: [peer], hostDown: true, onScan: noop, scanning: false });
|
|
564
|
+
const txt = textOf(el).join(" ");
|
|
565
|
+
assert.ok(txt.includes("与主机失去联系"), txt);
|
|
566
|
+
let sendDisabled = false;
|
|
567
|
+
walk(el, (n) => {
|
|
568
|
+
if (n.type === "button" && n.props && n.props.disabled === true && textOf(n).join("").includes("发送")) sendDisabled = true;
|
|
569
|
+
});
|
|
570
|
+
assert.ok(sendDisabled, "主机关联不上时不能假装能发");
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
console.log("\n── 锚定传输 ──");
|
|
574
|
+
|
|
575
|
+
const fakeCap = {
|
|
576
|
+
nodeType: 1,
|
|
577
|
+
tagName: "SPAN",
|
|
578
|
+
innerText: "3.12",
|
|
579
|
+
parentElement: null,
|
|
580
|
+
getAttribute(name) {
|
|
581
|
+
const attrs = { "data-mesh-cap": "python", "data-mesh-peer": "winbox", "data-mesh-instance": "p1" };
|
|
582
|
+
return attrs[name] ?? null;
|
|
583
|
+
},
|
|
584
|
+
getBoundingClientRect() {
|
|
585
|
+
return { left: 1, top: 2, width: 3, height: 4 };
|
|
586
|
+
},
|
|
587
|
+
closest(selector) {
|
|
588
|
+
return selector.includes("data-mesh-cap") ? this : null;
|
|
589
|
+
},
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
test("deriveAnchor 从 data-mesh-cap 生成语义锚点", () => {
|
|
593
|
+
const anchor = deriveAnchor(fakeCap, state);
|
|
594
|
+
assert.equal(anchor.kind, "capability");
|
|
595
|
+
assert.equal(anchor.cap, "python");
|
|
596
|
+
assert.equal(anchor.machine, "winbox");
|
|
597
|
+
assert.equal(anchor.instanceId, "p1");
|
|
598
|
+
assert.equal(anchor.rect.width, 3);
|
|
599
|
+
assert.ok(anchorLabel(anchor).includes("winbox"));
|
|
600
|
+
assert.ok(anchorLabel(anchor).includes("python"));
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
test("snapshotFor 带上 peer 与 capability 现场", () => {
|
|
604
|
+
const anchor = deriveAnchor(fakeCap, state);
|
|
605
|
+
const snapshot = snapshotFor(anchor, state);
|
|
606
|
+
assert.equal(snapshot.peer.machine, "winbox");
|
|
607
|
+
assert.equal(snapshot.peer.online, true);
|
|
608
|
+
assert.equal(snapshot.capability.key, "python");
|
|
609
|
+
assert.equal(snapshot.capability.value, "3.12");
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
test("transferPrompt 包含锚点、现场和线程", () => {
|
|
613
|
+
const anchor = deriveAnchor(fakeCap, state);
|
|
614
|
+
const snapshot = snapshotFor(anchor, state);
|
|
615
|
+
const prompt = transferPrompt({ id: "tr-test", route: "mesh", thread: "transfer:tr-test", anchor, snapshot, intent: "重新探一下" });
|
|
616
|
+
assert.ok(prompt.includes("Mesh 锚定传输 #tr-test"), prompt);
|
|
617
|
+
assert.ok(prompt.includes("winbox"), prompt);
|
|
618
|
+
assert.ok(prompt.includes("python"), prompt);
|
|
619
|
+
assert.ok(prompt.includes("transfer:tr-test"), prompt);
|
|
620
|
+
assert.ok(prompt.includes("重新探一下"), prompt);
|
|
621
|
+
const md = transferMarkdown({ id: "tr-test", route: "mesh", anchor, snapshot, intent: "重新探一下" });
|
|
622
|
+
assert.ok(md.includes("锚定传输"), md);
|
|
623
|
+
assert.ok(md.includes("winbox"), md);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
test("TransferComposer 显示目标、意图和预览", () => {
|
|
627
|
+
const anchor = deriveAnchor(fakeCap, state);
|
|
628
|
+
const snapshot = snapshotFor(anchor, state);
|
|
629
|
+
const txt = textOf(TransferComposer({
|
|
630
|
+
draft: { anchor, snapshot },
|
|
631
|
+
state,
|
|
632
|
+
sessionId: "s1",
|
|
633
|
+
onClose: noop,
|
|
634
|
+
onSend: async () => {},
|
|
635
|
+
})).join(" ");
|
|
636
|
+
assert.ok(txt.includes("锚定传输"), txt);
|
|
637
|
+
assert.ok(txt.includes("当前会话"), txt);
|
|
638
|
+
assert.ok(txt.includes("winbox"), txt);
|
|
639
|
+
assert.ok(txt.includes("剪贴板"), txt);
|
|
640
|
+
assert.ok(txt.includes("查看将发送的内容"), txt);
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
test("TransferLog 显示记录与状态", () => {
|
|
644
|
+
const anchor = deriveAnchor(fakeCap, state);
|
|
645
|
+
const snapshot = snapshotFor(anchor, state);
|
|
646
|
+
const txt = textOf(TransferLog({
|
|
647
|
+
items: [{ id: "tr-1", at: new Date().toISOString(), route: "mesh", status: "sent", anchor, snapshot, intent: "重新探一下" }],
|
|
648
|
+
onClose: noop,
|
|
649
|
+
onRetry: noop,
|
|
650
|
+
onLocate: noop,
|
|
651
|
+
onCopy: noop,
|
|
652
|
+
})).join(" ");
|
|
653
|
+
assert.ok(txt.includes("传输记录"), txt);
|
|
654
|
+
assert.ok(txt.includes("winbox"), txt);
|
|
655
|
+
assert.ok(txt.includes("已发送"), txt);
|
|
656
|
+
assert.ok(txt.includes("重新探一下"), txt);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
test("TopBar 提供锚定传输与记录入口", () => {
|
|
660
|
+
const el = TopBar({
|
|
661
|
+
view: "devices",
|
|
662
|
+
onView: noop,
|
|
663
|
+
online: 1,
|
|
664
|
+
total: 1,
|
|
665
|
+
taskCount: 0,
|
|
666
|
+
error: null,
|
|
667
|
+
lastOk: now,
|
|
668
|
+
now,
|
|
669
|
+
refreshing: false,
|
|
670
|
+
onRefresh: noop,
|
|
671
|
+
scanning: false,
|
|
672
|
+
onScan: noop,
|
|
673
|
+
disabled: false,
|
|
674
|
+
busy: false,
|
|
675
|
+
focus: false,
|
|
676
|
+
onToggleFocus: noop,
|
|
677
|
+
onTransfer: noop,
|
|
678
|
+
transferActive: true,
|
|
679
|
+
onLog: noop,
|
|
680
|
+
transferCount: 3,
|
|
681
|
+
});
|
|
682
|
+
const labels = [];
|
|
683
|
+
walk(el, (node) => {
|
|
684
|
+
if (node.type === "button" && node.props && node.props["aria-label"]) labels.push(node.props["aria-label"]);
|
|
685
|
+
});
|
|
686
|
+
assert.ok(labels.some((label) => label.includes("锚定传输")), labels.join(","));
|
|
687
|
+
assert.ok(labels.some((label) => label.includes("传输记录")), labels.join(","));
|
|
688
|
+
assert.ok(textOf(el).join(" ").includes("3"), "记录角标应显示条数");
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
await testAsync("sendToAgent 写入并提交当前会话草稿", async () => {
|
|
692
|
+
const calls = { draft: "", submitted: false, panel: "unchanged" };
|
|
693
|
+
mod.apply({
|
|
694
|
+
slots: {
|
|
695
|
+
inject: (name, cb) => cb(),
|
|
696
|
+
register: () => {},
|
|
697
|
+
},
|
|
698
|
+
get(name) {
|
|
699
|
+
if (name === "uiWorkspace") return { selection: { getSnapshot: () => ({ sessionId: "s1" }) } };
|
|
700
|
+
if (name === "sessions") return { scope: () => ({}) };
|
|
701
|
+
if (name === "conversation") {
|
|
702
|
+
return {
|
|
703
|
+
input: {
|
|
704
|
+
for: () => ({
|
|
705
|
+
setDraft: (text) => {
|
|
706
|
+
calls.draft = text;
|
|
707
|
+
},
|
|
708
|
+
submit: () => {
|
|
709
|
+
calls.submitted = true;
|
|
710
|
+
},
|
|
711
|
+
}),
|
|
712
|
+
},
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
if (name === "layout") return { selectPanel: (value) => { calls.panel = value; } };
|
|
716
|
+
return null;
|
|
717
|
+
},
|
|
718
|
+
});
|
|
719
|
+
assert.equal(currentSessionId(), "s1");
|
|
720
|
+
const status = await sendToAgent("hello mesh", "s1");
|
|
721
|
+
assert.equal(calls.draft, "hello mesh");
|
|
722
|
+
assert.equal(calls.submitted, true);
|
|
723
|
+
assert.equal(calls.panel, null);
|
|
724
|
+
assert.equal(status, "sent");
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
console.log(`\n${failed === 0 ? "全部通过" : "有失败"}:${passed} 通过 / ${failed} 失败\n`);
|
|
728
|
+
process.exit(failed ? 1 : 0);
|