mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 16:10:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38e3bdce70 | ||
|
|
3d49ccb501 | ||
|
|
d31894a931 | ||
|
|
16fb3ff634 |
No files matched your search
+100
-51
@@ -313,12 +313,13 @@ export function silenceCmdFlash(aiBase = findAiBase()) {
|
||||
const customBash = silenceLiangshenCustomBashFlash();
|
||||
const phase1 = silenceLiangshenPhase1Strip();
|
||||
const mnemon = silenceMnemonGitFlash();
|
||||
// bin.js 写失败(missing_bin / ACL)不阻断 Apply。
|
||||
// bin.js 写失败(missing_bin / ACL)不阻断 Apply。源码 cli 跳过注入也算成功(#41)。
|
||||
const ok =
|
||||
process.platform !== "win32" ||
|
||||
hide.entry === "injected" ||
|
||||
hide.entry === "already_injected" ||
|
||||
hide.entry === "skipped_not_win32" ||
|
||||
hide.entry === "skipped_source_cli" ||
|
||||
hide.entry === "missing_bin" ||
|
||||
hide.entry === "sealed_asar" ||
|
||||
(typeof hide.entry === "string" && hide.entry.startsWith("error:"));
|
||||
@@ -3256,6 +3257,100 @@ function flattenTargetPaths(files) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** 用户配置层:官方允许在 profiles/<name>/cordis.patch.yml 手写 insert,绝不能进 bak/回滚(#43)。 */
|
||||
export function isUserProfilePatchFile(fp) {
|
||||
const n = String(fp || "").replace(/\\/g, "/").toLowerCase();
|
||||
return /\/profiles\/[^/]+\/cordis\.patch\.yml$/i.test(n);
|
||||
}
|
||||
|
||||
/** 丢掉历史误建的 profile cordis.bak,不还原(保留用户当前文件)。 */
|
||||
export async function dropStaleUserProfilePatchBackups(dshHome = findDshHome()) {
|
||||
const dropped = [];
|
||||
const profilesRoot = path.join(dshHome, "profiles");
|
||||
if (!isDir(profilesRoot)) return dropped;
|
||||
let names = [];
|
||||
try {
|
||||
names = fs.readdirSync(profilesRoot, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
||||
} catch {
|
||||
return dropped;
|
||||
}
|
||||
for (const name of names) {
|
||||
const fp = path.join(profilesRoot, name, "cordis.patch.yml");
|
||||
const bak = `${fp}.dshpurge.bak`;
|
||||
if (!fs.existsSync(bak)) continue;
|
||||
try {
|
||||
await fsp.unlink(bak);
|
||||
dropped.push(bak);
|
||||
} catch {
|
||||
/* 下次再试 */
|
||||
}
|
||||
}
|
||||
return dropped;
|
||||
}
|
||||
|
||||
export async function backupAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const made = [];
|
||||
const errors = [];
|
||||
const skippedUser = [];
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
if (!fs.existsSync(fp)) continue;
|
||||
// 用户 patch 层永不建 bak(#43)。
|
||||
if (isUserProfilePatchFile(fp)) {
|
||||
skippedUser.push(fp);
|
||||
continue;
|
||||
}
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
if (!fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.copyFile(fp, bak);
|
||||
made.push(bak);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
const dropped = await dropStaleUserProfilePatchBackups();
|
||||
return { made, errors, skippedUser, dropped };
|
||||
}
|
||||
|
||||
export async function revertAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const reverted = [];
|
||||
const skipped = [];
|
||||
const preservedUser = [];
|
||||
const errors = [];
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
// 用户 patch 层:有 bak 也只丢掉 bak,绝不 copy 回去(#43)。
|
||||
if (isUserProfilePatchFile(fp)) {
|
||||
if (fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.unlink(bak);
|
||||
preservedUser.push(fp);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.copyFile(bak, fp);
|
||||
await fsp.unlink(bak);
|
||||
reverted.push(fp);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// 没有 bak 时绝不删除目标。源码部署的构建产物缺备份时,删了无法自愈(#41)。
|
||||
if (fs.existsSync(fp)) skipped.push(fp);
|
||||
}
|
||||
const dropped = await dropStaleUserProfilePatchBackups();
|
||||
return { reverted, skipped, preservedUser, dropped, errors };
|
||||
}
|
||||
|
||||
function nestedPkg(aiBase, pkg, ...rel) {
|
||||
return [
|
||||
path.join(aiBase, pkg, ...rel),
|
||||
@@ -3291,7 +3386,6 @@ function filterTargetFiles(files) {
|
||||
|
||||
export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
const root = packageRootFromAiBase(aiBase);
|
||||
const desktopHost = adapterFor(detectSurface()) === "desktop";
|
||||
const files = {
|
||||
"agent-instructions": firstExisting([
|
||||
path.join(aiBase, "dsh-agent-instructions", "lib", "index.js"),
|
||||
@@ -3312,17 +3406,9 @@ export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
...(root ? [path.join(root, "packages", "bundle", "headless", "cordis.patch.yml")] : []),
|
||||
]),
|
||||
"desktop-shell": officialShellMain(),
|
||||
"profile-web": firstExisting(desktopHost
|
||||
? [
|
||||
path.join(dshHome, "profiles", "desktop", "cordis.patch.yml"),
|
||||
path.join(aiBase, "dsh-web-app", "cordis.patch.yml"),
|
||||
...(root ? [path.join(root, "packages", "bundle", "web-app", "cordis.patch.yml")] : []),
|
||||
]
|
||||
: [
|
||||
path.join(dshHome, "profiles", "web", "cordis.patch.yml"),
|
||||
path.join(aiBase, "dsh-web-app", "cordis.patch.yml"),
|
||||
...(root ? [path.join(root, "packages", "bundle", "web-app", "cordis.patch.yml")] : []),
|
||||
]),
|
||||
// 注意:不要把 profiles/<name>/cordis.patch.yml 放进 targetFiles。
|
||||
// 那是官方文档支持的「用户 patch 层」,本插件没有任何补丁写入它;
|
||||
// 一旦进 backupAll/revertAll,版本升级自愈会把用户后来追加的 insert 盖掉(#43)。
|
||||
"agent-preset": firstExisting([
|
||||
...userPresetYml(dshHome, "unrestricted"),
|
||||
...shippedPresetYml(root, "standard", aiBase),
|
||||
@@ -3998,47 +4084,10 @@ export async function patchStatus(aiBase, patches = ALL_PATCHES) {
|
||||
return status;
|
||||
}
|
||||
|
||||
export async function backupAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const made = [];
|
||||
const errors = [];
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
if (!fs.existsSync(fp)) continue;
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
if (!fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.copyFile(fp, bak);
|
||||
made.push(bak);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { made, errors };
|
||||
}
|
||||
|
||||
export async function revertAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const reverted = [];
|
||||
const errors = [];
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
if (fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.copyFile(bak, fp);
|
||||
await fsp.unlink(bak);
|
||||
reverted.push(fp);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { reverted, errors };
|
||||
}
|
||||
|
||||
export async function hasBackup(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
if (isUserProfilePatchFile(fp)) continue;
|
||||
if (fs.existsSync(fp + ".dshpurge.bak")) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
+35
-1
@@ -176,6 +176,26 @@ function ioFor(explicit, targetPath) {
|
||||
return explicit ?? fsFor(targetPath);
|
||||
}
|
||||
|
||||
/** 源码 monorepo 的 apps/cli(tsdown 构建产物)。往这里注入/还原会动构建输出,缺 bak 时无法自愈(#41)。 */
|
||||
export function looksLikeSourceCliRoot(root, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
if (!root) return false;
|
||||
const n = String(root).replace(/\\/g, "/").toLowerCase();
|
||||
if (/\/apps\/cli\/?$/.test(n)) return true;
|
||||
if (/\/node_modules\//.test(n)) return false;
|
||||
try {
|
||||
const nodeFs = ioFor(fs, root);
|
||||
const libDir = p.join(root, "lib");
|
||||
if (nodeFs.existsSync(p.join(libDir, "tsconfig.tsbuildinfo"))) return true;
|
||||
if (nodeFs.existsSync(p.join(root, "tsdown.config.ts")) || nodeFs.existsSync(p.join(root, "tsdown.config.mjs"))) {
|
||||
return true;
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function resolveDshBinRoot(hint, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
const tries = [];
|
||||
@@ -196,6 +216,16 @@ export function resolveDshBinRoot(hint, { fs, path: nodePath } = {}) {
|
||||
if (typeof process.argv[1] === "string" && /[\\/]bin\.js$/i.test(process.argv[1])) {
|
||||
push(p.dirname(p.dirname(process.argv[1])));
|
||||
}
|
||||
for (const root of tries) {
|
||||
try {
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
if (isAsarSealedPath(root) || isAsarSealedPath(binJs)) continue;
|
||||
// 源码树只作探测候选的最后手段;优先 node_modules 包,避免改写 apps/cli/lib(#41)。
|
||||
if (looksLikeSourceCliRoot(root, { fs, path: p })) continue;
|
||||
if (ioFor(fs, binJs).existsSync(binJs)) return p.normalize(root);
|
||||
} catch {}
|
||||
}
|
||||
// 没有包装配路径时,才回退到 argv 指向的源码 cli(仍禁止注入,见 installHideConsoleIntoBin)。
|
||||
for (const root of tries) {
|
||||
try {
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
@@ -213,6 +243,8 @@ export function installHideConsoleIntoBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
const root = resolveDshBinRoot(aiBase, { fs, path: p });
|
||||
if (!root) return "missing_bin";
|
||||
// 源码部署的 apps/cli/lib 是 tsdown 产物:只准读、不准写 sidecar / 改 bin.js(#41)。
|
||||
if (looksLikeSourceCliRoot(root, { fs, path: p })) return "skipped_source_cli";
|
||||
const nodeFs = ioFor(fs, root);
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
const side = p.join(root, "lib", `${IMPORT_MARK}.js`);
|
||||
@@ -248,12 +280,14 @@ export function revertHideConsoleFromBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
const root = resolveDshBinRoot(aiBase, { fs, path: p });
|
||||
if (!root) return "missing_bin";
|
||||
// 源码 cli:只清理本插件留下的 sidecar,绝不改/删 bin.js 或其它构建产物(#41)。
|
||||
const sourceCli = looksLikeSourceCliRoot(root, { fs, path: p });
|
||||
const nodeFs = ioFor(fs, root);
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
const side = p.join(root, "lib", `${IMPORT_MARK}.js`);
|
||||
const facadeSide = p.join(root, "lib", "dsh-purge-child-process-hide.mjs");
|
||||
let changed = false;
|
||||
if (nodeFs.existsSync(binJs)) {
|
||||
if (!sourceCli && nodeFs.existsSync(binJs)) {
|
||||
try {
|
||||
const text = nodeFs.readFileSync(binJs, "utf8");
|
||||
const next = text.replace(/^import "\.\/dsh-purge-hide-console\.js";.*\r?\n/gm, "");
|
||||
|
||||
+6
-3
@@ -18,15 +18,18 @@ function exeName(execPath) {
|
||||
export function pathLooksDesktop(p) {
|
||||
const n = slash(p);
|
||||
if (!n) return false;
|
||||
// 安装目录可能叫 "DeepSeek Harness" / "deepseek-harness",但源码仓库(monorepo)也叫这个名字 ——
|
||||
// 所以只凭目录名不算,还必须带桌面安装形态(resources/、exe、.app/)。与 desktop.looksLikeDesktopName 对齐。
|
||||
const harnessDir = n.includes("/deepseek harness/") || n.includes("/deepseek-harness/");
|
||||
return (
|
||||
n.includes("/dsh desktop/") ||
|
||||
n.includes("/dsh desktop.app/") ||
|
||||
n.includes("dsh-desktop") ||
|
||||
n.includes("dsh-plugin-desktop") ||
|
||||
n.includes("/deepseek harness/") ||
|
||||
n.includes("deepseek-harness") ||
|
||||
n.includes("/deepseek harness.app/") ||
|
||||
(harnessDir && (n.includes("/resources/") || n.includes("/contents/resources/") || n.endsWith("/resources"))) ||
|
||||
/\/dsh desktop\.exe$/i.test(n) ||
|
||||
/\/deepseek harness\.exe$/i.test(n) ||
|
||||
/\/deepseek[- ]harness\.exe$/i.test(n) ||
|
||||
n.endsWith("/host-process-entry.js") ||
|
||||
n.endsWith("/desktop-cli.js")
|
||||
);
|
||||
|
||||
+4
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.23",
|
||||
"version": "1.1.25",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
@@ -32,7 +32,9 @@
|
||||
"test:yaml": "node scripts/test-yaml-comment.mjs",
|
||||
"test:update": "node scripts/test-update-guards.mjs",
|
||||
"test:rewind": "node scripts/test-rewind-plan.mjs",
|
||||
"test:idempotence": "node scripts/test-patch-idempotence.mjs"
|
||||
"test:idempotence": "node scripts/test-patch-idempotence.mjs",
|
||||
"test:surface": "node scripts/test-surface-desktop.mjs",
|
||||
"test:profile-patch": "node scripts/test-user-profile-patch.mjs"
|
||||
},
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
|
||||
@@ -1,3 +1,29 @@
|
||||
# 1.1.25
|
||||
|
||||
## 中文
|
||||
|
||||
- **修复 [#43](https://github.com/YuJunZhiXue/dsh-purge/issues/43)**:不再把 `profiles/*/cordis.patch.yml`(用户 patch 层)纳入 `backupAll`/`revertAll`;升级自愈时不会用旧 bak 覆盖用户后来追加的 `insert`。
|
||||
- 启动/还原时主动丢掉历史上误建的 `cordis.patch.yml.dshpurge.bak`,保留当前用户文件。
|
||||
- 新增 `npm run test:profile-patch`。
|
||||
|
||||
## English
|
||||
|
||||
- **Fix [#43](https://github.com/YuJunZhiXue/dsh-purge/issues/43)**: stop including `profiles/*/cordis.patch.yml` (user patch layer) in `backupAll`/`revertAll`, so upgrade reapply no longer restores an old bak over later user `insert`s.
|
||||
- Drop stale `cordis.patch.yml.dshpurge.bak` without restoring; keep the live user file.
|
||||
- Add `npm run test:profile-patch`.
|
||||
# 1.1.24
|
||||
|
||||
## 中文
|
||||
|
||||
- **修复 [#40](https://github.com/YuJunZhiXue/dsh-purge/issues/40)**:`pathLooksDesktop` 不再仅凭路径里的 `deepseek-harness` 子串把源码版判成桌面端;需带 `resources/` / `.exe` / `.app` 等安装形态。
|
||||
- **修复 [#41](https://github.com/YuJunZhiXue/dsh-purge/issues/41)**:源码部署的 `apps/cli`(tsdown 构建产物)禁止 hide-console 注入;`revertAll` 在无 `.dshpurge.bak` 时只跳过、绝不删除目标文件。
|
||||
- 新增 `npm run test:surface` 回归。
|
||||
|
||||
## English
|
||||
|
||||
- **Fix [#40](https://github.com/YuJunZhiXue/dsh-purge/issues/40)**: `pathLooksDesktop` no longer treats source trees as desktop just because the path contains `deepseek-harness`; require install shapes (`resources/`, `.exe`, `.app`).
|
||||
- **Fix [#41](https://github.com/YuJunZhiXue/dsh-purge/issues/41)**: skip hide-console injection into source `apps/cli` build output; `revertAll` never deletes targets when `.dshpurge.bak` is missing.
|
||||
- Add `npm run test:surface`.
|
||||
# 1.1.23
|
||||
|
||||
## 中文
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { pathLooksDesktop, detectSurface } from "../lib/surface.js";
|
||||
import { looksLikeSourceCliRoot, installHideConsoleIntoBin } from "../lib/hide-console.js";
|
||||
|
||||
// #40:源码仓库路径不能仅因目录名 deepseek-harness 被判成桌面端
|
||||
assert.equal(
|
||||
pathLooksDesktop("/home/me/deepseek-harness/apps/cli/lib/bin.js"),
|
||||
false,
|
||||
"源码 cli 路径不应命中 pathLooksDesktop",
|
||||
);
|
||||
assert.equal(
|
||||
pathLooksDesktop("/home/me/deepseek-harness/node_modules/@deepseek-ai/dsh/lib/bin.js"),
|
||||
false,
|
||||
"源码树里的 node_modules 也不应仅凭目录名判桌面",
|
||||
);
|
||||
assert.equal(
|
||||
detectSurface({
|
||||
argv: ["/usr/bin/node", "/home/me/deepseek-harness/apps/cli/lib/bin.js"],
|
||||
execPath: "/usr/bin/node",
|
||||
env: {},
|
||||
}),
|
||||
"web",
|
||||
"源码版 argv 应判为 web",
|
||||
);
|
||||
|
||||
// 官方桌面安装形态仍应命中
|
||||
assert.equal(
|
||||
pathLooksDesktop("C:/DeepSeek Harness/resources/app.asar/node_modules/@deepseek-ai/dsh"),
|
||||
true,
|
||||
"官方 Win resources 路径应判桌面",
|
||||
);
|
||||
assert.equal(
|
||||
pathLooksDesktop("/Applications/DeepSeek Harness.app/Contents/Resources/app"),
|
||||
true,
|
||||
"官方 macOS .app Resources 应判桌面",
|
||||
);
|
||||
assert.equal(
|
||||
pathLooksDesktop("C:/deepseek-harness/deepseek-harness.exe"),
|
||||
true,
|
||||
"官方 exe 路径应判桌面",
|
||||
);
|
||||
assert.equal(
|
||||
pathLooksDesktop("C:/dsh-desktop/DSH Desktop.exe"),
|
||||
true,
|
||||
"第三方 DSH Desktop 应判桌面",
|
||||
);
|
||||
|
||||
// #41:源码 apps/cli 识别 + 禁止注入
|
||||
assert.equal(looksLikeSourceCliRoot("E:/DSH/apps/cli"), true);
|
||||
assert.equal(looksLikeSourceCliRoot("/home/me/deepseek-harness/apps/cli"), true);
|
||||
assert.equal(
|
||||
looksLikeSourceCliRoot("/home/me/deepseek-harness/node_modules/@deepseek-ai/dsh"),
|
||||
false,
|
||||
);
|
||||
|
||||
const prev = process.platform;
|
||||
Object.defineProperty(process, "platform", { value: "win32" });
|
||||
try {
|
||||
const status = installHideConsoleIntoBin("E:/DSH/apps/cli", {
|
||||
fs: {
|
||||
existsSync: () => true,
|
||||
readFileSync: () => 'import "./x.js";\n',
|
||||
writeFileSync: () => {
|
||||
throw new Error("source cli must not be written");
|
||||
},
|
||||
unlinkSync: () => {
|
||||
throw new Error("source cli must not be unlinked");
|
||||
},
|
||||
},
|
||||
path: await import("node:path").then((m) => m.default),
|
||||
});
|
||||
assert.equal(status, "skipped_source_cli", "源码 cli 应跳过 hide-console 注入");
|
||||
} finally {
|
||||
Object.defineProperty(process, "platform", { value: prev });
|
||||
}
|
||||
|
||||
console.log("ok: surface desktop + source cli guards (#40/#41)");
|
||||
@@ -0,0 +1,52 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import {
|
||||
isUserProfilePatchFile,
|
||||
dropStaleUserProfilePatchBackups,
|
||||
targetFiles,
|
||||
} from "../lib/core.js";
|
||||
|
||||
assert.equal(
|
||||
isUserProfilePatchFile("D:/DeepSeek Harness/.dsh/profiles/web/cordis.patch.yml"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
isUserProfilePatchFile("C:/Users/x/.dsh/profiles/desktop/cordis.patch.yml"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
isUserProfilePatchFile("/home/me/.dsh/profiles/web/node_modules/dsh-purge/cordis.patch.yml"),
|
||||
false,
|
||||
"插件自己的 cordis.patch.yml 不是用户 profile 层",
|
||||
);
|
||||
assert.equal(
|
||||
isUserProfilePatchFile("/x/node_modules/@deepseek-ai/dsh-web-app/cordis.patch.yml"),
|
||||
false,
|
||||
);
|
||||
|
||||
// targetFiles 不得再收录 profiles/*/cordis.patch.yml(#43)
|
||||
const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-purge-43-"));
|
||||
const profilePatch = path.join(tmpHome, "profiles", "web", "cordis.patch.yml");
|
||||
fs.mkdirSync(path.dirname(profilePatch), { recursive: true });
|
||||
fs.writeFileSync(profilePatch, "patches:\n - insert: user-mcp\n", "utf8");
|
||||
const bak = `${profilePatch}.dshpurge.bak`;
|
||||
fs.writeFileSync(bak, "patches: []\n", "utf8");
|
||||
|
||||
const files = targetFiles(path.join(tmpHome, "missing-ai-base"), tmpHome);
|
||||
const flat = Object.values(files).flatMap((v) => (Array.isArray(v) ? v : [v])).filter(Boolean);
|
||||
assert.equal(
|
||||
flat.some((fp) => isUserProfilePatchFile(fp)),
|
||||
false,
|
||||
"targetFiles 不应包含用户 profile cordis.patch.yml",
|
||||
);
|
||||
|
||||
const before = fs.readFileSync(profilePatch, "utf8");
|
||||
const dropped = await dropStaleUserProfilePatchBackups(tmpHome);
|
||||
assert.equal(dropped.length, 1, "应丢掉误建 bak");
|
||||
assert.equal(fs.existsSync(bak), false, "bak 应已删除");
|
||||
assert.equal(fs.readFileSync(profilePatch, "utf8"), before, "用户当前内容必须保留");
|
||||
|
||||
fs.rmSync(tmpHome, { recursive: true, force: true });
|
||||
console.log("ok: user profile cordis.patch.yml not reverted (#43)");
|
||||
Reference in new issue
Block a user