yadflow 4.8.0 → 4.10.0
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/CHANGELOG.md +114 -0
- package/README.md +4 -3
- package/bin/commands.mjs +7 -0
- package/bin/yad.mjs +123 -8
- package/cli/agent-guard.mjs +793 -65
- package/cli/agent-rules.mjs +40 -5
- package/cli/argv-flags.mjs +1 -1
- package/cli/build.mjs +1 -1
- package/cli/ci-check.mjs +45 -1
- package/cli/codeowners-command.mjs +72 -6
- package/cli/commit.mjs +17 -3
- package/cli/docs.mjs +2 -0
- package/cli/doctor.mjs +176 -12
- package/cli/epic-state.mjs +94 -4
- package/cli/epic.mjs +11 -7
- package/cli/fold.mjs +31 -6
- package/cli/guide.mjs +3 -1
- package/cli/hook.mjs +50 -7
- package/cli/issue-links.mjs +61 -0
- package/cli/issues-act.mjs +327 -0
- package/cli/issues-write.mjs +428 -0
- package/cli/issues.mjs +474 -0
- package/cli/lifecycle.mjs +7 -0
- package/cli/machine.mjs +141 -0
- package/cli/manifest.mjs +9 -3
- package/cli/openpr.mjs +69 -9
- package/cli/plan.mjs +2 -0
- package/cli/platform.mjs +157 -2
- package/cli/preview.mjs +253 -0
- package/cli/protection.mjs +21 -3
- package/cli/reconcile.mjs +1 -1
- package/cli/repo.mjs +64 -3
- package/cli/review.mjs +4 -0
- package/cli/run-checks.mjs +10 -2
- package/cli/scan.mjs +314 -0
- package/cli/setup.mjs +12 -3
- package/cli/standup.mjs +33 -7
- package/cli/story-frames.mjs +307 -0
- package/cli/test-agents-file.mjs +378 -11
- package/cli/test-build.mjs +25 -0
- package/cli/test-ci-check.mjs +469 -10
- package/cli/test-guide.mjs +7 -0
- package/cli/test-machine.mjs +140 -0
- package/cli/test-node.mjs +15 -0
- package/cli/test-preview.mjs +511 -0
- package/cli/test-run-checks.mjs +17 -0
- package/cli/test-setup-agent.mjs +14 -0
- package/cli/test-story-frames.mjs +409 -0
- package/cli/toolbox-connect.mjs +244 -0
- package/cli/toolbox.mjs +159 -5
- package/package.json +7 -3
- package/skills/sdlc/config.yaml +1 -1
- package/skills/sdlc/module-help.csv +3 -1
- package/skills/yad-analysis/SKILL.md +4 -0
- package/skills/yad-backfill/SKILL.md +4 -0
- package/skills/yad-change/SKILL.md +4 -0
- package/skills/yad-checks/SKILL.md +13 -7
- package/skills/yad-checks/references/check-gates.md +62 -30
- package/skills/yad-checks/templates/checks/member-check.mjs +3 -2
- package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
- package/skills/yad-checks/templates/checks/verified-commits.sh +3 -3
- package/skills/yad-checks/templates/github/yad-checks.yml +357 -69
- package/skills/yad-checks/templates/github/yad-pr-text.yml +118 -0
- package/skills/yad-checks/templates/github/yad-product-checks.yml +130 -54
- package/skills/yad-checks/templates/github/yad-product-pr-text.yml +131 -0
- package/skills/yad-checks/templates/github/yad-update-guard.yml +2 -1
- package/skills/yad-checks/templates/github/yad-verified-commits.yml +49 -3
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +79 -20
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +59 -9
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +1 -0
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +49 -1
- package/skills/yad-checks/templates/hooks/agent-guard.mjs +44 -10
- package/skills/yad-checks/templates/hooks/ledger-guard-cursor.mjs +12 -6
- package/skills/yad-commit/SKILL.md +3 -1
- package/skills/yad-connect-design/SKILL.md +48 -13
- package/skills/yad-connect-design/references/design-context.md +56 -3
- package/skills/yad-connect-design/references/design-registry.md +4 -4
- package/skills/yad-connect-learning/SKILL.md +12 -2
- package/skills/yad-connect-repos/SKILL.md +12 -0
- package/skills/yad-connect-testing/SKILL.md +22 -5
- package/skills/yad-connect-testing/references/testing-context.md +1 -1
- package/skills/yad-engineer-review/SKILL.md +13 -0
- package/skills/yad-epic/SKILL.md +4 -0
- package/skills/yad-epic/references/state-schema.md +21 -0
- package/skills/yad-guide/SKILL.md +8 -4
- package/skills/yad-implement/SKILL.md +69 -3
- package/skills/yad-implement/references/implement-conventions.md +2 -1
- package/skills/yad-issues/SKILL.md +53 -0
- package/skills/yad-learn/SKILL.md +4 -0
- package/skills/yad-open-pr/SKILL.md +10 -1
- package/skills/yad-pair-review/SKILL.md +5 -0
- package/skills/yad-pr-template/SKILL.md +2 -1
- package/skills/yad-pr-template/templates/checks/pr-title.sh +34 -2
- package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -0
- package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -0
- package/skills/yad-product-bridge/references/bridge.md +28 -0
- package/skills/yad-product-bridge/templates/github/yad-gate-sync.yml +25 -11
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +38 -14
- package/skills/yad-review-companion/SKILL.md +4 -1
- package/skills/yad-run/SKILL.md +5 -0
- package/skills/yad-scan/SKILL.md +51 -0
- package/skills/yad-spec/SKILL.md +32 -0
- package/skills/yad-stories/SKILL.md +22 -0
- package/skills/yad-stories/references/story-schema.md +1 -0
- package/skills/yad-test-cases/SKILL.md +18 -2
- package/skills/yad-ui/SKILL.md +48 -8
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +0 -49
package/cli/test-agents-file.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
12
12
|
import fs from 'node:fs';
|
|
13
13
|
import os from 'node:os';
|
|
14
14
|
import path from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
15
16
|
|
|
16
17
|
// The #280 guard (cli/test.mjs): printed lines go to stderr while the runner owns stdout.
|
|
17
18
|
if (process.env.NODE_TEST_CONTEXT) {
|
|
@@ -279,6 +280,75 @@ test('the agent guard refuses every human-only yad command and every force push,
|
|
|
279
280
|
'cat <<< "x"\nyad gate approve EP-x epic',
|
|
280
281
|
'echo $((1<<2))\nyad gate approve EP-x epic',
|
|
281
282
|
'cat <<EOF\r\nx\r\nEOF\r\nyad gate approve EP-x epic',
|
|
283
|
+
// #492: the reader splits as bash and zsh do. A CR is a word character (so `x\r#` holds no comment), a heredoc's
|
|
284
|
+
// end word is every character the shell reads as one word and its end line must match exactly, `(` and `)`
|
|
285
|
+
// end a part, and a command nested past three levels is refused.
|
|
286
|
+
'x\r#; gh pr merge 5', 'x\r#; yad gate approve EP-x epic', 'cat <<EOF#;gh pr merge 5\nbody\nEOF#\n', 'cat <<EOF#;git push --force\nb\nEOF#',
|
|
287
|
+
'cat <<EOF+\nEOF\ncat <<X\nEOF+\ngh pr merge 5\nX\n', 'cat <<EOF\nEOF\r\ncat <<X\nEOF\ngh pr merge 5\nX\n', 'cat <<EOF\r\nEOF\ncat <<X\nEOF\r\ngh pr merge 5\nX\n',
|
|
288
|
+
'cat <(gh pr merge 5)', 'echo x > >(gh pr merge 5)', 'f(){ gh pr merge 5; }; f', 'case x in x) gh pr merge 5;; esac', '(gh pr merge 5)',
|
|
289
|
+
'echo $(echo $(echo $(echo $(gh pr merge 5))))', 'echo $(echo $(echo $(echo $(echo hi))))', "bash -c 'bash -c \"bash -c \\\"bash -c ls\\\"\"'",
|
|
290
|
+
'git push --force\r', 'git push \\\r\n--force',
|
|
291
|
+
// #492 review: a `\`-newline join hiding a `$(` or splitting an end word; an end word holding `$` (the outer
|
|
292
|
+
// shell expands it first); and a heredoc that never ends, whose `$(…)` the shell still runs.
|
|
293
|
+
'echo "$\\\r\n(gh pr merge 5)"', 'cat <<EOF\r\n$\\\r\n(npx yadflow gate advance EP-x)\nEOF\r\n', 'echo "$\\\n(gh pr merge 5)"', 'cat <<EOF\n$\\\n(gh pr merge 5)\nEOF',
|
|
294
|
+
'cat <<EOF\nx\nEO\\\nF\ngh pr merge 5\nEOF\n', 'bash -c "cat <<EOF$x\nEOF\ngh pr merge 5\nEOF$x"', 'bash -lc "cat <<E$F\nE$Fx\ngh pr merge 5\nE$F\n"',
|
|
295
|
+
'cat <<< "x"\ncat <<EOF+\nbody\nEOF#\ncat <<\'EOF\'\n$(git push --force)\nEOF\n\n', "cat <<X\ncat <<'EOF'\n$(gh pr merge 5)\nEOF", "cat <<X\necho '$(gh pr merge 5)'",
|
|
296
|
+
// #492 review 2: an expanding end word is still a redirect, read past; a `#` right after `(` or `)` starts no comment.
|
|
297
|
+
'<<"E$x" gh pr merge 1', 'echo hi; <<"E$x" gh pr merge 1', "<<'E`x`' yad gate approve EP-a", '<<E$x gh pr merge 1', 'x=1 <<E$x gh pr merge 1',
|
|
298
|
+
'[[ a =~ (#|$(gh pr merge 1)) ]]', '[[ a =~ (#|`gh pr merge 1`) ]]', '[[ a =~ (x)#$(gh pr merge 1) ]]', 'shopt -s extglob\necho @(#$(gh pr merge 1))',
|
|
299
|
+
'echo foo(#$(gh pr merge 1))', 'ls foo(#q$(gh pr merge 1))', 'A((#$(gh pr merge 1)', '<<<((###;gh pr merge 1',
|
|
300
|
+
// #492 review 3: every reading the shells may make — an expanding end word as a heredoc, as none, and line by
|
|
301
|
+
// line (its value is unknown); a `#` after a parenthesis as a comment (command position) and as text.
|
|
302
|
+
'cat <<"E$x"\n\'\nE$x\ngh pr merge 1', "cat <<'E$x'\n'\nE$x\ngh pr merge 1", 'cat <<"E$x"\n"\nE$x\ngh pr merge 1', 'bash -c "cat <<E$x\n\'\nE\ngh pr merge 1"',
|
|
303
|
+
'x=F; bash -c "cat <<E$x\n\'\nEF\ngh pr merge 1"', "cat <<E$x\nit's a note\nE$x\ngh pr merge 1",
|
|
304
|
+
"(cd web && npm ci)# don't skip\ngh pr merge 1", "(true)# x '\ngh pr merge 1", "(# '\ngh pr merge 1\n)", "if (true)# '\nthen gh pr merge 1; fi",
|
|
305
|
+
"x=(# '\n$(gh pr merge 1)\n)", "f()# '\n{ gh pr merge 1; }; f", "()# x '\ngh pr merge 1", "x=(a b)# don't\ngh pr merge 1",
|
|
306
|
+
// A body of many `$(` overflowed the stack (the hook then exited 1, which lets the command run).
|
|
307
|
+
`cat <<E >/dev/null\n${'$((1))\n'.repeat(130000)}$(gh pr merge 1)\n`, `cat <<E >/dev/null\n${'$((1))'.repeat(130000)}\nE\ngh pr merge 1\n`,
|
|
308
|
+
// #495: redirects in the middle of a command, $'…' strings, options after bash -c, more prefixes, commands
|
|
309
|
+
// that carry a command, an expanding command word, a shell fed its script, case inside $(…), # after |.
|
|
310
|
+
'git push origin main 2>&1 --force', 'git commit -m x 2>&1 --no-verify', '>out gh pr merge 5', 'gh >x pr merge 5', 'x=<<<1 git commit --no-verify -m x',
|
|
311
|
+
'git push --force>/dev/null', 'yad gate approve> EP-x epic', "git commit -m $'fix: don\\'t\\n' && gh pr merge 5 && echo 'done'", "bash -c $'gh pr merge 5'",
|
|
312
|
+
'bash -c $"gh pr merge 5"', 'bash -c -- "gh pr merge 5"', 'bash -c -x "gh pr merge 5"', 'bash -c -o pipefail "gh pr merge 5"', 'env -S "gh pr merge 5"',
|
|
313
|
+
'env --split-string="gh pr merge 5"', 'exec -a x gh pr merge 5', 'builtin command gh pr merge 5', 'function f { gh pr merge 5; }; f', 'coproc gh pr merge 5',
|
|
314
|
+
'coproc c { gh pr merge 5; }', 'find . -exec gh pr merge 5 \\;', 'find . -execdir git push --force {} +', "git -c alias.p='push --force' p", "git -c alias.m='!gh pr merge 5' m",
|
|
315
|
+
'noglob gh pr merge 5', '{gh pr merge 5;}', 'eval "gh pr merge 5"', 'eval gh pr merge 5', 'echo "gh pr merge 5" | bash', "printf 'gh pr merge 5' | sh",
|
|
316
|
+
'$(echo gh) pr merge 5', '${x:-gh} pr merge 5', '{gh,} pr merge 5', '$CMD pr merge 5', 'echo $(case x in x) gh pr merge 5;; esac)', '[[ a =~ x|#$(gh pr merge 1) ]]',
|
|
317
|
+
'bash <<EOF\ngh pr merge 5\nEOF', "sh <<'EOF'\ngit push --force\nEOF", 'bash <<< "gh pr merge 5"',
|
|
318
|
+
// #495 review: zsh's numeric globs are one word (both readings); and the gaps of the same kinds.
|
|
319
|
+
'git push origin main <-> --force', 'git push <1-9> --force', 'git commit -m x <-> --no-verify', 'git commit -am x <1-3000> -n', 'gh pr review >> 5 <1-9> --approve',
|
|
320
|
+
'bash -c - "gh pr merge 5"', '$SUDO gh pr merge 5', '${DRY} git push --force', '$X yad gate approve EP-x epic', '$SHELL -c "gh pr merge 5"', '$(which bash) -c "gh pr merge 5"',
|
|
321
|
+
'{bash,} -c "gh pr merge 5"', "find . -exec sh -c 'git push --force' {} +", 'env -u X -S "gh pr merge 5"', 'env -C . -S "gh pr merge 5"', "printf '%s\\n' 'gh pr merge 5' | bash",
|
|
322
|
+
'printf "%s" "gh pr merge 5" | bash', 'echo gh pr merge 5 | tee /dev/null | bash', "cat <<'EOF' | bash\ngh pr merge 5\nEOF", 'source /dev/stdin <<< "gh pr merge 5"',
|
|
323
|
+
'. /dev/stdin <<< "gh pr merge 5"', 'git push origin main --{force,}', 'gh pr {merge,} 5', 'git commit -m x --no-{verify,}', '=gh pr merge 5', "git -c alias.a=b -c alias.b='push --force' a",
|
|
324
|
+
// #495 review 2: a shell reads its input after -s, from /dev/stdin, past --rcfile; a brace list expands into words.
|
|
325
|
+
"echo 'gh pr merge 5' | bash -s foo", "bash -s foo <<'EOF'\ngit push --force origin main\nEOF", "echo 'yad gate approve EP-x analysis' | bash /dev/stdin",
|
|
326
|
+
"bash /dev/stdin <<< 'gh pr review 5 --approve'", "zsh /dev/stdin <<< 'git commit -n -m x'", "sh /dev/fd/0 <<'EOF'\nglab mr merge 5\nEOF", "echo 'gh pr merge 5' | bash --rcfile /dev/null",
|
|
327
|
+
"echo 'gh pr merge 5' | bash -xs foo", "echo 'gh pr merge 5' | ksh -s a", "cat <<'EOF' | bash -s x\ngh pr merge 5\nEOF", 'gh {pr,merge} 5', '{gh,pr} merge 5', 'git {push,--force} origin main',
|
|
328
|
+
'git {commit,-n} -m x', 'yad {gate,approve} EP-x analysis', 'gh {pr,review} 5 --approve', 'git push origin main {x,--fo}{rce,y}', 'git push origin {a,{--force,b}}', 'git push -{f..f} origin main',
|
|
329
|
+
'git push origin {main,main,main,main,main,main,main,main,--force}',
|
|
330
|
+
// #495 review 3: empty alternatives (bash drops the empty words); option clusters with o; zsh --emulate; a brace
|
|
331
|
+
// list or an expansion in a shell's words; zsh's one-character sequences.
|
|
332
|
+
'gh pr {,merge} 5', 'gh {,pr} merge 5', "bash -c 'gh pr {,merge} 5'", 'echo {,}; gh pr {,,merge} 5', 'gh pr {,{,{merge,x}}} 5',
|
|
333
|
+
"bash -euo pipefail <<'EOF'\ngh pr merge 5\nEOF", "echo 'gh pr merge 5' | bash -eo pipefail", "zsh --emulate sh <<< 'gh pr merge 5'", "echo 'gh pr merge 5' | bash {-s,}",
|
|
334
|
+
"{bash,} <<< 'gh pr merge 5'", "echo 'gh pr merge 5' | $SHELL", "${SHELL:-bash} <<< 'gh pr merge 5'", "echo 'gh pr merge 5' | bash $NOPE", 'git push origin {+..+}main',
|
|
335
|
+
'git push origin main -{-..-}force',
|
|
336
|
+
// #495 review 4: text printed in a group or a file reaches a real shell; `\||` is a pipe; quoted brace characters are text.
|
|
337
|
+
"{ echo 'gh pr merge 5'; } | bash", "{ echo 'gh pr merge 5'; } 2>&1 | bash", "(echo 'gh pr merge 5'; true) | bash", "if true; then echo 'gh pr merge 5'; fi | bash",
|
|
338
|
+
"for i in 1; do echo 'gh pr merge 5'; done | bash", "case x in x) echo 'gh pr merge 5';; esac | bash", "{ cat <<'E'; } | bash\ngh pr merge 5\nE", "f() { echo 'gh pr merge 5'; }; f | bash",
|
|
339
|
+
"echo 'gh pr merge 5' > f; bash < f", "echo 'gh pr merge 5 #' \\||bash", "git commit -m {'}',-n}", "git commit -m {'{',-n}", 'git commit -m {"}",--no-verify}', "git commit {-n,'{'} -m x",
|
|
340
|
+
// A typed shield character stays inert, in a carried command too.
|
|
341
|
+
'bash -c "gh pr {merge,} 5"', "eval 'gh pr {merge,} 5'", "echo 'gh pr {merge,} 5' | bash", "bash -c 'git push {--force,}'", "bash -c 'git commit {-n,} -m x'",
|
|
342
|
+
// A word too long to expand, or too many words, is refused rather than expanded: a 1 MB JSON word crashed the heap.
|
|
343
|
+
`echo x${'{'.repeat(200000)}a,b${'}'.repeat(200000)}; gh pr merge 5`, `echo ${'{a,b}'.repeat(190000)}; gh pr merge 5`,
|
|
344
|
+
// E167 review 5: a CRLF heredoc ends at `EOF\r`, as the shell's end word is `EOF\r`; a later plain EOF is not its end.
|
|
345
|
+
'cat <<EOF\r\nb\r\nEOF\r\ngh pr merge 5\nEOF\n', "cat <<'EOF'\r\nb\r\nEOF\r\ngh pr merge 5\nEOF\n",
|
|
346
|
+
// E167 review 4: \ + CR + LF does not join lines in bash or zsh.
|
|
347
|
+
'git log \\\r\ngh pr merge 5', 'git status \\\r\ngit push --force', 'git log \\\r\ngit commit --no-verify -m x',
|
|
348
|
+
// ... and a join to a shell that drops CRs (Git Bash with igncr): refused under either reading.
|
|
349
|
+
'git push \\\r\n--force', 'git push \\\r\n-f', 'yad gate \\\r\napprove EP-x epic', 'gh pr \\\r\nmerge 5',
|
|
350
|
+
// ... also inside a bash -c string built from quoted pieces.
|
|
351
|
+
"bash -c 'git push \\'\"\r\n\"'--force'", "bash -c 'git push \\''\r\n--force'",
|
|
282
352
|
'# <<x\nyad gate approve EP-x epic',
|
|
283
353
|
'env -i yad gate approve EP-x epic',
|
|
284
354
|
'sudo -u me yad gate approve EP-x epic',
|
|
@@ -482,6 +552,92 @@ test('the agent guard lets the rest through: reads, the agent\'s own pushes, tex
|
|
|
482
552
|
]) assert.equal(agentGuardDecision(cmd).allow, true, cmd);
|
|
483
553
|
assert.equal(agentGuardDecision(undefined).allow, true);
|
|
484
554
|
assert.deepEqual(shellParts('a "b c" \'d e\' && f\\ g | h'), [['a', 'b c', 'd e'], ['f g'], ['h']]);
|
|
555
|
+
// #492: a heredoc opened and closed with CRLF is text up to its `EOF\r` line; what follows is a command.
|
|
556
|
+
assert.deepEqual(shellParts('cat <<EOF\r\nb\r\nEOF\r\ngh pr merge 5\r\n'), [['cat'], ['gh', 'pr', 'merge', '5\r']]);
|
|
557
|
+
// A redirect's operator is not a word (#495): `<(` is a part break after it.
|
|
558
|
+
assert.deepEqual(shellParts('cat <(gh pr view 5) | f(){ x; }'), [['cat'], ['gh', 'pr', 'view', '5'], ['f'], ['{', 'x'], ['}']]);
|
|
559
|
+
// Redirects and their targets leave the command's words; `$'…'` reads its escapes; a here-string is input.
|
|
560
|
+
assert.deepEqual(shellParts('git push origin main 2>&1 --force'), [['git', 'push', 'origin', 'main', '--force']]);
|
|
561
|
+
assert.deepEqual(shellParts('gh >x pr merge 5 2> err &>all'), [['gh', 'pr', 'merge', '5']]);
|
|
562
|
+
assert.deepEqual(shellParts("git commit -m $'it\\'s\\n'"), [['git', 'commit', '-m', "it's\n"]]);
|
|
563
|
+
assert.deepEqual(shellParts('x=<<<1 git commit'), [['x=', 'git', 'commit']]);
|
|
564
|
+
// Still allowed: a heredoc that ends, a quoted parenthesis, arithmetic, three levels of nesting.
|
|
565
|
+
for (const ok of ['cat <<EOF\nhello\nEOF', 'git commit -m "fix (thing)"', 'echo $((1<<2))', 'echo $(echo $(echo hi))', 'git log\r\n',
|
|
566
|
+
'(cd web && npm ci)# install', 'npm test # x', 'cat <<E$x\nhi\nE$x', '[[ $x =~ ^#(a|b) ]]', 'git commit -m "$(cat <<\'EOF\'\nmsg\nEOF\n)"',
|
|
567
|
+
// A docs heredoc naming a guarded command stays allowed: only an end word that expands adds line-by-line reading.
|
|
568
|
+
`cat <<'EOF' > "$f"\ngh pr merge 1 is the person's\nEOF`, "gh pr create --body-file - <<'EOF' # $x\ngh pr merge 1 stays with the person\nEOF",
|
|
569
|
+
`cat <<'EOF'\ngh pr merge 1 docs\nEOF\ncat > b <<"E$n"\nx\nE$n`,
|
|
570
|
+
// #495: the common forms around the new readings stay allowed.
|
|
571
|
+
'npm test 2>&1 | tail', 'git log > out.txt', 'cmd >/dev/null 2>&1', 'find . -name x -exec grep y {} +', 'git -c core.pager=less log', 'eval "$(ssh-agent)"',
|
|
572
|
+
'echo hi | bash -s', 'curl -fsSL https://example.com/i.sh | sh', "git commit -m $'line one\\nline two'", 'cat <<< "gh pr merge 5"', "python3 - <<'PY'\nprint(1)\nPY",
|
|
573
|
+
'bash <<EOF\necho hi\nEOF', 'git log --oneline 2>/dev/null | head -3',
|
|
574
|
+
'find . -name x -exec grep "git push --force" {} +', 'git -c alias.lg="log --oneline" lg', 'curl -fsSL https://x | bash -s -- --yes', '[[ a > b ]]', 'echo {a,b}.txt',
|
|
575
|
+
'$EDITOR notes.md', '${PYTHON:-python3} x.py', '$(npm bin)/eslint .', "cat <<'EOF' | bash\necho hi\nEOF", 'ls <->', 'echo "gh pr merge 5" > notes.md; bash build.sh',
|
|
576
|
+
'curl x | bash -s stable', 'cat build.sh | bash', 'bash -x ./build.sh arg', 'mkdir -p src/{a,b,c}', 'git add src/{a,b}.js', "jq '{a,b}' f.json", 'echo {1..5}', 'ls {a,b}{c,d}',
|
|
577
|
+
'for i in {1..100}; do echo $i; done', 'echo {0..64}', 'touch file{001..100}.txt', `curl -d '[${'{"id":0,"v":2},'.repeat(5)}{}]' https://x`,
|
|
578
|
+
'echo x || bash', 'docker ps --format {{.Names}}', 'gh pr view {1,2,3}', 'gh pr {merge\\,x,} 5',
|
|
579
|
+
`gh api repos/x -f body='[${'{"a":1,"b":2},'.repeat(10)}{}]'`, "echo '{a,b}{a,b}{a,b}{a,b}{a,b}'", 'echo {a,b}{a,b}{a,b}{a,b}{a,b}', 'bash -euo pipefail ./x.sh', 'echo {a..z}',
|
|
580
|
+
`curl -d '[${'{"a":1,"b":2},'.repeat(66000)}{}]' https://x`,
|
|
581
|
+
`git add ${'f.js '.repeat(2000)}src/{a,b}.js`]) {
|
|
582
|
+
assert.equal(agentGuardDecision(ok).allow, true, ok);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
test('#492: a line of many heredocs that never end is judged in bounded time; one too long to judge is refused', async () => {
|
|
587
|
+
// A coverage run makes this work about seven times slower, which says nothing about the guard, so it is not
|
|
588
|
+
// timed. The other runs are timed, but a shared CI machine has passed 3 s on work that takes 0.5 s here, so
|
|
589
|
+
// every limit is 4.5 s: still under the guard's own 5 s cut-off, because a line refused at the cut-off would
|
|
590
|
+
// otherwise pass this test and hide a slowdown. Nested tails keep 6 s; that case runs into the cut-off inside
|
|
591
|
+
// the brace expansion by design.
|
|
592
|
+
const within = (ms) => (process.env.NODE_V8_COVERAGE ? Infinity : ms);
|
|
593
|
+
const { MAX_JUDGED } = await import('./agent-guard.mjs');
|
|
594
|
+
const line = `${'cat <<X\n'.repeat(60000)}gh pr merge 5`;
|
|
595
|
+
const t0 = Date.now();
|
|
596
|
+
assert.equal(agentGuardDecision(line).allow, false);
|
|
597
|
+
assert.ok(Date.now() - t0 < within(4500), `took ${Date.now() - t0} ms`);
|
|
598
|
+
// Distinct end words, just under the cap: each end line is found by a lookup, not a scan.
|
|
599
|
+
let distinct = '';
|
|
600
|
+
for (let i = 0; distinct.length < MAX_JUDGED - 20; i++) distinct += `<<A${i}\n`;
|
|
601
|
+
const t1 = Date.now();
|
|
602
|
+
assert.equal(agentGuardDecision(`${distinct}gh pr merge 5`).allow, false);
|
|
603
|
+
assert.ok(Date.now() - t1 < within(4500), `distinct words took ${Date.now() - t1} ms`);
|
|
604
|
+
// Many `$(…)`, each holding a heredoc, near the cap: one line index per text, shared by every `$(` in it.
|
|
605
|
+
for (const unit of ['$(cat <<E\nx\nE\n)', '$(cat <<E\n$(cat <<F\nx\nF\n)\nE\n)']) {
|
|
606
|
+
const many = `${unit.repeat(Math.floor((MAX_JUDGED - 100) / unit.length))}\ngh pr merge 1`;
|
|
607
|
+
const t3 = Date.now();
|
|
608
|
+
assert.equal(agentGuardDecision(many).allow, false);
|
|
609
|
+
assert.ok(Date.now() - t3 < within(4500), `many $( took ${Date.now() - t3} ms`);
|
|
610
|
+
}
|
|
611
|
+
// A run of `<<` with no newline: the expanding-word check reads the matches one by one, never a backtracking regex.
|
|
612
|
+
const t4 = Date.now();
|
|
613
|
+
assert.equal(agentGuardDecision(`gh pr merge 1 # ${'<<'.repeat(125000)}`).allow, false);
|
|
614
|
+
assert.ok(Date.now() - t4 < within(4500), `a run of << took ${Date.now() - t4} ms`);
|
|
615
|
+
// #495 review: a `case` scan per `$(` and a loop over every body for every part were quadratic.
|
|
616
|
+
// Many words under the length bound, each with lists and a nested tail: the budget is checked inside the expansion.
|
|
617
|
+
const nestedTail = `x {a,b}{a,b}{a,b}{a,b}{a,b}{a,b}${'{'.repeat(2000)}${'}'.repeat(2000)};`;
|
|
618
|
+
const t7 = Date.now();
|
|
619
|
+
assert.equal(agentGuardDecision(`${nestedTail.repeat(245)} gh pr merge 5`).allow, false);
|
|
620
|
+
assert.ok(Date.now() - t7 < within(6000), `nested tails took ${Date.now() - t7} ms`);
|
|
621
|
+
// A `{` and many commas with no `}`: the brace check is a scan, never a backtracking regex.
|
|
622
|
+
for (const l of [`echo '{${','.repeat(250000)}'; gh pr merge 5`, `git status {${','.repeat(990000)}`]) {
|
|
623
|
+
const t6 = Date.now();
|
|
624
|
+
agentGuardDecision(l);
|
|
625
|
+
assert.ok(Date.now() - t6 < within(4500), `{ + commas took ${Date.now() - t6} ms`);
|
|
626
|
+
}
|
|
627
|
+
for (const [unit, tail] of [['$()', '$()'], ['$(a) ', '$(a) '], [':<<<x;', 'sh;'], [':<<E\nE\n', 'sh;']]) {
|
|
628
|
+
const l = unit.repeat(Math.floor(495000 / unit.length)) + tail.repeat(Math.floor(495000 / tail.length));
|
|
629
|
+
const t5 = Date.now();
|
|
630
|
+
agentGuardDecision(l);
|
|
631
|
+
assert.ok(Date.now() - t5 < within(4500), `${JSON.stringify(unit)} took ${Date.now() - t5} ms`);
|
|
632
|
+
}
|
|
633
|
+
let inSub = 'echo $(';
|
|
634
|
+
for (let i = 0; i < 10000; i++) inSub += `<<B${i}\n`;
|
|
635
|
+
const t2 = Date.now();
|
|
636
|
+
agentGuardDecision(`${inSub})`);
|
|
637
|
+
assert.ok(Date.now() - t2 < within(4500), `inside $( took ${Date.now() - t2} ms`);
|
|
638
|
+
const long = agentGuardDecision(`echo ${'x'.repeat(MAX_JUDGED)}`);
|
|
639
|
+
assert.equal(long.allow, false);
|
|
640
|
+
assert.match(long.message, /too long to judge/);
|
|
485
641
|
});
|
|
486
642
|
|
|
487
643
|
test('the refusal says what to do instead: the person runs it', () => {
|
|
@@ -509,25 +665,84 @@ const runGuard = (T, payload, env = {}) => {
|
|
|
509
665
|
|
|
510
666
|
test('hooks/agent-guard.mjs: Claude Code reads the exit code, Cursor a JSON verdict, always', () => {
|
|
511
667
|
const T = guardScript();
|
|
668
|
+
// Every assertion carries the hook's exit code, answer and stderr: the reason it allowed is on stderr,
|
|
669
|
+
// and without it a failure on CI (macOS, #459 and #460) said nothing.
|
|
670
|
+
const said = (r) => `hook said ${JSON.stringify(r)}`;
|
|
671
|
+
const parse = (r) => { try { return JSON.parse(r.out); } catch { assert.fail(`not a JSON verdict — ${said(r)}`); } };
|
|
512
672
|
try {
|
|
513
673
|
const claude = (command) => runGuard(T, { hook_event_name: 'PreToolUse', tool_name: 'Bash', tool_input: { command } });
|
|
514
674
|
const denied = claude('yad gate approve EP-a epic --by me');
|
|
515
|
-
assert.equal(denied.code, 2);
|
|
516
|
-
assert.match(denied.err, /the person's to run
|
|
517
|
-
|
|
675
|
+
assert.equal(denied.code, 2, said(denied));
|
|
676
|
+
assert.match(denied.err, /the person's to run/, said(denied));
|
|
677
|
+
const status = claude('yad status');
|
|
678
|
+
assert.equal(status.code, 0, said(status));
|
|
518
679
|
const cursor = (command) => runGuard(T, { hook_event_name: 'beforeShellExecution', command });
|
|
519
680
|
const no = cursor('git push --force');
|
|
520
|
-
assert.equal(no.code, 0);
|
|
521
|
-
assert.equal(
|
|
522
|
-
assert.match(
|
|
523
|
-
|
|
681
|
+
assert.equal(no.code, 0, said(no));
|
|
682
|
+
assert.equal(parse(no).permission, 'deny', said(no));
|
|
683
|
+
assert.match(parse(no).agent_message, /force push/, said(no));
|
|
684
|
+
const ls = cursor('ls');
|
|
685
|
+
assert.deepEqual(parse(ls), { permission: 'allow' }, said(ls));
|
|
524
686
|
// Fail-open: an unreadable payload, a switched-off guard, and no yad at all.
|
|
525
|
-
|
|
526
|
-
assert.equal(
|
|
687
|
+
const junk = runGuard(T, 'not json');
|
|
688
|
+
assert.equal(junk.code, 0, said(junk));
|
|
689
|
+
const off = runGuard(T, { tool_input: { command: 'yad gate advance EP-a epic' } }, { YAD_HOOK_DISABLE: '1' });
|
|
690
|
+
assert.equal(off.code, 0, said(off));
|
|
527
691
|
const none = runGuard(T, { hook_event_name: 'beforeShellExecution', command: 'git push -f' }, { YAD_BIN: '', PATH: '' });
|
|
528
|
-
assert.deepEqual(
|
|
529
|
-
assert.match(none.err, /allowing
|
|
692
|
+
assert.deepEqual(parse(none), { permission: 'allow' }, said(none));
|
|
693
|
+
assert.match(none.err, /allowing/, said(none));
|
|
694
|
+
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
test('the hooks read a payload that arrives late or in pieces, retry a pipe that is not ready (EAGAIN), and never lose a verdict at exit', async () => {
|
|
698
|
+
const { readStdin } = await import('./hook.mjs');
|
|
699
|
+
// EAGAIN twice, then data in two pieces, then the end: all of it, once.
|
|
700
|
+
const pieces = [Buffer.from('{"a":'), Buffer.from('1}')];
|
|
701
|
+
let calls = 0;
|
|
702
|
+
const fake = (fd, buf) => {
|
|
703
|
+
calls += 1;
|
|
704
|
+
if (calls <= 2) throw Object.assign(new Error('try again'), { code: 'EAGAIN' });
|
|
705
|
+
const next = pieces.shift();
|
|
706
|
+
if (!next) return 0;
|
|
707
|
+
next.copy(buf);
|
|
708
|
+
return next.length;
|
|
709
|
+
};
|
|
710
|
+
assert.equal(readStdin({ readSync: fake }), '{"a":1}');
|
|
711
|
+
// Windows ends a pipe with an EOF error rather than a read of 0.
|
|
712
|
+
let once = false;
|
|
713
|
+
assert.equal(readStdin({ readSync: (fd, buf) => { if (once) throw Object.assign(new Error('end'), { code: 'EOF' }); once = true; buf.write('x'); return 1; } }), 'x');
|
|
714
|
+
// A pipe that never becomes ready gives up after the limit, and the caller fails open.
|
|
715
|
+
const t0 = Date.now();
|
|
716
|
+
assert.throws(() => readStdin({ readSync: () => { throw Object.assign(new Error('try again'), { code: 'EAGAIN' }); }, limitMs: 50 }), /try again/);
|
|
717
|
+
assert.ok(Date.now() - t0 < 2000, 'the limit holds');
|
|
718
|
+
assert.throws(() => readStdin({ readSync: () => { throw Object.assign(new Error('bad'), { code: 'EBADF' }); } }), /bad/, 'any other error goes to the caller');
|
|
719
|
+
// The real script, its payload written late and in pieces: the verdict is still right.
|
|
720
|
+
const T = guardScript();
|
|
721
|
+
try {
|
|
722
|
+
const { spawn } = await import('node:child_process');
|
|
723
|
+
const child = spawn(process.execPath, [path.join(T, 'hooks/agent-guard.mjs')], {
|
|
724
|
+
cwd: T, stdio: ['pipe', 'pipe', 'pipe'],
|
|
725
|
+
env: { ...process.env, YAD_BIN: `"${process.execPath}" "${YAD_MJS}"`, YAD_HOOK_DISABLE: '' },
|
|
726
|
+
});
|
|
727
|
+
let out = ''; let err = '';
|
|
728
|
+
child.stdout.on('data', (d) => { out += d; });
|
|
729
|
+
child.stderr.on('data', (d) => { err += d; });
|
|
730
|
+
const payload = JSON.stringify({ hook_event_name: 'beforeShellExecution', command: 'git push --force' });
|
|
731
|
+
child.stdin.write(payload.slice(0, 10));
|
|
732
|
+
const { setTimeout: sleep } = await import('node:timers/promises');
|
|
733
|
+
await sleep(300);
|
|
734
|
+
child.stdin.end(payload.slice(10));
|
|
735
|
+
const code = await new Promise((r) => child.on('close', r));
|
|
736
|
+
assert.equal(code, 0, err);
|
|
737
|
+
assert.equal(JSON.parse(out.trim()).permission, 'deny', `out ${JSON.stringify(out)} err ${JSON.stringify(err)}`);
|
|
530
738
|
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
739
|
+
// Every write of a verdict in the hook scripts is followed by an exit only once it is written.
|
|
740
|
+
const dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'skills/yad-checks/templates/hooks');
|
|
741
|
+
for (const f of ['agent-guard.mjs', 'ledger-guard-cursor.mjs']) {
|
|
742
|
+
const src = fs.readFileSync(path.join(dir, f), 'utf8');
|
|
743
|
+
assert.ok(!/process\.stdout\.write\([^)]*\);?\s*process\.exit\(/.test(src), `${f}: no exit straight after a stdout write`);
|
|
744
|
+
assert.match(src, /process\.stdout\.write\(text, \(\) => process\.exit\(code\)\)/, `${f}: the verdict is written, then the exit`);
|
|
745
|
+
}
|
|
531
746
|
});
|
|
532
747
|
|
|
533
748
|
test('check --fix wires the agent guard on every Product, beside the team\'s own hooks; a target that leaves takes its entry', () => {
|
|
@@ -991,3 +1206,155 @@ test('E158b case 14: on a repo wired before E158b the guard files are new, so ya
|
|
|
991
1206
|
assert.deepEqual(guardItems(repoActions(P, repo)).map((a) => a.status), ['new', 'new', 'new']);
|
|
992
1207
|
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
993
1208
|
});
|
|
1209
|
+
|
|
1210
|
+
// ---- pre-approval (E167, #353) ------------------------------------------------------------------------
|
|
1211
|
+
|
|
1212
|
+
const { agentGuardPreapproval, PREAPPROVED, PREAPPROVED_GATES } = await import('./agent-guard.mjs');
|
|
1213
|
+
|
|
1214
|
+
test('E167: a line the guard sees only reads is pre-approved; any write, secret or unknown form is not', () => {
|
|
1215
|
+
const T = tmp();
|
|
1216
|
+
try {
|
|
1217
|
+
fs.writeFileSync(path.join(T, 'a.json'), '{}');
|
|
1218
|
+
fs.mkdirSync(path.join(T, 'src'));
|
|
1219
|
+
const yes = (line) => assert.equal(agentGuardPreapproval(line, { cwd: T }).preapproved, true, `should be pre-approved: ${line}`);
|
|
1220
|
+
const no = (line) => assert.equal(agentGuardPreapproval(line, { cwd: T }).preapproved, false, `must NOT be pre-approved: ${line}`);
|
|
1221
|
+
for (const line of [
|
|
1222
|
+
'gh api repos/o/r/pulls',
|
|
1223
|
+
'gh api repos/o/r/pulls --paginate --jq ".[].number"',
|
|
1224
|
+
'gh api -X GET repos/o/r/commits/abc',
|
|
1225
|
+
'gh api repos/o/r/pulls/5 -H "Accept: application/vnd.github.diff"',
|
|
1226
|
+
'glab api projects/1/merge_requests',
|
|
1227
|
+
"gh api repos/o/r/pulls | jq '.[0].number'",
|
|
1228
|
+
'git log --oneline -5', 'git status --porcelain', 'git diff main...HEAD', 'git show HEAD:package.json', 'git rev-parse HEAD', 'git ls-files', 'git blame a.json',
|
|
1229
|
+
'git status 2>/dev/null', 'git log 2>&1 | head -n 3', 'git diff >/dev/null',
|
|
1230
|
+
'jq . a.json', "jq -r '.a > 1' a.json", "jq --arg x y -n '$x'", "git log -- '*.mjs'", 'git log -n5 -p', 'git blame -L 1,2 a.json',
|
|
1231
|
+
'cat a.json', 'head -5 a.json', 'tail -n 2 a.json', 'wc -l a.json', 'grep -rn foo src/', 'grep -e foo a.json', 'git log | cut -d" " -f1 | uniq -c | tr a-z A-Z',
|
|
1232
|
+
'yad status --json | jq .x', 'yad gate status EP-a', 'yad doctor && git status',
|
|
1233
|
+
// Decoded paths and suffixes do not block ordinary reads.
|
|
1234
|
+
'glab api projects/grp%2Fproj/merge_requests', 'gh api repos/o/r/contents/README.md', 'gh api repos/o/r/releases/tags/v1.2.3', 'gh api repos/o/r/compare/main...feat',
|
|
1235
|
+
// Review 2: forms the allow list of characters keeps.
|
|
1236
|
+
'gh api repos/{owner}/{repo}/pulls', 'git rev-parse @{u}', 'git log -S foo', 'git diff --text', 'git diff HEAD~1', "git diff 'HEAD^' -- a.json", 'git diff main...HEAD -- src',
|
|
1237
|
+
'git log --format=%H -3', "grep -n 'a.*b' a.json", 'git blame --ignore-rev abc a.json', 'git log\t--oneline -2', 'git log \\\n --oneline',
|
|
1238
|
+
]) yes(line);
|
|
1239
|
+
for (const line of [
|
|
1240
|
+
// API writes, GraphQL, other hosts, and the human-only area.
|
|
1241
|
+
'gh api -X POST repos/o/r/issues', 'gh api -XPOST repos/x', 'gh api --method=PATCH repos/x', 'gh api --method DELETE repos/x', 'gh api repos/x -f title=t',
|
|
1242
|
+
'gh api repos/x -F a=@file', 'gh api repos/x --field a=b', 'gh api repos/x --raw-field a=b', 'gh api repos/x --input body.json', 'gh api graphql -f query="{viewer{login}}"',
|
|
1243
|
+
'gh api graphql', 'gh api --hostname evil.example repos/x', 'gh api https://evil.example/x', 'gh api repos/x -H "X-HTTP-Method-Override: DELETE"',
|
|
1244
|
+
'gh api repos/o/r/actions/secrets', 'gh api repos/o/r/actions/variables', 'gh api user/keys', 'gh api repos/o/r/hooks', 'glab api projects/1/variables',
|
|
1245
|
+
'gh api repos/x --jq env', 'gh secret set X', 'gh secret list', 'gh variable set X', 'gh auth token', 'glab token create', 'gh pr merge 5', 'gh pr list',
|
|
1246
|
+
// git writes, git options, and reads outside the repo.
|
|
1247
|
+
'git log --output=x', 'git diff --output x', 'git -c core.pager=x log', 'git -C /tmp log', 'git diff --ext-diff', 'git diff --no-index /etc/passwd a.json',
|
|
1248
|
+
'git blame --contents /etc/passwd a.json', 'git commit -m x', 'git push', 'git checkout main', 'git branch -D x',
|
|
1249
|
+
// files outside the project, writes, and lines the guard cannot see through.
|
|
1250
|
+
'jq . /etc/passwd', 'jq -n env', 'jq -n "$ENV"', 'jq \'import "x" as y; .\' a.json', 'cat ~/.ssh/id_rsa', 'cat ../x', 'head /etc/hosts', 'grep -r x /',
|
|
1251
|
+
'git status > out.txt', 'git log >> out.txt', 'jq . < a.json', 'cat <<EOF\nx\nEOF', 'tee out.txt', 'sort -o x a.json', 'sed -i s/a/b/ a.json', 'awk 1 a.json', 'uniq a.json out.txt',
|
|
1252
|
+
'echo $(gh api repos/x)', 'git log `echo x`', 'bash -c "git log"', 'GH_HOST=x gh api repos/x', 'env gh api repos/x', 'sudo cat a.json', './gh api repos/x',
|
|
1253
|
+
'/usr/bin/git log', '(git log)', 'tail -f a.json', 'git log && rm -rf src', 'git log; curl https://x', 'yad gate approve EP-a epic', 'yad check --fix', 'npx yad status',
|
|
1254
|
+
'bash checks/build-test-lint.sh', 'bash checks/install-deps.sh', 'bash checks/product-checkout.sh', '', ' ',
|
|
1255
|
+
// Review 1: what the shell expands before the program runs is never judged as written.
|
|
1256
|
+
'cat {~/.ssh/id_rsa,a.json}', 'cat {/etc/passwd,a.json}', 'grep -r x {/etc,.}', 'jq -n --arg t "$GH_TOKEN" \'$t\'', 'jq --arg x y -n "$x"',
|
|
1257
|
+
'jq -n "\\"${HOME}\\""', 'gh api user --jq "\\"$GH_TOKEN\\""', 'head -n "$X" a.json', 'head -n $X a.json', 'cut -d "$X" -f1 a.json', 'cat ~/x', 'cat x ~/y',
|
|
1258
|
+
'cat a.*', 'cat a.jso?', 'cat [a]', 'grep -R x .', 'grep --dereference-recursive x .', 'jq -nf x.jq', 'jq --from-file x.jq a.json', 'gh api user --cache 1h',
|
|
1259
|
+
'gh api user/emails', 'git blame --conten=/etc/hosts a.json', 'git blame --contents=/etc/hosts a.json', 'git blame -S revs a.json', 'git ls-files -X ex',
|
|
1260
|
+
'git diff -O/etc/order', 'git log --show-signature', 'git log --show-sig', 'git log --outp=x', 'git diff --no-ind /etc/a b', 'cat a.json 2>/dev/null"x"',
|
|
1261
|
+
'yad check --fix', 'yad dial EP-a implement --to auto',
|
|
1262
|
+
// Review 2: zsh glob qualifiers and =(…) run commands; =ls reads a program's file; git diff reads files outside.
|
|
1263
|
+
'cat a.json(e:touch\\ PWNED:)', 'cat a.json(e:"touch PWNED":)', 'head -c 100 a.json(e:id:)', 'cat =(id)', 'cat =ls', 'cat x =ls', 'git log --x=~/y',
|
|
1264
|
+
'git diff /dev/null /etc/hosts', 'git diff --stat a.json /etc/passwd', 'git diff -- /etc/hosts /etc/passwd', 'git diff ../../x a.json', 'git log --format=%GS -1',
|
|
1265
|
+
'git log --pretty=format:%G?', 'git blame -S revs a.json', 'git diff -Oorder', 'gh api repos/{a,b}', 'cat a!b', 'git log #(x)\nrm -rf src', 'git log a#b',
|
|
1266
|
+
// Review 3: a "comment" the shell reads as part of a word, after a \-newline, a \r, or a character JavaScript calls a space.
|
|
1267
|
+
'git log -1 --format=x\\\n#$GH_TOKEN', 'git log -1 --format=x\r#$GH_TOKEN', 'git log -1 --format=x\u00a0#$GH_TOKEN', 'git log -1 --format=x\v#$GH_TOKEN',
|
|
1268
|
+
'git log -1 --format=x\f#$GH_TOKEN', 'git log -1 --format=x\u2028#$GH_TOKEN', 'git rev-parse --sq-quote x\\\n#${GH_TOKEN}', 'git log --oneline # a note', 'git status\r',
|
|
1269
|
+
// Review 4: \ + CR + LF runs the next line; a zsh extendedglob ^; $ ENV; paths that return secrets.
|
|
1270
|
+
'git log \\\r\ntouch PWNED', 'cat a.json \\\r\ntouch X', 'cat ^a.json', 'git log HEAD^', "jq -n '$ ENV.HOME'", "gh api --jq '$ ENV' user",
|
|
1271
|
+
'glab api projects/1/triggers', 'glab api projects/1/integrations/slack', 'gh api repos/o/r/actions/runs/1/logs', 'glab api projects/1/jobs/2/trace',
|
|
1272
|
+
'glab api projects/1/secure_files/3/download', 'glab api projects/1/terraform/state/prod', 'glab api projects/1/pipeline_schedules/2', 'glab api projects/1/jobs/2/artifacts',
|
|
1273
|
+
'gh api repos/o/r/actions/artifacts/1/zip', 'glab api application/settings', 'glab api user',
|
|
1274
|
+
'glab api user.json', 'glab api user.', 'glab api projects/1/jobs/2/trace.json', 'glab api user%2F', 'glab api application%2Fsettings', 'gh api user', 'gh api %zz',
|
|
1275
|
+
]) no(line);
|
|
1276
|
+
// A refusal always wins: a refused line is never pre-approved.
|
|
1277
|
+
assert.equal(agentGuardDecision('git log && gh pr merge 5').allow, false);
|
|
1278
|
+
// The working folder must be inside the project.
|
|
1279
|
+
assert.equal(agentGuardPreapproval('cat etc/hosts', { cwd: '/', root: T }).preapproved, false);
|
|
1280
|
+
assert.equal(agentGuardPreapproval('cat ../a.json', { cwd: path.join(T, 'src'), root: T }).preapproved, true, 'inside the project, from a subfolder');
|
|
1281
|
+
// A link that leaves the project is outside it.
|
|
1282
|
+
fs.symlinkSync('/etc/hosts', path.join(T, 'hosts'));
|
|
1283
|
+
no('cat hosts');
|
|
1284
|
+
// A name holding a brace-shield character would be read under another name, past the link check: the prompt.
|
|
1285
|
+
fs.symlinkSync('/etc', path.join(T, 'link'));
|
|
1286
|
+
no("cat 'link/hosts'"); no('cat "link/hosts"');
|
|
1287
|
+
no('cat host*'); no('cat host?');
|
|
1288
|
+
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
1289
|
+
});
|
|
1290
|
+
|
|
1291
|
+
test('E167: a read gate is pre-approved only while its file is the copy this yadflow ships', () => {
|
|
1292
|
+
const T = tmp();
|
|
1293
|
+
try {
|
|
1294
|
+
fs.mkdirSync(path.join(T, 'checks'));
|
|
1295
|
+
const shipped = path.join(path.dirname(new URL(import.meta.url).pathname), '..', 'skills/yad-checks/templates/checks');
|
|
1296
|
+
for (const g of PREAPPROVED_GATES) {
|
|
1297
|
+
assert.ok(fs.existsSync(path.join(shipped, g)), `${g} is shipped`);
|
|
1298
|
+
fs.copyFileSync(path.join(shipped, g), path.join(T, 'checks', g));
|
|
1299
|
+
const run = g.endsWith('.mjs') ? `node checks/${g} --base origin/main` : `bash checks/${g} origin/main`;
|
|
1300
|
+
assert.equal(agentGuardPreapproval(run, { cwd: T }).preapproved, true, run);
|
|
1301
|
+
if (!g.endsWith('.mjs')) assert.equal(agentGuardPreapproval(`sh ./checks/${g} origin/main`, { cwd: T }).preapproved, true, g);
|
|
1302
|
+
// The wrong runner, or one byte changed: the prompt.
|
|
1303
|
+
assert.equal(agentGuardPreapproval(g.endsWith('.mjs') ? `bash checks/${g}` : `node checks/${g}`, { cwd: T }).preapproved, false, g);
|
|
1304
|
+
fs.appendFileSync(path.join(T, 'checks', g), ' ');
|
|
1305
|
+
assert.equal(agentGuardPreapproval(run, { cwd: T }).preapproved, false, `${g} edited`);
|
|
1306
|
+
}
|
|
1307
|
+
// The gates that run the repo's own code, install or clone are never on the list.
|
|
1308
|
+
for (const g of ['build-test-lint.sh', 'install-deps.sh', 'product-checkout.sh', 'package-manager.sh']) {
|
|
1309
|
+
assert.ok(!PREAPPROVED_GATES.includes(g), g);
|
|
1310
|
+
fs.copyFileSync(path.join(shipped, g), path.join(T, 'checks', g));
|
|
1311
|
+
assert.equal(agentGuardPreapproval(`bash checks/${g}`, { cwd: T }).preapproved, false, g);
|
|
1312
|
+
}
|
|
1313
|
+
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
test('E167: the hook answers a read with a PreToolUse allow under Claude Code; Cursor, refusals and the switches are unchanged', () => {
|
|
1317
|
+
const T = guardScript();
|
|
1318
|
+
const said = (r) => `hook said ${JSON.stringify(r)}`;
|
|
1319
|
+
try {
|
|
1320
|
+
const claude = (command, env) => runGuard(T, { hook_event_name: 'PreToolUse', tool_name: 'Bash', tool_input: { command }, cwd: T }, env);
|
|
1321
|
+
const read = claude('git status | head -3');
|
|
1322
|
+
assert.equal(read.code, 0, said(read));
|
|
1323
|
+
const answer = JSON.parse(read.out);
|
|
1324
|
+
assert.equal(answer.hookSpecificOutput.hookEventName, 'PreToolUse', said(read));
|
|
1325
|
+
assert.equal(answer.hookSpecificOutput.permissionDecision, 'allow', said(read));
|
|
1326
|
+
assert.match(answer.hookSpecificOutput.permissionDecisionReason, /read-only command \(git status, head\)/, said(read));
|
|
1327
|
+
// Not a read: no answer, so Claude Code asks as before.
|
|
1328
|
+
const write = claude('gh api -X POST repos/o/r/issues');
|
|
1329
|
+
assert.deepEqual([write.code, write.out], [0, ''], said(write));
|
|
1330
|
+
// A refusal still refuses.
|
|
1331
|
+
const merge = claude('git log && gh pr merge 5');
|
|
1332
|
+
assert.equal(merge.code, 2, said(merge));
|
|
1333
|
+
// The switches: YAD_NO_PREAPPROVE drops only this half; YAD_HOOK_DISABLE the whole guard.
|
|
1334
|
+
const off = claude('git status', { YAD_NO_PREAPPROVE: '1' });
|
|
1335
|
+
assert.deepEqual([off.code, off.out], [0, ''], said(off));
|
|
1336
|
+
assert.equal(claude('gh pr merge 5', { YAD_NO_PREAPPROVE: '1' }).code, 2);
|
|
1337
|
+
const disabled = claude('git status', { YAD_HOOK_DISABLE: '1' });
|
|
1338
|
+
assert.deepEqual([disabled.code, disabled.out], [0, ''], said(disabled));
|
|
1339
|
+
// Cursor's answer is the same literal as before.
|
|
1340
|
+
const cursor = runGuard(T, { hook_event_name: 'beforeShellExecution', command: 'git status' });
|
|
1341
|
+
assert.deepEqual(JSON.parse(cursor.out), { permission: 'allow' }, said(cursor));
|
|
1342
|
+
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
1343
|
+
});
|
|
1344
|
+
|
|
1345
|
+
test('E167: nothing that creates, prints or changes a secret, token or variable is ever pre-approved', () => {
|
|
1346
|
+
const T = tmp();
|
|
1347
|
+
try {
|
|
1348
|
+
const lines = [];
|
|
1349
|
+
for (const prog of ['gh', 'glab']) {
|
|
1350
|
+
for (const sub of ['secret set X', 'secret list', 'secret delete X', 'variable set X', 'variable list', 'auth token', 'auth login', 'token create', 'ssh-key add k', 'gpg-key add k']) lines.push(`${prog} ${sub}`);
|
|
1351
|
+
for (const p of ['repos/o/r/actions/secrets', 'repos/o/r/actions/secrets/public-key', 'repos/o/r/actions/variables', 'orgs/o/actions/secrets', 'repos/o/r/environments/e/secrets',
|
|
1352
|
+
'projects/1/variables', 'user/keys', 'user/gpg_keys', 'repos/o/r/keys', 'repos/o/r/hooks', 'personal_access_tokens', 'user/installations/1/access_tokens', 'projects/1/access_tokens',
|
|
1353
|
+
'repos/o/r/dependabot/secrets', 'repos/o/r/codespaces/secrets', 'groups/1/variables']) {
|
|
1354
|
+
lines.push(`${prog} api ${p}`, `${prog} api ${p} --paginate`, `${prog} api ${p} | jq .`);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
for (const line of lines) assert.equal(agentGuardPreapproval(line, { cwd: T }).preapproved, false, line);
|
|
1358
|
+
assert.match(PREAPPROVED.never, /secrets, tokens, variables/);
|
|
1359
|
+
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
1360
|
+
});
|
package/cli/test-build.mjs
CHANGED
|
@@ -1557,3 +1557,28 @@ test('yad build done: a tasks.md that exists wins over a light spec\'s tasks blo
|
|
|
1557
1557
|
assert.equal(status(dir), 'shipped');
|
|
1558
1558
|
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
1559
1559
|
});
|
|
1560
|
+
|
|
1561
|
+
test('#450 yad open-pr --via auto: a branch cut from another branch, with no base chosen, is a YAD-STATE-009 error and nothing is pushed', async () => {
|
|
1562
|
+
const { runOpenPr } = await import('./openpr.mjs');
|
|
1563
|
+
const { W, P, api } = workspace();
|
|
1564
|
+
try {
|
|
1565
|
+
// The registry names no default_branch for api, so the base is origin/HEAD (main): nobody chose it.
|
|
1566
|
+
git(api, 'checkout', '-q', '-b', 'develop');
|
|
1567
|
+
write(api, { 'src/other.js': 'o\n' });
|
|
1568
|
+
git(api, 'add', '-A');
|
|
1569
|
+
git(api, 'commit', '-q', '-m', 'feat: other\n\nTask: EP-l-S01-T09');
|
|
1570
|
+
git(api, 'push', '-q', 'origin', 'develop');
|
|
1571
|
+
const branch = 'feat/EP-l-S01-T01-orders';
|
|
1572
|
+
git(api, 'checkout', '-q', '-b', branch);
|
|
1573
|
+
write(api, { 'src/orders.js': 'x\n' });
|
|
1574
|
+
git(api, 'add', '-A');
|
|
1575
|
+
git(api, 'commit', '-q', '-m', 'feat: orders\n\nTask: EP-l-S01-T01');
|
|
1576
|
+
let created = 0;
|
|
1577
|
+
const creator = () => { created += 1; return { ok: true, url: 'https://github.com/o/api/pull/12' }; };
|
|
1578
|
+
const runner = () => ({ ok: false, stdout: '', stderr: 'no platform here' });
|
|
1579
|
+
await assert.rejects(() => runOpenPr(api, { product: P, via: 'auto', platform: 'github', creator, runner }),
|
|
1580
|
+
(e) => e.code === 'YAD-STATE-009' && /holds 1 commit of other tasks from origin\/develop/.test(e.message));
|
|
1581
|
+
assert.equal(git(api, 'ls-remote', '--heads', 'origin', branch), '', 'nothing was pushed');
|
|
1582
|
+
assert.equal(created, 0);
|
|
1583
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
1584
|
+
});
|