dsh-config-sync-plugin 0.4.3 → 0.4.5
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.en.md +12 -0
- package/README.md +12 -0
- package/index.js +16 -8
- package/package.json +1 -1
- package/runtime/post-exit.ps1 +8 -3
- package/tools/selftest.mjs +17 -0
package/README.en.md
CHANGED
|
@@ -257,6 +257,16 @@ Two display fixes on top of 0.3.77:
|
|
|
257
257
|
|
|
258
258
|
The "Plugin update" card now shows an **npm download URL** line with the actual fallback addresses (domestic mirror `registry.npmmirror.com` + official `registry.npmjs.org`). When the GitHub release download is unreachable (common in mainland China), the update package automatically falls back to npm. It is still verified against the authoritative sha256 in `version.json` — switching source never relaxes verification. The two sources back each other up: the mirror can briefly 404 during its first-sync window, and the official source takes over. The npm tarball is byte-identical to the GitHub release tgz (same sha256).
|
|
259
259
|
|
|
260
|
+
### Pending push but nothing happens on × close: backend periodic pre-queue (0.4.05)
|
|
261
|
+
|
|
262
|
+
End-to-end diagnosis (manual POST to `/config-sync/auto-exit`) proved the backend check and route are fine — it instantly returns `queued:true`, queues the watcher, force-exits DSH and completes the push. Root cause is the frontend: `pagehide → navigator.sendBeacon('/config-sync/auto-exit')` never reaches the backend when DSH really exits (no beacon arrival in launch.log during × close), yet 0.3.96+ relied solely on it — code-level selftests passed but real UI never verified it.
|
|
263
|
+
|
|
264
|
+
Now independent of the frontend beacon: the backend 2-min periodic check queues a watcher into `wait` state as soon as it detects pending pull/push (`shouldCloseDsh:false`, **no auto-close**); when the user clicks × to close DSH, the pre-queued watcher auto-runs the push/pull. The frontend beacon is kept as a backup — if it does arrive it reuses the existing queue, no duplication. Also: periodic check is unattended (no confirm), the queue guard checks watcher liveness (allows re-queue after timeout), and switches are re-read every cycle. 4 selftest assertions added.
|
|
265
|
+
|
|
266
|
+
### Fix watcher stuck in wait after × close due to orphan process (0.4.04)
|
|
267
|
+
|
|
268
|
+
After clicking × the push watcher gets queued but can stall in wait. Root cause: when WatchPid is force-killed it often leaves a **windowless orphan DSH child** (started before the watcher, parent dead). The stale-watcher check required "all DSH processes newer than the watcher", which this orphan permanently broke — `newerAll.Count ≠ byName.Count`, so the watcher idled 30 min holding `auto-sync.lock` and no new watcher could take over. The check now looks for "a DSH instance older than the watcher WITH a foreground window": the real signal that "the queued DSH is still in use" is a windowed instance; windowless leftovers and new instances no longer block handoff, and the watcher exits 3 to clear the lock immediately. Selftest assertion added.
|
|
269
|
+
|
|
260
270
|
### npm fallback version normalization fix (0.4.02)
|
|
261
271
|
|
|
262
272
|
npm normalizes `0.4.01` to `0.4.1` per semver, so the tarball is `dsh-config-sync-plugin-0.4.1.tgz`. Before 0.4.02 the fallback URL was built as `-0.4.01.tgz`, which 404s on npm. `npmTgzUrls` now strips leading zeros from numeric segments (`0.4.01`→`0.4.1`) before building the URL; GitHub release and version.json keep the user-specified version (same artifact, identical sha256). Selftest assertion added.
|
|
@@ -781,6 +791,8 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
|
|
|
781
791
|
|
|
782
792
|
| Date | Version | Summary |
|
|
783
793
|
|---|---|---|
|
|
794
|
+
| 2026-11-25 | 0.4.05 | Pending push but nothing on × close: root cause frontend beacon not delivered; backend periodic check now pre-queues watcher (no auto-close), runs on window close; frontend beacon demoted to backup |
|
|
795
|
+
| 2026-11-25 | 0.4.04 | Fix watcher stuck in wait after × close due to windowless orphan process: stale check now looks for a leftover foreground window, clears lock and hands over immediately |
|
|
784
796
|
| 2026-11-25 | 0.4.03 | Repackaged release: code identical to 0.4.02; only version and release metadata updated to 0.4.03 |
|
|
785
797
|
| 2026-11-25 | 0.4.02 | Fix npm fallback version normalization: npm semver turns 0.4.01 into 0.4.1; strip leading zeros when building tarball URL, otherwise 404 |
|
|
786
798
|
| 2026-11-25 | 0.4.01 | Auto sync only on active × close: scheduleAutoStart updates drift status only, handleSettings queues watcher without close, only × close/pagehide (shouldCloseDsh:true) actually closes DSH after queuing |
|
package/README.md
CHANGED
|
@@ -277,6 +277,16 @@ pwsh -File runtime\sync.ps1 pull `
|
|
|
277
277
|
|
|
278
278
|
「插件更新」卡新增一行 **npm 下载路径**,直接显示实际兜底地址(国内镜像 `registry.npmmirror.com` + 官方 `registry.npmjs.org` 两个源)。GitHub release 整段不通时(国内常见),更新包会自动兜底从 npm 下载;仍按 `version.json` 里的权威 sha256 校验,换源不放宽校验。两个源互为备份:镜像首发同步窗口期会短暂 404,官方源随即兜上。实测 npm tarball 与 GitHub release tgz 是同一份产物、sha256 完全一致。
|
|
279
279
|
|
|
280
|
+
### 点 × 有待推送却没推送:改后端定时预排 watcher(0.4.05)
|
|
281
|
+
|
|
282
|
+
端到端诊断(手动 POST `/config-sync/auto-exit`)证明后端判据与路由完全正常——立即返回 `queued:true`、排上 watcher、强制退出 DSH 并完成推送。根因在前端:`pagehide → navigator.sendBeacon('/config-sync/auto-exit')` 在 DSH 真正退出时请求送不到后端(launch.log 里点 × 时段无任何信标到达记录),而 0.3.96 起一直依赖它,代码级自测过、真实 UI 却从未验证到。
|
|
283
|
+
|
|
284
|
+
改为不依赖前端信标的可靠架构:后端 2 分钟定时复查检测到待拉取/推送时,直接排队一个 watcher 进 `wait` 态(`shouldCloseDsh:false`,**不关闭 DSH**);用户点 × 关闭 DSH 后,预排的 watcher 自动进入 run 执行推送/拉取。前端信标保留作双保险——它若送达,发现已排队会直接复用,不会重复。配套:定时复查无人值守不弹确认框、已排队守卫检查 watcher 存活(超时后允许重排)、开关每次复查重新读取。selftest 加 4 条断言防回归。
|
|
285
|
+
|
|
286
|
+
### 修复点 × 关闭后 watcher 被孤儿进程卡在 wait(0.4.04)
|
|
287
|
+
|
|
288
|
+
点 × 关闭后 push watcher 已经排上,但可能卡在 wait 阶段迟迟不执行。根因:`WatchPid` 被强杀后,常留下一个**无前台窗口的孤儿 DSH 子进程**(启动时间比 watcher 还早,父进程已死)。僵死 watcher 自清的旧判据要求「所有现存 DSH 都比 watcher 新」,这个孤儿进程把它永久破坏——`newerAll.Count ≠ byName.Count`,watcher 死等 30 分钟还霸占 `auto-sync.lock`,新 watcher 也没法接管。判定改成「有没有比 watcher 更早、且有前台窗口的 DSH 实例」:真正代表「排队那次 DSH 还在用」的是有窗口的实例;无窗口残留和新实例都不该挡住让位,watcher 立即 `exit 3` 清锁让新 watcher 接管。selftest 加断言防回归。
|
|
289
|
+
|
|
280
290
|
### npm 兜底下载的版本规范化修复(0.4.02)
|
|
281
291
|
|
|
282
292
|
npm 按 semver 把版本号 `0.4.01` 规范化成 `0.4.1`,tarball 文件名是 `dsh-config-sync-plugin-0.4.1.tgz`。0.4.01 之前拼的是 `-0.4.01.tgz`,npm 兜底下载会 404。`npmTgzUrls` 现在对数字段去前导零(`0.4.01`→`0.4.1`)再拼 URL;GitHub release 与 version.json 仍保留用户指定的版本号(同一份产物、sha256 一致)。selftest 加断言防回归。
|
|
@@ -763,6 +773,8 @@ pwsh -File sync.ps1 push -ScanHistory
|
|
|
763
773
|
|
|
764
774
|
| 日期 | 版本 | 要点 |
|
|
765
775
|
|---|---|---|
|
|
776
|
+
| 2026-11-25 | 0.4.05 | 点 × 有待推送却没推送:根因前端信标未送达,改后端定时复查预排 watcher(不关 DSH),关窗后自动执行;前端信标降为双保险 |
|
|
777
|
+
| 2026-11-25 | 0.4.04 | 修复点 × 关闭后 push watcher 被无窗口孤儿进程卡在 wait 不执行:过期判定改看有无遗留前台窗口,立即清锁让位 |
|
|
766
778
|
| 2026-11-25 | 0.4.03 | 重新打包发布:代码与 0.4.02 一致,仅版本与发布元数据更新到 0.4.03 |
|
|
767
779
|
| 2026-11-25 | 0.4.02 | 修复 npm 兜底下载的版本规范化:0.4.01 被 npm semver 规范化成 0.4.1,拼 tarball 时去前导零,否则 404 |
|
|
768
780
|
| 2026-11-25 | 0.4.01 | 自动同步仅在主动关闭 DSH 窗口(×)时触发:scheduleAutoStart 只做 drift 状态更新,handleSettings 只排队不退出,只有 × 关闭/页面卸载走 shouldCloseDsh: true 真正关闭 DSH |
|
package/index.js
CHANGED
|
@@ -3507,9 +3507,9 @@ async function handleAuto(req, res, config) {
|
|
|
3507
3507
|
/** 核心判断逻辑:给定配置与仓库,判断是否需要自动拉取/推送,需要则排队 watcher(可选关闭 DSH)。
|
|
3508
3508
|
* 供 scheduleAutoStart(定时)、triggerAutoSyncOnClose(关闭钩子)、handleSettings(开关即时触发)复用。 */
|
|
3509
3509
|
async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, options = {}) {
|
|
3510
|
-
const { skipConfirm = false, isManualTrigger = false, shouldCloseDsh = true } = options
|
|
3511
|
-
// 已经排队等退出了就别重复拉起 watcher
|
|
3512
|
-
if (autoState.pending) return { queued: false, reason: 'already_pending' }
|
|
3510
|
+
const { skipConfirm = false, isManualTrigger = false, shouldCloseDsh = true, isPeriodic = false } = options
|
|
3511
|
+
// 已经排队等退出了就别重复拉起 watcher;但 watcher 已死(超时退出)时允许重排
|
|
3512
|
+
if (autoState.pending && isProcessAlive(autoState.pending.watcherPid)) return { queued: false, reason: 'already_pending' }
|
|
3513
3513
|
if (!repo || !isDir(join(repo, '.git'))) {
|
|
3514
3514
|
return { queued: false, reason: 'no_repo' }
|
|
3515
3515
|
}
|
|
@@ -3521,7 +3521,8 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
|
|
|
3521
3521
|
|
|
3522
3522
|
// autoPull:云端领先,且开启了自动拉取
|
|
3523
3523
|
if (settings.autoPull && drift.behind > 0) {
|
|
3524
|
-
|
|
3524
|
+
// 定时复查是无人值守,不弹确认框;用户显式动作(关闭/手动)才可能弹。
|
|
3525
|
+
if (!skipConfirm && !isManualTrigger && !isPeriodic) {
|
|
3525
3526
|
const yes = await askConfirm(
|
|
3526
3527
|
t('云端有更新,要同步到本机吗?', 'The cloud has new commits — sync them to this machine?'),
|
|
3527
3528
|
t(
|
|
@@ -3577,12 +3578,13 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
|
|
|
3577
3578
|
* 只做 drift 检查与状态更新,不自动关闭 DSH;关闭只在用户显式动作(× 关闭、手动按钮)触发。 */
|
|
3578
3579
|
function scheduleAutoStart(config) {
|
|
3579
3580
|
const dshHome = config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
3580
|
-
const settings = readSettings(dshHome)
|
|
3581
|
-
if (!settings.autoPull && !settings.autoPush) return
|
|
3582
3581
|
if (autoState.timer) return
|
|
3583
3582
|
const run = async () => {
|
|
3584
3583
|
try {
|
|
3585
|
-
|
|
3584
|
+
// 每次复查都重新读开关:用户中途改了 autoPull/autoPush,下一次复查就要按新值走
|
|
3585
|
+
const settings = readSettings(dshHome)
|
|
3586
|
+
if (!settings.autoPull && !settings.autoPush) return
|
|
3587
|
+
if (autoState.pending && isProcessAlive(autoState.pending.watcherPid)) return
|
|
3586
3588
|
const repo = resolveRepo(config?.repoPath, dshHome).repo || ''
|
|
3587
3589
|
if (!repo || !isDir(join(repo, '.git'))) {
|
|
3588
3590
|
autoState.lastCheckError = (repo && repoPhase(repo) === 'empty') ? '' : '仓库未就位'
|
|
@@ -3598,7 +3600,13 @@ function scheduleAutoStart(config) {
|
|
|
3598
3600
|
return
|
|
3599
3601
|
}
|
|
3600
3602
|
autoState.drift = drift
|
|
3601
|
-
//
|
|
3603
|
+
// 0.4.05:不再只更新状态。前端卸载信标(pagehide→sendBeacon)实测在 DSH 退出时
|
|
3604
|
+
// 请求送不到后端,导致点 × 后虽然有待推送却没排 watcher。改为由这条可靠的后端
|
|
3605
|
+
// 定时复查直接排队:有待拉取/推送就排一个 watcher 进 wait 态,但不关闭 DSH
|
|
3606
|
+
// (shouldCloseDsh:false)。用户点 × 关闭 DSH 后,预排的 watcher 自动进入 run 执行。
|
|
3607
|
+
// 前端信标仍保留作双保险:它若送达、发现已排队会直接复用,不会重复。
|
|
3608
|
+
const appRoot = resolveAppRoot(config?.appRoot) || ''
|
|
3609
|
+
await checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, { shouldCloseDsh: false, isPeriodic: true })
|
|
3602
3610
|
} catch (error) {
|
|
3603
3611
|
autoState.checking = false
|
|
3604
3612
|
autoState.lastCheckAt = Date.now()
|
package/package.json
CHANGED
package/runtime/post-exit.ps1
CHANGED
|
@@ -73,9 +73,14 @@ if ($Phase -eq 'wait') {
|
|
|
73
73
|
if ($WatchPid -gt 0 -and -not $byPid -and $byName.Count -gt 0) {
|
|
74
74
|
$myStart = (Get-Process -Id $PID -ErrorAction SilentlyContinue).StartTime
|
|
75
75
|
if ($myStart) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
# 0.4.04:原判据「所有 DSH 都比 watcher 新」会被**无窗口的孤儿进程**破坏——
|
|
77
|
+
# 实测 WatchPid 被强杀后留下一个比 watcher 还早启动的子进程(父已死、hwnd=0),
|
|
78
|
+
# 它既不是用户在用的实例、也不会消失,把 newerAll.Count -eq byName.Count 永远卡死,
|
|
79
|
+
# watcher 死等 30 分钟还霸占 auto-sync.lock。真正代表「排队那次 DSH 还在用」的,
|
|
80
|
+
# 是比 watcher 早启动**且有前台窗口**的实例;无窗口残留/新实例都不该挡住让位。
|
|
81
|
+
$visibleOld = @($byName | Where-Object { $_.MainWindowHandle -ne 0 -and $_.StartTime -and $_.StartTime -lt $myStart })
|
|
82
|
+
if ($visibleOld.Count -eq 0) {
|
|
83
|
+
WaitLog ('WatchPid {0} 已退出,无遗留前台窗口(现存为残留进程或新实例),判定为过期 watcher,退出让位' -f $WatchPid)
|
|
79
84
|
try {
|
|
80
85
|
$lockFile = Join-Path $DshHome 'auto-sync.lock'
|
|
81
86
|
if (Test-Path -LiteralPath $lockFile) {
|
package/tools/selftest.mjs
CHANGED
|
@@ -1830,6 +1830,10 @@ console.log('== 0.3.94:清理跨重启僵死 watcher,锁不再被旧实例
|
|
|
1830
1830
|
check('post-exit wait:WatchPid 已死但进程名有新实例时判定过期 watcher',
|
|
1831
1831
|
postSrc.includes('-not $byPid -and $byName.Count -gt 0')
|
|
1832
1832
|
&& postSrc.includes('判定为过期 watcher'), 'post-exit.ps1 过期判定')
|
|
1833
|
+
check('0.4.04:过期判定改为看有无遗留前台窗口,不被无窗口孤儿进程卡死',
|
|
1834
|
+
postSrc.includes('$visibleOld = @($byName | Where-Object { $_.MainWindowHandle -ne 0')
|
|
1835
|
+
&& postSrc.includes('$visibleOld.Count -eq 0')
|
|
1836
|
+
&& postSrc.includes('无遗留前台窗口'), 'post-exit.ps1 孤儿进程让位')
|
|
1833
1837
|
check('post-exit wait:过期 watcher 清自己的锁并 exit 3 让位',
|
|
1834
1838
|
/\$lock\.pid -eq \$PID/.test(postSrc) && /\bexit 3\b/.test(postSrc), 'post-exit.ps1 让位')
|
|
1835
1839
|
}
|
|
@@ -1964,5 +1968,18 @@ console.log('== 0.4.02:npm tarball 版本按 semver 规范化(0.4.01 → 0.4
|
|
|
1964
1968
|
check('npmTgzUrls 保留预发布/构建后缀清洗',
|
|
1965
1969
|
idxSrc.includes("semver.replace(/[^0-9A-Za-z.+\\-]/g, '')"), 'index.js 版本清洗')
|
|
1966
1970
|
}
|
|
1971
|
+
console.log('')
|
|
1972
|
+
console.log('== 0.4.05:定时复查预排 watcher,不依赖前端信标 ==')
|
|
1973
|
+
{
|
|
1974
|
+
const idxSrc = readFileSync(join(pluginRootSelf, 'index.js'), 'utf8')
|
|
1975
|
+
check('scheduleAutoStart 的 run 调用 checkAndQueueAutoSync 预排 watcher',
|
|
1976
|
+
/await checkAndQueueAutoSync\(dshHome, config, settings, repo, appRoot, \{ shouldCloseDsh: false, isPeriodic: true \}\)/.test(idxSrc), 'index.js 定时预排')
|
|
1977
|
+
check('checkAndQueueAutoSync 支持 isPeriodic 参数',
|
|
1978
|
+
/isPeriodic = false/.test(idxSrc) && /isManualTrigger/.test(idxSrc), 'index.js isPeriodic 参数')
|
|
1979
|
+
check('定时复查无人值守不弹确认框',
|
|
1980
|
+
/!skipConfirm && !isManualTrigger && !isPeriodic/.test(idxSrc), 'index.js 定时免确认')
|
|
1981
|
+
check('已排队守卫检查 watcher 存活(超时后可重排)',
|
|
1982
|
+
/autoState\.pending && isProcessAlive\(autoState\.pending\.watcherPid\)/.test(idxSrc), 'index.js 存活守卫')
|
|
1983
|
+
}
|
|
1967
1984
|
process.exit(failures === 0 ? 0 : 1)
|
|
1968
1985
|
|