mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 10:10:22 +08:00
fix: 补丁失配判定加 drifted,宿主版本门禁与 expect 命中数契约(#188 通用部分)
从 PR #188(Pluto-Yt,fix/drift-detection)手改取通用部分落地,不含
0.2.1-rc.3 专属适配:
- 补丁失配不再静默成 skipped:文件在、marker 没有、pattern 一条都不中
→ 新增 drifted 状态(filePatchOutcome / patchStatus / rollupPatchStatus)。
以前这种情况一律返回 skipped 并被当软成功,官方一升级插件就静默失效,
状态页却全绿
- isSelfMarkedPatch() 例外:pattern 本身就是本插件写进宿主的痕迹
(#80 撤销型),找不到 = 本来没加过或已撤过,仍算 skipped
- ALWAYS_SOFT_STATUSES 去掉 skipped;skipped 改为只有可选/自标记型才算
软成功;drifted 看得见(状态页标红、不计入 ready)但不阻断 Apply,
免得把 0.1.6 / 0.2.0 / 0.2.1-rc.2 上的用户堵死
- tallyDisplayPatches / rollupDisplayStatus:drifted 压过 applied
- ensureHostClean 不再过滤 pattern_not_found:没打上就是没打上
- 宿主版本门禁:读 package.json 的 dshTarget,比对宿主真实版本,
gatherState 暴露 host_version / host_target / host_supported,
CLI 与状态页在未适配时直接告警
- applyReplacementsToText 支持 { pattern, replace, expect } 命中数契约:
命中数与声明不符就整条拒写,并回传实际命中数
- #77 锚点容错:写死 5 行改成锚首尾 + 非贪婪窗口 (?:(?!isRewindMarker)[\s\S]){0,300}?,
官方在中间插一行也照样命中;窗口排除 isRewindMarker 保证二次应用不叠加
额外修的 bug:
- rollupPatchStatus 的 lastError 提到最前:以前只在 strictFiles 分支里返回,
一个文件写成功就把别的文件 EACCES / read_error 吞成绿
- applyReplacementsToText 的 expect 契约原先只对字面量 pattern 生效,正则
分支直接 continue 掉了 —— 官方把同一段代码复制成两份时正则会把两处一起
改掉,补上正则分支的命中数检查
- patchStatus 的 drifted 计数排在 strictFiles 的 unmatched 之前:严格补丁的
文件宿主一定在,原文对不上只可能是上游漂移,报 drifted 比 unmatched 更准
- 与 PR 的有意偏差:rollupPatchStatus 里 drifted 排在 already 之后。
多文件补丁(#50/#57/#62)有个别文件本来就不含这段代码(barrel 文件),
按 PR 的顺序会把这几条从 already/applied 翻成 drifted,制造假告警
未取(0.2.1-rc.3 专属、与通用逻辑无法拆开):新增 targetFiles 键
(harness-dev-context / skill-badge)、#32/#53 扩到 rc.3 新位置、
新增 #89 SANDBOX_POLICY_BRAND_NEUTRAL 与 #90 SKILL_BADGE_DESCRIPTION_NEUTRAL
新增 test/patch-status.test.js(29 条,全量 74 条全过)
Based-on: PR #188 by Pluto-Yt
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
0ea7872505
commit
97c5de75fa
5 files changed
+526
-38
No files matched your search
+14
-2
@@ -164,10 +164,18 @@ function renderStatus(state) {
|
||||
? state.display_patches
|
||||
: core.groupPatchesForDisplay(core.ALL_PATCHES, state.patch_status || {});
|
||||
const displayTally = core.tallyDisplayPatches(displayRows);
|
||||
out.push(`补丁 / patches: ${displayTally.applied}/${displayTally.total || 0} applied, ${displayTally.pending} pending`);
|
||||
out.push(`补丁 / patches: ${displayTally.applied}/${displayTally.total || 0} applied, ${displayTally.pending} pending`
|
||||
+ (displayTally.drifted ? `, ${displayTally.drifted} drifted(官方原文已改,需更新 pattern)` : ""));
|
||||
if (state.host_version) {
|
||||
const supported = state.host_supported !== false;
|
||||
const compat = supported
|
||||
? ""
|
||||
: ` ← 未适配:插件声明 ${state.host_target || "?"}`;
|
||||
out.push(`宿主 / host: ${state.host_version}${compat}`);
|
||||
}
|
||||
for (const row of displayRows) {
|
||||
const s = row.status || "n/a";
|
||||
const mark = s === "applied" ? "✓" : s === "pending" ? "✗" : "·";
|
||||
const mark = s === "applied" ? "✓" : s === "pending" ? "✗" : s === "drifted" ? "!" : "·";
|
||||
const patch = core.ALL_PATCHES.find((item) => item.id === row.id);
|
||||
const label = patch ? patch.name : `patch-${row.id}`;
|
||||
const layer = patch ? `${patch.layer}/${patch.layer_en}` : row.layer || "";
|
||||
@@ -1899,9 +1907,13 @@ function installWebServer(ctx, cfg) {
|
||||
patches_applied: state.ai_base ? (state.display_applied ?? state.patches_applied) : 0,
|
||||
patches_pending: state.display_pending ?? state.patches_pending,
|
||||
patches_skipped: state.display_skipped ?? state.patches_skipped ?? 0,
|
||||
patches_drifted: state.display_drifted ?? state.patches_drifted ?? 0,
|
||||
patches_ready: state.display_ready ?? state.patches_ready ?? 0,
|
||||
patches_na: state.patches_na || 0,
|
||||
patches_total: state.ai_base ? (state.display_total ?? state.patches_total ?? 0) : 0,
|
||||
host_version: state.host_version || "",
|
||||
host_target: state.host_target || "",
|
||||
host_supported: state.host_supported !== false,
|
||||
patches_lost: reapply.patchesLostAfterHostReset(),
|
||||
patch_status: state.patch_status,
|
||||
patches: (state.display_patches || []).map((p) => ({
|
||||
|
||||
Reference in new issue
Block a user