dsh-config-sync-plugin 0.4.4 → 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 CHANGED
@@ -257,6 +257,12 @@ 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
+
260
266
  ### Fix watcher stuck in wait after × close due to orphan process (0.4.04)
261
267
 
262
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.
@@ -785,6 +791,7 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
785
791
 
786
792
  | Date | Version | Summary |
787
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 |
788
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 |
789
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 |
790
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 |
package/README.md CHANGED
@@ -277,6 +277,12 @@ 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
+
280
286
  ### 修复点 × 关闭后 watcher 被孤儿进程卡在 wait(0.4.04)
281
287
 
282
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 加断言防回归。
@@ -767,6 +773,7 @@ pwsh -File sync.ps1 push -ScanHistory
767
773
 
768
774
  | 日期 | 版本 | 要点 |
769
775
  |---|---|---|
776
+ | 2026-11-25 | 0.4.05 | 点 × 有待推送却没推送:根因前端信标未送达,改后端定时复查预排 watcher(不关 DSH),关窗后自动执行;前端信标降为双保险 |
770
777
  | 2026-11-25 | 0.4.04 | 修复点 × 关闭后 push watcher 被无窗口孤儿进程卡在 wait 不执行:过期判定改看有无遗留前台窗口,立即清锁让位 |
771
778
  | 2026-11-25 | 0.4.03 | 重新打包发布:代码与 0.4.02 一致,仅版本与发布元数据更新到 0.4.03 |
772
779
  | 2026-11-25 | 0.4.02 | 修复 npm 兜底下载的版本规范化:0.4.01 被 npm semver 规范化成 0.4.1,拼 tarball 时去前导零,否则 404 |
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
- if (!skipConfirm && !isManualTrigger) {
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
- if (autoState.pending) return
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
- // 仅更新状态供面板显示;不自动关闭 DSH,关闭由用户显式动作触发
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-config-sync-plugin",
3
- "version": "0.4.04",
3
+ "version": "0.4.05",
4
4
  "type": "module",
5
5
  "description": "在 DSH 设置里查看 dsh-config 仓库与本机的同步状态,并生成退出后执行的 push/pull 脚本。同步动作本身不在应用内执行。面板与文案跟随客户端语言(中文/English)。",
6
6
  "main": "./index.js",
@@ -1968,5 +1968,18 @@ console.log('== 0.4.02:npm tarball 版本按 semver 规范化(0.4.01 → 0.4
1968
1968
  check('npmTgzUrls 保留预发布/构建后缀清洗',
1969
1969
  idxSrc.includes("semver.replace(/[^0-9A-Za-z.+\\-]/g, '')"), 'index.js 版本清洗')
1970
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
+ }
1971
1984
  process.exit(failures === 0 ? 0 : 1)
1972
1985