dsh-plugin-mesh 0.5.0 → 0.5.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/AGENTS.md +1 -1
- package/README.md +7 -7
- package/client/client.js +6410 -893
- package/cordis.patch.yml +3 -2
- package/lib/_rehearsal-peer.mjs +2 -1
- package/lib/_selftest-capabilities.mjs +28 -2
- 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-tsnet.mjs +26 -1
- package/lib/_selftest-workbench.mjs +728 -0
- package/lib/capabilities.js +16 -4
- package/lib/discovery.js +43 -6
- package/lib/index.js +302 -49
- package/lib/layout.js +128 -0
- package/lib/persist.js +4 -0
- package/lib/prompt.js +25 -7
- package/lib/scan.js +11 -10
- package/lib/tsnet/download.js +5 -1
- package/package.json +4 -3
- package/scripts/_selftest-release-plan.mjs +33 -2
- package/scripts/release-plan.mjs +19 -1
|
@@ -27,7 +27,7 @@ async function makeNode(machine) {
|
|
|
27
27
|
const home = join(root, machine);
|
|
28
28
|
mkdirSync(join(home, "mesh"), { recursive: true });
|
|
29
29
|
writeFileSync(join(home, "mesh", "state.json"), JSON.stringify({ secret: "test-only-shared-secret" }));
|
|
30
|
-
const node = { machine, home, peers: [], tools: new Map(), agents: new Map(), inbound: [], outbound: [], threadState: new Map(), created: 0, sent: 0 };
|
|
30
|
+
const node = { machine, home, peers: [], tools: new Map(), agents: new Map(), inbound: [], outbound: [], threadState: new Map(), hostDispatched: new Map(), created: 0, sent: 0 };
|
|
31
31
|
const context = vm.createContext({
|
|
32
32
|
console, Buffer, URL, AbortSignal, setTimeout, clearTimeout, setInterval, clearInterval,
|
|
33
33
|
process: { ...process, env: { ...process.env, DSH_HOME: home } },
|
|
@@ -109,6 +109,17 @@ try {
|
|
|
109
109
|
assert.equal(a.created, 0, "reply must not create a new A session");
|
|
110
110
|
console.log("✓ real mesh_run/HTTP roundtrip: original session receives reply, zero new A sessions");
|
|
111
111
|
|
|
112
|
+
// 宿主(页面派发)已经替用户发过同一 thread:绑定会话里的 agent 再调 mesh_run
|
|
113
|
+
// 就是对端收两份,必须在 HTTP 之前挡住。这条也顺带守住 hostDispatched 的作用域
|
|
114
|
+
// —— 它曾经只在 applyUnsafe 里声明,而用点在 registerTools/registerUiRoutes,
|
|
115
|
+
// 结果每次带 thread 的 mesh_run 都抛 ReferenceError(真机 + 本测试都撞上)。
|
|
116
|
+
a.hostDispatched.set("host-thread", Date.now());
|
|
117
|
+
a.threadState.set(key("host-thread"), { sessionId: "original-session", wakesAt: [] });
|
|
118
|
+
const sentBeforeGuard = a.sent;
|
|
119
|
+
assert.match(await a.send("B", "host-thread", "original-session"), /已经由宿主发出去/);
|
|
120
|
+
assert.equal(a.sent, sentBeforeGuard, "被挡下的重复派发不能真的发出 HTTP");
|
|
121
|
+
console.log("✓ host-dispatched thread is refused in the bound session, no duplicate HTTP");
|
|
122
|
+
|
|
112
123
|
// Very fast return before the sending tool receives its acknowledgement.
|
|
113
124
|
a.beforeAck = async () => {
|
|
114
125
|
assert.equal(disk().threads[key("fast")].sessionId, "original-session");
|
package/lib/_selftest-tsnet.mjs
CHANGED
|
@@ -54,7 +54,7 @@ check("detectTarget 给出当前平台", () => {
|
|
|
54
54
|
|
|
55
55
|
check("assetName 命名与 sidecar 构建脚本一致", () => {
|
|
56
56
|
const name = assetName();
|
|
57
|
-
assert.match(name, /^dsh-mesh-tsnet-(darwin|windows|linux|android)-(amd64|arm64)\.gz$/);
|
|
57
|
+
assert.match(name, /^dsh-mesh-tsnet-(darwin|windows|linux|android)-(amd64|arm64)(\.exe)?\.gz$/);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
check("下载源:镜像在前、直连 GitHub 兜底", () => {
|
|
@@ -553,6 +553,17 @@ check("note() 显式传端口时以显式为准(tailnet / 扫描路径)", ()
|
|
|
553
553
|
assert.equal(d.peers()[0].endpoints.find((e) => e.transport === "tsnet").port, 46150);
|
|
554
554
|
});
|
|
555
555
|
|
|
556
|
+
check("note() 以观察到的地址为准,自述 host 不能改派发目标", () => {
|
|
557
|
+
const d = new MeshDiscovery({ id: "self-1", port: 45917, meta: { machine: "me" } });
|
|
558
|
+
d.note(
|
|
559
|
+
{ app: "dsh-mesh", id: "spoof", machine: "peer", host: "attacker.example.com", port: 8080 },
|
|
560
|
+
"10.1.2.3",
|
|
561
|
+
);
|
|
562
|
+
const p = d.peers()[0];
|
|
563
|
+
assert.equal(p.host, "10.1.2.3", "LAN 也必须用观察到的地址");
|
|
564
|
+
assert.equal(p.endpoints[0].host, "10.1.2.3");
|
|
565
|
+
});
|
|
566
|
+
|
|
556
567
|
check("endpointAlive:存活窗口跟随探测间隔(慢节奏通道不被 TTL 判死)", () => {
|
|
557
568
|
const now = 1_000_000;
|
|
558
569
|
// tailnet 通道每 60s 才探一次,而默认 TTL 是 20s ——
|
|
@@ -565,6 +576,20 @@ check("endpointAlive:存活窗口跟随探测间隔(慢节奏通道不被 TT
|
|
|
565
576
|
assert.equal(endpointAlive(fast, now, 20_000), false, "10s 节奏的通道 50s 没消息就该判死");
|
|
566
577
|
});
|
|
567
578
|
|
|
579
|
+
check("心跳不清零出站失败冷却(单向可达时不再永远先打 LAN)", () => {
|
|
580
|
+
const d = new MeshDiscovery({ id: "self-1", port: 45917, meta: { machine: "me" } });
|
|
581
|
+
const rec = { app: "dsh-mesh", id: "dev", machine: "hos", host: "10.0.0.9", port: 45917 };
|
|
582
|
+
d.note(rec, "10.0.0.9");
|
|
583
|
+
d.markEndpoint("dev", "lan", { ok: false });
|
|
584
|
+
d.markEndpoint("dev", "lan", { ok: false });
|
|
585
|
+
const before = d.peers()[0].endpoints.find((e) => e.transport === "lan");
|
|
586
|
+
assert.ok(before.downUntil > Date.now(), "连续失败后应进入冷却");
|
|
587
|
+
d.note(rec, "10.0.0.9");
|
|
588
|
+
const after = d.peers()[0].endpoints.find((e) => e.transport === "lan");
|
|
589
|
+
assert.equal(after.failCount, 2, "心跳不该清零 failCount");
|
|
590
|
+
assert.equal(after.downUntil, before.downUntil, "心跳不该清掉冷却截止时间");
|
|
591
|
+
});
|
|
592
|
+
|
|
568
593
|
check("全部端点冷却时:投影为空,但 orderedEndpoints 仍要给出发送目标", () => {
|
|
569
594
|
const d = new MeshDiscovery({ id: "self-1", port: 45917, meta: { machine: "me" } });
|
|
570
595
|
d.note(
|