claude-everything-workflow 0.2.11 → 0.2.12
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/.claude-plugin/hooks.json +1 -6
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/docs/plugins.md +3 -2
- package/evals/routing-scenarios.json +9 -0
- package/hooks/check-code-size.js +4 -126
- package/hooks/check-console-log.js +4 -79
- package/hooks/check-edited-file.js +139 -0
- package/hooks/commit-quality.js +1029 -72
- package/hooks/runtime/antigravity-pre-tool.js +116 -0
- package/package.json +4 -2
- package/rules/02-implementation.md +1 -1
- package/rules/common/hooks.md +2 -2
- package/scripts/cleanup-retired-skills.js +36 -3
- package/scripts/install-antigravity.js +63 -19
- package/scripts/install-rules.js +27 -7
- package/scripts/install.ps1 +21 -24
- package/scripts/install.sh +2 -1
- package/scripts/merge-claude-settings.cjs +14 -2
- package/scripts/retired-skill-files.json +12 -0
- package/scripts/verify/commit-quality.test.js +481 -0
- package/scripts/verify/install-rules.test.js +212 -5
- package/scripts/verify/metadata-checks.js +4 -1
- package/scripts/verify/runtime-checks.js +57 -2
- package/scripts/verify/workflow-checks.js +5 -1
- package/settings.json +1 -6
- package/skills/systematic-debugging/SKILL.md +7 -4
- package/skills/systematic-debugging/references/diagnostic-scenarios.md +7 -0
- package/agents/harness-optimizer.md +0 -93
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const assert = require("node:assert/strict");
|
|
4
|
+
const { execFileSync } = require("node:child_process");
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
const os = require("node:os");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
const test = require("node:test");
|
|
9
|
+
|
|
10
|
+
const { run, diffPath, extractGitCommitInvocation } = require("../../hooks/commit-quality");
|
|
11
|
+
|
|
12
|
+
function git(repo, ...args) {
|
|
13
|
+
return execFileSync("git", args, { cwd: repo, encoding: "utf8" });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function initRepo(tempRoot, name) {
|
|
17
|
+
const repo = path.join(tempRoot, name);
|
|
18
|
+
fs.mkdirSync(repo, { recursive: true });
|
|
19
|
+
git(repo, "init", "-q");
|
|
20
|
+
git(repo, "config", "user.name", "Test");
|
|
21
|
+
git(repo, "config", "user.email", "test@example.com");
|
|
22
|
+
return repo;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function payload(command) {
|
|
26
|
+
return JSON.stringify({ tool_input: { command } });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test("extractGitCommitInvocation matches git commit variants and ignores non-commit commands", () => {
|
|
30
|
+
assert.ok(extractGitCommitInvocation('git commit -m "feat: ok"'));
|
|
31
|
+
assert.equal(extractGitCommitInvocation('git commit -m "feat: ok"').message, "feat: ok");
|
|
32
|
+
|
|
33
|
+
const withC = extractGitCommitInvocation("git -C /tmp/demo commit -m 'fix: bug'");
|
|
34
|
+
assert.ok(withC);
|
|
35
|
+
assert.deepEqual(withC.gitDirArgs, ["-C", "/tmp/demo"]);
|
|
36
|
+
assert.equal(withC.message, "fix: bug");
|
|
37
|
+
|
|
38
|
+
const chained = extractGitCommitInvocation('cd /tmp/demo && git -c user.name=Bot commit -m "bad msg"');
|
|
39
|
+
assert.ok(chained);
|
|
40
|
+
assert.equal(chained.cdDir, "/tmp/demo");
|
|
41
|
+
assert.equal(chained.message, "bad msg");
|
|
42
|
+
|
|
43
|
+
const subshellCd = extractGitCommitInvocation('(cd /tmp/sub) && git commit -m "feat: ok"', "/tmp/root");
|
|
44
|
+
assert.ok(subshellCd);
|
|
45
|
+
assert.equal(subshellCd.cdDir, null, "subshell cd must not leak to subsequent git commit");
|
|
46
|
+
|
|
47
|
+
const withGitDir = extractGitCommitInvocation("git --git-dir=/tmp/r/.git --work-tree=/tmp/r commit -m 'fix: wt'");
|
|
48
|
+
assert.ok(withGitDir);
|
|
49
|
+
assert.deepEqual(withGitDir.gitDirArgs, ["--git-dir=/tmp/r/.git", "--work-tree=/tmp/r"]);
|
|
50
|
+
|
|
51
|
+
assert.ok(extractGitCommitInvocation('npm test; git commit -m "chore: update"'));
|
|
52
|
+
assert.equal(extractGitCommitInvocation("git status"), null);
|
|
53
|
+
assert.equal(extractGitCommitInvocation('echo "git commit"'), null);
|
|
54
|
+
assert.equal(extractGitCommitInvocation('git log --grep="git commit"'), null);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("diffPath decodes Git quoted UTF-8 paths and strips b/ prefix", () => {
|
|
58
|
+
assert.equal(diffPath("b/src/app.js"), "src/app.js");
|
|
59
|
+
assert.equal(diffPath('"b/src/\\344\\270\\255\\346\\226\\207 file.js"'), "src/中文 file.js");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test(
|
|
63
|
+
"multi-file staged diff attributes secret and debug lines to the exact first file without echoing secrets",
|
|
64
|
+
(t) => {
|
|
65
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-"));
|
|
66
|
+
t.after(() => fs.rmSync(tempRoot, { recursive: true, force: true }));
|
|
67
|
+
|
|
68
|
+
const repo = initRepo(tempRoot, "multi-file");
|
|
69
|
+
const secretValue = "skTest0123456789abcdef012345";
|
|
70
|
+
fs.writeFileSync(
|
|
71
|
+
path.join(repo, "a-secret.js"),
|
|
72
|
+
`const apiKey = "${secretValue}";\nconsole.log(apiKey);\n`,
|
|
73
|
+
);
|
|
74
|
+
fs.writeFileSync(path.join(repo, "z-clean.js"), "export const ok = 1;\n");
|
|
75
|
+
git(repo, "add", "a-secret.js", "z-clean.js");
|
|
76
|
+
|
|
77
|
+
const result = run(payload('git commit -m "feat: add files"'), { cwd: repo });
|
|
78
|
+
assert.equal(result.exitCode, 2);
|
|
79
|
+
assert.match(result.stderr, /检测到疑似密钥: a-secret\.js:1/);
|
|
80
|
+
assert.match(result.stderr, /检测到调试代码: a-secret\.js:2/);
|
|
81
|
+
assert.doesNotMatch(result.stderr, /z-clean\.js/);
|
|
82
|
+
assert.equal(result.stderr.includes(secretValue), false, "must never echo secret value");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("same-line secret and console.log blocks and never leaks secret text", (t) => {
|
|
86
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-"));
|
|
87
|
+
t.after(() => fs.rmSync(tempRoot, { recursive: true, force: true }));
|
|
88
|
+
|
|
89
|
+
const repo = initRepo(tempRoot, "same-line");
|
|
90
|
+
const secretValue = "super_secret_token_value_12345";
|
|
91
|
+
fs.writeFileSync(
|
|
92
|
+
path.join(repo, "leak.js"),
|
|
93
|
+
`console.log({ token: "${secretValue}" });\n`,
|
|
94
|
+
);
|
|
95
|
+
git(repo, "add", "leak.js");
|
|
96
|
+
|
|
97
|
+
const result = run(payload('git commit -m "fix: leak check"'), { cwd: repo });
|
|
98
|
+
assert.equal(result.exitCode, 2);
|
|
99
|
+
assert.match(result.stderr, /检测到疑似密钥: leak\.js:1/);
|
|
100
|
+
assert.match(result.stderr, /检测到调试代码: leak\.js:1/);
|
|
101
|
+
assert.equal(result.stderr.includes(secretValue), false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("multi-hunk diff attributes second hunk to exact new-file line number", (t) => {
|
|
105
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-"));
|
|
106
|
+
t.after(() => fs.rmSync(tempRoot, { recursive: true, force: true }));
|
|
107
|
+
|
|
108
|
+
const repo = initRepo(tempRoot, "multi-hunk");
|
|
109
|
+
const baseLines = Array.from({ length: 20 }, (_, i) => `const line${i + 1} = ${i + 1};`);
|
|
110
|
+
fs.writeFileSync(path.join(repo, "app.js"), baseLines.join("\n") + "\n");
|
|
111
|
+
git(repo, "add", "app.js");
|
|
112
|
+
git(repo, "commit", "-q", "-m", "chore: initial");
|
|
113
|
+
|
|
114
|
+
const updatedLines = [...baseLines];
|
|
115
|
+
updatedLines[1] = "const line2 = 200;";
|
|
116
|
+
updatedLines[17] = "console.log('hunk2');";
|
|
117
|
+
fs.writeFileSync(path.join(repo, "app.js"), updatedLines.join("\n") + "\n");
|
|
118
|
+
git(repo, "add", "app.js");
|
|
119
|
+
|
|
120
|
+
const result = run(payload('git commit -m "fix: update app"'), { cwd: repo });
|
|
121
|
+
assert.equal(result.exitCode, 0);
|
|
122
|
+
assert.match(result.stderr, /检测到调试代码: app\.js:18\b/);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("UTF-8, spaces, deleted files, and git -C commits are handled accurately", (t) => {
|
|
126
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-"));
|
|
127
|
+
t.after(() => fs.rmSync(tempRoot, { recursive: true, force: true }));
|
|
128
|
+
|
|
129
|
+
const repo = initRepo(tempRoot, "utf8-del");
|
|
130
|
+
fs.writeFileSync(path.join(repo, "removed.js"), "console.log('old');\n");
|
|
131
|
+
git(repo, "add", "removed.js");
|
|
132
|
+
git(repo, "commit", "-q", "-m", "chore: seed");
|
|
133
|
+
|
|
134
|
+
git(repo, "rm", "-q", "removed.js");
|
|
135
|
+
fs.writeFileSync(path.join(repo, "中文 file.js"), "debugger;\n");
|
|
136
|
+
git(repo, "add", "中文 file.js");
|
|
137
|
+
|
|
138
|
+
// Invoke from outside repo using git -C <repo>
|
|
139
|
+
const result = run(payload(`git -C "${repo}" commit -m "feat: utf8"`), { cwd: tempRoot });
|
|
140
|
+
assert.equal(result.exitCode, 0);
|
|
141
|
+
assert.match(result.stderr, /检测到调试代码: 中文 file\.js:1/);
|
|
142
|
+
assert.doesNotMatch(result.stderr, /removed\.js/);
|
|
143
|
+
|
|
144
|
+
// Invoke from outside repo using chained cd <repo> && git commit
|
|
145
|
+
const cdResult = run(payload(`cd "${repo}" && git commit -m "feat: cd"`), { cwd: tempRoot });
|
|
146
|
+
assert.equal(cdResult.exitCode, 0);
|
|
147
|
+
assert.match(cdResult.stderr, /检测到调试代码: 中文 file\.js:1/);
|
|
148
|
+
assert.doesNotMatch(cdResult.stderr, /无法检查暂存区/);
|
|
149
|
+
|
|
150
|
+
// Unresolvable cd before git commit warns instead of scanning wrong cwd
|
|
151
|
+
const unresolvedResult = run(payload('cd "$TARGET_REPO" && git commit -m "feat: var"'), { cwd: repo });
|
|
152
|
+
assert.equal(unresolvedResult.exitCode, 0);
|
|
153
|
+
assert.match(unresolvedResult.stderr, /无法检查暂存区/);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("non-git directory reports warning instead of silently skipping, and invalid commit message warns", (t) => {
|
|
157
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-nongit-"));
|
|
158
|
+
t.after(() => fs.rmSync(tempRoot, { recursive: true, force: true }));
|
|
159
|
+
|
|
160
|
+
const result = run(payload('git commit -m "bad message"'), { cwd: tempRoot });
|
|
161
|
+
assert.equal(result.exitCode, 0);
|
|
162
|
+
assert.match(result.stderr, /Commit message 格式不符合规范/);
|
|
163
|
+
assert.match(result.stderr, /无法检查暂存区/);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("subshells inherit and restore their working directories independently", (t) => {
|
|
167
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-groups-"));
|
|
168
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
169
|
+
const outer = initRepo(root, "outer");
|
|
170
|
+
const inner = initRepo(outer, "inner");
|
|
171
|
+
fs.writeFileSync(path.join(inner, "inner.js"), "debugger;\n");
|
|
172
|
+
git(inner, "add", "inner.js");
|
|
173
|
+
assert.match(run(payload("(cd inner && (git commit -m 'test: nested'))"), { cwd: outer }).stderr, /inner\.js:1/);
|
|
174
|
+
assert.equal(run(payload("(cd inner); (git commit -m 'test: sibling')"), { cwd: outer }).stderr, undefined);
|
|
175
|
+
const multiple = run(payload("git commit -m 'test: outer'; (cd inner && git commit -m 'test: inner')"), { cwd: outer });
|
|
176
|
+
assert.match(multiple.stderr, /inner\.js:1/);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("pipeline stages and background command lists keep their own working directories", (t) => {
|
|
180
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-processes-"));
|
|
181
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
182
|
+
const outer = initRepo(root, "outer");
|
|
183
|
+
const inner = initRepo(outer, "inner");
|
|
184
|
+
for (const [dir, file] of [[outer, "outer.js"], [inner, "inner.js"]]) {
|
|
185
|
+
fs.writeFileSync(path.join(dir, file), "debugger;\n");
|
|
186
|
+
git(dir, "add", file);
|
|
187
|
+
}
|
|
188
|
+
const commit = "git commit -m 'test: context'";
|
|
189
|
+
for (const prefix of ["cd inner | cat;", "cat | cd inner;", "cat |&\n cd inner;",
|
|
190
|
+
"cd inner & wait;", "cd inner && true &", "cd inner |", "(cd inner) | cat;"]) {
|
|
191
|
+
const result = run(payload(prefix + " " + commit), { cwd: outer });
|
|
192
|
+
assert.match(result.stderr, /outer\.js:1/, prefix);
|
|
193
|
+
assert.doesNotMatch(result.stderr, /inner\.js:1/, prefix);
|
|
194
|
+
}
|
|
195
|
+
for (const command of ["cd inner 2>&1; " + commit, "cd inner && " + commit + " &",
|
|
196
|
+
"cd inner; cat | cd ..; " + commit]) {
|
|
197
|
+
assert.match(run(payload(command), { cwd: outer }).stderr, /inner\.js:1/, command);
|
|
198
|
+
}
|
|
199
|
+
const both = run(payload("cd inner &&\n " + commit + " & " + commit), { cwd: outer });
|
|
200
|
+
assert.match(both.stderr, /inner\.js:1/);
|
|
201
|
+
assert.match(both.stderr, /outer\.js:1/);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("brace groups share directory changes with their caller, including inside a pipeline", (t) => {
|
|
205
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-braces-"));
|
|
206
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
207
|
+
const outer = initRepo(root, "outer");
|
|
208
|
+
const inner = initRepo(outer, "inner");
|
|
209
|
+
fs.writeFileSync(path.join(inner, "inner.js"), "debugger;\n");
|
|
210
|
+
git(inner, "add", "inner.js");
|
|
211
|
+
const commit = "git commit -m 'test: current'";
|
|
212
|
+
for (const cmd of ["{ cd inner; " + commit + "; }", "{ { cd inner; }; }; " + commit]) {
|
|
213
|
+
assert.match(run(payload(cmd), { cwd: outer }).stderr, /inner\.js:1/, cmd);
|
|
214
|
+
}
|
|
215
|
+
assert.equal(run(payload("{ cd inner; } | cat; " + commit), { cwd: outer }).stderr, undefined);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("shell function definitions run at their call site and unused bodies are skipped", () => {
|
|
219
|
+
assert.equal(extractGitCommitInvocation("save() {\n git commit -m ignored;\n}\nprintf done"), null);
|
|
220
|
+
assert.equal(extractGitCommitInvocation("printf '%s' 'save() { git commit; }'"), null);
|
|
221
|
+
assert.match(run(payload("again() { again; }; again")).stderr, /静态分析范围/);
|
|
222
|
+
const body = "{ { git commit -m 'test: called'; }; }";
|
|
223
|
+
for (const definition of ["save() " + body, "function save " + body, "save () ( git commit -m 'test: called' )"]) {
|
|
224
|
+
assert.equal(extractGitCommitInvocation(definition + "\nprintf 'done'"), null);
|
|
225
|
+
assert.equal(extractGitCommitInvocation(definition + "\ngit commit -m 'test: direct'").message, "test: direct");
|
|
226
|
+
const called = extractGitCommitInvocation(definition + "\n(cd nested && save)", "/root");
|
|
227
|
+
assert.equal(called.cdDir, path.resolve("/root", "nested"));
|
|
228
|
+
assert.equal(called.message, "test: called");
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("here-document input is data, including tab-stripped and quoted terminators", () => {
|
|
233
|
+
const doc = "cat <<'FIRST' <<-SECOND\ngit commit -m example\nFIRST\n\tgit commit -m other\n\tSECOND";
|
|
234
|
+
assert.equal(extractGitCommitInvocation(doc), null);
|
|
235
|
+
assert.equal(extractGitCommitInvocation("echo $((1 << 2))\ngit commit -m arithmetic").message, "arithmetic");
|
|
236
|
+
assert.equal(extractGitCommitInvocation(doc + "\ngit commit -m 'docs: real'").message, "docs: real");
|
|
237
|
+
assert.equal(extractGitCommitInvocation('echo "cat <<EOF"; git commit -m "docs: quoted"').message, "docs: quoted");
|
|
238
|
+
assert.equal(extractGitCommitInvocation('cat <<< word; git commit -m "docs: string"').message, "docs: string");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("Git directory and index settings select the actual staged files", (t) => {
|
|
242
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-env-"));
|
|
243
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
244
|
+
const outer = initRepo(root, "outer");
|
|
245
|
+
const inner = initRepo(root, "inner repo");
|
|
246
|
+
const alternate = path.join(inner, "alternate.index");
|
|
247
|
+
fs.writeFileSync(path.join(inner, "alternate.js"), "debugger;\n");
|
|
248
|
+
execFileSync("git", ["add", "alternate.js"], {
|
|
249
|
+
cwd: inner,
|
|
250
|
+
env: { ...process.env, GIT_INDEX_FILE: alternate },
|
|
251
|
+
});
|
|
252
|
+
const prefix =
|
|
253
|
+
"env GIT_DIR='../inner repo/.git' GIT_WORK_TREE='../inner repo'" +
|
|
254
|
+
" GIT_INDEX_FILE='../inner repo/alternate.index'";
|
|
255
|
+
assert.match(run(payload(prefix + " git commit -m 'test: index'"), { cwd: outer }).stderr, /alternate\.js:1/);
|
|
256
|
+
const commit = "git commit -m 'test: exported index'";
|
|
257
|
+
const exported = prefix.replace(/^env /, "export ");
|
|
258
|
+
for (const command of [exported + "; " + commit, "{ " + exported + "; }; " + commit,
|
|
259
|
+
prefix.slice(4) + "; export GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE; " + commit]) {
|
|
260
|
+
assert.match(run(payload(command), { cwd: outer }).stderr, /alternate\.js:1/, command);
|
|
261
|
+
}
|
|
262
|
+
for (const command of ["(" + exported + "); " + commit, exported + " | cat; " + commit,
|
|
263
|
+
exported + "; unset GIT_INDEX_FILE; " + commit, exported + "; export -n GIT_INDEX_FILE; " + commit]) {
|
|
264
|
+
assert.equal(run(payload(command), { cwd: outer }).stderr, undefined, command);
|
|
265
|
+
}
|
|
266
|
+
assert.match(run(payload("export GIT_INDEX_FILE=$LATER; " + commit), { cwd: outer }).stderr, /无法检查暂存区/);
|
|
267
|
+
|
|
268
|
+
assert.match(
|
|
269
|
+
run(payload('GIT_INDEX_FILE="$OTHER_INDEX" git commit -m "test: dynamic"'), { cwd: outer }).stderr,
|
|
270
|
+
/无法检查暂存区/,
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("command substitution, nested subshells, heredoc messages, wrappers, and Windows paths", (t) => {
|
|
275
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "cew-cq-edge-"));
|
|
276
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
277
|
+
const repo = initRepo(root, "repo");
|
|
278
|
+
const inner = initRepo(repo, "inner");
|
|
279
|
+
const secret = "skTest0123456789abcdef012345";
|
|
280
|
+
fs.writeFileSync(path.join(inner, "s.js"), `const apiKey = "${secret}";\n`);
|
|
281
|
+
git(inner, "add", "s.js");
|
|
282
|
+
|
|
283
|
+
// $(...) in -C / GIT_DIR must warn explicitly rather than silently skipping or scanning wrong dir.
|
|
284
|
+
const subArg = run(payload('git -C $(pwd)/inner commit -m "feat: sub"'), { cwd: repo });
|
|
285
|
+
assert.match(subArg.stderr, /无法检查暂存区/);
|
|
286
|
+
const dynEnv = run(payload('GIT_DIR=$(git rev-parse --git-dir) git commit -m "feat: dyn"'), { cwd: inner });
|
|
287
|
+
assert.match(dynEnv.stderr, /无法检查暂存区/);
|
|
288
|
+
|
|
289
|
+
// $(...) in non-path option (-c) still runs and catches staged secret.
|
|
290
|
+
const cfgSub = run(payload('git -c user.name=$(whoami) commit -m "feat: c"'), { cwd: inner });
|
|
291
|
+
assert.equal(cfgSub.exitCode, 2);
|
|
292
|
+
assert.match(cfgSub.stderr, /s\.js:1/);
|
|
293
|
+
|
|
294
|
+
// Bare nested subshells ((cd inner); git commit) must not be dropped as arithmetic.
|
|
295
|
+
const nested = run(payload('((cd inner); git commit -m "feat: nested")'), { cwd: repo });
|
|
296
|
+
assert.equal(nested.exitCode, 0);
|
|
297
|
+
const nestedIn = run(payload('(cd inner && (git commit -m "feat: in"))'), { cwd: repo });
|
|
298
|
+
assert.equal(nestedIn.exitCode, 2);
|
|
299
|
+
|
|
300
|
+
// Claude Code heredoc commit with internal quotes and semicolons: no false format warning or split.
|
|
301
|
+
const heredocCmd = 'git commit -m "$(cat <<\'EOF\'\nfix: handle "foo; cd /tmp"\nEOF\n)"';
|
|
302
|
+
const heredocRes = run(payload(heredocCmd), { cwd: repo });
|
|
303
|
+
assert.equal(heredocRes.exitCode, 0);
|
|
304
|
+
assert.equal(heredocRes.stderr, undefined);
|
|
305
|
+
|
|
306
|
+
// cd -P, control keywords, wrappers, and ~ path warning.
|
|
307
|
+
const cdFlag = run(payload('cd -P inner && git commit -m "feat: flag"'), { cwd: repo });
|
|
308
|
+
assert.equal(cdFlag.exitCode, 2);
|
|
309
|
+
const ifWrap = run(payload('if true; then command git -C inner commit -m "feat: if"; fi'), { cwd: repo });
|
|
310
|
+
assert.equal(ifWrap.exitCode, 2);
|
|
311
|
+
const tildeWarn = run(payload('git -C ~/repo commit -m "feat: tilde"'), { cwd: repo });
|
|
312
|
+
assert.match(tildeWarn.stderr, /无法检查暂存区/);
|
|
313
|
+
|
|
314
|
+
// git add && git commit emits pre-staging notice.
|
|
315
|
+
const addCommit = run(payload('git add clean.js && git commit -m "feat: staged"'), { cwd: repo });
|
|
316
|
+
assert.match(addCommit.stderr, /仅检查执行前的已暂存区/);
|
|
317
|
+
|
|
318
|
+
// Windows paths and git.exe recognition.
|
|
319
|
+
const winCd = extractGitCommitInvocation('cd C:\\Users\\dev\\repo && git commit -m "feat: win"', "/tmp/base");
|
|
320
|
+
assert.equal(winCd.cdDir, "C:\\Users\\dev\\repo");
|
|
321
|
+
const winC = extractGitCommitInvocation('git -C C:\\Users\\dev\\repo commit -m "feat: winc"');
|
|
322
|
+
assert.deepEqual(winC.gitDirArgs, ["-C", "C:\\Users\\dev\\repo"]);
|
|
323
|
+
const winExe = extractGitCommitInvocation('"C:\\Program Files\\Git\\cmd\\git.exe" commit -m "feat: exe"');
|
|
324
|
+
assert.ok(winExe);
|
|
325
|
+
assert.equal(winExe.message, "feat: exe");
|
|
326
|
+
|
|
327
|
+
// Non-git and invalid -C errors preserve stderr reason rather than truncated command line.
|
|
328
|
+
const nonGit = run(payload('git commit -m "feat: nongit"'), { cwd: root });
|
|
329
|
+
assert.match(nonGit.stderr, /unknown option.*cached|not a git repository/i);
|
|
330
|
+
assert.doesNotMatch(nonGit.stderr, /Command failed:/);
|
|
331
|
+
const badDir = run(payload('git -C ./no-such-dir commit -m "feat: bad"'), { cwd: root });
|
|
332
|
+
assert.match(badDir.stderr, /cannot change to|No such file/i);
|
|
333
|
+
|
|
334
|
+
// env -i clears inherited GIT_* env vars, and identical sequential commits emit scan warnings once.
|
|
335
|
+
const origGitDir = process.env.GIT_DIR;
|
|
336
|
+
process.env.GIT_DIR = path.join(root, "nonexistent.git");
|
|
337
|
+
try {
|
|
338
|
+
const envCleared = run(payload('env -i git commit -m "feat: env-clear"'), { cwd: inner });
|
|
339
|
+
assert.equal(envCleared.exitCode, 2);
|
|
340
|
+
assert.match(envCleared.stderr, /s\.js:1/);
|
|
341
|
+
} finally {
|
|
342
|
+
if (origGitDir === undefined) delete process.env.GIT_DIR;
|
|
343
|
+
else process.env.GIT_DIR = origGitDir;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const dup = run(payload('git commit -m "feat: one" && git commit -m "feat: two"'), { cwd: inner });
|
|
347
|
+
assert.equal(dup.exitCode, 2);
|
|
348
|
+
assert.equal(dup.stderr.match(/s\.js:1/g)?.length, 1);
|
|
349
|
+
|
|
350
|
+
// env -u / -i applies in order and conditional branches do not assume cd/export took effect.
|
|
351
|
+
const unsetEnv = run(
|
|
352
|
+
payload("GIT_DIR=inner/.git GIT_WORK_TREE=inner env -u GIT_DIR -u GIT_WORK_TREE git commit -m 'feat: outer'"),
|
|
353
|
+
{ cwd: repo },
|
|
354
|
+
);
|
|
355
|
+
assert.equal(unsetEnv.exitCode, 0);
|
|
356
|
+
assert.equal(unsetEnv.stderr, undefined);
|
|
357
|
+
|
|
358
|
+
const clearedPrefix = run(payload("GIT_DIR=inner/.git env -i git commit -m 'feat: outer'"), { cwd: repo });
|
|
359
|
+
assert.equal(clearedPrefix.exitCode, 0);
|
|
360
|
+
assert.equal(clearedPrefix.stderr, undefined);
|
|
361
|
+
|
|
362
|
+
for (const condCmd of [
|
|
363
|
+
"if false; then cd inner; fi; git commit -m 'feat: outer'",
|
|
364
|
+
"false && cd inner; git commit -m 'feat: outer'",
|
|
365
|
+
"true || cd inner; git commit -m 'feat: outer'",
|
|
366
|
+
"if false; then export GIT_DIR=inner/.git GIT_WORK_TREE=inner; fi; git commit -m 'feat: outer'",
|
|
367
|
+
]) {
|
|
368
|
+
const condRes = run(payload(condCmd), { cwd: repo });
|
|
369
|
+
assert.equal(condRes.exitCode, 0, condCmd);
|
|
370
|
+
assert.match(condRes.stderr, /无法检查暂存区/, condCmd);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const inBranch = run(payload("if true; then cd inner && git commit -m 'feat: in'; fi"), { cwd: repo });
|
|
374
|
+
assert.equal(inBranch.exitCode, 2);
|
|
375
|
+
assert.match(inBranch.stderr, /s\.js:1/);
|
|
376
|
+
|
|
377
|
+
const elseBranch = run(payload("if false; then cd inner; else git commit -m 'feat: else'; fi"), { cwd: repo });
|
|
378
|
+
assert.equal(elseBranch.exitCode, 0);
|
|
379
|
+
assert.equal(elseBranch.stderr, undefined);
|
|
380
|
+
|
|
381
|
+
// command suppresses function lookup; array assignments are data; cd -P resolves physical symlinks.
|
|
382
|
+
const bypassCmd = "git() { /usr/bin/git commit -m 'test: helper'; }; command git status --short";
|
|
383
|
+
const bypassRes = run(payload(bypassCmd), { cwd: inner });
|
|
384
|
+
assert.equal(bypassRes.exitCode, 0);
|
|
385
|
+
assert.equal(bypassRes.stderr, undefined);
|
|
386
|
+
|
|
387
|
+
const cmdV = run(payload("command -v git commit -m 'test: v'"), { cwd: inner });
|
|
388
|
+
assert.equal(cmdV.exitCode, 0);
|
|
389
|
+
assert.equal(cmdV.stderr, undefined);
|
|
390
|
+
|
|
391
|
+
for (const arrCmd of [
|
|
392
|
+
"args=(git commit -m 'test: example'); printf '%s\\n' \"${args[@]}\"",
|
|
393
|
+
"args=( git commit -m 'test: spaced' )",
|
|
394
|
+
]) {
|
|
395
|
+
const arrRes = run(payload(arrCmd), { cwd: inner });
|
|
396
|
+
assert.equal(arrRes.exitCode, 0, arrCmd);
|
|
397
|
+
assert.equal(arrRes.stderr, undefined, arrCmd);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const physOuter = initRepo(root, "phys-outer");
|
|
401
|
+
fs.writeFileSync(path.join(physOuter, "secret.js"), `const apiKey = "${secret}";\n`);
|
|
402
|
+
git(physOuter, "add", "secret.js");
|
|
403
|
+
const physInner = initRepo(root, "phys-inner");
|
|
404
|
+
const physChild = path.join(physInner, "child");
|
|
405
|
+
fs.mkdirSync(physChild, { recursive: true });
|
|
406
|
+
fs.symlinkSync(physChild, path.join(physOuter, "link"), process.platform === "win32" ? "junction" : "dir");
|
|
407
|
+
const physRes = run(payload("cd -P link/.. && git commit -m 'test: physical'"), { cwd: physOuter });
|
|
408
|
+
assert.equal(physRes.exitCode, 0);
|
|
409
|
+
assert.equal(physRes.stderr, undefined);
|
|
410
|
+
|
|
411
|
+
const badPhys = run(payload("cd -P nonexistent/.. && git commit -m 'feat: bad-phys'"), { cwd: root });
|
|
412
|
+
assert.equal(badPhys.exitCode, 0);
|
|
413
|
+
assert.match(badPhys.stderr, /无法检查暂存区/);
|
|
414
|
+
|
|
415
|
+
// Deterministic return/exit stops unreachable commands without leaking out of subshells.
|
|
416
|
+
for (const unreach of [
|
|
417
|
+
"save() { return 0; git commit -m 'test: unreachable'; }; save; printf done",
|
|
418
|
+
"save() { { return 0; }; git commit -m 'test: brace-unreach'; }; save",
|
|
419
|
+
"exit 0; git commit -m 'test: after-exit'",
|
|
420
|
+
]) {
|
|
421
|
+
const res = run(payload(unreach), { cwd: inner });
|
|
422
|
+
assert.equal(res.exitCode, 0, unreach);
|
|
423
|
+
assert.equal(res.stderr, undefined, unreach);
|
|
424
|
+
}
|
|
425
|
+
for (const reach of [
|
|
426
|
+
"save() { ( return 0; git commit -m 'test: sub-unreach' ); git commit -m 'feat: after-sub'; }; save",
|
|
427
|
+
"save() { if false; then return 0; fi; git commit -m 'feat: cond-reach'; }; save",
|
|
428
|
+
"save() { false && return 0; git commit -m 'feat: short-reach'; }; save",
|
|
429
|
+
"f() { exit 0; }; false && f; git commit -m 'feat: cond-fn-exit'",
|
|
430
|
+
"save() { if false; then { return 0; }; fi; git commit -m 'feat: cond-brace-ret'; }; save",
|
|
431
|
+
"{ exit 0; } | cat; git commit -m 'feat: pipe-brace-exit'",
|
|
432
|
+
]) {
|
|
433
|
+
const res = run(payload(reach), { cwd: inner });
|
|
434
|
+
assert.equal(res.exitCode, 2, reach);
|
|
435
|
+
assert.match(res.stderr, /s\.js:1/, reach);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// exec -c clears inherited Git env, and local -x applies within the function without leaking out.
|
|
439
|
+
const prevGitDir = process.env.GIT_DIR;
|
|
440
|
+
const prevGitWorkTree = process.env.GIT_WORK_TREE;
|
|
441
|
+
process.env.GIT_DIR = path.join(inner, ".git");
|
|
442
|
+
process.env.GIT_WORK_TREE = inner;
|
|
443
|
+
try {
|
|
444
|
+
const execClear = run(payload("exec -c git commit -m 'feat: exec-c'"), { cwd: repo });
|
|
445
|
+
assert.equal(execClear.exitCode, 0);
|
|
446
|
+
assert.equal(execClear.stderr, undefined);
|
|
447
|
+
} finally {
|
|
448
|
+
if (prevGitDir === undefined) delete process.env.GIT_DIR;
|
|
449
|
+
else process.env.GIT_DIR = prevGitDir;
|
|
450
|
+
if (prevGitWorkTree === undefined) delete process.env.GIT_WORK_TREE;
|
|
451
|
+
else process.env.GIT_WORK_TREE = prevGitWorkTree;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const execPrefixClear = run(
|
|
455
|
+
payload("GIT_DIR=inner/.git GIT_WORK_TREE=inner exec -c git commit -m 'feat: prefix-exec-c'"),
|
|
456
|
+
{ cwd: repo },
|
|
457
|
+
);
|
|
458
|
+
assert.equal(execPrefixClear.exitCode, 0);
|
|
459
|
+
assert.equal(execPrefixClear.stderr, undefined);
|
|
460
|
+
|
|
461
|
+
const localIn = run(
|
|
462
|
+
payload("save() { local -x GIT_DIR=inner/.git GIT_WORK_TREE=inner; git commit -m 'feat: local-in'; }; save"),
|
|
463
|
+
{ cwd: repo },
|
|
464
|
+
);
|
|
465
|
+
assert.equal(localIn.exitCode, 2);
|
|
466
|
+
assert.match(localIn.stderr, /s\.js:1/);
|
|
467
|
+
|
|
468
|
+
const localOut = run(
|
|
469
|
+
payload("save() { local -x GIT_DIR=inner/.git GIT_WORK_TREE=inner; }; save; git commit -m 'feat: local-out'"),
|
|
470
|
+
{ cwd: repo },
|
|
471
|
+
);
|
|
472
|
+
assert.equal(localOut.exitCode, 0);
|
|
473
|
+
assert.equal(localOut.stderr, undefined);
|
|
474
|
+
|
|
475
|
+
const localClean = run(
|
|
476
|
+
payload("save() { local -x GIT_DIR=../.git GIT_WORK_TREE=..; git commit -m 'feat: local-clean'; }; save"),
|
|
477
|
+
{ cwd: inner },
|
|
478
|
+
);
|
|
479
|
+
assert.equal(localClean.exitCode, 0);
|
|
480
|
+
assert.equal(localClean.stderr, undefined);
|
|
481
|
+
});
|