dsh-git-push 2.10.1 → 2.10.4
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.md +4 -0
- package/assets/tree-sitter/LICENSE +0 -0
- package/assets/tree-sitter/README.md +0 -0
- package/assets/tree-sitter/tree-sitter-javascript.wasm +0 -0
- package/assets/tree-sitter/tree-sitter-python.wasm +0 -0
- package/assets/tree-sitter/tree-sitter-typescript.wasm +0 -0
- package/assets/tree-sitter/tree-sitter.js +0 -0
- package/assets/tree-sitter/tree-sitter.wasm +0 -0
- package/lib/ARCHITECTURE.md +27 -0
- package/lib/app/apply.js +0 -0
- package/lib/app/handlers/settings.js +0 -0
- package/lib/app/handlers/workspace-paths.js +0 -0
- package/lib/app/schema.js +0 -0
- package/lib/app/settings-bridge.js +0 -0
- package/lib/ast/code-lines.js +0 -0
- package/lib/ast/fs-hotspots.js +0 -0
- package/lib/ast/index.js +0 -0
- package/lib/ast/tokenizer.js +0 -0
- package/lib/ast/treesitter.js +0 -0
- package/lib/checks/fs-scanner.js +0 -0
- package/lib/checks/regex.js +0 -0
- package/lib/core/workspace-paths.js +0 -0
- package/lib/exempt/tool.js +0 -0
- package/lib/git/clone-history-mode.js +22 -9
- package/lib/git/clone-replay-io.js +10 -4
- package/lib/git/clone.js +8 -2
- package/lib/git/commit-message.js +0 -0
- package/lib/git/index-format.js +0 -0
- package/lib/git/init-compat.js +118 -0
- package/lib/git/push-diagnose.js +0 -0
- package/lib/self/index.js +1 -1
- package/package.json +1 -1
- package/scripts/check.mjs +68 -0
- package/scripts/cpu-sample.mjs +0 -0
- package/scripts/picker-repro.mjs +0 -0
- package/scripts/scan-fs-hotspots.mjs +0 -0
- package/skills/guide/guide-audit.md +29 -0
package/README.md
CHANGED
|
@@ -422,6 +422,7 @@ dsh-git-push/
|
|
|
422
422
|
│ │ ├── ignore.js — .gitignore 兜底(DEFAULT_IGNORE_PATTERNS 补齐)
|
|
423
423
|
│ │ ├── index-format.js — (待注释)
|
|
424
424
|
│ │ ├── index.js — Git 执行层统一出口
|
|
425
|
+
│ │ ├── init-compat.js — (待注释)
|
|
425
426
|
│ │ ├── module-splitter.js — (待注释)
|
|
426
427
|
│ │ ├── post-push.js — 推送后增强(remote-tracking ref/aux remote/tag)
|
|
427
428
|
│ │ ├── push-diagnose.js — (待注释)
|
|
@@ -592,7 +593,9 @@ dsh-git-push/
|
|
|
592
593
|
│ ├── test-gitignore-nongit-dir.mjs — (待注释)
|
|
593
594
|
│ ├── test-history-audit.mjs — (待注释)
|
|
594
595
|
│ ├── test-http.mjs — HTTP 总入口测试(Origin/CSRF/413/路由)
|
|
596
|
+
│ ├── test-ignore-e2e.mjs — (待注释)
|
|
595
597
|
│ ├── test-index-jsonl.mjs — (待注释)
|
|
598
|
+
│ ├── test-init-compat.mjs — (待注释)
|
|
596
599
|
│ ├── test-inject-switch.mjs — 注入开发者要求清单子开关回归
|
|
597
600
|
│ ├── test-inject-system-prompt.mjs — 注入系统提示词回归
|
|
598
601
|
│ ├── test-io-risk.mjs — IO 风险分级测试(四级判定/字段完整性/汇总/排序/finding 转换)
|
|
@@ -659,6 +662,7 @@ dsh-git-push/
|
|
|
659
662
|
│ ├── test-workspace-paths.mjs — (待注释)
|
|
660
663
|
│ ├── fixtures/ — (待注释)
|
|
661
664
|
│ │ ├── TimeZoneComboBox-CRnoCikG.js — Pawchive 混淆产物样本(hash 文件名——跳过判定 fixture)
|
|
665
|
+
│ │ └── …(5 个更深文件)
|
|
662
666
|
│ ├── helpers/ — (待注释)
|
|
663
667
|
│ │ ├── test-cache.mjs — (待注释)
|
|
664
668
|
│ │ ├── tmp-dir.mjs — (待注释)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/ARCHITECTURE.md
CHANGED
|
@@ -32,3 +32,30 @@
|
|
|
32
32
|
`lib/rule/compilers.js` 只做纯再导出。
|
|
33
33
|
- 仓库级/文件系统上下文类检查(如读 .gitignore、git 命令)不在逐文件检查器里臆测,
|
|
34
34
|
交给 `lib/audit/` 编排层或 `lib/checks/` 中带上下文参数的入口。
|
|
35
|
+
|
|
36
|
+
## 审计引擎与提交推送:不拆成两个包,但把边界钉死
|
|
37
|
+
|
|
38
|
+
**决策(2026-10-24)**:保持单包 `dsh-git-push`,不拆出独立审计 npm 包。
|
|
39
|
+
|
|
40
|
+
拆包换不到收益:
|
|
41
|
+
|
|
42
|
+
- 外部使用者的需求是「提交前拦截」这个整体(`git_commit_push` 的门禁 + `code_audit`),不是「只装审计引擎」;
|
|
43
|
+
- 「脱离 DSH 跑审计」已由 `cli.mjs`(`git-sluice`,不依赖宿主)覆盖;
|
|
44
|
+
- 而拆包的代价是**持续**的:两包版本同步、固定发布顺序、依赖范围约束——同类 monorepo 双包仓库上刚观察到这些成本落地成 bug(版本各升各的、`files` 声明漂移)。
|
|
45
|
+
|
|
46
|
+
但不拆包 ≠ 放弃边界。实测依赖方向是干净的:
|
|
47
|
+
|
|
48
|
+
| 方向 | 数量 | 说明 |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| 审计层 → git/npm/commit-push | **0** | 审计层完全不知道提交推送存在 |
|
|
51
|
+
| git/npm/commit-push → 审计层 | **7** | 唯一耦合面:`commit-push.js` 3 处(audit/exempt/score)+ `git/{ignore,repos,sensitive}.js` 4 处 |
|
|
52
|
+
|
|
53
|
+
由 `scripts/check.mjs` 的**层边界门禁**钉住(两处都已自证会变红):
|
|
54
|
+
|
|
55
|
+
1. 审计层任一文件 import git 层 ⇒ 直接失败;
|
|
56
|
+
2. 反向接缝数超过预算 7 ⇒ 失败(要上调必须写明理由)。
|
|
57
|
+
|
|
58
|
+
**维护约定**:审计层需要 git 能力时(读 `.gitignore`、跑 `git status`),走**自己文件内的轻量
|
|
59
|
+
`execFileSync('git', …)`**(如 `lib/audit/collector.js`),不得顺手 `import` `lib/git/` 的
|
|
60
|
+
`runGit`/`transport.js`——那 7 处接缝是「提交门禁要调审计」的必需耦合,多一处都是在把它糊掉。
|
|
61
|
+
真出现外部只要审计引擎的用户,按这张表拆:动那 7 行 import + 建包,其余是机械操作。
|
package/lib/app/apply.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/app/schema.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/ast/code-lines.js
CHANGED
|
File without changes
|
package/lib/ast/fs-hotspots.js
CHANGED
|
File without changes
|
package/lib/ast/index.js
CHANGED
|
File without changes
|
package/lib/ast/tokenizer.js
CHANGED
|
File without changes
|
package/lib/ast/treesitter.js
CHANGED
|
File without changes
|
package/lib/checks/fs-scanner.js
CHANGED
|
File without changes
|
package/lib/checks/regex.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/exempt/tool.js
CHANGED
|
File without changes
|
|
@@ -16,6 +16,7 @@ import { fetchCommitChain } from './clone-history.js';
|
|
|
16
16
|
import { replayHistory } from './clone-replay.js';
|
|
17
17
|
import { createReplayIo } from './clone-replay-io.js';
|
|
18
18
|
import { runGit } from './exec.js';
|
|
19
|
+
import { initRepoCompat } from './init-compat.js';
|
|
19
20
|
import { resolveOwnerVisibility, accessPlan, sshGitUrl } from './visibility.js';
|
|
20
21
|
import { resolveSshKeys } from './credentials.js';
|
|
21
22
|
|
|
@@ -134,15 +135,27 @@ export async function cloneWithGitFetch({
|
|
|
134
135
|
};
|
|
135
136
|
|
|
136
137
|
const n = Number(depth) > 0 ? Number(depth) : 0;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
138
|
+
// 初始化 + origin 一步做完:本地盘走 git init + remote add;不支持 chmod 的卷
|
|
139
|
+
// (CIFS/SMB nounix)走手工 .git 结构降级 —— 那些卷上 git init / git config /
|
|
140
|
+
// git remote add 全都要写 .git/config,而写 config 时的 chmod(config.lock) 必然
|
|
141
|
+
// EPERM,git 直接 fatal。降级路径把 remote 段一并手写进 config(见 init-compat.js)
|
|
142
|
+
const initRes = initRepoCompat(repoPath, {
|
|
143
|
+
branch: branch || 'master',
|
|
144
|
+
remoteUrl,
|
|
145
|
+
chmodOk: deps.chmodOk,
|
|
146
|
+
gitInit: (args, o) => git(args, { ...gitOpts, ...o }),
|
|
147
|
+
});
|
|
148
|
+
steps.push({ cmd: `init (${initRes.via})`, ok: !!initRes.ok });
|
|
149
|
+
if (!initRes.ok) return fail(`git init 失败:${initRes.stderr || '未知'}`);
|
|
150
|
+
if (initRes.filemode) {
|
|
151
|
+
// 权限噪音抑制(只对本地盘有意义;降级路径已把 filemode=false 写进手工 config)
|
|
152
|
+
run(['config', 'core.fileMode', 'false']);
|
|
153
|
+
if (!git(['remote', 'get-url', 'origin'], gitOpts)?.ok) {
|
|
154
|
+
run(['remote', 'add', 'origin', remoteUrl]);
|
|
155
|
+
} else {
|
|
156
|
+
// 已存在 origin(续跑):按本次判断纠正,避免上次留下的 https 形态继续走镜像
|
|
157
|
+
run(['remote', 'set-url', 'origin', remoteUrl]);
|
|
158
|
+
}
|
|
146
159
|
}
|
|
147
160
|
|
|
148
161
|
// 显式 refspec:同时写入 refs/remotes/origin/<branch>,后续可据此建本地分支并设上游
|
|
@@ -22,9 +22,10 @@ import { existsSync, readFileSync, writeFileSync, renameSync, rmSync } from 'nod
|
|
|
22
22
|
|
|
23
23
|
import { githubFetch } from './api.js';
|
|
24
24
|
import { runGit } from './exec.js';
|
|
25
|
+
import { initRepoCompat } from './init-compat.js';
|
|
25
26
|
import { downloadBlobs } from './clone-download.js';
|
|
26
27
|
import {
|
|
27
|
-
blobEntriesOf,
|
|
28
|
+
blobEntriesOf, setRemoteArgs, configFileModeArgs, addAllArgs, writeTreeArgs,
|
|
28
29
|
commitTreeArgs, updateRefArgs, setUpstreamArgs, localBranchRef, remoteTrackingRef, markerJson,
|
|
29
30
|
} from './clone-replay.js';
|
|
30
31
|
|
|
@@ -145,13 +146,18 @@ export function createReplayIo({
|
|
|
145
146
|
|
|
146
147
|
/** 重放前准备:init → 显式写 core.fileMode=false → 设 origin(已有 origin 则不覆盖)。 */
|
|
147
148
|
async prepare() {
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
// 不支持 chmod 的卷(CIFS/SMB nounix)上 git init / git config / git remote add
|
|
150
|
+
// 全都要写 .git/config,而写 config 时的 chmod(config.lock) 必然 EPERM ⇒ fatal。
|
|
151
|
+
// 改走手工 .git 结构降级:HEAD + config(filemode=false) + remote 段一次写好
|
|
152
|
+
const url = `https://github.com/${owner}/${repo}.git`;
|
|
153
|
+
const initRes = initRepoCompat(gitOpts.cwd, { remoteUrl: url, chmodOk: deps.chmodOk, gitInit: (args, o) => git(args, { ...gitOpts, ...o }) });
|
|
154
|
+
if (!initRes.ok) return { ok: false, error: `git init 失败:${initRes.stderr || '未知'}` };
|
|
155
|
+
// 降级路径:filemode 与 origin 都已写进 config,无需再执行 git config / remote add
|
|
156
|
+
if (!initRes.filemode) return { ok: true, fileModeSet: true, originSet: true, via: initRes.via };
|
|
150
157
|
const cfg = git(configFileModeArgs(false), gitOpts);
|
|
151
158
|
const hasOrigin = git(['remote', 'get-url', 'origin'], gitOpts);
|
|
152
159
|
let originSet = true;
|
|
153
160
|
if (!hasOrigin?.ok) {
|
|
154
|
-
const url = `https://github.com/${owner}/${repo}.git`;
|
|
155
161
|
const add = git(setRemoteArgs('origin', url), gitOpts);
|
|
156
162
|
originSet = !!add?.ok;
|
|
157
163
|
}
|
package/lib/git/clone.js
CHANGED
|
@@ -18,6 +18,7 @@ import { resolveToken } from './credentials.js';
|
|
|
18
18
|
import { downloadBlobs, partitionBySize, DEFAULT_MAX_FILE_MB, DEFAULT_CONCURRENCY, removeDirForce, PARTS_DIR } from './clone-download.js';
|
|
19
19
|
import { cloneAbortSignal, cloneLog } from './clone-jobs.js';
|
|
20
20
|
import { runGit } from './exec.js';
|
|
21
|
+
import { initRepoCompat } from './init-compat.js';
|
|
21
22
|
|
|
22
23
|
/* ───────────────────────── clone / 建仓 / 可见性 ───────────────────────── */
|
|
23
24
|
|
|
@@ -322,12 +323,17 @@ export async function cloneViaApi({
|
|
|
322
323
|
// 先删「进行中」标记:与 history 模式同理,它若留在目录里会被 git add -A 一并提交,
|
|
323
324
|
// 使快照提交多出一个本不该存在的文件(此前实测残留在仓库里,需人工清理)。
|
|
324
325
|
try { unlinkSync(join(targetDir, CLONE_MARKER)); } catch { /* 标记本就不在则忽略 */ }
|
|
326
|
+
// 初始化:本地盘走 git init;不支持 chmod 的卷(CIFS/SMB nounix)走手工 .git 结构,
|
|
327
|
+
// origin 一并手写进 config —— 那些卷上 `git remote add` 同样要写 .git/config 而失败
|
|
328
|
+
const apiRemoteUrl = `${GH_API}/repos/${owner}/${repo}`;
|
|
329
|
+
const initRes = initRepoCompat(targetDir, { branch: useBranch, remoteUrl: apiRemoteUrl });
|
|
330
|
+
if (!initRes.ok) return { ok: false, error: `git init 失败:${initRes.stderr || '未知'}`, dest: targetDir };
|
|
325
331
|
for (const args of [
|
|
326
|
-
['
|
|
332
|
+
['add', '-A'], ['-c', 'user.email=v2-clone@local', '-c', 'user.name=v2-clone', 'commit', '-q', '-m', `clone from ${owner}/${repo}@${useBranch}`],
|
|
327
333
|
]) {
|
|
328
334
|
runGit(args, { cwd: targetDir });
|
|
329
335
|
}
|
|
330
|
-
runGit(['remote', 'add', 'origin',
|
|
336
|
+
if (initRes.filemode) runGit(['remote', 'add', 'origin', apiRemoteUrl], { cwd: targetDir });
|
|
331
337
|
|
|
332
338
|
// 成功:移除进行中标记,此后该目录不再被当作「可清理的残留」
|
|
333
339
|
try { unlinkSync(join(targetDir, CLONE_MARKER)); } catch { /* 标记本就不在则忽略 */ }
|
|
File without changes
|
package/lib/git/index-format.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git 仓库初始化兼容层(CIFS/SMB 等不支持 chmod 的文件系统)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要(实测根因,2026-10-28):
|
|
5
|
+
* `git init` 末尾要把探测到的 `core.filemode` **写入** `.git/config`。写 config 走的是
|
|
6
|
+
* `config.lock` → chmod(继承原权限) → rename,而 CIFS 挂载带 `nounix` 时 chmod 一律
|
|
7
|
+
* `EPERM`,于是 git 直接 fatal:
|
|
8
|
+
* `error: chmod on .../.git/config.lock failed: Operation not permitted`
|
|
9
|
+
* `fatal: could not set 'core.filemode' to 'false'`
|
|
10
|
+
* 结果是在目标目录留下一个**未初始化的空 .git**,后续 add/commit 还会向上命中父仓库
|
|
11
|
+
* (把父仓库整棵树写进错误的历史,历史事故)。
|
|
12
|
+
* 同样的 chmod 也会让 `git config core.fileMode false` 失效——所以「先 git init 再关
|
|
13
|
+
* filemode」这条自救路线在 CIFS 上根本不成立。
|
|
14
|
+
*
|
|
15
|
+
* 实测结论(这三条是设计依据,改动前请重跑确认):
|
|
16
|
+
* ① `git init` / `git config` 写 config → 必然失败(chmod);
|
|
17
|
+
* ② **手工搭最小 .git 结构**后,`git add -A` / `git commit` / `git log` / `git reset`
|
|
18
|
+
* 全部正常——index.lock 与 refs 的写入不受影响,只有 config 的 chmod 是死穴;
|
|
19
|
+
* ③ `core.filemode = false` 写进 config 后,`git status` 才不再把所有文件报成 M
|
|
20
|
+
* (CIFS 上文件 mode 恒为 777,与 index 里记录的 100644 不符)。
|
|
21
|
+
*
|
|
22
|
+
* 因此降级路径 = 手写 `.git/{HEAD,config}` + 空 `objects/refs/info` 目录,绕开 git 的
|
|
23
|
+
* config 写入流程;config 里预先写死 `filemode = false`。
|
|
24
|
+
*/
|
|
25
|
+
import { existsSync, mkdirSync, writeFileSync, chmodSync, rmSync } from 'node:fs';
|
|
26
|
+
import { join } from 'node:path';
|
|
27
|
+
import { runGit } from './exec.js';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 探测目录所在文件系统是否支持 chmod。
|
|
31
|
+
*
|
|
32
|
+
* 判据就是真去 chmod 一个临时文件——比看 mount 类型可靠(同类挂载的选项可能不同,
|
|
33
|
+
* 而且同一台机器上 NFS/CIFS/本地盘混合)。用完即删,不留残余。
|
|
34
|
+
* @param {string} dir 目标目录(不存在会先创建——clone 的目标目录本来就是新建的)
|
|
35
|
+
* @returns {boolean} true = 支持 chmod(可走标准 git init)
|
|
36
|
+
*/
|
|
37
|
+
export function fsSupportsChmod(dir) {
|
|
38
|
+
const probe = join(dir, `.dshgp-chmod-probe-${process.pid}-${Date.now()}`);
|
|
39
|
+
try {
|
|
40
|
+
// 先确保目录存在:目标目录可能还没建,此时 writeFile 会 ENOENT,
|
|
41
|
+
// 若把 ENOENT 误判成「不支持 chmod」就会让所有全新目标目录都走降级分支(实测踩过)
|
|
42
|
+
mkdirSync(dir, { recursive: true });
|
|
43
|
+
writeFileSync(probe, '');
|
|
44
|
+
chmodSync(probe, 0o600);
|
|
45
|
+
return true;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
} finally {
|
|
49
|
+
try { rmSync(probe, { force: true }); } catch { /* 探测文件残留无所谓 */ }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 手工搭最小可用的 .git 结构(不经 git init)。
|
|
55
|
+
*
|
|
56
|
+
* 只写 git 真正必需的四样:HEAD(指分支)、config(含 filemode=false)、
|
|
57
|
+
* objects/(对象库)、refs/heads(提交后放分支引用);info/ 是配套惯例目录。
|
|
58
|
+
* 不写 index —— 交给首次 `git add` 自动生成(实测可行)。
|
|
59
|
+
* @param {string} dir 仓库工作树目录
|
|
60
|
+
* @param {{branch?: string, remoteName?: string, remoteUrl?: string}} [opts]
|
|
61
|
+
* branch 为目标分支名(HEAD 指向它);给了 remoteUrl 就把 remote 段一并写进 config
|
|
62
|
+
* —— 因为 `git remote add` 同样是写 config,在 CIFS 上一样会 chmod 失败
|
|
63
|
+
*/
|
|
64
|
+
export function writeMinimalGitDir(dir, { branch = 'master', remoteName = 'origin', remoteUrl = '' } = {}) {
|
|
65
|
+
const g = join(dir, '.git');
|
|
66
|
+
for (const d of ['objects', 'refs/heads', 'refs/tags', 'info']) {
|
|
67
|
+
mkdirSync(join(g, d), { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
// HEAD 指向分支名而不是具体 sha:首次 commit 后 git 会把 refs/heads/<branch> 建好
|
|
70
|
+
writeFileSync(join(g, 'HEAD'), `ref: refs/heads/${branch}\n`);
|
|
71
|
+
// filemode=false 是关键项:不加则 CIFS 上所有文件因 777 vs 100644 恒被报为已修改
|
|
72
|
+
const lines = [
|
|
73
|
+
'[core]',
|
|
74
|
+
'\trepositoryformatversion = 0',
|
|
75
|
+
'\tfilemode = false',
|
|
76
|
+
'\tbare = false',
|
|
77
|
+
'\tlogallrefupdates = true',
|
|
78
|
+
];
|
|
79
|
+
if (remoteUrl) {
|
|
80
|
+
lines.push(`[remote "${remoteName}"]`, `\turl = ${remoteUrl}`, `\tfetch = +refs/heads/*:refs/remotes/${remoteName}/*`);
|
|
81
|
+
}
|
|
82
|
+
writeFileSync(join(g, 'config'), lines.join('\n') + '\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 初始化 git 仓库(自动适配不支持 chmod 的文件系统)。
|
|
87
|
+
*
|
|
88
|
+
* 能 chmod → 走标准 `git init -q`(行为与之前完全一致);
|
|
89
|
+
* 不能 chmod → 手写最小 .git 结构,等价于「已 init 完成」的仓库。
|
|
90
|
+
* @param {string} dir 目标目录(必须已存在)
|
|
91
|
+
* @param {{branch?: string, remoteUrl?: string, chmodOk?: boolean, gitInit?: (args: string[], opts: object) => object}} [opts]
|
|
92
|
+
* branch: 目标分支(降级路径写进 HEAD);remoteUrl: 降级路径一并写进 config 的 remote 段;
|
|
93
|
+
* chmodOk: 强制指定 chmod 能力(测试用,省略则真去探测目标卷);
|
|
94
|
+
* gitInit: 可注入的 git 执行器(测试用,缺省走 runGit)
|
|
95
|
+
* @returns {{ok: boolean, via: 'git-init'|'manual', filemode: boolean, stderr?: string}}
|
|
96
|
+
*/
|
|
97
|
+
export function initRepoCompat(dir, { branch = 'master', remoteUrl = '', chmodOk, gitInit } = {}) {
|
|
98
|
+
const exec = typeof gitInit === 'function' ? gitInit : (args, opts) => runGit(args, opts);
|
|
99
|
+
const canChmod = typeof chmodOk === 'boolean' ? chmodOk : fsSupportsChmod(dir);
|
|
100
|
+
if (canChmod) {
|
|
101
|
+
const r = exec(['init', '-q'], { cwd: dir });
|
|
102
|
+
return { ok: !!r?.ok, via: 'git-init', filemode: true, stderr: r?.stderr };
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
writeMinimalGitDir(dir, { branch, remoteUrl });
|
|
106
|
+
// 自检:结构搭好后 git 必须能识别出工作树,否则等于静默失败(历史事故的形态)
|
|
107
|
+
const rc = exec(['rev-parse', '--git-dir'], { cwd: dir });
|
|
108
|
+
if (!rc?.ok) return { ok: false, via: 'manual', filemode: false, stderr: rc?.stderr || '自检失败:git 未识别出新仓库' };
|
|
109
|
+
return { ok: true, via: 'manual', filemode: false };
|
|
110
|
+
} catch (e) {
|
|
111
|
+
return { ok: false, via: 'manual', filemode: false, stderr: String((e && e.message) || e) };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** .git 目录是否已存在(续跑判断:已 init 过就不再重复写)。 */
|
|
116
|
+
export function hasGitDir(dir) {
|
|
117
|
+
return existsSync(join(dir, '.git'));
|
|
118
|
+
}
|
package/lib/git/push-diagnose.js
CHANGED
|
File without changes
|
package/lib/self/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
export const VERSION = '2.10.
|
|
12
|
+
export const VERSION = '2.10.4'; // 2.10.4:修掉「克隆到 CIFS/SMB 挂载失败」——根因是 git init 要把 core.filemode 写进 .git/config,而写 config 走 config.lock→chmod→rename,挂载带 nounix 时 chmod 恒 EPERM ⇒ git 直接 fatal(留下未初始化的空 .git,整体克隆失败)。新增 lib/git/init-compat.js:真去 chmod 一个临时文件探测能力,不支持时手工搭最小 .git 结构(HEAD + config[filemode=false] + 空 objects/refs/info;remote 段一并手写,因 git remote add 同样要写 config),绕开 git 的 config 写入流程;实测降级后 add/commit/log/status/remote 全部正常。三处 init 调用点(clone.js / clone-history-mode.js / clone-replay-io.js)统一走该兼容层,deps 可注入 chmodOk 便于测试。新增 test/test-init-compat.mjs(6 例,含「降级结构必须是真仓库」与自证)。实测:katboi01/UmaViewer(157MB)经插件成功克隆到 CIFS 挂载,HEAD 与远端一致、脏文件 0。历史:2.10.3:忽略链路端到端回归。
|
|
13
13
|
// 实测后果:该目录有 package.json ⇒ npm 去打包整棵 DSH 树、输出 2.1MB > spawnSync 默认 maxBuffer 1MB ⇒ ENOBUFS(npm_publish 的体检与真发全部失败);
|
|
14
14
|
// 该目录没有 package.json 时报 ENOENT。现 publish 的两个调用点显式传 cwd=目标包目录,并给 runNpm 加 16MB maxBuffer。
|
|
15
15
|
// 2.8.3:文案修正——「零改动 / 无新提交」明确为**正常成功路径**(注入用法、工具描述、README、skill 同批改),并修 job 输出自相矛盾(cleanSkipCommit 路径补 committed:false,不再显示「已提交,未推送」)
|
package/package.json
CHANGED
package/scripts/check.mjs
CHANGED
|
@@ -83,6 +83,74 @@ try {
|
|
|
83
83
|
console.error(`✗ 分片构建校验失败:${e.message}`);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// ── 层边界门禁(2026-10-24)────────────────────────────────────────────
|
|
87
|
+
// 背景:审计引擎与提交推送**决定不拆成两个 npm 包**(拆包的持续成本——双包版本同步、
|
|
88
|
+
// 固定发布顺序、依赖范围——换不到真实收益:外部使用者要的是「提交前拦截」这个整体,
|
|
89
|
+
// 而「脱离 DSH 跑审计」已由 cli.mjs 的独立 CLI 覆盖)。
|
|
90
|
+
// 但不拆包不等于放弃边界:审计层对 git 层是**实测零依赖**,这个事实一旦被顺手 import
|
|
91
|
+
// 侵蚀就再也回不来(历史包袱太重 = 不可逆)。所以把它钉成门禁。
|
|
92
|
+
// 不变量:
|
|
93
|
+
// ① 审计层任何文件都不得 import git/npm/commit-push 层(方向唯一:git → audit);
|
|
94
|
+
// ② 反向接缝数量有预算上限——允许存在(提交门禁必须调审计),但要能看见它在膨胀。
|
|
95
|
+
const AUDIT_DIRS = new Set(['ast', 'audit', 'audit-rules', 'checks', 'exempt', 'rule', 'score']);
|
|
96
|
+
const GIT_DIRS = new Set(['git', 'npm']);
|
|
97
|
+
const GIT_TOP = new Set(['commit-push.js']);
|
|
98
|
+
const AUDIT_TOP = new Set(['audit-defaults.js', 'skip-dirs.js']);
|
|
99
|
+
/** 反向接缝预算:实测 7 处(commit-push 3 + git/{ignore,repos,sensitive} 4);上调需写明理由。 */
|
|
100
|
+
const SEAM_BUDGET = 7;
|
|
101
|
+
|
|
102
|
+
const layerOf = (rel) => {
|
|
103
|
+
const top = rel.split('/')[0];
|
|
104
|
+
if (rel.includes('/') && AUDIT_DIRS.has(top)) return 'AUDIT';
|
|
105
|
+
if (rel.includes('/') && GIT_DIRS.has(top)) return 'GIT';
|
|
106
|
+
if (!rel.includes('/') && GIT_TOP.has(rel)) return 'GIT';
|
|
107
|
+
if (!rel.includes('/') && AUDIT_TOP.has(rel)) return 'AUDIT';
|
|
108
|
+
return 'OTHER';
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
let boundaryViolations = 0;
|
|
112
|
+
const seams = [];
|
|
113
|
+
for (const f of files) {
|
|
114
|
+
const rel = f.replace(ROOT + '/', '');
|
|
115
|
+
if (!rel.startsWith('lib/')) continue;
|
|
116
|
+
const inner = rel.slice('lib/'.length);
|
|
117
|
+
if (layerOf(inner) !== 'AUDIT') continue;
|
|
118
|
+
let src = '';
|
|
119
|
+
try { src = readFileSync(f, 'utf8'); } catch { continue; }
|
|
120
|
+
for (const m of src.matchAll(/from\s+['"](\.[^'"]+)['"]/g)) {
|
|
121
|
+
const target = join(dirname(f), m[1]).replace(ROOT + '/lib/', '');
|
|
122
|
+
if (layerOf(target) === 'GIT') {
|
|
123
|
+
boundaryViolations++;
|
|
124
|
+
console.error(`✗ 层边界违规:审计层 lib/${inner} import 了 git 层 ${m[1]}(审计引擎解耦)`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// 反向接缝统计(允许,但要可见)
|
|
129
|
+
for (const f of files) {
|
|
130
|
+
const rel = f.replace(ROOT + '/', '');
|
|
131
|
+
if (!rel.startsWith('lib/')) continue;
|
|
132
|
+
const inner = rel.slice('lib/'.length);
|
|
133
|
+
if (layerOf(inner) !== 'GIT') continue;
|
|
134
|
+
let src = '';
|
|
135
|
+
try { src = readFileSync(f, 'utf8'); } catch { continue; }
|
|
136
|
+
for (const m of src.matchAll(/from\s+['"](\.[^'"]+)['"]/g)) {
|
|
137
|
+
const target = join(dirname(f), m[1]).replace(ROOT + '/lib/', '');
|
|
138
|
+
if (layerOf(target) === 'AUDIT') seams.push(`${inner} → ${target}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (boundaryViolations) {
|
|
142
|
+
fail += boundaryViolations;
|
|
143
|
+
console.error(`✗ 层边界:${boundaryViolations} 处违规——审计层不得依赖 git/npm/commit-push`);
|
|
144
|
+
} else {
|
|
145
|
+
console.log(`✔ 层边界:审计层对 git 层 0 依赖(解耦成立)`);
|
|
146
|
+
}
|
|
147
|
+
if (seams.length > SEAM_BUDGET) {
|
|
148
|
+
fail++;
|
|
149
|
+
console.error(`✗ 反向接缝 ${seams.length} 处 > 预算 ${SEAM_BUDGET}:提交门禁调审计是必需的,但膨胀说明边界在糊掉——要么收敛,要么改预算并写明理由`);
|
|
150
|
+
} else {
|
|
151
|
+
console.log(`✔ 反向接缝(git → audit,唯一耦合面):${seams.length}/${SEAM_BUDGET} 处`);
|
|
152
|
+
}
|
|
153
|
+
|
|
86
154
|
console.log(`\n${files.length - fail}/${files.length} 文件语法通过`);
|
|
87
155
|
console.log(`${jsonFiles.length - jsonFail}/${jsonFiles.length} 个 JSON 可解析`);
|
|
88
156
|
process.exitCode = (fail > 0 || jsonFail > 0) ? 1 : 0;
|
package/scripts/cpu-sample.mjs
CHANGED
|
File without changes
|
package/scripts/picker-repro.mjs
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -239,3 +239,32 @@ console.log(x); // dsh-skip-residue: 本行为刻意保留的调试输出样本
|
|
|
239
239
|
多种形态出现,小写搜会漏(实测:搜 `partFilter` 漏掉 `setPartFilter`,误判「零引用」而删掉底层实现)。
|
|
240
240
|
注意这只针对「人工核查引用」;规则内部的**标识符匹配必须保持大小写敏感**(JS/Python 本身区分大小写,
|
|
241
241
|
放宽只会引入新误报)。
|
|
242
|
+
|
|
243
|
+
## 15. 忽略链路(.gitignore / .auditignore)的测试纪律
|
|
244
|
+
|
|
245
|
+
**这块历史上反复回归,而且每次都不是判定逻辑写错,而是接线层断掉。** 已知三次形态:
|
|
246
|
+
|
|
247
|
+
| 回归形态 | 症状 | 为什么内部函数测试挡不住 |
|
|
248
|
+
|---|---|---|
|
|
249
|
+
| 以**空 stdin** 调 `check-ignore`,从未传文件路径 | 忽略集恒空 ⇒ 全仓文件都进审计 | `buildIgnoreSet` 内部逻辑没改,改的是它的输入 |
|
|
250
|
+
| 大仓库降级:枚举全部文件被改成目录级判定 | 文件级规则(单个文件名)失效 | 降级是**性能分支**,内部单测仍走全量分支 |
|
|
251
|
+
| 调用方**漏传 `gitIgnoreRoot`** | 函数默认值 `null` = 不判定忽略 ⇒ 忽略完全不生效 | 函数行为没变,变的是调用参数 |
|
|
252
|
+
|
|
253
|
+
**纪律**:
|
|
254
|
+
|
|
255
|
+
- 忽略相关改动必须跑**端到端**(`auditFull` / `runAudit`),不能只测 `collectTextFiles`。
|
|
256
|
+
既有 `test-collector-ignore.mjs` / `test-auditignore.mjs` 都只测内部函数,对上面三类天然失明;
|
|
257
|
+
端到端守门员是 `test/test-ignore-e2e.mjs`(三条链路 + 对照组)。
|
|
258
|
+
- **必须有对照组**:断言「忽略的文件没出现」时,同时断言「该被审的文件出现了」。
|
|
259
|
+
否则「全部文件都被排除」也会让测试假通过。
|
|
260
|
+
- 三条链路各自要有一条用例:full(走 `gitIgnoreRoot`)、diff(走 `collectChangedFiles` 独立路径)、
|
|
261
|
+
非 git 目录(git check-ignore 不可用,靠 `parseGitignore` 纯 JS 兜底)。
|
|
262
|
+
- 样本要**入库**为固定 fixture(`test/fixtures/ignore-e2e/`),不要测试里现造:
|
|
263
|
+
现造样本会随实现漂移,也让「什么叫被忽略」没有唯一答案。
|
|
264
|
+
样本文件名用 `.js.fixture` / `.rules` 后缀——若直接叫 `gib.js` 且同目录放 `.gitignore`,
|
|
265
|
+
这两份样本自己就会被忽略而**无法入库**(自我反噬)。
|
|
266
|
+
- 新增/修改忽略相关代码后,用「把 `gitIgnoreRoot` 强制改 `null`」自证测试会红——这是最容易复发的接线断点。
|
|
267
|
+
|
|
268
|
+
**排查时的第一个坑(我踩过)**:直接调 `collectTextFiles(dir, { repoPath: dir })` 会得到
|
|
269
|
+
「忽略全失效」的假象——因为参数名是 `gitIgnoreRoot`,传错就等于显式关掉忽略判定。
|
|
270
|
+
复现前先确认自己的探针参数与真实调用方一致(见 `lib/audit/orchestrate.js` 的调用处)。
|