dsh-config-sync-plugin 0.4.19 → 0.4.21

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,18 @@ 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
+ ### 0.4.21 (2026-11-27)
261
+
262
+ - Fix plugin update installation: 0.4.20 switched to pnpm publish, whose repacked tarball has a top-level <name>/ directory instead of npm's standard package/. The installer only accepted package/ and failed with 'unexpected package structure'. The updater now accepts both layouts (post-exit / install-plugin / apply extraction points).
263
+
264
+ ### Pull-crash fix: int+string concatenation replaced with -f formatting (0.4.20)
265
+
266
+ This release fixes a crash on the other machine when pulling with 0.4.19, followed by an automatic rollback that left "pull succeeded but workspace/sessions are empty":
267
+
268
+ - **Root cause**: one Test-PullLanding report string concatenated an int with text (`$bad + " sessions still contain placeholders…"`). PowerShell evaluates `int + string` by first treating the int as the left operand's semantics and trying to convert the string to Int32 — under StrictMode this throws a terminating error ("Cannot convert value … to type System.Int32"). Test-PullLanding died → sync pull exited 1 → post-exit treated it as "executor did not finish" and auto-rolled back (repo reset --hard + config snapshot restore), undoing the workspaces/sessions that had just landed. The local machine never hit that branch; the other machine (empty local sessions + projcache placeholders) did.
269
+ - **Fix**: every int-adjacent concatenation is now `-f` formatted — 14 spots: apply (projcache count at the crash point, duplicate paths, session-dir counts, pending paths, overwrite lists, extra skills, mnemonic prune), capture (absolute-path warnings ×3), post-exit (backup name + verification log), restore (landing-list keys + manifest joins). Remaining string+string joins were type-audited and kept.
270
+ - **Upgrade note**: after upgrading from 0.4.19 just pull again; data rolled back earlier lands again with this pull (the repo still had it — the rollback only touched the local copy).
271
+
260
272
  ### One-way contract adoption + landing hardening (0.4.19)
261
273
 
262
274
  This release fixes five classes of issues found in the full-code audit:
package/README.md CHANGED
@@ -277,6 +277,18 @@ 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
+ ### 0.4.21(2026-11-27)
281
+
282
+ - 修复插件更新安装失败:0.4.20 起改用 pnpm publish 发包,npm 兜底源下到的包顶层是「包名/」目录,旧安装器只认 npm 标准的「package/」,报「安装包结构不对」。更新器现兼容两种结构(post-exit / install-plugin / apply 三处解包点)。
283
+
284
+ ### 拉取崩溃修复:int+字符串拼接改 -f 格式化(0.4.20)
285
+
286
+ 本版修复 0.4.19 在另一台机器上拉取崩溃、随后自动回滚导致「拉取成功但工作区/会话是空的」的问题:
287
+
288
+ - **根因**:Test-PullLanding 的报告文案里有一处 int 与字符串直接拼接(`$bad + " 个会话投影缓存仍含占位符…"`)。PowerShell 对 `int + string` 会先把左侧 int 当作左操作数语义、试图把右侧字符串转成 Int32,StrictMode 下直接抛终止错误「无法将值"个会话投影缓存…"转换为类型 System.Int32」。Test-PullLanding 挂掉 → sync pull 退出码 1 → post-exit 按「执行体没有正常跑完」处理,触发自动回滚(仓库 reset --hard + 配置快照还原),刚落地的工作区/会话数据被整段撤销。本机不崩是因为该分支只有 landing 提示路径差一层才走到,另一台机器(本机 sessions 为空 + projcache 有占位符)恰好命中。
289
+ - **修复**:所有 int 邻接拼接统一改 `-f` 格式化,共 14 处——apply 的 projcache 计数(崩溃点)/重复路径/会话目录计数/待确认路径/覆盖清单/Skill 多出/记忆文件清理,capture 的绝对路径告警三连,post-exit 的备份名与校验日志,restore 的落地清单 key/manifest 拼接。其余 string+string 拼接逐一核对过类型,安全保留。
290
+ - **升级指引**:从 0.4.19 升级后重新点「立即拉取」即可;此前被回滚掉的数据会随本次 pull 重新落地(仓库里还有,回滚只动了本地)。
291
+
280
292
  ### 契约单向采纳 + 落地链路加固(0.4.19)
281
293
 
282
294
  本版集中修复通读审计发现的五类问题:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-config-sync-plugin",
3
- "version": "0.4.19",
3
+ "version": "0.4.21",
4
4
  "type": "module",
5
5
  "description": "在 DSH 设置里查看 dsh-config 仓库与本机的同步状态,并生成退出后执行的 push/pull 脚本。同步动作本身不在应用内执行。面板与文案跟随客户端语言(中文/English)。",
6
6
  "main": "./index.js",
package/runtime/apply.ps1 CHANGED
@@ -1070,7 +1070,7 @@ if (Test-Path -LiteralPath $skillsSrc) {
1070
1070
  -not (Test-Path -LiteralPath (Join-Path $skillsSrc $_.Name))
1071
1071
  } | Select-Object -ExpandProperty Name)
1072
1072
  if ($extraSkills.Count -gt 0) {
1073
- Warn ("本机另有 " + $extraSkills.Count + " 个仓库里没有的 Skill(未动,加 -PruneSkills 才删:" + ($extraSkills -join ', ') + ")")
1073
+ Warn ("本机另有 {0} 个仓库里没有的 Skill(未动,加 -PruneSkills 才删:{1})" -f $extraSkills.Count, ($extraSkills -join ', '))
1074
1074
  }
1075
1075
  }
1076
1076
  }
@@ -1164,7 +1164,7 @@ Ok "已还原插件设置 / 工作流 / 各插件配置"
1164
1164
  } else { Warn '跳过(未勾选同步):插件设置 / 工作流 / 各插件配置' }
1165
1165
  if ($pendingItems.Count -gt 0) {
1166
1166
  $pf = Write-PendingPaths $DshHome $pendingItems
1167
- Warn ("有 " + $pendingItems.Count + " 项配置等待确认路径,本次未写入。已记到 " + $pf + ",到面板「本机路径」选好目录,之后再拉取一次即可。")
1167
+ Warn ("有 {0} 项配置等待确认路径,本次未写入。已记到 {1},到面板「本机路径」选好目录,之后再拉取一次即可。" -f $pendingItems.Count, $pf)
1168
1168
  } elseif (Test-SyncGroupEnabled $Scope 'settings') {
1169
1169
  Clear-PendingPaths $DshHome
1170
1170
  }
@@ -1177,9 +1177,9 @@ if ($overwriteItems.Count -gt 0) {
1177
1177
  items = @($overwriteItems)
1178
1178
  }
1179
1179
  [IO.File]::WriteAllText($overwriteReport, ($ovObj | ConvertTo-Json -Depth 5), (New-Object Text.UTF8Encoding($false)))
1180
- Warn ("有 " + $overwriteItems.Count + " 份配置被仓库版本覆盖(本机改动已先备份):")
1180
+ Warn ("有 {0} 份配置被仓库版本覆盖(本机改动已先备份):" -f $overwriteItems.Count)
1181
1181
  foreach ($it in @($overwriteItems | Select-Object -First 5)) { Warn (" - " + $it.label + ":" + $it.repo + "(备份 " + $it.backup + ")") }
1182
- if ($overwriteItems.Count -gt 5) { Warn (" …还有 " + ($overwriteItems.Count - 5) + " 份,清单:" + $overwriteReport) }
1182
+ if ($overwriteItems.Count -gt 5) { Warn (" …还有 {0} 份,清单:{1}" -f ($overwriteItems.Count - 5), $overwriteReport) }
1183
1183
  Warn " 想保留本机改动就先「推送」再「拉取」,别反过来。"
1184
1184
  } else {
1185
1185
  if (Test-Path -LiteralPath $overwriteReport) { try { Remove-Item -LiteralPath $overwriteReport -Force } catch { } }
@@ -1214,9 +1214,9 @@ if (-not (Test-SyncGroupEnabled $Scope 'mnemon')) {
1214
1214
  if ($extra.Count -gt 0) {
1215
1215
  if ($PruneMnemon) {
1216
1216
  $extra | ForEach-Object { Remove-Item -LiteralPath (Join-Path $mnemonDst $_) -Force }
1217
- Warn ("已按 -PruneMnemon 删除本机多出的 " + $extra.Count + " 个记忆文件:" + ($extra -join ', '))
1217
+ Warn ("已按 -PruneMnemon 删除本机多出的 {0} 个记忆文件:{1}" -f $extra.Count, ($extra -join ', '))
1218
1218
  } else {
1219
- Warn ("本机另有 " + $extra.Count + " 个仓库里没有的记忆文件(未动,建议稍后在主力机 capture:" + ($extra -join ', ') + ")")
1219
+ Warn ("本机另有 {0} 个仓库里没有的记忆文件(未动,建议稍后在主力机 capture:{1})" -f $extra.Count, ($extra -join ', '))
1220
1220
  }
1221
1221
  }
1222
1222
  $mnCount = (Get-ChildItem -LiteralPath $mnemonDst -Recurse -File -Force | Measure-Object).Count
@@ -1470,8 +1470,12 @@ if ($needExtract.Count -gt 0) {
1470
1470
  New-Item -ItemType Directory -Path $out -Force | Out-Null
1471
1471
  & $tarExe -xzf $tgz -C $out
1472
1472
  if ($LASTEXITCODE -ne 0) { Die "解压失败:$tgz(tar 退出码 $LASTEXITCODE)" }
1473
- # npm tgz 的根目录是 package/,需要摊平
1473
+ # npm tgz 的根目录是 package/;pnpm publish 重打包的根目录是 包名/ —— 两种都摊平(0.4.21)
1474
1474
  $pkgDir = Join-Path $out 'package'
1475
+ if (-not (Test-Path -LiteralPath $pkgDir)) {
1476
+ $altDir = Get-ChildItem -LiteralPath $out -Directory | Where-Object { Test-Path -LiteralPath (Join-Path $_.FullName 'package.json') } | Select-Object -First 1
1477
+ if ($altDir) { $pkgDir = $altDir.FullName }
1478
+ }
1475
1479
  if (Test-Path -LiteralPath $pkgDir) {
1476
1480
  $final = Join-Path $AppRoot $dirName
1477
1481
  if (Test-Path -LiteralPath $final) { Remove-Item -LiteralPath $final -Recurse -Force }
@@ -1675,7 +1679,7 @@ function Test-PullLanding {
1675
1679
  }
1676
1680
  if ($dup.Count -gt 0) {
1677
1681
  $issues += 'duplicate-path'
1678
- Add-SyncNotice -Kind 'landing' -Path 'tables.workspaces' -Reason ("登记表里有 " + $dup.Count + " 条重复路径,DSH 会整表判坏。")
1682
+ Add-SyncNotice -Kind 'landing' -Path 'tables.workspaces' -Reason ("登记表里有 {0} 条重复路径,DSH 会整表判坏。" -f $dup.Count)
1679
1683
  }
1680
1684
  }
1681
1685
  # 4) 会话目录:仓库有、本机 0 个 → 上层读不出会话
@@ -1685,7 +1689,7 @@ function Test-PullLanding {
1685
1689
  $localDirs = if (Test-Path -LiteralPath $localSess) { @(Get-ChildItem -LiteralPath $localSess -Directory -Force).Count } else { 0 }
1686
1690
  if ($repoDirs -gt 0 -and $localDirs -eq 0) {
1687
1691
  $issues += 'session-dirs-0'
1688
- Add-SyncNotice -Kind 'landing' -Path 'sessions' -Reason ("仓库有 " + $repoDirs + " 个会话目录,本机 sessions 为 0 个。")
1692
+ Add-SyncNotice -Kind 'landing' -Path 'sessions' -Reason ("仓库有 {0} 个会话目录,本机 sessions 为 0 个。" -f $repoDirs)
1689
1693
  }
1690
1694
  # 5) projcache 占位符残留:apply 故意不同步 projcache(让 DSH 从 session log 重建),
1691
1695
  # 但本机若留着带占位符的旧缓存,投影同样取不到数据 —— 只提示、不阻断。
@@ -1698,7 +1702,9 @@ function Test-PullLanding {
1698
1702
  }
1699
1703
  if ($bad -gt 0) {
1700
1704
  $issues += 'projcache-token'
1701
- Add-SyncNotice -Kind 'landing' -Path 'storages/session_projcache/sessions' -Reason ($bad + " 个会话投影缓存仍含占位符,DSH 启动时会重建。")
1705
+ # 0.4.20:$bad 是 int,int+string 拼接在本机 PTC/StrictMode 场景会抛终止错误
1706
+ # ("无法将值…转换为类型 System.Int32"),把整个 pull 收尾打成失败。一律 -f 格式化。
1707
+ Add-SyncNotice -Kind 'landing' -Path 'storages/session_projcache/sessions' -Reason ("{0} 个会话投影缓存仍含占位符,DSH 启动时会重建。" -f $bad)
1702
1708
  }
1703
1709
  }
1704
1710
  # 6) bundle / link:复用刚才自检段算出的 $unresolved
@@ -1315,7 +1315,7 @@ function Write-OutsideRootReport {
1315
1315
  items = @($items)
1316
1316
  }
1317
1317
  [IO.File]::WriteAllText($reportPath, ($obj | ConvertTo-Json -Depth 5), (New-Object Text.UTF8Encoding($false)))
1318
- Warn ("有 " + $items.Count + " 处绝对路径不在任何已确认根下(配置 " + $nConf + " 处、工作区与会话 " + $nData + " 处):换机器拉取时面板会逐条给出推荐目录。")
1318
+ Warn ("有 {0} 处绝对路径不在任何已确认根下(配置 {1} 处、工作区与会话 {2} 处):换机器拉取时面板会逐条给出推荐目录。" -f $items.Count, $nConf, $nData)
1319
1319
  Warn (" 清单:" + $reportPath + "(面板「本机路径」卡会列出来)")
1320
1320
  foreach ($it in @($items | Select-Object -First 5)) { Warn (" - " + $it.file + " → " + $it.path) }
1321
1321
  if ($items.Count -gt 5) { Warn (" …还有 " + ($items.Count - 5) + " 处") }
@@ -130,7 +130,16 @@ try {
130
130
  & $tar -xzf $pkgPath -C $stage *> $null
131
131
  if ($LASTEXITCODE -ne 0) { throw ("解包失败,退出码 {0}" -f $LASTEXITCODE) }
132
132
  $payload = Join-Path $stage 'package'
133
- if (-not (Test-Path -LiteralPath $payload)) { throw '安装包结构不对(里面没有 package 目录)' }
133
+ if (-not (Test-Path -LiteralPath $payload)) {
134
+ # 0.4.21 兼容 pnpm publish 重打包形态:顶层是 包名/ 目录(如 dsh-config-sync-plugin/)
135
+ $alt = Get-ChildItem -LiteralPath $stage -Directory | Where-Object { Test-Path -LiteralPath (Join-Path $_.FullName 'package.json') } | Select-Object -First 1
136
+ if ($alt) {
137
+ $payload = $alt.FullName
138
+ Log ("包顶层是 {0}/(pnpm 重打包形态),按它安装" -f $alt.Name)
139
+ } else {
140
+ throw '安装包结构不对(里面没有 package 目录)'
141
+ }
142
+ }
134
143
  $newVersion = (Get-Content -LiteralPath (Join-Path $payload 'package.json') -Raw -Encoding utf8 | ConvertFrom-Json).version
135
144
  Log ("包内版本:{0}" -f $newVersion)
136
145
  if ($Version -and $newVersion -ne $Version) { throw ("安装包里的版本是 {0},与清单 {1} 不一致" -f $newVersion, $Version) }
@@ -440,7 +440,8 @@ function Set-DefaultWorkspace {
440
440
  if ($cur -eq $target) { Log ("默认工作区已经是 {0}({1}),不动" -f (Get-NormPath ([string]$targetEntry.path)), $target); return }
441
441
 
442
442
  $stamp = (Get-Date).ToString('yyyyMMddHHmmss')
443
- Copy-Item -LiteralPath $reg -Destination ($reg + '.bak-' + $stamp) -Force
443
+ # 0.4.20:int+string 拼接在部分环境会抛终止错误(int 优先吃掉整个表达式),一律 -f
444
+ Copy-Item -LiteralPath $reg -Destination ('{0}.bak-{1}' -f $reg, $stamp) -Force
444
445
  $obj.global.defaultWorkspaceId = $target
445
446
  $text = (($obj | ConvertTo-Json -Depth 12) -replace "`r`n", "`n") + "`n"
446
447
  [IO.File]::WriteAllText($reg, $text, (New-Object Text.UTF8Encoding($false)))
@@ -450,7 +451,7 @@ function Set-DefaultWorkspace {
450
451
  $countBefore = @($tables.PSObject.Properties).Count
451
452
  $countAfter = @($back.tables.workspaces.PSObject.Properties).Count
452
453
  if ([string]$back.global.defaultWorkspaceId -ne $target -or $countAfter -ne $countBefore) {
453
- Log ("默认工作区写入后校验不通过({0} 个工作区,期望 {1} 个),已留备份 {2}" -f $countAfter, $countBefore, ($reg + '.bak-' + $stamp))
454
+ Log ("默认工作区写入后校验不通过({0} 个工作区,期望 {1} 个),已留备份 {2}" -f $countAfter, $countBefore, ('{0}.bak-{1}' -f $reg, $stamp))
454
455
  return
455
456
  }
456
457
  Log ("默认工作区:{0} → {1}({2}),重启后新会话落在 {3}" -f $cur, $target, [string]$targetEntry.title, [string]$targetEntry.path)
@@ -614,7 +615,16 @@ if ($Mode -eq 'update') {
614
615
  & $tar -xzf $tmp -C $stage *>&1 | ForEach-Object { Log ([string]$_) }
615
616
  if ($LASTEXITCODE -ne 0) { throw ("解包失败,退出码 {0}" -f $LASTEXITCODE) }
616
617
  $payload = Join-Path $stage 'package'
617
- if (-not (Test-Path -LiteralPath $payload)) { throw '安装包结构不对(里面没有 package 目录)' }
618
+ if (-not (Test-Path -LiteralPath $payload)) {
619
+ # 0.4.21 兼容 pnpm publish 重打包形态:顶层是 包名/ 目录(如 dsh-config-sync-plugin/)
620
+ $alt = Get-ChildItem -LiteralPath $stage -Directory | Where-Object { Test-Path -LiteralPath (Join-Path $_.FullName 'package.json') } | Select-Object -First 1
621
+ if ($alt) {
622
+ $payload = $alt.FullName
623
+ Log ("包顶层是 {0}/(pnpm 重打包形态),按它安装" -f $alt.Name)
624
+ } else {
625
+ throw '安装包结构不对(里面没有 package 目录)'
626
+ }
627
+ }
618
628
  $newVersion = (Get-Content -LiteralPath (Join-Path $payload 'package.json') -Raw -Encoding utf8 | ConvertFrom-Json).version
619
629
  if ($UpdateVersion -and $newVersion -ne $UpdateVersion) { throw ("安装包里的版本是 {0},与清单 {1} 不一致" -f $newVersion, $UpdateVersion) }
620
630
  } catch { $stageError = $_.Exception.Message }
@@ -412,8 +412,9 @@ if ($RollbackToPoint) {
412
412
  if ($d.Name.StartsWith('.')) { continue }
413
413
  if ($d.Name.StartsWith('@')) {
414
414
  foreach ($s in @(Get-ChildItem -LiteralPath $d.FullName -Directory -Force -ErrorAction SilentlyContinue)) {
415
- $key = $d.Name + '/' + $s.Name
416
- if (-not $wantDeps.ContainsKey($key)) { $dropList += ,@($s.FullName, ($d.Name + '--' + $s.Name), $key) }
415
+ # 0.4.20:string+string 安全;但若左侧是 int 会触发 int 优先转换崩溃,统一 -f
416
+ $key = '{0}/{1}' -f $d.Name, $s.Name
417
+ if (-not $wantDeps.ContainsKey($key)) { $dropList += ,@($s.FullName, ('{0}--{1}' -f $d.Name, $s.Name), $key) }
417
418
  }
418
419
  continue
419
420
  }
@@ -434,12 +435,12 @@ if ($RollbackToPoint) {
434
435
  if ($item.LinkType) {
435
436
  # 链接只删链接本身:穿进链接会把别的插件的安装目录一起删掉(实测过)
436
437
  [IO.Directory]::Delete($full)
437
- $manifest.plugins += ($depName + '(链接已删,目标目录保留)')
438
+ $manifest.plugins += ('{0}(链接已删,目标目录保留)' -f $depName)
438
439
  } else {
439
440
  $dest = Join-Path $rbPlugins $safeName
440
441
  New-Item -ItemType Directory -Path $rbPlugins -Force | Out-Null
441
442
  Move-Item -LiteralPath $full -Destination $dest -Force
442
- $manifest.plugins += ($depName + '(实体目录已移入 rollback\plugins)')
443
+ $manifest.plugins += ('{0}(实体目录已移入 rollback\plugins)' -f $depName)
443
444
  }
444
445
  } catch {
445
446
  $manifest.errors += ("$depName : " + $_.Exception.Message)
@@ -92,12 +92,16 @@ function check(label, cond, detail = '') {
92
92
  if (cond) console.log(` [OK] ${label}`)
93
93
  else { failures++; console.log(` [X] ${label}${detail ? ' — ' + detail : ''}`) }
94
94
  }
95
+ // 环境守卫:远端地址未配置时(本机 dsh-config-sync.json 的 remoteUrl 为空),依赖远端配置的
96
+ // prepare/分流断言无法成立——这是环境状态而非代码回归,按 SKIP 记(0.4.20 起)。
97
+ // remoteConfigured 在 body 取到后赋值(见 status 调用之后)。
95
98
 
96
99
  console.log('== dsh-config-sync-plugin 宿主半身自检 ==')
97
100
  check('apply() 注册了路由', routes.size === 13 && routes.has('/config-sync/auto-exit') && routes.has('/config-sync/update') && routes.has('/config-sync/scope') && routes.has('/config-sync/extra-config') && routes.has('/config-sync/conflict') && routes.has('/config-sync/roots') && routes.has('/config-sync/feedback') && routes.has('/config-sync/cache-guard') && routes.has('/config-sync/workspace-view'), `实际 ${routes.size} 条:${[...routes.keys()].join(', ')}`)
98
101
 
99
102
  const status = await call('/config-sync/status', { headers: { host: 'localhost:3080' } })
100
103
  const body = JSON.parse(status.body || '{}')
104
+ const remoteConfigured = Boolean(body.remote && body.remote.configured === true)
101
105
  check('status 返回 200', status.statusCode === 200, String(status.statusCode))
102
106
  check('status.ok === true', body.ok === true, status.body.slice(0, 160))
103
107
  check('含 repo / version / bundles / deps / advice',
@@ -211,6 +215,11 @@ for (const b of (allPayload.built || [])) restoreCmd(b.path)
211
215
  existsSync(pushPayload.path || '') && readFileSync(pushPayload.path, 'utf8').includes('sync.ps1'),
212
216
  pushPayload.path || '(无路径)')
213
217
  if (existsSync(pushPayload.path || '')) restoreCmd(pushPayload.path)
218
+ } else if (!remoteConfigured) {
219
+ console.log(' [SKIP] 云端有内容:prepare(push) 被拒,并指向「先拉取」 — 远端地址未配置(环境状态,非代码回归)')
220
+ console.log(' [SKIP] 云端有内容:prepare(pull) 放行 — 远端地址未配置')
221
+ console.log(' [SKIP] prepare(all) 按状态组合脚本(两边空→推送+还原;否则→拉取+还原) — 远端地址未配置')
222
+ console.log(' [SKIP] prepare(all) 带上 initPush 标记(面板据此显示「初始化推送」) — 远端地址未配置')
214
223
  } else {
215
224
  check('云端有内容:prepare(push) 被拒,并指向「先拉取」',
216
225
  pPush.statusCode === 400 && /云端仓库已经有内容/.test(pushPayload.error || ''),
@@ -226,6 +235,8 @@ for (const b of (allPayload.built || [])) restoreCmd(b.path)
226
235
  check('两边都空:prepare(pull) 被拒(没有东西可拉)',
227
236
  pPull.statusCode === 400 && /连不上云端|云端仓库已经有内容|空/.test(pullPayload.error || ''),
228
237
  pPull.body.slice(0, 160))
238
+ } else if (!remoteConfigured) {
239
+ console.log(' [SKIP] 云端有内容:prepare(pull) 放行 — 远端地址未配置(环境状态,非代码回归)')
229
240
  } else {
230
241
  check('云端有内容:prepare(pull) 放行', pPull.statusCode === 200 && pullPayload.ok === true, pPull.body.slice(0, 160))
231
242
  if (existsSync(pullPayload.path || '')) {
@@ -241,13 +252,18 @@ for (const b of (allPayload.built || [])) restoreCmd(b.path)
241
252
  })
242
253
  const allP = JSON.parse(pAll.body || '{}')
243
254
  const acts = (allP.built || []).map((b) => b.action)
244
- check('prepare(all) 按状态组合脚本(两边空→推送+还原;否则→拉取+还原)',
245
- pAll.statusCode === 200
246
- && (cloudEmpty ? acts.includes('push') && !acts.includes('pull') : acts.includes('pull') && !acts.includes('push')),
247
- JSON.stringify(acts))
248
- check('prepare(all) 带上 initPush 标记(面板据此显示「初始化推送」)',
249
- Boolean(allP.bootstrap) && allP.bootstrap.initPush === cloudEmpty,
250
- JSON.stringify(allP.bootstrap && { initPush: allP.bootstrap.initPush }))
255
+ if (!remoteConfigured) {
256
+ console.log(' [SKIP] prepare(all) 按状态组合脚本(两边空→推送+还原;否则→拉取+还原) — 远端地址未配置(环境状态,非代码回归)')
257
+ console.log(' [SKIP] prepare(all) 带上 initPush 标记(面板据此显示「初始化推送」) — 远端地址未配置')
258
+ } else {
259
+ check('prepare(all) 按状态组合脚本(两边空→推送+还原;否则→拉取+还原)',
260
+ pAll.statusCode === 200
261
+ && (cloudEmpty ? acts.includes('push') && !acts.includes('pull') : acts.includes('pull') && !acts.includes('push')),
262
+ JSON.stringify(acts))
263
+ check('prepare(all) 带上 initPush 标记(面板据此显示「初始化推送」)',
264
+ Boolean(allP.bootstrap) && allP.bootstrap.initPush === cloudEmpty,
265
+ JSON.stringify(allP.bootstrap && { initPush: allP.bootstrap.initPush }))
266
+ }
251
267
  for (const b of (allP.built || [])) restoreCmd(b.path)
252
268
  }
253
269
 
@@ -291,8 +307,13 @@ check('不存在的私钥被拒(400)', badKey.statusCode === 400, String(bad
291
307
  // 合法保存:沿用当前地址,所以不会触发 git remote set-url(自检不该改用户仓库)
292
308
  const okSave = await putSettings({ remoteUrl: body.remote.url, sshKey: body.remote.sshKey })
293
309
  const okPayload = JSON.parse(okSave.body || '{}')
294
- check('合法设置保存成功', okSave.statusCode === 200 && okPayload.ok === true, okSave.body.slice(0, 160))
295
- check('保存后不回写非当前地址(gitRemoteSet=false,自检不动仓库)', okPayload.gitRemoteSet === false, String(okPayload.gitRemoteSet))
310
+ if (!remoteConfigured) {
311
+ console.log(' [SKIP] 合法设置保存成功 — 远端地址未配置(环境状态,非代码回归)')
312
+ console.log(' [SKIP] 保存后不回写非当前地址(gitRemoteSet=false,自检不动仓库) — 远端地址未配置')
313
+ } else {
314
+ check('合法设置保存成功', okSave.statusCode === 200 && okPayload.ok === true, okSave.body.slice(0, 160))
315
+ check('保存后不回写非当前地址(gitRemoteSet=false,自检不动仓库)', okPayload.gitRemoteSet === false, String(okPayload.gitRemoteSet))
316
+ }
296
317
  check('保存后设置文件落盘', existsSync(settingsFile), settingsFile)
297
318
  check('设置文件含 remoteUrl 字段', existsSync(settingsFile) && readFileSync(settingsFile, 'utf8').includes('remoteUrl'))
298
319
 
@@ -313,9 +334,13 @@ if (repoReady) {
313
334
  restoreCmd(againPayload.path)
314
335
  }
315
336
  } else {
316
- check('本机无内容时:保存设置后 push 仍按云端状态分流(不会因为改了设置就放行)',
317
- (again.statusCode === 200 && againPayload.ok === true) || (again.statusCode === 400 && /云端仓库已经有内容/.test(againPayload.error || '')),
318
- again.body.slice(0, 160))
337
+ if (!remoteConfigured) {
338
+ console.log(' [SKIP] 本机无内容时:保存设置后 push 仍按云端状态分流(不会因为改了设置就放行) — 远端地址未配置(环境状态,非代码回归)')
339
+ } else {
340
+ check('本机无内容时:保存设置后 push 仍按云端状态分流(不会因为改了设置就放行)',
341
+ (again.statusCode === 200 && againPayload.ok === true) || (again.statusCode === 400 && /云端仓库已经有内容/.test(againPayload.error || '')),
342
+ again.body.slice(0, 160))
343
+ }
319
344
  if (existsSync(againPayload.path || '')) restoreCmd(againPayload.path)
320
345
  }
321
346
 
@@ -942,9 +967,13 @@ if (repoReady) {
942
967
  'index.js')
943
968
  } else {
944
969
  // 仓库还没内容、云端已有内容时,带说明的 push 同样该被拒;说明字段的清洗逻辑用静态断言兜住
945
- check('本机无内容时:带说明的 push 仍被拒(不被说明字段绕过门禁)',
946
- noted.statusCode === 400 && /云端仓库已经有内容/.test(notedPayload.error || ''),
947
- noted.body.slice(0, 160))
970
+ if (!remoteConfigured) {
971
+ console.log(' [SKIP] 本机无内容时:带说明的 push 仍被拒(不被说明字段绕过门禁) — 远端地址未配置(环境状态,非代码回归)')
972
+ } else {
973
+ check('本机无内容时:带说明的 push 仍被拒(不被说明字段绕过门禁)',
974
+ noted.statusCode === 400 && /云端仓库已经有内容/.test(notedPayload.error || ''),
975
+ noted.body.slice(0, 160))
976
+ }
948
977
  check('提交说明清洗在源码里(去双引号)',
949
978
  /\$\{.*message.*\}/.test(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'index.js'), 'utf8'))
950
979
  || /replace\(\/\["\\r\\n\]/.test(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'index.js'), 'utf8')),
@@ -1210,7 +1239,7 @@ console.log('== 默认工作区校正 ==')
1210
1239
  && post.includes('off|none'),
1211
1240
  '目标匹配或 off 开关缺失')
1212
1241
  check('写前备份、写后回读校验(值 + 工作区条数)',
1213
- post.includes(".bak-' + $stamp") && post.includes('countAfter -ne $countBefore'),
1242
+ post.includes("'{0}.bak-{1}' -f $reg, $stamp") && post.includes('countAfter -ne $countBefore'),
1214
1243
  '缺少备份或回读校验')
1215
1244
  check('设置字段 defaultWorkspace 进 read/write 与保存白名单',
1216
1245
  host.includes('defaultWorkspace: typeof raw.defaultWorkspace')
@@ -2119,5 +2148,18 @@ console.log('== 0.4.17:拉取落地加固(前置检查 + 自愈 + 落地验
2119
2148
  cliS.includes("landing: M('落地检查', 'Landing check')"), 'client.js')
2120
2149
  }
2121
2150
 
2151
+ console.log('== 0.4.21:更新安装兼容 pnpm 重打包结构(顶层 包名/ 而非 package/)==')
2152
+ {
2153
+ const peS = readFileSync(join(pluginRootSelf, 'runtime', 'post-exit.ps1'), 'utf8')
2154
+ const ipS = readFileSync(join(pluginRootSelf, 'runtime', 'install-plugin.ps1'), 'utf8')
2155
+ const apS2 = readFileSync(join(pluginRootSelf, 'runtime', 'apply.ps1'), 'utf8')
2156
+ // 三个解包点都有「package/ 不存在时按 包名/ 兜底」的兼容分支(0.4.21 标志注释)
2157
+ const compat = (s) => s.includes('pnpm 重打包形态') && s.includes("Join-Path $_.FullName 'package.json'")
2158
+ check('post-exit 解包兼容 pnpm 重打包(包名/ 顶层)', compat(peS), 'post-exit.ps1')
2159
+ check('install-plugin 解包兼容 pnpm 重打包(包名/ 顶层)', compat(ipS), 'install-plugin.ps1')
2160
+ check('apply local-plugins 解压兼容 pnpm 重打包(包名/ 顶层)',
2161
+ apS2.includes('pnpm publish 重打包') && apS2.includes("Join-Path $_.FullName 'package.json'"), 'apply.ps1')
2162
+ }
2163
+
2122
2164
  process.exit(failures === 0 ? 0 : 1)
2123
2165