@mrrisega/dsh-remote 0.6.4-beta.2 → 0.6.4-beta.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrrisega/dsh-remote",
|
|
3
|
-
"version": "0.6.4-beta.
|
|
3
|
+
"version": "0.6.4-beta.3",
|
|
4
4
|
"description": "手机远程控制 DeepSeek Harness · Remote control DeepSeek Harness (dsh web) from any phone browser — 100% 全功能 App 级体验:发消息、看工具执行、审批权限、改设置、管凭据,含特权操作,免内网穿透。一条命令安装 npx @mrrisega/dsh-remote。Mobile remote control for DSH, self-host or SaaS, no server needed on LAN.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
@@ -142,6 +142,8 @@ window.__ModuleLoader__.load({
|
|
|
142
142
|
".dru-popup-foot button:hover{color:#0969da}",
|
|
143
143
|
".dru-popup .dru-msg{text-align:left}",
|
|
144
144
|
".dru-community-qr{display:block;width:220px;max-width:62vw;margin:0 auto;background:#ffffff;padding:10px;border-radius:10px;border:1px solid #d0d7de;box-sizing:content-box}",
|
|
145
|
+
".dru-restart-auto{display:flex;align-items:center;gap:8px;margin-top:10px;font-size:12.5px;color:#1a7f37;background:#dafbe1;border-radius:8px;padding:8px 10px}",
|
|
146
|
+
".dru-restart-auto.muted{color:#57606a;background:#f6f8fa}",
|
|
145
147
|
".dru-fb-community{margin-top:16px;padding-top:14px;border-top:1px dashed #d0d7de;text-align:center}",
|
|
146
148
|
".dru-fb-community .dru-community-qr{width:180px;max-width:56vw}",
|
|
147
149
|
// ── 自管理:版本与更新(插件面板内提供在线更新/彻底卸载,市场无更新按钮) ──
|
|
@@ -1189,6 +1191,10 @@ window.__ModuleLoader__.load({
|
|
|
1189
1191
|
// ── 💬 交流群(「加入交流群」按钮 + 弹窗):同样放在全部既有字段之后 ──
|
|
1190
1192
|
var communityArr = useState(null); var community = communityArr[0]; var setCommunity = communityArr[1]; // {qrcode,wechat};null=未加载
|
|
1191
1193
|
var commOpenArr = useState(false); var commOpen = commOpenArr[0]; var setCommOpen = commOpenArr[1];
|
|
1194
|
+
// 【自动化】重启倒计时 / 是否已被用户取消(初值按本次 pending 事件的持久化标记,跨刷新生效)
|
|
1195
|
+
var restartCancelArr = useState(function () { return autoRestartCancelled((st && st.restart && st.restart.at) || 0); });
|
|
1196
|
+
var restartCancelled = restartCancelArr[0]; var setRestartCancelled = restartCancelArr[1];
|
|
1197
|
+
var restartCountArr = useState(null); var restartCountdown = restartCountArr[0]; var setRestartCountdown = restartCountArr[1];
|
|
1192
1198
|
// ── 🔗 登录后自动闭环:连接阶段(运行环境 → bridge 进程 → 设备已在中继注册=online) ──
|
|
1193
1199
|
// conn 来自 GET /dsh-remote/bridge-status(node 半在返回前会自动补装/拉起/退避重试),
|
|
1194
1200
|
// 面板据它显示「正在准备运行环境…/正在启动 Bridge…/正在连接中继…/已连接 ✅」,
|
|
@@ -1861,6 +1867,25 @@ window.__ModuleLoader__.load({
|
|
|
1861
1867
|
});
|
|
1862
1868
|
};
|
|
1863
1869
|
|
|
1870
|
+
/**
|
|
1871
|
+
* 【自动化】首次安装/在线更新后自动重启 DeepSeek harness —— 用户不需要点任何按钮。
|
|
1872
|
+
*
|
|
1873
|
+
* 为什么能自动:① 重启只是重启 dsh web(bridge 与手机端连接不受影响);② 重启后
|
|
1874
|
+
* waitHarnessBack 会轮询到它回来并**自动刷新页面**,面板与「连接中→已连接」流程继续跑完。
|
|
1875
|
+
* 安全阀:① 面板不可见(用户没在看)→ 不计时,回来再继续;② 15 秒倒计时内可一键取消,
|
|
1876
|
+
* 取消标记按本次 pending 事件(at 时间戳)持久化,同一事件不再自动重启(下次安装/更新会重新触发);
|
|
1877
|
+
* ③ 面板上有其他操作在跑(busy≠"")→ 暂停计时,避免打断用户正在做的事。
|
|
1878
|
+
*/
|
|
1879
|
+
var AUTO_RESTART_DELAY_MS = 15000;
|
|
1880
|
+
var RESTART_CANCEL_KEY = "dsh-remote-auto-restart-cancelled";
|
|
1881
|
+
|
|
1882
|
+
function autoRestartCancelled(at) {
|
|
1883
|
+
try { return localStorage.getItem(RESTART_CANCEL_KEY) === String(at || ""); } catch (e) { return false; }
|
|
1884
|
+
}
|
|
1885
|
+
function markAutoRestartCancelled(at) {
|
|
1886
|
+
try { localStorage.setItem(RESTART_CANCEL_KEY, String(at || "")); } catch (e) { /* 忽略 */ }
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1864
1889
|
/** 轮询等待 harness 回来;观察到「断过又恢复」或等待足够久后自动刷新页面。 */
|
|
1865
1890
|
var waitHarnessBack = function (tries, sawDown) {
|
|
1866
1891
|
if (tries > 40) { setMsg("err", "重启后仍未就绪,请手动刷新页面或重启 DeepSeek harness。"); setBusy(""); return; }
|
|
@@ -2402,6 +2427,31 @@ window.__ModuleLoader__.load({
|
|
|
2402
2427
|
);
|
|
2403
2428
|
}
|
|
2404
2429
|
|
|
2430
|
+
// 【自动化】待重启时自动倒计时重启(见 autoRestartCancelled 说明);倒计时只在面板可见且无其他操作时推进
|
|
2431
|
+
useEffect(function () {
|
|
2432
|
+
if (!restartPending || busy !== "" || restartCancelled) { setRestartCountdown(null); return undefined; }
|
|
2433
|
+
var at = restartInfo.at || 0;
|
|
2434
|
+
if (autoRestartCancelled(at)) { setRestartCountdown(null); return undefined; }
|
|
2435
|
+
var left = Math.round(AUTO_RESTART_DELAY_MS / 1000);
|
|
2436
|
+
setRestartCountdown(left);
|
|
2437
|
+
var iv = setInterval(function () {
|
|
2438
|
+
if (document.hidden) return; // 用户没在看 → 暂停计时
|
|
2439
|
+
left -= 1;
|
|
2440
|
+
if (left > 0) { setRestartCountdown(left); return; }
|
|
2441
|
+
clearInterval(iv);
|
|
2442
|
+
setRestartCountdown(0);
|
|
2443
|
+
restartHarness(); // 已有实现:重启 + 轮询等它回来 + 自动刷新页面
|
|
2444
|
+
}, 1000);
|
|
2445
|
+
return function () { clearInterval(iv); };
|
|
2446
|
+
}, [restartPending, restartInfo.at, busy, restartCancelled]);
|
|
2447
|
+
|
|
2448
|
+
/** 取消本次自动重启(按事件持久化:同一 pending 事件不再自动重启)。 */
|
|
2449
|
+
var cancelAutoRestart = function () {
|
|
2450
|
+
markAutoRestartCancelled(restartInfo.at || 0);
|
|
2451
|
+
setRestartCancelled(true);
|
|
2452
|
+
setRestartCountdown(null);
|
|
2453
|
+
};
|
|
2454
|
+
|
|
2405
2455
|
/** 交流群弹窗(复用满意度弹窗的 dru-popup 视觉;点遮罩/关闭即收起)。 */
|
|
2406
2456
|
function renderCommunityModal() {
|
|
2407
2457
|
if (!commOpen || !(community && community.qrcode)) return null;
|
|
@@ -2442,13 +2492,32 @@ window.__ModuleLoader__.load({
|
|
|
2442
2492
|
restartInfo.kind === "update" ? "在线更新已完成,需要重启 DeepSeek harness" : "首次安装需要重启 DeepSeek harness"),
|
|
2443
2493
|
h("div", { className: "dru-restart-alert-sub" },
|
|
2444
2494
|
"插件本体与「远程访问」面板是在 DeepSeek harness 启动时装载的,重启之后即可正常使用(账号、二维码、bridge 全部生效)。"),
|
|
2495
|
+
// 【自动化】待重启时自动倒计时重启(用户零操作);倒计时期间可一键取消
|
|
2496
|
+
restartCountdown !== null && restartCountdown > 0
|
|
2497
|
+
? h("div", { className: "dru-restart-auto", role: "status" },
|
|
2498
|
+
h("span", { className: "loading" }),
|
|
2499
|
+
h("span", null, "安装已完成,将在 " + restartCountdown + " 秒后自动重启 DeepSeek harness(页面会自动恢复,无需操作)"))
|
|
2500
|
+
: null,
|
|
2501
|
+
restartCountdown === 0
|
|
2502
|
+
? h("div", { className: "dru-restart-auto", role: "status" }, h("span", { className: "loading" }), h("span", null, "正在自动重启…"))
|
|
2503
|
+
: null,
|
|
2504
|
+
restartCancelled && restartCountdown === null
|
|
2505
|
+
? h("div", { className: "dru-restart-auto muted" }, "已取消自动重启 —— 你也可以随时点下面的按钮完成安装")
|
|
2506
|
+
: null,
|
|
2445
2507
|
h("div", { className: "dru-actions", style: { marginTop: 10 } },
|
|
2446
2508
|
h("button", {
|
|
2447
2509
|
type: "button",
|
|
2448
2510
|
className: "dru-btn dru-btn-primary",
|
|
2449
2511
|
disabled: busy !== "",
|
|
2450
2512
|
onClick: function () { restartHarness(); }
|
|
2451
|
-
}, busy === "restart" ? "重启中…" : "重启 DeepSeek harness")
|
|
2513
|
+
}, busy === "restart" ? "重启中…" : (restartCountdown !== null && restartCountdown > 0 ? "立即重启(不用等)" : "重启 DeepSeek harness")),
|
|
2514
|
+
restartCountdown !== null && restartCountdown > 0
|
|
2515
|
+
? h("button", {
|
|
2516
|
+
type: "button",
|
|
2517
|
+
className: "dru-btn dru-btn-ghost",
|
|
2518
|
+
onClick: cancelAutoRestart
|
|
2519
|
+
}, "取消自动重启")
|
|
2520
|
+
: null
|
|
2452
2521
|
)
|
|
2453
2522
|
)
|
|
2454
2523
|
)
|
|
@@ -1723,7 +1723,7 @@ const PLUGIN_ID = "dsh-remote-web";
|
|
|
1723
1723
|
const PLUGIN_LEGACY_IDS = ["dsh-remote-ui"];
|
|
1724
1724
|
const PLUGIN_ALL_IDS = [PLUGIN_ID, ...PLUGIN_LEGACY_IDS];
|
|
1725
1725
|
/** 插件自身发布版本(与 dsh-remote 根包同步递增)。 */
|
|
1726
|
-
const PLUGIN_VERSION = "0.6.4-beta.
|
|
1726
|
+
const PLUGIN_VERSION = "0.6.4-beta.3";
|
|
1727
1727
|
const UPDATE_LOG = ".dsh-update.log";
|
|
1728
1728
|
const UPDATE_MARKER = ".dsh-update-running";
|
|
1729
1729
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote-web",
|
|
3
|
-
"version": "0.6.4-beta.
|
|
3
|
+
"version": "0.6.4-beta.3",
|
|
4
4
|
"description": "公网远程控制 DeepSeek Harness(dsh web):安装即得专属加密地址,人在外面也能用手机访问电脑上的 dsh——无需同一局域网/WiFi、无需公网 IP 与内网穿透,全程加密;手机端 100% 还原电脑体验(对话/工具/审批/设置)。技术用户可选自建服务,流量走自己的服务器。Remote control DeepSeek Harness (dsh web) from anywhere over the public internet — install, get an encrypted URL, use it from your phone on any network (dual-half cordis plugin: Settings panel + same-origin /dsh-remote routes). (2026-09 由 dsh-remote-ui 更名 / renamed from dsh-remote-ui; dsh-remote 的 dsh web 插件半,不是纯 UI/皮肤插件)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// 【自动化】首次安装/更新后「自动重启 DeepSeek harness」的安全回归(浏览器半,0.6.4)。
|
|
2
|
+
//
|
|
3
|
+
// 目标:用户装完不需要点任何按钮 —— 面板发现「待重启」后自己倒计时重启,重启后自动恢复页面
|
|
4
|
+
// (复用既有 restartHarness + waitHarnessBack:轮询到 harness 回来即自动刷新)。
|
|
5
|
+
// 但「自动重启进程」是危险动作,本用例锁死四条安全阀:
|
|
6
|
+
// ① 只在面板可见时计时(用户没在看就不动);
|
|
7
|
+
// ② 15 秒倒计时内可一键取消,取消标记按本次事件(restart.at)持久化,同一事件不再自动重启;
|
|
8
|
+
// ③ 面板上有其他操作在跑(busy≠"")时暂停计时,不打断用户正在做的事;
|
|
9
|
+
// ④ 只重启一次(重启后 pending 结清即停);无待重启时一个请求都不发。
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import test from "node:test";
|
|
13
|
+
import vm from "node:vm";
|
|
14
|
+
|
|
15
|
+
const SOURCE = readFileSync(new URL("../lib/client.js", import.meta.url), "utf8");
|
|
16
|
+
|
|
17
|
+
function walk(node, visit) {
|
|
18
|
+
if (node == null) return;
|
|
19
|
+
if (Array.isArray(node)) { for (const item of node) walk(item, visit); return; }
|
|
20
|
+
if (typeof node !== "object") return;
|
|
21
|
+
visit(node);
|
|
22
|
+
for (const child of node.children || []) walk(child, visit);
|
|
23
|
+
}
|
|
24
|
+
function find(tree, predicate) {
|
|
25
|
+
let match;
|
|
26
|
+
walk(tree, (node) => { if (!match && predicate(node)) match = node; });
|
|
27
|
+
return match;
|
|
28
|
+
}
|
|
29
|
+
function textHas(tree, substr) {
|
|
30
|
+
return !!find(tree, (node) => (node.children || []).some((c) => typeof c === "string" && c.includes(substr)));
|
|
31
|
+
}
|
|
32
|
+
function nodeWithText(tree, substr) {
|
|
33
|
+
return find(tree, (node) => typeof node.props?.onClick === "function" && (node.children || []).some((c) => typeof c === "string" && c.includes(substr)));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const flush = () => new Promise((resolve) => setImmediate(resolve));
|
|
37
|
+
|
|
38
|
+
const NOT_LOGGED = { ok: true, config: { phone: "", hasPhone: false, mode: "saas", deviceId: "" }, service: { running: false }, remoteUrl: "https://app.test/" };
|
|
39
|
+
const LOGGED = { ok: true, config: { phone: "138****0000", hasPhone: true, mode: "saas", deviceId: "dev-x" }, service: { running: true }, remoteUrl: "https://app.test/" };
|
|
40
|
+
const KEY_URL = "https://app.test/a/K1";
|
|
41
|
+
const SESSIONS = [{ id: "ms_1", label: "iPhone 15", os: "iOS", browser: "Safari", created_at: 1700000000000, last_seen_at: 1700000600000, revoked_at: null }];
|
|
42
|
+
function statusWithRestart(pending, at) {
|
|
43
|
+
return Object.assign({}, LOGGED, { restart: { pending: !!pending, kind: "first-install", reason: "首次安装需要重启 DeepSeek harness", at: at || 0 } });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function loadPlugin(opts = {}) {
|
|
47
|
+
let moduleFactory;
|
|
48
|
+
const registered = new Map();
|
|
49
|
+
const injects = new Map();
|
|
50
|
+
const requests = [];
|
|
51
|
+
const clipboard = [];
|
|
52
|
+
const states = [];
|
|
53
|
+
let hook = 0;
|
|
54
|
+
let effectCursor = 0;
|
|
55
|
+
let effectSlots = [];
|
|
56
|
+
let pending = [];
|
|
57
|
+
const listeners = new Map();
|
|
58
|
+
|
|
59
|
+
let clock = 0;
|
|
60
|
+
let timerSeq = 1;
|
|
61
|
+
const timers = new Map();
|
|
62
|
+
const job = (fn) => { try { fn(); } catch (e) { /* 内部错误由断言暴露 */ } };
|
|
63
|
+
const fakeSetTimeout = (fn, ms) => { const id = timerSeq++; timers.set(id, { at: clock + (Number(ms) || 0), fn, every: 0 }); return id; };
|
|
64
|
+
const fakeSetInterval = (fn, ms) => { const id = timerSeq++; const every = Math.max(1, Number(ms) || 1); timers.set(id, { at: clock + every, fn, every }); return id; };
|
|
65
|
+
const fakeClear = (id) => { timers.delete(id); };
|
|
66
|
+
async function advance(ms) {
|
|
67
|
+
const target = clock + ms;
|
|
68
|
+
for (let guard = 0; guard < 2000; guard++) {
|
|
69
|
+
let due = null;
|
|
70
|
+
for (const [id, t] of timers) if (t.at <= target && (!due || t.at < due[1].at)) due = [id, t];
|
|
71
|
+
if (!due) break;
|
|
72
|
+
const [id, t] = due;
|
|
73
|
+
clock = t.at;
|
|
74
|
+
if (t.every) t.at = clock + t.every; else timers.delete(id);
|
|
75
|
+
job(t.fn);
|
|
76
|
+
await flush();
|
|
77
|
+
}
|
|
78
|
+
clock = target;
|
|
79
|
+
await flush(); await flush();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const react = {
|
|
83
|
+
createElement(type, props, ...children) { return { type, props: props || {}, children }; },
|
|
84
|
+
useState(initial) {
|
|
85
|
+
const index = hook++;
|
|
86
|
+
if (!(index in states)) states[index] = typeof initial === "function" ? initial() : initial;
|
|
87
|
+
return [states[index], (value) => { states[index] = typeof value === "function" ? value(states[index]) : value; }];
|
|
88
|
+
},
|
|
89
|
+
useEffect(fn, deps) {
|
|
90
|
+
const index = effectCursor++;
|
|
91
|
+
const prev = effectSlots[index];
|
|
92
|
+
const changed = !prev || !deps || deps.length !== prev.deps.length || deps.some((d, i) => !Object.is(d, prev.deps[i]));
|
|
93
|
+
if (changed) pending.push({ index, fn, deps: deps ? [...deps] : deps });
|
|
94
|
+
},
|
|
95
|
+
useCallback(fn) { return fn; },
|
|
96
|
+
useSyncExternalStore(_subscribe, getSnapshot) { return getSnapshot(); },
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const response = (status, body) => Promise.resolve({
|
|
100
|
+
ok: status >= 200 && status < 300,
|
|
101
|
+
status,
|
|
102
|
+
text: async () => JSON.stringify(body),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
let statusBody = opts.status || NOT_LOGGED;
|
|
106
|
+
let restartCalls = 0;
|
|
107
|
+
const connBody = null;
|
|
108
|
+
let connCalls = 0;
|
|
109
|
+
let keyCalls = 0;
|
|
110
|
+
let sessCalls = 0;
|
|
111
|
+
|
|
112
|
+
const makeEl = () => ({
|
|
113
|
+
tag: "div", children: [], style: {}, className: "", attributes: {}, textContent: "",
|
|
114
|
+
setAttribute(k, v) { this.attributes[k] = v; },
|
|
115
|
+
getAttribute(k) { return this.attributes[k] ?? null; },
|
|
116
|
+
appendChild(c) { this.children.push(c); },
|
|
117
|
+
addEventListener(type, fn) { if (!listeners.has(type)) listeners.set(type, []); listeners.get(type).push(fn); },
|
|
118
|
+
removeEventListener(type, fn) {
|
|
119
|
+
const list = listeners.get(type) || [];
|
|
120
|
+
const i = list.indexOf(fn);
|
|
121
|
+
if (i >= 0) list.splice(i, 1);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
const doc = {
|
|
125
|
+
hidden: false,
|
|
126
|
+
createElement: makeEl,
|
|
127
|
+
head: makeEl(),
|
|
128
|
+
body: makeEl(),
|
|
129
|
+
querySelector() { return null; },
|
|
130
|
+
querySelectorAll() { return []; },
|
|
131
|
+
getElementById() { return null; },
|
|
132
|
+
addEventListener(type, fn) { if (!listeners.has(type)) listeners.set(type, []); listeners.get(type).push(fn); },
|
|
133
|
+
removeEventListener(type, fn) {
|
|
134
|
+
const list = listeners.get(type) || [];
|
|
135
|
+
const i = list.indexOf(fn);
|
|
136
|
+
if (i >= 0) list.splice(i, 1);
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
class MutationObserverMock { constructor() {} observe() {} disconnect() {} }
|
|
140
|
+
const localStorage = {
|
|
141
|
+
// 支持预置存储(验证「取消标记跨刷新生效」:getItem 走真实读取路径)
|
|
142
|
+
_s: new Map(Object.entries(opts.localStorage || {})),
|
|
143
|
+
getItem(k) { return this._s.has(k) ? this._s.get(k) : null; },
|
|
144
|
+
setItem(k, v) { this._s.set(k, String(v)); },
|
|
145
|
+
removeItem(k) { this._s.delete(k); },
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const sandbox = {
|
|
149
|
+
window: { __ModuleLoader__: { load(spec) { moduleFactory = spec.factory; } }, open() { return null; } },
|
|
150
|
+
document: doc,
|
|
151
|
+
localStorage,
|
|
152
|
+
MutationObserver: MutationObserverMock,
|
|
153
|
+
navigator: { clipboard: { writeText: async (t) => { clipboard.push(String(t)); } } },
|
|
154
|
+
setTimeout: fakeSetTimeout,
|
|
155
|
+
clearTimeout: fakeClear,
|
|
156
|
+
setInterval: fakeSetInterval,
|
|
157
|
+
clearInterval: fakeClear,
|
|
158
|
+
fetch(path, options = {}) {
|
|
159
|
+
requests.push({ path, method: options.method || "GET", body: options.body ? JSON.parse(options.body) : null });
|
|
160
|
+
if (path === "/dsh-remote/status") return response(200, statusBody);
|
|
161
|
+
if (path === "/dsh-remote/bridge-status") { connCalls += 1; return response(200, { ok: true }); }
|
|
162
|
+
if (path === "/dsh-remote/harness/restart") {
|
|
163
|
+
restartCalls += 1;
|
|
164
|
+
// 重启后 harness 会带着新的 bootId 回来:模拟「待重启已结清」
|
|
165
|
+
statusBody = Object.assign({}, statusBody, { restart: { pending: false, kind: "", reason: "", at: statusBody.restart?.at || 0 } });
|
|
166
|
+
return response(200, Object.assign({}, statusBody, { ok: true, mode: "launchd" }));
|
|
167
|
+
}
|
|
168
|
+
if (path === "/dsh-remote/access-key") {
|
|
169
|
+
keyCalls += 1;
|
|
170
|
+
return response(200, { ok: true, url: KEY_URL, key: "K1", expires_at: Date.now() + 1800000, ttl_ms: 1800000, qr_data_url: "data:image/png;base64,AAAA" });
|
|
171
|
+
}
|
|
172
|
+
if (path === "/dsh-remote/mobile-sessions") {
|
|
173
|
+
sessCalls += 1;
|
|
174
|
+
return response(200, { ok: true, sessions: opts.sessions || SESSIONS });
|
|
175
|
+
}
|
|
176
|
+
if (path === "/dsh-remote/captcha") return response(200, { captcha_id: "cap-1", svg: "<svg></svg>" });
|
|
177
|
+
if (path === "/dsh-remote/register") return response(201, { ok: true, token: "jwt-reg" });
|
|
178
|
+
if (path === "/dsh-remote/config") return response(200, statusBody);
|
|
179
|
+
if (path === "/dsh-remote/account") return response(200, { ok: true, account: { phone: "138****0000", plan: "free", plan_source: "plan" } });
|
|
180
|
+
if (path === "/dsh-remote/quota") return response(200, { ok: true, quota: null });
|
|
181
|
+
if (path === "/dsh-remote/remote-url") return response(200, { ok: true, remoteUrl: "https://app.test/", publicConfig: {} });
|
|
182
|
+
return response(200, { ok: true });
|
|
183
|
+
},
|
|
184
|
+
Set, Symbol, Date, JSON, Math, Number, String, Object, Array, console,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
vm.runInNewContext(SOURCE, sandbox);
|
|
188
|
+
const plugin = moduleFactory((name) => {
|
|
189
|
+
assert.equal(name, "react");
|
|
190
|
+
return react;
|
|
191
|
+
});
|
|
192
|
+
plugin.apply({
|
|
193
|
+
slots: {
|
|
194
|
+
inject(name, cb) { injects.set(name, cb); cb(); },
|
|
195
|
+
register(meta, component) { registered.set(meta.id, component); return () => {}; },
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
requests, states, clipboard,
|
|
201
|
+
counts() { return { connCalls, keyCalls, sessCalls, restartCalls }; },
|
|
202
|
+
/** 改写状态响应(模拟 pending 被结清/用户取消后再次出现等)。 */
|
|
203
|
+
setStatus(body) { statusBody = body; },
|
|
204
|
+
/** 渲染一轮并执行本轮需要运行的 effects(含 cleanup)。 */
|
|
205
|
+
render() {
|
|
206
|
+
hook = 0; effectCursor = 0; pending = [];
|
|
207
|
+
const tree = registered.get("dsh-remote")({ close() {} });
|
|
208
|
+
const todos = pending; pending = [];
|
|
209
|
+
for (const t of todos) {
|
|
210
|
+
const prev = effectSlots[t.index];
|
|
211
|
+
if (prev && typeof prev.cleanup === "function") job(prev.cleanup);
|
|
212
|
+
const cleanup = t.fn();
|
|
213
|
+
effectSlots[t.index] = { deps: t.deps, cleanup: typeof cleanup === "function" ? cleanup : null };
|
|
214
|
+
}
|
|
215
|
+
return tree;
|
|
216
|
+
},
|
|
217
|
+
async settle(times = 3) {
|
|
218
|
+
for (let i = 0; i < times; i++) { this.render(); await flush(); await flush(); }
|
|
219
|
+
return this.render();
|
|
220
|
+
},
|
|
221
|
+
advance,
|
|
222
|
+
/** 登录成功(面板读到登录态)→ 登录态 effect 重跑,自动开始推进连接。 */
|
|
223
|
+
async login() {
|
|
224
|
+
statusBody = LOGGED;
|
|
225
|
+
await advance(30_000); // 等 30s 状态轮询把登录态带进面板
|
|
226
|
+
return this.settle();
|
|
227
|
+
},
|
|
228
|
+
/** 连接阶段推进(node 半短轮询的应答变化)。 */
|
|
229
|
+
setConnect(phase, extra) { connBody = connectPayload(phase, extra); },
|
|
230
|
+
setConnectRaw(body) { connBody = body; },
|
|
231
|
+
hide() { doc.hidden = true; },
|
|
232
|
+
show() { doc.hidden = false; for (const fn of listeners.get("visibilitychange") || []) job(fn); },
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
test("待重启 + 面板可见 → 15 秒后自动重启(用户零操作),重启后 pending 结清即停止", async () => {
|
|
239
|
+
const plugin = loadPlugin({ status: statusWithRestart(true, 1111) });
|
|
240
|
+
let tree = await plugin.settle();
|
|
241
|
+
assert.ok(textHas(tree, "首次安装需要重启 DeepSeek harness"), "应显示待重启横幅");
|
|
242
|
+
assert.ok(textHas(tree, "秒后自动重启"), "应显示自动重启倒计时文案");
|
|
243
|
+
assert.equal(plugin.counts().restartCalls, 0, "倒计时期间不得提前重启");
|
|
244
|
+
|
|
245
|
+
await plugin.advance(14000);
|
|
246
|
+
assert.equal(plugin.counts().restartCalls, 0, "14 秒时还没到点");
|
|
247
|
+
await plugin.advance(2000);
|
|
248
|
+
assert.equal(plugin.counts().restartCalls, 1, "15 秒到点应自动重启一次");
|
|
249
|
+
|
|
250
|
+
tree = await plugin.settle();
|
|
251
|
+
assert.ok(!textHas(tree, "秒后自动重启"), "重启后不应残留倒计时");
|
|
252
|
+
await plugin.advance(60000);
|
|
253
|
+
assert.equal(plugin.counts().restartCalls, 1, "pending 结清后不得反复重启");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("点「取消自动重启」→ 不再自动重启,且标记按事件持久化(刷新后仍不自动重启)", async () => {
|
|
257
|
+
const plugin = loadPlugin({ status: statusWithRestart(true, 2222) });
|
|
258
|
+
const tree = await plugin.settle();
|
|
259
|
+
const cancelBtn = nodeWithText(tree, "取消自动重启");
|
|
260
|
+
assert.ok(cancelBtn, "倒计时期间必须提供取消入口");
|
|
261
|
+
cancelBtn.props.onClick();
|
|
262
|
+
assert.ok(textHas(plugin.render(), "已取消自动重启"), "取消后应有明确反馈");
|
|
263
|
+
|
|
264
|
+
await plugin.advance(120000);
|
|
265
|
+
assert.equal(plugin.counts().restartCalls, 0, "取消后不得自动重启");
|
|
266
|
+
|
|
267
|
+
// 模拟用户刷新页面:同一 pending 事件(at=2222)仍不自动重启
|
|
268
|
+
const plugin2 = loadPlugin({ status: statusWithRestart(true, 2222), localStorage: { "dsh-remote-auto-restart-cancelled": "2222" } });
|
|
269
|
+
await plugin2.settle();
|
|
270
|
+
await plugin2.advance(120000);
|
|
271
|
+
assert.equal(plugin2.counts().restartCalls, 0, "刷新后仍尊重取消标记");
|
|
272
|
+
|
|
273
|
+
// 但下一次安装/更新(新的 at)应重新自动触发
|
|
274
|
+
const plugin3 = loadPlugin({ status: statusWithRestart(true, 3333), localStorage: { "dsh-remote-auto-restart-cancelled": "2222" } });
|
|
275
|
+
await plugin3.settle();
|
|
276
|
+
await plugin3.advance(16000);
|
|
277
|
+
assert.equal(plugin3.counts().restartCalls, 1, "新的待重启事件应重新自动重启");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("面板不可见 → 倒计时暂停;回到前台继续", async () => {
|
|
281
|
+
const plugin = loadPlugin({ status: statusWithRestart(true, 4444) });
|
|
282
|
+
await plugin.settle();
|
|
283
|
+
plugin.hide();
|
|
284
|
+
await plugin.advance(60000);
|
|
285
|
+
assert.equal(plugin.counts().restartCalls, 0, "页面隐藏时绝不能在用户没看到的情况下重启进程");
|
|
286
|
+
plugin.show();
|
|
287
|
+
await plugin.advance(16000);
|
|
288
|
+
assert.equal(plugin.counts().restartCalls, 1, "回到前台应继续倒计时并最终重启");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test("无待重启 → 一个请求都不发;横幅不出现", async () => {
|
|
292
|
+
const plugin = loadPlugin({ status: LOGGED });
|
|
293
|
+
const tree = await plugin.settle();
|
|
294
|
+
await plugin.advance(60000);
|
|
295
|
+
assert.equal(plugin.counts().restartCalls, 0);
|
|
296
|
+
assert.ok(!textHas(tree, "自动重启"), "无待重启时不应出现自动重启文案");
|
|
297
|
+
});
|