@jeiemgi/cckit 0.8.0 → 0.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.
Files changed (309) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +505 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +189 -20
  6. package/cckit.config.json +1 -1
  7. package/commands/kit-doctor.md +13 -5
  8. package/commands/kit-export-project.md +0 -2
  9. package/commands/kit-export-training.md +6 -9
  10. package/commands/kit-init.md +43 -13
  11. package/commands/kit-routines.md +1 -1
  12. package/commands/kit-update.md +11 -6
  13. package/databases/supabase/guide.html +106 -0
  14. package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
  15. package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
  16. package/databases/supabase.json +70 -0
  17. package/integrations/emil-design-eng.json +41 -0
  18. package/integrations/graft.json +81 -0
  19. package/integrations/impeccable.json +42 -0
  20. package/integrations/integration.schema.json +215 -0
  21. package/integrations/lavish.json +43 -0
  22. package/integrations/mempalace.json +28 -0
  23. package/integrations/mlx-lm.json +32 -0
  24. package/integrations/web-design-guidelines.json +42 -0
  25. package/kit.config.schema.json +183 -5
  26. package/package.json +4 -1
  27. package/profiles/automation.json +7 -1
  28. package/profiles/content.json +10 -2
  29. package/profiles/marketing.json +57 -0
  30. package/profiles/minimal.json +7 -1
  31. package/profiles/research.json +7 -1
  32. package/profiles/software.json +7 -1
  33. package/recipes/nextjs-shadcn.json +49 -0
  34. package/scripts/agent-skills-external.txt +45 -0
  35. package/scripts/agent-skills-lint-test.sh +131 -0
  36. package/scripts/agent-skills-lint.sh +115 -0
  37. package/scripts/agent-template-lint-test.sh +42 -0
  38. package/scripts/agent-template-lint.sh +58 -0
  39. package/scripts/annotate-setup.sh +1 -1
  40. package/scripts/autopilot-run-test.sh +338 -0
  41. package/scripts/autopilot-run.sh +448 -0
  42. package/scripts/autopilot-test.sh +8 -0
  43. package/scripts/autopilot.sh +10 -1
  44. package/scripts/benchmark/benchmark-test.sh +85 -0
  45. package/scripts/benchmark/checkpoint-test.sh +314 -0
  46. package/scripts/benchmark/checkpoint.sh +408 -0
  47. package/scripts/benchmark/lib/model.sh +31 -6
  48. package/scripts/benchmark/report.sh +17 -2
  49. package/scripts/benchmark/run-quality.sh +36 -10
  50. package/scripts/benchmark/verb-timings-test.sh +124 -0
  51. package/scripts/benchmark/verb-timings.sh +149 -0
  52. package/scripts/check.sh +29 -19
  53. package/scripts/content-skills-test.sh +144 -0
  54. package/scripts/copilot-loop-test.sh +25 -0
  55. package/scripts/database-supabase-test.sh +121 -0
  56. package/scripts/docs-marketing-words-test.sh +73 -0
  57. package/scripts/docs-record-tables-test.sh +72 -0
  58. package/scripts/guard-raw-git-ops-test.sh +8 -0
  59. package/scripts/hook-adapter-test.sh +193 -0
  60. package/scripts/init-content-test.sh +225 -0
  61. package/scripts/init-guided-test.sh +474 -0
  62. package/scripts/init-recipes-test.sh +104 -0
  63. package/scripts/init-upgrade-test.sh +341 -2
  64. package/scripts/init.sh +746 -95
  65. package/scripts/instruction-budget-baseline.txt +8 -0
  66. package/scripts/instruction-budget-lint-test.sh +166 -0
  67. package/scripts/instruction-budget-lint.sh +219 -0
  68. package/scripts/integrations-check-test.sh +200 -0
  69. package/scripts/integrations-check.sh +157 -0
  70. package/scripts/kit-add-test.sh +214 -0
  71. package/scripts/kit-add.sh +305 -5
  72. package/scripts/kit-adopt-test.sh +16 -0
  73. package/scripts/kit-adopt.sh +3 -2
  74. package/scripts/kit-digest.sh +2 -2
  75. package/scripts/kit-doctor-test.sh +293 -0
  76. package/scripts/kit-doctor.sh +272 -140
  77. package/scripts/kit-export-project-test.sh +3 -3
  78. package/scripts/kit-remove-test.sh +19 -0
  79. package/scripts/kit-routines.sh +2 -2
  80. package/scripts/kit-self-update.sh +1 -1
  81. package/scripts/kit-version-check-test.sh +4 -0
  82. package/scripts/kit-version-check.sh +4 -2
  83. package/scripts/knowledge-lint.sh +4 -4
  84. package/scripts/leak-fence-test.sh +89 -0
  85. package/scripts/lib/adapter-select-test.sh +136 -0
  86. package/scripts/lib/adapter-select.sh +158 -0
  87. package/scripts/lib/agent-def-test.sh +69 -0
  88. package/scripts/lib/agent-def.sh +106 -0
  89. package/scripts/lib/agent-launch-test.sh +212 -0
  90. package/scripts/lib/agent-launch.sh +335 -0
  91. package/scripts/lib/board-view-test.sh +11 -0
  92. package/scripts/lib/board-view.sh +42 -26
  93. package/scripts/lib/branch-owner-test.sh +26 -0
  94. package/scripts/lib/branch-owner.sh +16 -9
  95. package/scripts/lib/captain-test.sh +105 -0
  96. package/scripts/lib/captain.sh +87 -8
  97. package/scripts/lib/codex-hooks-test.sh +100 -0
  98. package/scripts/lib/codex-hooks.sh +69 -0
  99. package/scripts/lib/commitlint.sh +1 -1
  100. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  101. package/scripts/lib/copilot-test.sh +70 -4
  102. package/scripts/lib/copilot.sh +66 -14
  103. package/scripts/lib/effort-dispatch-test.sh +3 -3
  104. package/scripts/lib/effort-metrics-test.sh +178 -1
  105. package/scripts/lib/effort-metrics.sh +188 -35
  106. package/scripts/lib/effort-ops-test.sh +217 -7
  107. package/scripts/lib/effort-ops.sh +281 -49
  108. package/scripts/lib/effort-parity-test.sh +49 -13
  109. package/scripts/lib/effort-plan-test.sh +337 -0
  110. package/scripts/lib/effort-plan.sh +200 -23
  111. package/scripts/lib/effort-slug.sh +16 -2
  112. package/scripts/lib/effort.sh +67 -12
  113. package/scripts/lib/errors-header-test.sh +1 -1
  114. package/scripts/lib/gh-project-test.sh +35 -1
  115. package/scripts/lib/gh-project.sh +37 -16
  116. package/scripts/lib/gh-rest-test.sh +330 -0
  117. package/scripts/lib/gh-rest.sh +304 -0
  118. package/scripts/lib/hook-refresh.sh +1 -1
  119. package/scripts/lib/init-github.sh +412 -0
  120. package/scripts/lib/init-guide.sh +630 -0
  121. package/scripts/lib/integration-install-test.sh +343 -0
  122. package/scripts/lib/integration-install.sh +257 -0
  123. package/scripts/lib/integrations-test.sh +366 -0
  124. package/scripts/lib/integrations.sh +244 -0
  125. package/scripts/lib/kinds-test.sh +125 -0
  126. package/scripts/lib/kinds.sh +66 -0
  127. package/scripts/lib/kit-brief-test.sh +22 -3
  128. package/scripts/lib/kit-brief.sh +45 -5
  129. package/scripts/lib/kit-config-resolve.sh +2 -2
  130. package/scripts/lib/kit-config-test.sh +64 -1
  131. package/scripts/lib/kit-config.sh +37 -1
  132. package/scripts/lib/kit-events.sh +7 -0
  133. package/scripts/lib/kit-gc-test.sh +173 -1
  134. package/scripts/lib/kit-gc.sh +244 -37
  135. package/scripts/lib/kit-hotfix.sh +216 -0
  136. package/scripts/lib/kit-interview-test.sh +93 -0
  137. package/scripts/lib/kit-interview.sh +117 -8
  138. package/scripts/lib/kit-lib-test.sh +1 -1
  139. package/scripts/lib/kit-lib.sh +3 -3
  140. package/scripts/lib/kit-local.sh +2 -2
  141. package/scripts/lib/kit-manifest.sh +33 -1
  142. package/scripts/lib/kit-profile-test.sh +3 -3
  143. package/scripts/lib/kit-status-test.sh +112 -4
  144. package/scripts/lib/kit-status.sh +246 -16
  145. package/scripts/lib/kit-task-ops-test.sh +37 -0
  146. package/scripts/lib/kit-task-ops.sh +362 -89
  147. package/scripts/lib/kto-hotfix-test.sh +232 -0
  148. package/scripts/lib/kto-task-close-test.sh +83 -0
  149. package/scripts/lib/kto-task-new-test.sh +95 -0
  150. package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
  151. package/scripts/lib/kto-task-pr-test.sh +70 -0
  152. package/scripts/lib/leak-fence.sh +89 -0
  153. package/scripts/lib/light-task-run-test.sh +255 -0
  154. package/scripts/lib/light-task-test.sh +309 -0
  155. package/scripts/lib/light-task.sh +706 -0
  156. package/scripts/lib/next-test.sh +99 -0
  157. package/scripts/lib/next.sh +9 -3
  158. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  159. package/scripts/lib/orchestration-runtime.sh +57 -5
  160. package/scripts/lib/plan-machine-test.sh +15 -2
  161. package/scripts/lib/plan-machine.sh +20 -7
  162. package/scripts/lib/plan-next-test.sh +1 -1
  163. package/scripts/lib/plan-next.sh +4 -4
  164. package/scripts/lib/pr-evidence-test.sh +3 -3
  165. package/scripts/lib/pr-evidence.sh +1 -1
  166. package/scripts/lib/qa-lane-test.sh +626 -0
  167. package/scripts/lib/qa-lane.sh +1357 -0
  168. package/scripts/lib/qa-lanes-test.sh +175 -0
  169. package/scripts/lib/react-detect.sh +1 -1
  170. package/scripts/lib/render-test.sh +1 -1
  171. package/scripts/lib/review-page-test.sh +318 -0
  172. package/scripts/lib/review-page.sh +369 -0
  173. package/scripts/lib/review-stage-test.sh +62 -11
  174. package/scripts/lib/review-stage.sh +42 -60
  175. package/scripts/lib/role-identity-test.sh +65 -0
  176. package/scripts/lib/role-identity.sh +25 -2
  177. package/scripts/lib/secret-guard.sh +3 -3
  178. package/scripts/lib/session-registry-test.sh +111 -0
  179. package/scripts/lib/session-registry.sh +233 -0
  180. package/scripts/lib/stage-receipt-test.sh +14 -1
  181. package/scripts/lib/stage-receipt.sh +13 -8
  182. package/scripts/lib/task-source-file.sh +309 -0
  183. package/scripts/lib/task-source.sh +130 -0
  184. package/scripts/lib/test-env-test.sh +3 -3
  185. package/scripts/lib/test-env.sh +7 -4
  186. package/scripts/lib/upgrade-report-test.sh +120 -0
  187. package/scripts/lib/upgrade-report.sh +138 -0
  188. package/scripts/lib/version-bump.sh +3 -3
  189. package/scripts/lib/wave-result-test.sh +80 -0
  190. package/scripts/lib/wave-result.sh +127 -0
  191. package/scripts/lib/worker-brief-test.sh +5 -0
  192. package/scripts/lib/worker-brief.sh +2 -2
  193. package/scripts/lib/worktree-issue-test.sh +30 -1
  194. package/scripts/lib/worktree-issue.sh +93 -9
  195. package/scripts/lib/worktree-ports-test.sh +57 -4
  196. package/scripts/lib/worktree-start-test.sh +197 -0
  197. package/scripts/lib/worktree-start.sh +169 -32
  198. package/scripts/lib/zsh-safety-test.sh +19 -3
  199. package/scripts/marketing-walkthrough-test.sh +152 -0
  200. package/scripts/night-grant-test.sh +37 -0
  201. package/scripts/night-grant.sh +448 -0
  202. package/scripts/night-run-test.sh +8 -0
  203. package/scripts/night-run.mjs +275 -0
  204. package/scripts/night-run.test.mjs +324 -0
  205. package/scripts/orchestrate-test.sh +190 -0
  206. package/scripts/orchestrate.sh +79 -8
  207. package/scripts/portable-test.sh +11 -2
  208. package/scripts/publish.sh +28 -3
  209. package/scripts/review-lint-test.sh +7 -7
  210. package/scripts/review-lint.sh +2 -2
  211. package/scripts/review-rules.conf +8 -0
  212. package/scripts/rule-recipes-test.sh +96 -0
  213. package/scripts/self-install-test.sh +39 -9
  214. package/scripts/setup-labels.sh +18 -1
  215. package/scripts/setup-milestones.sh +1 -1
  216. package/scripts/showcase.sh +1 -1
  217. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  218. package/scripts/skill-frontmatter-lint.sh +1 -1
  219. package/scripts/status-test.sh +113 -2
  220. package/scripts/status.sh +16 -3
  221. package/scripts/task-sync-test.sh +154 -0
  222. package/scripts/task-sync.sh +243 -32
  223. package/scripts/test-runner-test.sh +158 -0
  224. package/scripts/test.sh +131 -23
  225. package/scripts/update-path-test.sh +279 -0
  226. package/scripts/ux-ds-audit.sh +1 -1
  227. package/scripts/ux-graph-scan.sh +6 -6
  228. package/scripts/wave-worker.sh +54 -0
  229. package/skills/kit-add/SKILL.md +77 -0
  230. package/skills/kit-autopilot/SKILL.md +123 -12
  231. package/skills/kit-cleanup/SKILL.md +5 -2
  232. package/skills/kit-contribute/SKILL.md +4 -4
  233. package/skills/kit-docs-writer/SKILL.md +16 -6
  234. package/skills/kit-effort-close/SKILL.md +17 -8
  235. package/skills/kit-effort-new/SKILL.md +15 -9
  236. package/skills/kit-effort-pr/SKILL.md +15 -7
  237. package/skills/kit-effort-start/SKILL.md +5 -2
  238. package/skills/kit-gc/SKILL.md +5 -2
  239. package/skills/kit-next/SKILL.md +5 -1
  240. package/skills/kit-onboard/SKILL.md +3 -3
  241. package/skills/kit-page/SKILL.md +93 -0
  242. package/skills/kit-plan-next/SKILL.md +8 -4
  243. package/skills/kit-security-sweep/SKILL.md +1 -3
  244. package/skills/kit-ship/SKILL.md +2 -3
  245. package/skills/kit-status/SKILL.md +35 -4
  246. package/skills/kit-task-new/SKILL.md +3 -3
  247. package/skills/kit-task-pr/SKILL.md +7 -2
  248. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  249. package/skills/kit-task-start/SKILL.md +7 -7
  250. package/skills/kit-task-sync/SKILL.md +19 -3
  251. package/skills/kit-ux-audit/SKILL.md +3 -2
  252. package/templates/agents/auto-dev.md +5 -4
  253. package/templates/agents/backend.md +1 -1
  254. package/templates/agents/designer.md +2 -0
  255. package/templates/agents/devops.md +1 -1
  256. package/templates/agents/editor.md +9 -1
  257. package/templates/agents/frontend.md +1 -1
  258. package/templates/agents/local-delegate.md +1 -1
  259. package/templates/agents/pm.md +5 -5
  260. package/templates/agents/tech-lead.md +1 -1
  261. package/templates/benchmarks/SCHEMA.md +9 -3
  262. package/templates/codex/hooks.json.tmpl +89 -0
  263. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  264. package/templates/hooks/guard-raw-git-ops.sh.tmpl +27 -14
  265. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  266. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  267. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  268. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  269. package/templates/instructions.md.tmpl +174 -0
  270. package/templates/kit.config.json.tmpl +3 -3
  271. package/templates/knowledge-INDEX.md.tmpl +1 -1
  272. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  273. package/templates/rules/authoring.md +106 -0
  274. package/templates/rules/branch-naming.md +40 -4
  275. package/templates/rules/code-retrieval.md +63 -0
  276. package/templates/rules/delegation-brief.md +0 -3
  277. package/templates/rules/design-routing.md +3 -3
  278. package/templates/rules/effort-model.md +14 -10
  279. package/templates/rules/gate-and-review.md +94 -0
  280. package/templates/rules/issue-lifecycle.md +88 -0
  281. package/templates/rules/knowledge-base.md +1 -1
  282. package/templates/rules/mempalace.md +1 -1
  283. package/templates/rules/merge-safety.md +108 -0
  284. package/templates/rules/naming-and-ids.md +23 -17
  285. package/templates/rules/plain-language.md +59 -0
  286. package/templates/rules/plan-next.md +9 -11
  287. package/templates/rules/react-annotate.md +6 -0
  288. package/templates/rules/review-pages.md +49 -0
  289. package/templates/rules/risk-tiered-review.md +13 -4
  290. package/templates/rules/shared-checkout.md +106 -0
  291. package/templates/rules/skill-gaps.md +2 -7
  292. package/templates/rules/task-management.md +13 -1
  293. package/templates/skills/brand-voice/SKILL.md +91 -0
  294. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  295. package/templates/skills/campaign/SKILL.md +123 -0
  296. package/templates/skills/campaign/references/plan-template.md +55 -0
  297. package/templates/skills/concrete/SKILL.md +2 -2
  298. package/templates/skills/copywriting/SKILL.md +8 -1
  299. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  300. package/templates/skills/morning-briefing/SKILL.md +2 -2
  301. package/templates/skills/page-design/SKILL.md +145 -0
  302. package/templates/skills/page-design/add.json +5 -0
  303. package/templates/skills/page-design/references/design-file-template.md +40 -0
  304. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  305. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  306. package/templates/skills/speckit/SKILL.md +4 -5
  307. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  308. package/commands/kit-add.md +0 -42
  309. package/templates/CLAUDE.md.tmpl +0 -106
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # kto-hotfix-test.sh — `cckit hotfix <pr|sha> [--base B]` end to end (#360), against a stubbed gh, a
4
+ # throwaway repo and a bare remote: the worktree is cut from origin/<base>, the branch carries
5
+ # exactly the source commit's diff, the push exports KIT_PR_BASE, and the PR targets <base> with
6
+ # `Cherry-pick of #N` in its body. Covers both transports, a merge-commit source, a re-run, and the
7
+ # rebase-merged multi-commit PR (every commit carried), a squash of a multi-commit PR (one commit), a
8
+ # refusal reported as `--llm` JSON, and the refusals (unmerged PR, unknown sha, missing base,
9
+ # conflict).
10
+ # Run: bash scripts/lib/kto-hotfix-test.sh
11
+ # errors: strict — a test runner: rc 1 on any failed assertion
12
+ set -u
13
+ LIB="$(cd "$(dirname "$0")" && pwd)"
14
+ CCKIT="$(cd "$LIB/../.." && pwd)/bin/cckit"
15
+ # shellcheck source=/dev/null
16
+ . "$LIB/test-env.sh" && test_env_seal
17
+ unset CLAUDE_CODE_REMOTE CCKIT_GH_TRANSPORT
18
+ fail=0
19
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
20
+ tc() { if grep -qE -- "$2" "$1"; then echo "ok: $3"; else echo "FAIL: $3 (no /$2/ in $1)"; fail=1; fi; }
21
+ tn() { if grep -qE -- "$2" "$1"; then echo "FAIL: $3 (/$2/ in $1)"; fail=1; else echo "ok: $3"; fi; }
22
+ command -v jq >/dev/null 2>&1 || { echo "kto-hotfix-test: jq required" >&2; exit 1; }
23
+
24
+ tmp="$(cd "$(mktemp -d)" && pwd -P)"; trap 'rm -rf "$tmp"' EXIT
25
+ export GH_LOG="$tmp/gh.log" GH_SHA="" GH_STATE="MERGED" GH_OPEN_URL="" GH_SUBJECTS="wip"
26
+ : > "$GH_LOG"
27
+ mkdir -p "$tmp/bin"
28
+ # A gh that logs one call per line (newlines in a body become \036) and answers both transports.
29
+ cat > "$tmp/bin/gh" <<'SH'
30
+ #!/usr/bin/env bash
31
+ { printf '%s' "$*" | tr '\n' '\036'; echo; } >> "$GH_LOG"
32
+ jqx=""; prev=""; for a in "$@"; do [ "$prev" = "--jq" ] && jqx="$a"; prev="$a"; done
33
+ out() { if [ -n "$jqx" ]; then printf '%s' "$1" | jq -r -c "$jqx"; else printf '%s\n' "$1"; fi; }
34
+ merged="null"; [ "$GH_STATE" = "MERGED" ] && merged='"2026-10-30T00:00:00Z"'
35
+ # GH_SUBJECTS: the PR's own commit subjects, one per line, oldest first.
36
+ commits="$(printf '%s\n' "$GH_SUBJECTS" | jq -R -s -c '[split("\n")[] | select(length > 0)]')"
37
+ case "$1 $2" in
38
+ "pr view")
39
+ if [ "$GH_STATE" = "MERGED" ]; then mc="{\"oid\":\"$GH_SHA\"}"; else mc="null"; fi
40
+ out "{\"title\":\"fix: the thing [#11]\",\"state\":\"$GH_STATE\",\"mergeCommit\":$mc,\"commits\":$(printf '%s' "$commits" | jq -c '[.[] | {messageHeadline: .}]')}" ;;
41
+ "pr list") out "[$( [ -n "$GH_OPEN_URL" ] && printf '{"url":"%s"}' "$GH_OPEN_URL" )]" ;;
42
+ "pr create") echo "https://github.com/o/r/pull/77" ;;
43
+ "api repos/o/r/pulls")
44
+ case " $* " in
45
+ *" POST "*) out '{"number":77,"html_url":"https://github.com/o/r/pull/77","user":{"login":"me"}}' ;;
46
+ *) out "[]" ;;
47
+ esac ;;
48
+ "api repos/o/r/pulls/"*"/commits")
49
+ out "$(printf '%s' "$commits" | jq -c '[.[] | {commit: {message: (. + "\n\nbody text")}}]')" ;;
50
+ "api repos/o/r/pulls/"*)
51
+ out "{\"title\":\"fix: the thing [#11]\",\"mergeable\":null,\"mergeable_state\":\"unknown\",\"base\":{\"ref\":\"develop\"},\"head\":{\"ref\":\"fix/11-x\"},\"body\":\"\",\"state\":\"closed\",\"merged_at\":$merged,\"merge_commit_sha\":\"$GH_SHA\"}" ;;
52
+ *) exit 0 ;;
53
+ esac
54
+ SH
55
+ chmod +x "$tmp/bin/gh"
56
+ export PATH="$tmp/bin:$PATH" KIT_WT_INSTALL=0
57
+
58
+ # The fixture: `main` (the release branch) one commit behind `develop`, which carries the fix as a
59
+ # squash commit `… (#12)`, a later unrelated commit, and a true merge commit.
60
+ git init -q --bare "$tmp/remote.git"
61
+ git clone -q "$tmp/remote.git" "$tmp/work" 2>/dev/null
62
+ cd "$tmp/work" || exit 1
63
+ git config user.email t@t; git config user.name t
64
+ cat > cckit.config.json <<'JSON'
65
+ {"kitVersion":"0.0.0","project":{"name":"x","slug":"x","owner":"o","language":"en"},"profile":"p",
66
+ "github":{"repo":"o/r","owner":"o","baseBranch":"develop","projectsV2":false}}
67
+ JSON
68
+ printf 'a\nb\nc\n' > app.txt
69
+ git add -A; git commit -q -m init; git branch -M main; git push -q origin main
70
+ git checkout -q -b develop
71
+ printf 'a\nB\nc\n' > app.txt; git commit -q -am "fix: the thing (#12)"; SRC="$(git rev-parse HEAD)"
72
+ echo other > other.txt; git add other.txt; git commit -q -m "feat: unrelated (#13)"
73
+ git checkout -q -b side HEAD~1; echo side > side.txt; git add side.txt; git commit -q -m "side work"
74
+ git checkout -q develop; git merge -q --no-ff side -m "Merge pull request #14 from o/side"
75
+ MERGE="$(git rev-parse HEAD)"
76
+ printf 'a\nB\nc\nd\n' > app.txt; git commit -q -am "feat: conflicts with a main-only edit (#15)"; CONF="$(git rev-parse HEAD)"
77
+ # PR 20 as a REBASE merge leaves it: its two commits on develop, subjects unchanged, no merge commit.
78
+ echo one > r1.txt; git add r1.txt; git commit -q -m "fix: rebased part one"
79
+ echo two > r2.txt; git add r2.txt; git commit -q -m "fix: rebased part two"; REB="$(git rev-parse HEAD)"
80
+ git push -q origin develop
81
+ cat > .git/hooks/pre-push <<SH
82
+ #!/usr/bin/env bash
83
+ echo "KIT_PR_BASE=\${KIT_PR_BASE:-}" >> "$tmp/prepush.log"
84
+ SH
85
+ chmod +x .git/hooks/pre-push
86
+ : > "$tmp/prepush.log"
87
+
88
+ # Drop the hotfix branch everywhere, so the next case starts from nothing.
89
+ reset_hotfix() {
90
+ git worktree remove --force "$wt"; git branch -q -D fix/12-hotfix-main
91
+ git push -q origin :fix/12-hotfix-main 2>/dev/null; : > "$tmp/prepush.log"
92
+ }
93
+
94
+ # ── <sha> --base main ────────────────────────────────────────────────────────────────────────────
95
+ out="$("$CCKIT" hotfix "$SRC" --base main 2>"$tmp/err")"; rc=$?
96
+ t "hotfix <sha> --base main succeeds" "$rc" "0"
97
+ wt="$tmp/work/.claude/worktrees/fix+12-hotfix-main"
98
+ t "the worktree exists" "$([ -d "$wt" ] && echo yes || echo no)" "yes"
99
+ t "its branch is fix/12-hotfix-main" "$(git -C "$wt" rev-parse --abbrev-ref HEAD 2>/dev/null)" "fix/12-hotfix-main"
100
+ t "the branch is cut from origin/main" "$(git merge-base origin/main fix/12-hotfix-main)" "$(git rev-parse origin/main)"
101
+ t "one commit on top of origin/main" "$(git rev-list --count origin/main..fix/12-hotfix-main)" "1"
102
+ t "the branch diff equals the source commit's" "$(git diff origin/main fix/12-hotfix-main)" "$(git diff "$SRC~1" "$SRC")"
103
+ t "the unrelated develop commit is not carried" "$(git ls-tree --name-only fix/12-hotfix-main | grep -c '^other.txt$')" "0"
104
+ tc <(git log -1 --format=%B fix/12-hotfix-main) "cherry picked from commit $SRC" "cherry-pick -x records the source"
105
+ t "the branch reached the remote" "$(git -C "$tmp/remote.git" rev-parse fix/12-hotfix-main 2>/dev/null)" "$(git rev-parse fix/12-hotfix-main)"
106
+ t "the pre-push hook sees KIT_PR_BASE=main" "$(cat "$tmp/prepush.log")" "KIT_PR_BASE=main"
107
+ tc "$GH_LOG" '^pr create .*--base main --head fix/12-hotfix-main ' "the PR targets main from the hotfix branch"
108
+ tc "$GH_LOG" '--title fix: the thing --body ' "titled after the source, squash suffix dropped"
109
+ tc "$GH_LOG" 'Cherry-pick of #12' "the body says Cherry-pick of #12"
110
+ tn "$GH_LOG" 'Closes #' "the body closes no issue"
111
+ t "stdout ends with the PR url" "$(printf '%s\n' "$out" | tail -1)" "✓ https://github.com/o/r/pull/77"
112
+
113
+ # ── re-run: nothing is picked twice, and an open PR is reported, not re-created ──────────────────
114
+ : > "$GH_LOG"
115
+ out="$(GH_OPEN_URL="https://github.com/o/r/pull/77" "$CCKIT" hotfix "$SRC" --base main 2>/dev/null)"; rc=$?
116
+ t "a re-run succeeds" "$rc" "0"
117
+ t "…and does not pick the commit twice" "$(git rev-list --count origin/main..fix/12-hotfix-main)" "1"
118
+ tn "$GH_LOG" '^pr create' "…and opens no second PR"
119
+ t "…and still reports the url" "$(printf '%s\n' "$out" | tail -1)" "✓ https://github.com/o/r/pull/77"
120
+
121
+ # ── <pr>: the merge commit and title come from GitHub; main is the default base ─────────────────
122
+ reset_hotfix
123
+ : > "$GH_LOG"
124
+ out="$(GH_SHA="$SRC" "$CCKIT" hotfix 12 2>"$tmp/err")"; rc=$?
125
+ t "hotfix <pr> succeeds (default base main)" "$rc" "0"
126
+ tc "$GH_LOG" '^pr view 12 ' "the source PR is read from GitHub"
127
+ t "the branch diff equals the source commit's" "$(git diff origin/main fix/12-hotfix-main)" "$(git diff "$SRC~1" "$SRC")"
128
+ tc "$GH_LOG" '^pr create .*--base main .*--title fix: the thing \[#11\] ' "titled after the source PR"
129
+ tc "$GH_LOG" 'Cherry-pick of #12' "the body says Cherry-pick of #12"
130
+
131
+ # --llm: one JSON object carrying the url and the worktree
132
+ reset_hotfix
133
+ js="$(GH_SHA="$SRC" "$CCKIT" hotfix '#12' --llm 2>/dev/null)"
134
+ t "--llm: ok + url" "$(printf '%s' "$js" | jq -r '"\(.ok) \(.url)"' 2>/dev/null)" "true https://github.com/o/r/pull/77"
135
+ t "--llm: the worktree path" "$(printf '%s' "$js" | jq -r .worktree 2>/dev/null)" "$wt"
136
+
137
+ # --llm on a refusal: still one JSON object, ok false, the reason in `detail`
138
+ js="$(GH_STATE="OPEN" "$CCKIT" hotfix 99 --llm 2>/dev/null)"; rc=$?
139
+ t "--llm: a refusal exits 1" "$rc" "1"
140
+ t "--llm: a refusal reports ok false" "$(printf '%s' "$js" | jq -r '"\(.verb) \(.ok)"' 2>/dev/null)" "hotfix false"
141
+ t "--llm: …and carries the reason" "$(printf '%s' "$js" | jq -r .detail 2>/dev/null | grep -c 'not merged')" "1"
142
+
143
+ # ── REST transport: only `gh api repos/…` calls ──────────────────────────────────────────────────
144
+ reset_hotfix
145
+ : > "$GH_LOG"
146
+ GH_SHA="$SRC" CCKIT_GH_TRANSPORT=rest "$CCKIT" hotfix 12 >/dev/null 2>"$tmp/err"; rc=$?
147
+ t "rest: hotfix <pr> succeeds" "$rc" "0"
148
+ tn "$GH_LOG" '^(pr|issue) |graphql' "rest: no gh pr/issue/graphql call"
149
+ tc "$GH_LOG" '^api repos/o/r/pulls -X POST .*base=main' "rest: the PR is created against main"
150
+ tc "$GH_LOG" 'Cherry-pick of #12' "rest: the body says Cherry-pick of #12"
151
+ t "rest: the branch diff equals the source's" "$(git diff origin/main fix/12-hotfix-main)" "$(git diff "$SRC~1" "$SRC")"
152
+
153
+ # ── a merge commit is picked against its first parent ────────────────────────────────────────────
154
+ : > "$GH_LOG"
155
+ "$CCKIT" hotfix "$MERGE" --base main >/dev/null 2>"$tmp/err"; rc=$?
156
+ t "a merge-commit source succeeds" "$rc" "0"
157
+ t "…carrying the merged side's diff" "$(git diff origin/main fix/14-hotfix-main)" "$(git diff "$MERGE~1" "$MERGE")"
158
+ tc "$GH_LOG" 'Cherry-pick of #14' "…and the PR number from the merge subject"
159
+
160
+ # ── a rebase-merged PR: GitHub names only its LAST commit, every one of its commits is carried ───
161
+ for tr in graphql rest; do
162
+ : > "$GH_LOG"
163
+ GH_SHA="$REB" GH_SUBJECTS="$(printf 'fix: rebased part one\nfix: rebased part two')" CCKIT_GH_TRANSPORT="$tr" \
164
+ "$CCKIT" hotfix 20 >/dev/null 2>"$tmp/err"; rc=$?
165
+ t "$tr: a rebase-merged PR succeeds" "$rc" "0"
166
+ t "$tr: …carrying both of its commits" "$(git rev-list --count origin/main..fix/20-hotfix-main 2>/dev/null)" "2"
167
+ t "$tr: …whose diff is the whole PR's" "$(git diff origin/main fix/20-hotfix-main)" "$(git diff "$REB~2" "$REB")"
168
+ tc "$tmp/err" 'rebase-merged: carrying its 2 commits' "$tr: …and says so"
169
+ tc "$GH_LOG" "Source commits.*$(git rev-parse "$REB~1").*$REB" "$tr: the body lists both source commits"
170
+ git worktree remove --force "$tmp/work/.claude/worktrees/fix+20-hotfix-main"; git branch -q -D fix/20-hotfix-main
171
+ git push -q origin :fix/20-hotfix-main 2>/dev/null
172
+ done
173
+ # A SQUASH of a multi-commit PR is one commit carrying all of it: the subjects under it are not the PR's.
174
+ reset_hotfix
175
+ : > "$GH_LOG"
176
+ GH_SHA="$SRC" GH_SUBJECTS="$(printf 'wip one\nwip two')" "$CCKIT" hotfix 12 >/dev/null 2>"$tmp/err"; rc=$?
177
+ t "a squashed two-commit PR succeeds" "$rc" "0"
178
+ t "…as the one squash commit" "$(git rev-list --count origin/main..fix/12-hotfix-main)" "1"
179
+ tn "$tmp/err" 'rebase-merged' "…and is not taken for a rebase merge"
180
+ # A PR whose commits cannot be read is refused, not guessed at.
181
+ GH_SHA="$SRC" GH_SUBJECTS="" "$CCKIT" hotfix 12 >/dev/null 2>"$tmp/err"; rc=$?
182
+ t "unreadable PR commits are refused" "$rc" "1"
183
+ tc "$tmp/err" 'cannot read the commits' "…and says why"
184
+
185
+ # ── a commit with no PR in its subject: named by sha ─────────────────────────────────────────────
186
+ : > "$GH_LOG"
187
+ SIDE="$(git rev-parse side)"
188
+ "$CCKIT" hotfix "$SIDE" --base main >/dev/null 2>"$tmp/err"; rc=$?
189
+ t "a commit with no (#N) succeeds" "$rc" "0"
190
+ short="$(git rev-parse --short=7 "$SIDE")"
191
+ t "…on a branch named by sha" "$(git rev-parse --verify --quiet "fix/hotfix-$short-main" >/dev/null && echo yes || echo no)" "yes"
192
+ tc "$GH_LOG" "Cherry-pick of $SIDE" "…and the body names the commit"
193
+
194
+ # ── refusals: nothing is created ─────────────────────────────────────────────────────────────────
195
+ : > "$GH_LOG"
196
+ GH_STATE="OPEN" "$CCKIT" hotfix 99 >/dev/null 2>"$tmp/err"; rc=$?
197
+ t "an unmerged PR is refused" "$rc" "1"
198
+ tc "$tmp/err" 'not merged' "…and says why"
199
+ t "…with no branch made" "$(git branch --list 'fix/99-*' | wc -l | tr -d ' ')" "0"
200
+ "$CCKIT" hotfix deadbeefdeadbeef --base main >/dev/null 2>"$tmp/err"; rc=$?
201
+ t "an unknown sha is refused" "$rc" "1"
202
+ tc "$tmp/err" 'is not a commit' "…and says why"
203
+ "$CCKIT" hotfix "$SRC" --base nope >/dev/null 2>"$tmp/err"; rc=$?
204
+ t "a base missing on origin is refused" "$rc" "1"
205
+ tc "$tmp/err" "origin has no branch 'nope'" "…and says why"
206
+ t "…with no branch made" "$(git branch --list 'fix/12-hotfix-nope' | wc -l | tr -d ' ')" "0"
207
+ "$CCKIT" hotfix >/dev/null 2>"$tmp/err"; rc=$?
208
+ t "no source is a usage error" "$rc" "2"
209
+ "$CCKIT" hotfix "$SRC" --base >/dev/null 2>"$tmp/err"; rc=$?
210
+ t "--base with no value is a usage error" "$rc" "2"
211
+ tn "$GH_LOG" '^pr create|-X POST' "no refusal opened a PR"
212
+
213
+ # ── a conflict stops before the push and says how to continue ────────────────────────────────────
214
+ git checkout -q -b rel-edit origin/main; printf 'a\nb\nc\nZ\n' > app.txt; git commit -q -am "main-only edit"
215
+ git push -q origin rel-edit:rel; git checkout -q develop
216
+ : > "$GH_LOG"; : > "$tmp/prepush.log"
217
+ "$CCKIT" hotfix "$CONF" --base rel >/dev/null 2>"$tmp/err"; rc=$?
218
+ t "a conflicting pick fails" "$rc" "1"
219
+ tc "$tmp/err" 'cherry-pick --continue' "…telling you how to continue"
220
+ t "…without pushing" "$(wc -l < "$tmp/prepush.log" | tr -d ' ')" "0"
221
+ tn "$GH_LOG" '^pr create' "…and without opening a PR"
222
+ "$CCKIT" hotfix "$CONF" --base rel >/dev/null 2>"$tmp/err"; rc=$?
223
+ t "a re-run mid-conflict is refused" "$rc" "1"
224
+ cwt="$tmp/work/.claude/worktrees/fix+15-hotfix-rel"
225
+ printf 'a\nB\nc\nZ\nd\n' > "$cwt/app.txt"; git -C "$cwt" add app.txt
226
+ GIT_EDITOR=true git -C "$cwt" cherry-pick --continue >/dev/null 2>&1
227
+ "$CCKIT" hotfix "$CONF" --base rel >/dev/null 2>"$tmp/err"; rc=$?
228
+ t "after --continue the re-run finishes" "$rc" "0"
229
+ tc "$GH_LOG" '^pr create .*--base rel ' "…opening the PR against the chosen base"
230
+
231
+ [ "$fail" -eq 0 ] && echo "kto-hotfix: all passed" || echo "kto-hotfix: FAILURES"
232
+ exit "$fail"
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env bash
2
+ # kto-task-close-test.sh — `cckit close` closes with a reason from the close-reason set, maps it to
3
+ # GitHub's state_reason, still posts the summary and still sets the board to Done (#377).
4
+ # Hermetic: stubbed gh and board helpers. Run: bash scripts/lib/kto-task-close-test.sh
5
+ # errors: strict — a test runner: rc 1 on any failed assertion
6
+ set -u
7
+ LIB="$(cd "$(dirname "$0")" && pwd)"
8
+ ROOT="$(cd "$LIB/../.." && pwd)"
9
+ fail=0
10
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
11
+ tc() { if grep -qE -- "$2" "$1"; then echo "ok: $3"; else echo "FAIL: $3 (no /$2/ in $1)"; fail=1; fi; }
12
+ command -v jq >/dev/null 2>&1 || { echo "kto-task-close-test: jq required" >&2; exit 1; }
13
+
14
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
15
+ export GH_LOG="$tmp/gh.log" GH_STATE="OPEN"
16
+ mkdir -p "$tmp/bin"
17
+ cat > "$tmp/bin/gh" <<'SH'
18
+ #!/usr/bin/env bash
19
+ echo "$*" >> "$GH_LOG"
20
+ case "$1 $2" in
21
+ "issue view") printf '{"state":"%s","projectItems":[]}\n' "$GH_STATE" ;;
22
+ *) exit 0 ;;
23
+ esac
24
+ SH
25
+ chmod +x "$tmp/bin/gh"
26
+ export PATH="$tmp/bin:$PATH" KIT_REPO="o/r" KIT_PROJECTS_V2="true"
27
+ unset KIT_CONFIG
28
+
29
+ # shellcheck source=/dev/null
30
+ . "$LIB/kit-task-ops.sh"
31
+ # Board stubs: the close must still move the item to Done whatever the reason.
32
+ BOARD_LOG="$tmp/board.log"
33
+ load_project_ids() { STATUS_FIELD_ID="SF"; STATUS_OPT_DONE="DONE"; return 0; }
34
+ project_find_item_by_issue() { echo "ITEM-$1"; }
35
+ project_set_single_select() { echo "$*" >> "$BOARD_LOG"; }
36
+
37
+ run() { : > "$GH_LOG"; : > "$BOARD_LOG"; kto_task_close "$@" >/dev/null 2>"$tmp/err"; echo $?; }
38
+ closed() { grep -E '^issue close ' "$GH_LOG" | sed -n 1p; }
39
+
40
+ t "default close succeeds" "$(run 5 "Shipped in #9.")" 0
41
+ tc "$GH_LOG" '^issue close 5 --repo o/r --reason completed --comment Shipped in #9\.$' "default reason is completed, with the summary"
42
+ tc "$BOARD_LOG" '^ITEM-5 SF DONE$' "the board goes to Done"
43
+
44
+ t "--reason not-planned succeeds" "$(run 6 "Measured; not worth it." --reason not-planned)" 0
45
+ tc "$GH_LOG" '^issue close 6 --repo o/r --reason not planned --comment Measured; not worth it\.$' "not-planned maps to GitHub's 'not planned'"
46
+ tc "$BOARD_LOG" '^ITEM-6 SF DONE$' "not planned still sets Done"
47
+
48
+ t "--duplicate-of succeeds without a summary" "$(run 7 --duplicate-of 4)" 0
49
+ tc "$GH_LOG" '^issue close 7 --repo o/r --duplicate-of 4 --comment Duplicate of #4\.$' "--duplicate-of links the original and defaults the comment"
50
+ tc "$BOARD_LOG" '^ITEM-7 SF DONE$' "a duplicate still sets Done"
51
+ t "--reason duplicate + --duplicate-of" "$(run 7 "Same as #4." --reason duplicate --duplicate-of '#4')" 0
52
+ tc "$GH_LOG" '^issue close 7 --repo o/r --duplicate-of 4 --comment Same as #4\.$' "an explicit summary is kept; '#4' is accepted"
53
+
54
+ t "--superseded-by succeeds" "$(run 8 "Folded into the new effort." --superseded-by 12)" 0
55
+ tc "$GH_LOG" '^issue close 8 --repo o/r --reason not planned --comment Folded into the new effort\.$' "superseded closes as not planned"
56
+ tc "$GH_LOG" '^Superseded by #12\.$' "and the comment says Superseded by #12"
57
+ t "--superseded-by alone defaults the comment" "$(run 8 --superseded-by 12)" 0
58
+ tc "$GH_LOG" '^issue close 8 --repo o/r --reason not planned --comment Superseded by #12\.$' "default superseded comment"
59
+
60
+ t "--reason completed is accepted explicitly" "$(run 9 "Done." --reason completed)" 0
61
+ tc "$GH_LOG" '^issue close 9 --repo o/r --reason completed ' "explicit completed"
62
+
63
+ # refusals: nothing is closed and the board is not touched
64
+ t "an unknown reason is refused (rc 2)" "$(run 10 "x" --reason wontfix)" 2
65
+ t "an unknown flag is refused (rc 2)" "$(run 10 "x" --force)" 2
66
+ t "duplicate without --duplicate-of (rc 2)" "$(run 10 "x" --reason duplicate)" 2
67
+ t "--duplicate-of contradicting --reason (rc 2)" "$(run 10 "x" --reason completed --duplicate-of 4)" 2
68
+ t "--duplicate-of + --superseded-by (rc 2)" "$(run 10 "x" --duplicate-of 4 --superseded-by 5)" 2
69
+ t "a non-number --duplicate-of (rc 2)" "$(run 10 "x" --duplicate-of abc)" 2
70
+ t "no summary and no default (rc 1)" "$(run 10)" 1
71
+ t "refusals closed nothing" "$(grep -c 'issue close' "$GH_LOG")" 0
72
+ t "refusals left the board alone" "$(wc -l < "$BOARD_LOG" | tr -d ' ')" 0
73
+
74
+ # an already-closed issue: board only, no second close
75
+ GH_STATE="CLOSED"
76
+ t "an already-closed issue is fine" "$(run 11 "x" --reason not-planned)" 0
77
+ t "it is not closed again" "$(grep -c '^issue close' "$GH_LOG")" 0
78
+ tc "$BOARD_LOG" '^ITEM-11 SF DONE$' "but the board still goes to Done"
79
+
80
+ t "the dispatcher answers --help" "$("$ROOT/bin/cckit" close --help | cut -c1-19)" "cckit close <issue>"
81
+
82
+ [ "$fail" -eq 0 ] && echo "kto-task-close: all passed" || echo "kto-task-close: FAILURES"
83
+ exit "$fail"
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env bash
2
+ # kto-task-new-test.sh — kto_task_new against a stubbed gh (#387): a label the repo does not have
3
+ # is dropped with a warning and the issue is still created; with every label present the create
4
+ # call is unchanged; a failed create returns non-zero and prints no URL.
5
+ # Run: bash scripts/lib/kto-task-new-test.sh
6
+ # errors: strict — a test runner: rc 1 on any failed assertion
7
+ set -u
8
+ LIB="$(cd "$(dirname "$0")" && pwd)"
9
+ fail=0
10
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
11
+ tc() { if grep -qE -- "$2" "$1"; then echo "ok: $3"; else echo "FAIL: $3 (no /$2/ in $1)"; fail=1; fi; }
12
+ tn() { if grep -qE -- "$2" "$1"; then echo "FAIL: $3 (/$2/ in $1)"; fail=1; else echo "ok: $3"; fi; }
13
+
14
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
15
+ export GH_LOG="$tmp/gh.log"; : > "$GH_LOG"
16
+ mkdir -p "$tmp/bin"
17
+ # GH_HAVE: the repo's labels, comma-separated. GH_LIST_FAIL=1: `gh label list` fails.
18
+ # GH_CREATE_FAIL=1: `gh issue create` fails. Like real gh, a create naming a label the repo does
19
+ # not have fails with "could not add label".
20
+ cat > "$tmp/bin/gh" <<'SH'
21
+ #!/usr/bin/env bash
22
+ echo "$*" >> "$GH_LOG"
23
+ case "$1 $2" in
24
+ "label list")
25
+ [ -n "${GH_LIST_FAIL:-}" ] && { echo "gh: HTTP 403" >&2; exit 1; }
26
+ printf '%s\n' "$GH_HAVE" | tr ',' '\n' ;;
27
+ "issue create")
28
+ [ -n "${GH_CREATE_FAIL:-}" ] && { echo "gh: HTTP 500" >&2; exit 1; }
29
+ want=""; while [ $# -gt 0 ]; do [ "$1" = "--label" ] && want="${2:-}"; shift; done
30
+ for l in $(printf '%s' "$want" | tr ',' ' '); do
31
+ case ",$(printf '%s' "$GH_HAVE" | tr 'A-Z' 'a-z')," in *",$l,"*) ;; *) echo "could not add label: '$l' not found" >&2; exit 1 ;; esac
32
+ done
33
+ echo "https://github.com/o/r/issues/50" ;;
34
+ *) exit 0 ;;
35
+ esac
36
+ SH
37
+ chmod +x "$tmp/bin/gh"
38
+ export PATH="$tmp/bin:$PATH" KIT_REPO="o/r" KIT_BASE_BRANCH="main" KIT_PROJECTS_V2="false"
39
+ unset KIT_CONFIG CLAUDE_CODE_REMOTE CCKIT_GH_TRANSPORT GH_LIST_FAIL GH_CREATE_FAIL
40
+ cd "$tmp" || exit 1
41
+
42
+ # shellcheck source=/dev/null
43
+ . "$LIB/kit-task-ops.sh"
44
+
45
+ # ── a missing label is a warning, not an abort ────────────────────────────────────────────────────
46
+ export GH_HAVE="kind:task,priority:p2,role:backend"
47
+ : > "$GH_LOG"
48
+ kto_task_new "Test" backend feat p2 "" "" "" x >"$tmp/out" 2>"$tmp/err"; rc=$?
49
+ t "missing kind label: rc 0" "$rc" "0"
50
+ tc "$tmp/out" '^✓ https://github.com/o/r/issues/50$' "missing kind label: prints the issue URL"
51
+ t "missing kind label: echoes the number" "$(tail -1 "$tmp/out")" "50"
52
+ tc "$tmp/err" "kind:feat" "missing kind label: the warning names kind:feat"
53
+ tc "$GH_LOG" '^issue create .*--label priority:p2,role:backend( |$)' "missing kind label: only existing labels are sent"
54
+ tn "$GH_LOG" '^issue create .*kind:feat' "missing kind label: kind:feat is not sent"
55
+ tn "$GH_LOG" '^label create' "missing kind label: no label is created"
56
+
57
+ # Label names are case-insensitive on GitHub.
58
+ export GH_HAVE="Kind:Feat,priority:p2,role:backend"
59
+ : > "$GH_LOG"
60
+ kto_task_new "Test" backend feat p2 "" "" "" x >"$tmp/out" 2>"$tmp/err"; rc=$?
61
+ t "case-insensitive match: rc 0" "$rc" "0"
62
+ t "case-insensitive match: no warning" "$(grep -c 'kind:feat' "$tmp/err")" "0"
63
+ tc "$GH_LOG" '^issue create .*--label kind:feat,priority:p2,role:backend ' "case-insensitive match: the label is sent"
64
+
65
+ # ── every label missing: the issue is created with no --label at all ──────────────────────────────
66
+ export GH_HAVE="bug"
67
+ : > "$GH_LOG"
68
+ kto_task_new "Test" backend feat p2 "" "" "" x >"$tmp/out" 2>"$tmp/err"; rc=$?
69
+ t "no label exists: rc 0" "$rc" "0"
70
+ tc "$tmp/out" '^✓ https://github.com/o/r/issues/50$' "no label exists: prints the issue URL"
71
+ tn "$GH_LOG" '^issue create .*--label' "no label exists: no --label flag"
72
+ t "no label exists: three labels warned" "$(grep -cE 'kind:feat|priority:p2|role:backend' "$tmp/err")" "3"
73
+
74
+ # ── all labels present: the create call is unchanged ──────────────────────────────────────────────
75
+ export GH_HAVE="kind:feat,priority:p2,role:backend"
76
+ : > "$GH_LOG"
77
+ kto_task_new "Test" backend feat p2 "" "" "" x >"$tmp/out" 2>"$tmp/err"; rc=$?
78
+ t "all labels present: rc 0" "$rc" "0"
79
+ tc "$GH_LOG" '^issue create --repo o/r --title Test --body .*--label kind:feat,priority:p2,role:backend --assignee @me$' "all labels present: the create call is unchanged"
80
+ t "all labels present: no warning" "$(wc -c < "$tmp/err" | tr -d ' ')" "0"
81
+
82
+ # ── the label list cannot be read: send every label, as before ────────────────────────────────────
83
+ : > "$GH_LOG"
84
+ GH_LIST_FAIL=1 kto_task_new "Test" backend feat p2 "" "" "" x >"$tmp/out" 2>"$tmp/err"; rc=$?
85
+ t "unreadable label list: rc 0" "$rc" "0"
86
+ tc "$GH_LOG" '^issue create .*--label kind:feat,priority:p2,role:backend ' "unreadable label list: every label is sent"
87
+
88
+ # ── the create itself fails: non-zero, no URL ─────────────────────────────────────────────────────
89
+ : > "$GH_LOG"
90
+ GH_CREATE_FAIL=1 kto_task_new "Test" backend feat p2 "" "" "" x >"$tmp/out" 2>"$tmp/err"; rc=$?
91
+ t "create fails: rc non-zero" "$([ "$rc" -ne 0 ] && echo nonzero)" "nonzero"
92
+ t "create fails: prints nothing on stdout" "$(wc -c < "$tmp/out" | tr -d ' ')" "0"
93
+
94
+ [ "$fail" -eq 0 ] && echo "kto-task-new: all passed" || echo "kto-task-new: FAILURES"
95
+ exit "$fail"
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env bash
2
- # kto-task-pr-merge-test.sh — kto_task_pr_merge never acts on the base branch (#366).
2
+ # kto-task-pr-merge-test.sh — kto_task_pr_merge never acts on the base branch (#366), cleans up from
3
+ # the PR's own worktree (#371), and merges by squash, merge commit or rebase into develop or an
4
+ # effort branch (#376). An effort/* HEAD is refused — its PR merges with `cckit effort close` (#379).
3
5
  # A flag taken as the PR number used to "merge" (gh pr merge --help exits 0) and then run the branch
4
6
  # cleanup on the base branch; a conflicting PR merged from the hub would rebase + force-push it.
5
7
  # Hermetic: stubbed gh, throwaway repo + bare remote. Run: bash scripts/lib/kto-task-pr-merge-test.sh
@@ -12,13 +14,19 @@ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]'
12
14
  command -v jq >/dev/null 2>&1 || { echo "kto-task-pr-merge-test: jq required" >&2; exit 1; }
13
15
 
14
16
  tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
15
- export GH_LOG="$tmp/gh.log" GH_MERGEABLE="MERGEABLE"; : > "$GH_LOG"
17
+ export GH_LOG="$tmp/gh.log" GH_MERGEABLE="MERGEABLE" GH_BASE="develop" GH_HEAD="" GH_CLOSING="" GH_ISSUE_STATE=""; : > "$GH_LOG"
16
18
  mkdir -p "$tmp/bin"
17
19
  cat > "$tmp/bin/gh" <<'SH'
18
20
  #!/usr/bin/env bash
19
21
  echo "$*" >> "$GH_LOG"
20
22
  case "$1 $2" in
21
- "pr view") echo "{\"mergeable\":\"$GH_MERGEABLE\",\"status\":\"CLEAN\"}" ;;
23
+ "pr view") case "$*" in
24
+ *closingIssuesReferences*) [ -n "${GH_CLOSING:-}" ] && printf '%s\n' $GH_CLOSING; exit 0 ;;
25
+ *"--json body"*) exit 0 ;;
26
+ esac
27
+ printf '{"mergeable":"%s","mergeStateStatus":"CLEAN","baseRefName":"%s","headRefName":"%s"}\n' \
28
+ "$GH_MERGEABLE" "${GH_BASE:-develop}" "${GH_HEAD:-}" ;;
29
+ "issue view") [ -n "${GH_ISSUE_STATE:-}" ] && echo "$GH_ISSUE_STATE"; exit 0 ;;
22
30
  *) exit 0 ;;
23
31
  esac
24
32
  SH
@@ -39,14 +47,31 @@ kto_task_pr_merge --help >/dev/null 2>&1; rc=$?
39
47
  t "a flag is refused as a PR number (rc 2)" "$rc" "2"
40
48
  t "nothing was merged on a refused flag" "$(grep -c 'pr merge' "$GH_LOG")" "0"
41
49
  t "the dispatcher answers --help with usage" "$("$ROOT/bin/cckit" merge --help | cut -c1-18)" "cckit merge [<pr>]"
50
+ # #376: a bad flag, or a second PR number, is refused with usage and merges nothing
51
+ kto_task_pr_merge 7 --fast >/dev/null 2>"$tmp/errf"; rc=$?
52
+ t "an unknown flag is refused (rc 2)" "$rc" "2"
53
+ t "the refusal prints the usage" "$(grep -c 'usage: cckit merge \[<pr>\] \[--squash|--merge|--rebase\]' "$tmp/errf")" "1"
54
+ kto_task_pr_merge 7 8 >/dev/null 2>&1; rc=$?
55
+ t "two PR numbers are refused (rc 2)" "$rc" "2"
56
+ t "nothing was merged on a refused flag" "$(grep -c 'pr merge' "$GH_LOG")" "0"
42
57
 
43
- : > "$GH_LOG"
58
+ : > "$GH_LOG"; GH_HEAD="fix/7-x"
44
59
  kto_task_pr_merge 7 >/dev/null 2>&1
45
60
  t "a numeric PR merges" "$(grep -c 'pr merge 7' "$GH_LOG")" "1"
61
+ t "the default method is still squash" "$(grep -c 'pr merge 7 --repo o/r --squash' "$GH_LOG")" "1"
62
+ # #376: --merge (a merge commit) and --rebase reach gh unchanged
63
+ : > "$GH_LOG"; GH_HEAD="fix/10-x"
64
+ kto_task_pr_merge 10 --merge >/dev/null 2>&1; rc=$?
65
+ t "--merge succeeds" "$rc" "0"
66
+ t "--merge asks GitHub for a merge commit" "$(grep -c 'pr merge 10 --repo o/r --merge' "$GH_LOG")" "1"
67
+ : > "$GH_LOG"; GH_HEAD="fix/13-x"
68
+ kto_task_pr_merge --rebase 13 >/dev/null 2>&1; rc=$?
69
+ t "--rebase succeeds (flag before the number)" "$rc" "0"
70
+ t "--rebase asks GitHub for a rebase merge" "$(grep -c 'pr merge 13 --repo o/r --rebase' "$GH_LOG")" "1"
46
71
  t "merging from the base branch keeps it" "$(git branch --list develop | tr -d ' *')" "develop"
47
72
  t "and keeps it on origin" "$(git ls-remote --heads origin develop | wc -l | tr -d ' ')" "1"
48
73
 
49
- : > "$GH_LOG"; GH_MERGEABLE="CONFLICTING"
74
+ : > "$GH_LOG"; GH_MERGEABLE="CONFLICTING"; GH_HEAD="fix/8-x"
50
75
  before="$(git rev-parse develop)"
51
76
  kto_task_pr_merge 8 >/dev/null 2>&1; rc=$?
52
77
  t "a conflicting PR from the base branch is refused" "$rc" "1"
@@ -54,7 +79,7 @@ t "the base branch was not rebased" "$(git rev-parse develop)" "$be
54
79
  t "nothing was merged on a conflict refusal" "$(grep -c 'pr merge' "$GH_LOG")" "0"
55
80
 
56
81
  # ── #371: merged from the PR's OWN worktree, the cleanup still finishes ─────────────────────────
57
- : > "$GH_LOG"; GH_MERGEABLE="MERGEABLE"
82
+ : > "$GH_LOG"; GH_MERGEABLE="MERGEABLE"; GH_HEAD="fix/9-x"
58
83
  wt="$tmp/work/.claude/worktrees/fix+9-x"
59
84
  git worktree add -q -b fix/9-x "$wt" develop
60
85
  git -C "$wt" commit -q --allow-empty -m "the fix"
@@ -68,5 +93,71 @@ t "its remote branch is deleted" "$(git ls-remote --heads origi
68
93
  t "no 'Unable to read current working directory'" "$(grep -c 'current working directory' "$tmp/err9")" "0"
69
94
  t "the base branch survives" "$(git branch --list develop | tr -d ' *')" "develop"
70
95
 
96
+ # ── #376: a sub PR whose base is an effort branch ────────────────────────────────────────────────
97
+ git checkout -q develop
98
+ ewt="$tmp/work/.claude/worktrees/effort+5-e"
99
+ git worktree add -q -b effort/5-e "$ewt" develop
100
+ git -C "$ewt" commit -q --allow-empty -m "effort start"; git -C "$ewt" push -q origin effort/5-e
101
+ swt="$tmp/work/.claude/worktrees/sub+5a-x"
102
+ git worktree add -q -b sub/5a-x "$swt" effort/5-e
103
+ git -C "$swt" commit -q --allow-empty -m "sub a"; git -C "$swt" push -q origin sub/5a-x
104
+ # what GitHub's merge does to the effort branch: a new commit on origin/effort/5-e
105
+ git clone -q "$tmp/remote.git" "$tmp/gh-side" 2>/dev/null
106
+ git -C "$tmp/gh-side" checkout -q effort/5-e
107
+ git -C "$tmp/gh-side" -c user.email=t@t -c user.name=t commit -q --allow-empty -m "Merge pull request #11"
108
+ git -C "$tmp/gh-side" push -q origin effort/5-e
109
+
110
+ : > "$GH_LOG"; GH_BASE="effort/5-e"; GH_HEAD="sub/5a-x"
111
+ ( cd "$swt" && kto_task_pr_merge 11 --merge ) >/dev/null 2>&1; rc=$?
112
+ t "a sub PR into an effort branch merges (rc 0)" "$rc" "0"
113
+ t "with a merge commit" "$(grep -c 'pr merge 11 --repo o/r --merge' "$GH_LOG")" "1"
114
+ t "the sub worktree is removed" "$([ -d "$swt" ] && echo present || echo gone)" "gone"
115
+ t "the sub branch is deleted" "$(git branch --list sub/5a-x | wc -l | tr -d ' ')" "0"
116
+ t "the effort branch survives" "$(git branch --list effort/5-e | tr -d ' *+')" "effort/5-e"
117
+ t "the effort worktree survives" "$([ -d "$ewt" ] && echo present || echo gone)" "present"
118
+ t "the effort worktree is pulled to the merge" "$(git -C "$ewt" rev-parse HEAD)" "$(git -C "$tmp/gh-side" rev-parse HEAD)"
119
+ t "the main checkout stays on develop" "$(git rev-parse --abbrev-ref HEAD)" "develop"
120
+
121
+ # Run from the EFFORT worktree with a sub PR number: the current branch is the PR's base, and it
122
+ # must never be treated as the branch to clean up (before #376 this deleted effort/5-e).
123
+ git branch -q sub/5b-y effort/5-e; git push -q origin sub/5b-y
124
+ : > "$GH_LOG"; GH_HEAD="sub/5b-y"
125
+ ( cd "$ewt" && kto_task_pr_merge 12 ) >/dev/null 2>&1; rc=$?
126
+ t "merging a sub PR from the effort worktree: rc 0" "$rc" "0"
127
+ t "the effort branch still survives" "$(git branch --list effort/5-e | tr -d ' *+')" "effort/5-e"
128
+ t "the effort worktree still survives" "$([ -d "$ewt" ] && echo present || echo gone)" "present"
129
+ t "the sub branch (not the cwd branch) is deleted" "$(git branch --list sub/5b-y | wc -l | tr -d ' ')" "0"
130
+ t "and on origin" "$(git ls-remote --heads origin sub/5b-y | wc -l | tr -d ' ')" "0"
131
+ t "effort/5-e is still on origin" "$(git ls-remote --heads origin effort/5-e | wc -l | tr -d ' ')" "1"
132
+
133
+ # ── #379: the linked-issue loop does not depend on IFS ───────────────────────────────────────────
134
+ # The effort worktree lives under the main checkout here; keep it out of `git status` so the main
135
+ # checkout reads clean.
136
+ echo ".claude/" >> "$tmp/work/.git/info/exclude"
137
+ # A caller that left IFS NUL-polluted made `for n in $issues` pass "21\n22" as ONE issue number.
138
+ : > "$GH_LOG"; GH_BASE="develop"; GH_HEAD="fix/20-x"; GH_CLOSING="21 22"; GH_ISSUE_STATE="OPEN"
139
+ ( IFS=$'\0'; kto_task_pr_merge 20 ) >/dev/null 2>&1; rc=$?
140
+ t "merge under IFS=\$'\\0' exits 0" "$rc" "0"
141
+ t "issue 21 is closed on its own" "$(grep -c '^issue close 21 ' "$GH_LOG")" "1"
142
+ t "issue 22 is closed on its own" "$(grep -c '^issue close 22 ' "$GH_LOG")" "1"
143
+ t "exactly two issue close calls" "$(grep -c '^issue close ' "$GH_LOG")" "2"
144
+ GH_CLOSING=""; GH_ISSUE_STATE=""
145
+
146
+ # ── #379: an effort/* head is refused — the squash would destroy the per-sub trace ───────────────
147
+ : > "$GH_LOG"; GH_BASE="develop"; GH_HEAD="effort/5-e"
148
+ kto_task_pr_merge 14 >/dev/null 2>"$tmp/err14"; rc=$?
149
+ t "an effort head is refused (rc 1)" "$rc" "1"
150
+ t "the refusal names cckit effort close 5" "$(grep -c 'cckit effort close 5' "$tmp/err14")" "1"
151
+ t "nothing was merged on the effort refusal" "$(grep -c 'pr merge' "$GH_LOG")" "0"
152
+ t "the refused effort branch survives" "$(git branch --list effort/5-e | tr -d ' *+')" "effort/5-e"
153
+ ( cd "$ewt" && kto_task_pr_merge ) >/dev/null 2>&1; rc=$?
154
+ t "refused from the effort worktree too (rc 1)" "$rc" "1"
155
+ t "still nothing merged" "$(grep -c 'pr merge' "$GH_LOG")" "0"
156
+ : > "$GH_LOG"
157
+ KIT_FORCE=1 kto_task_pr_merge 14 >/dev/null 2>"$tmp/err14f"; rc=$?
158
+ t "KIT_FORCE=1 merges the effort head (rc 0)" "$rc" "0"
159
+ t "KIT_FORCE=1 warns about the lost trace" "$(grep -c 'KIT_FORCE=1' "$tmp/err14f")" "1"
160
+ t "KIT_FORCE=1 reaches gh pr merge" "$(grep -c 'pr merge 14' "$GH_LOG")" "1"
161
+
71
162
  [ "$fail" -eq 0 ] && echo "kto-task-pr-merge: all passed" || echo "kto-task-pr-merge: FAILURES"
72
163
  exit "$fail"