Files
dsh-purge/test/desktop-asar-swap.test.js
T
iigzx c236e689f3 fix(desktop): 换包先杀 Electron main,挪不动时把原版拉起来 (#197)
- ASAR_SWAP_PS1 先按安装根路径 + 非 --type= 识别并 kill Electron main,再扫安装目录其余进程:main 是唯一会弹「host stopped」的对话框来源,先杀它就不会出现 host 死了 main 还活着的半死状态
- 挪包失败的分支补上 Start-Process:用户至少拿到原版应用,不再面对空桌面;失败原因写入 %TEMP%\\dsh-purge-desktop.log
- 导出 ASAR_SWAP_PS1 并新增 test/desktop-asar-swap.test.js(3 例,守住顺序与两条重启分支)
- 全量 node --test 94/94 通过
2026-10-31 21:51:32 +08:00

26 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from "node:test";
import assert from "node:assert/strict";
import { ASAR_SWAP_PS1 } from "../lib/desktop.js";
// #197b:桌面端点「应用」时 host 被杀、main 还活着 → 弹「host stopped」,
// 且 asar 没挪动 → 应用变成半死状态。这里守住两条顺序性约束。
test("先杀 Electron main,再杀安装目录其余进程", () => {
const mainKill = ASAR_SWAP_PS1.indexOf("Stop-Process -Id $p.ProcessId");
// 只看「作为独立一行的调用」,不要命中函数定义 `function Stop-HarnessInstall` 与缩进的内部调用
const sweep = ASAR_SWAP_PS1.indexOf("\r\nStop-HarnessInstall\r\n");
assert.ok(mainKill > 0, "缺少 main 进程 kill");
assert.ok(sweep > 0, "缺少 Stop-HarnessInstall 调用");
assert.ok(sweep > mainKill, "Stop-HarnessInstall 必须在 main kill 之后");
});
test("main 进程的识别排除渲染/GPU 子进程(--type=)", () => {
assert.match(ASAR_SWAP_PS1, /CommandLine -notmatch '--type='/);
});
test("挪包失败时也要把原版拉起来,不留空桌面", () => {
const relaunch = ASAR_SWAP_PS1.split("Start-Process -FilePath $ExePath").length - 1;
assert.equal(relaunch, 2, "成功/失败两个分支都要重启 exe");
assert.match(ASAR_SWAP_PS1, /move failed; relaunching original app/);
});