@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,474 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # init-guided-test.sh — the guided `cckit init` (#456), end to end and offline.
4
+ #
5
+ # Covers every detection branch (home directory, missing / empty folder, files without a project
6
+ # marker, a project without git, a git repository without a remote, a repository with a remote),
7
+ # the answers file, the one confirmation (--yes; no terminal without it), --dry-run writing
8
+ # nothing, --no-github, an idempotent re-run, a refused branch protection, a failed step that does
9
+ # not hide the later ones, and --upgrade staying out of the flow.
10
+ #
11
+ # Hermetic: HOME is a temp dir, `gh` and `pnpm` are stubs on PATH, "GitHub" is a directory of bare
12
+ # repositories plus a log of every write the stub was asked to make, and the recipe is a fixture
13
+ # whose commands are plain shell. Nothing here reaches the network or a real repository.
14
+ # Run: bash scripts/init-guided-test.sh
15
+ # errors: strict — a test runner: rc 1 on any failed assertion
16
+ set -u
17
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
18
+ # shellcheck source=/dev/null
19
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
20
+ INIT="$ROOT/scripts/init.sh"
21
+ fail=0
22
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
23
+ has() { if grep -qF -- "$3" <<<"$2"; then echo "ok: $1"; else echo "FAIL: $1 -> '$3' not in output:"; printf '%s\n' "$2" | tail -25; fail=1; fi; }
24
+ hasnt() { if grep -qF -- "$3" <<<"$2"; then echo "FAIL: $1 -> '$3' found in output"; fail=1; else echo "ok: $1"; fi; }
25
+ yes_if() { if eval "$2"; then echo "ok: $1"; else echo "FAIL: $1 -> not true: $2"; fail=1; fi; }
26
+
27
+ for dep in jq git perl; do
28
+ command -v "$dep" >/dev/null 2>&1 || { echo "init-guided-test: $dep absent — skipping (dependency-light gate)"; exit 0; }
29
+ done
30
+
31
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
32
+ tmp="$(cd "$tmp" && pwd -P)"
33
+ export HOME="$tmp/home"; mkdir -p "$HOME"
34
+ printf '[user]\n\tname = Test Person\n\temail = test@example.com\n[init]\n\tdefaultBranch = trunk\n' > "$HOME/.gitconfig"
35
+ export GHS="$tmp/github"; mkdir -p "$GHS/git" "$GHS/repos"; : > "$GHS/writes.log"
36
+
37
+ # ── stubs ────────────────────────────────────────────────────────────────────────────────────────
38
+ mkdir -p "$tmp/stubs"
39
+ cat > "$tmp/stubs/gh" <<'STUB'
40
+ #!/usr/bin/env bash
41
+ # A GitHub made of files: $GHS/repos/<owner>__<name>/ holds one repository's state, $GHS/git/ the
42
+ # bare repositories git pushes to, $GHS/writes.log one line per write the caller asked for.
43
+ set -u
44
+ log() { printf '%s\n' "$*" >> "$GHS/writes.log"; }
45
+ rdir() { printf '%s/repos/%s\n' "$GHS" "$(printf '%s' "$1" | tr '/' '_' | sed 's/_/__/')"; }
46
+ here_repo() { # the repository the cwd's origin points at, when it is one of ours
47
+ local u; u="$(git remote get-url origin 2>/dev/null)" || return 1
48
+ case "$u" in "$GHS/git/"*) u="${u#"$GHS/git/"}"; printf '%s\n' "${u%.git}" ;; *) return 1 ;; esac
49
+ }
50
+ case "${1:-} ${2:-}" in
51
+ "auth status") exit 0 ;;
52
+ "config get") echo https; exit 0 ;;
53
+ "api user") echo tester; exit 0 ;;
54
+ "repo view")
55
+ shift 2; repo=""; fields=""
56
+ while [ $# -gt 0 ]; do case "$1" in --json) fields="$2"; shift 2 ;; -q|--jq) shift 2 ;; *) repo="$1"; shift ;; esac; done
57
+ [ -n "$repo" ] || repo="$(here_repo)" || exit 1
58
+ d="$(rdir "$repo")"; [ -d "$d" ] || { echo "GraphQL: Could not resolve to a Repository" >&2; exit 1; }
59
+ case "$fields" in
60
+ nameWithOwner) echo "$repo" ;;
61
+ defaultBranchRef) cat "$d/default" 2>/dev/null || echo main ;;
62
+ url,sshUrl) printf '%s\t%s\n' "$GHS/git/$repo" "" ;;
63
+ esac
64
+ exit 0 ;;
65
+ "repo create")
66
+ shift 2; repo="$1"; shift; vis=""; src=""
67
+ while [ $# -gt 0 ]; do case "$1" in --private|--public) vis="$1"; shift ;; --source) src="$2"; shift 2 ;; --remote) shift 2 ;; *) shift ;; esac; done
68
+ [ -f "$GHS/fail-create" ] && { echo "gh: could not create the repository (HTTP 500)" >&2; exit 1; }
69
+ log "repo create $repo $vis"
70
+ d="$(rdir "$repo")"; mkdir -p "$d" "$GHS/git/$(dirname "$repo")"
71
+ git init -q --bare "$GHS/git/$repo.git"
72
+ git -C "$src" remote add origin "$GHS/git/$repo.git"
73
+ exit 0 ;;
74
+ "repo edit")
75
+ repo="$3"; log "repo edit $*"; printf '%s\n' "$5" > "$(rdir "$repo")/default"; exit 0 ;;
76
+ "label list")
77
+ shift 2; while [ $# -gt 0 ]; do case "$1" in --repo) repo="$2"; shift 2 ;; *) shift ;; esac; done
78
+ cat "$(rdir "$repo")/labels" 2>/dev/null; exit 0 ;;
79
+ "label create")
80
+ name="$3"; shift 3; while [ $# -gt 0 ]; do case "$1" in --repo) repo="$2"; shift 2 ;; *) shift ;; esac; done
81
+ [ -f "$GHS/fail-labels" ] && { echo "gh: label could not be created (HTTP 500)" >&2; exit 1; }
82
+ log "label create $repo $name"; printf '%s\n' "$name" >> "$(rdir "$repo")/labels"; exit 0 ;;
83
+ "api graphql") exit 1 ;;
84
+ esac
85
+ if [ "${1:-}" = "api" ]; then
86
+ shift; method=GET; ep=""; title=""
87
+ while [ $# -gt 0 ]; do
88
+ case "$1" in
89
+ -X) method="$2"; shift 2 ;;
90
+ -f) case "$2" in title=*) title="${2#title=}"; method=POST ;; esac; shift 2 ;;
91
+ -F|--jq|-q|--input) shift 2 ;;
92
+ *) ep="$1"; shift ;;
93
+ esac
94
+ done
95
+ case "$ep" in
96
+ repos/*/*/milestones*)
97
+ repo="$(printf '%s' "$ep" | cut -d/ -f2-3)"; d="$(rdir "$repo")"
98
+ if [ "$method" = POST ]; then log "milestone create $repo $title"; printf '%s\n' "$title" >> "$d/milestones"; else cat "$d/milestones" 2>/dev/null; fi
99
+ exit 0 ;;
100
+ repos/*/*/branches/*/protection)
101
+ repo="$(printf '%s' "$ep" | cut -d/ -f2-3)"; d="$(rdir "$repo")"; br="$(printf '%s' "$ep" | cut -d/ -f5)"
102
+ if [ -f "$GHS/plan-refuses" ]; then echo "gh: Upgrade to GitHub Pro or make this repository public to enable this feature. (HTTP 403)" >&2; exit 1; fi
103
+ if [ "$method" = PUT ]; then cat >/dev/null; log "protect $repo $br"; : > "$d/protected-$br"; echo '{}'; exit 0; fi
104
+ [ -f "$d/protected-$br" ] && { echo '{}'; exit 0; }
105
+ echo "gh: Branch not protected (HTTP 404)" >&2; exit 1 ;;
106
+ repos/*/*)
107
+ repo="$(printf '%s' "$ep" | cut -d/ -f2-3)"; d="$(rdir "$repo")"
108
+ if [ "$method" = PATCH ]; then log "repo patch $repo delete_branch_on_merge"; echo true > "$d/delete-on-merge"; exit 0; fi
109
+ cat "$d/delete-on-merge" 2>/dev/null || echo false
110
+ exit 0 ;;
111
+ esac
112
+ fi
113
+ echo "stub gh: unhandled: $*" >&2
114
+ exit 1
115
+ STUB
116
+ # pnpm: the database option's install command. Adds each named package to package.json.
117
+ cat > "$tmp/stubs/pnpm" <<'STUB'
118
+ #!/usr/bin/env bash
119
+ [ "${1:-}" = "add" ] || { echo "stub pnpm: unhandled: $*" >&2; exit 1; }
120
+ shift
121
+ for p in "$@"; do
122
+ jq --arg p "$p" '.dependencies[$p] = "0.0.0-stub"' package.json > package.json.tmp && mv package.json.tmp package.json
123
+ done
124
+ STUB
125
+ chmod +x "$tmp/stubs/gh" "$tmp/stubs/pnpm"
126
+ export PATH="$tmp/stubs:$PATH"
127
+
128
+ # A fixture recipe: plain shell, no network. That init runs it is the proof that a recipe is data —
129
+ # the verb names no recipe id.
130
+ fx="$tmp/recipes"; mkdir -p "$fx"
131
+ cat > "$fx/demo.json" <<'JSON'
132
+ {
133
+ "id": "demo", "label": "Demo app", "summary": "A fixture.", "recommended": true,
134
+ "profile": "minimal", "stack": "nextjs", "folderName": "^[a-z0-9][a-z0-9._-]*$",
135
+ "requires": [{ "command": "jq", "why": "fixture" }],
136
+ "steps": [
137
+ { "label": "Write the app", "run": "printf '{\"name\":\"demo\",\"dependencies\":{\"next\":\"1.0.0\"}}\\n' > package.json && mkdir -p app && echo page > app/page.tsx" },
138
+ { "label": "Ignore env files", "run": "printf '.env*\\n' > .gitignore" }
139
+ ],
140
+ "config": { "tasks": { "check": "pnpm build && pnpm lint" } },
141
+ "start": "pnpm dev", "lastVerified": "2026-11-12"
142
+ }
143
+ JSON
144
+ export KIT_RECIPES_DIR="$fx"
145
+ export KIT_INIT_PREFLIGHT=0 KIT_INIT_BROWSER=0 KIT_INIT_TTY=0 KIT_ASCII=1 NO_COLOR=1
146
+
147
+ run() { # run <cwd> <init args…> -> OUT, RC
148
+ local d="$1"; shift
149
+ OUT="$(cd "$d" && CLAUDE_PLUGIN_ROOT="$ROOT" bash "$INIT" "$@" 2>&1)"; RC=$?
150
+ }
151
+ writes() { wc -l < "$GHS/writes.log" | tr -d ' '; }
152
+ tree_sum() { # a checksum of every file outside .git
153
+ ( cd "$1" && find . -type f ! -path './.git/*' -print0 | sort -z | xargs -0 cksum | cksum )
154
+ }
155
+
156
+ # ── 1. detection ────────────────────────────────────────────────────────────────────────────────
157
+ # shellcheck source=/dev/null
158
+ . "$ROOT/scripts/lib/init-guide.sh"
159
+ mkdir -p "$tmp/d/empty" "$tmp/d/files" "$tmp/d/proj" "$tmp/d/gitno" "$tmp/d/gitre" "$HOME/Documents"
160
+ echo notes > "$tmp/d/files/notes.txt"; : > "$tmp/d/empty/.DS_Store"
161
+ echo '{}' > "$tmp/d/proj/package.json"
162
+ git -C "$tmp/d/gitno" init -q
163
+ git -C "$tmp/d/gitre" init -q; git -C "$tmp/d/gitre" remote add origin "https://github.com/tester/gitre.git"
164
+ t "detect: home directory" "$(init_detect_class "$HOME")" "home"
165
+ t "detect: ~/Documents" "$(init_detect_class "$HOME/Documents")" "home"
166
+ t "detect: /" "$(init_detect_class /)" "home"
167
+ t "detect: a folder that is not there" "$(init_detect_class "$tmp/d/nope")" "missing"
168
+ t "detect: empty (only .DS_Store)" "$(init_detect_class "$tmp/d/empty")" "empty"
169
+ t "detect: files, no marker" "$(init_detect_class "$tmp/d/files")" "files"
170
+ t "detect: project marker, no git" "$(init_detect_class "$tmp/d/proj")" "project-nogit"
171
+ t "detect: git, no remote" "$(init_detect_class "$tmp/d/gitno")" "git-noremote"
172
+ t "detect: git with a remote" "$(init_detect_class "$tmp/d/gitre")" "project-remote"
173
+ t "abs path of a missing nested folder" "$(init_abs_path "$tmp/d/a/b")" "$tmp/d/a/b"
174
+
175
+ # ── 2. home directory ───────────────────────────────────────────────────────────────────────────
176
+ run "$HOME" --profile minimal
177
+ t "home, no terminal, no answers: refused (rc 2)" "$RC" "2"
178
+ has "home: says it is not a project folder" "$OUT" "not a project folder"
179
+ yes_if "home: nothing was scaffolded into it" '[ ! -e "$HOME/.claude" ] && [ ! -e "$HOME/CLAUDE.md" ] && [ ! -e "$HOME/scripts" ]'
180
+
181
+ printf '{"new_project":"no"}\n' > "$tmp/a-no.json"
182
+ run "$HOME" --answers "$tmp/a-no.json" --yes
183
+ t "home, 'not a new project': rc 0" "$RC" "0"
184
+ has "home, 'not a new project': says nothing was written" "$OUT" "Nothing was written"
185
+ yes_if "home, 'not a new project': nothing written" '[ ! -e "$HOME/.claude" ] && [ "$(writes)" = "0" ]'
186
+
187
+ printf '{"new_project":"yes","project_name":"My Shop","location":"here"}\n' > "$tmp/a-here.json"
188
+ run "$HOME" --answers "$tmp/a-here.json" --yes
189
+ t "home, location 'here': refused (rc 2)" "$RC" "2"
190
+ yes_if "home, location 'here': nothing written" '[ ! -e "$HOME/.claude" ]'
191
+
192
+ # The whole path: home -> new project in its own folder -> recipe -> database -> kit -> GitHub.
193
+ printf '{"new_project":"yes","project_name":"My Shop","recipe":"demo","database_needed":"yes","database":"supabase"}\n' > "$tmp/a-new.json"
194
+ run "$HOME" --answers "$tmp/a-new.json" --yes
195
+ shop="$HOME/my-shop"
196
+ t "new project from home: rc 0" "$RC" "0"
197
+ yes_if "new project: lives in its own folder, named from the answer" '[ -d "$shop" ]'
198
+ yes_if "new project: home itself got nothing" '[ ! -e "$HOME/.claude" ] && [ ! -e "$HOME/package.json" ]'
199
+ yes_if "new project: the recipe ran" '[ -f "$shop/app/page.tsx" ]'
200
+ yes_if "new project: the kit is installed" '[ -f "$shop/.claude/kit.config.json" ] && [ -f "$shop/CLAUDE.md" ]'
201
+ t "new project: profile comes from the recipe" "$(jq -r .profile "$shop/.claude/kit.config.json")" "minimal"
202
+ t "new project: the recipe's config keys are in the project config" "$(jq -r .tasks.check "$shop/.claude/kit.config.json")" "pnpm build && pnpm lint"
203
+ t "new project: base branch is develop" "$(jq -r .github.baseBranch "$shop/.claude/kit.config.json")" "develop"
204
+ t "new project: repo is <login>/<slug>" "$(jq -r .github.repo "$shop/.claude/kit.config.json")" "tester/my-shop"
205
+ yes_if "database: client code is in the project" '[ -f "$shop/lib/supabase/client.ts" ] && [ -f "$shop/lib/supabase/server.ts" ]'
206
+ yes_if "database: env file names both variables" 'grep -q "^NEXT_PUBLIC_SUPABASE_URL=" "$shop/.env.local" && grep -q "^NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=" "$shop/.env.local"'
207
+ yes_if "database: packages were added" 'jq -e ".dependencies | has(\"@supabase/ssr\") and has(\"@supabase/supabase-js\")" "$shop/package.json" >/dev/null'
208
+ has "database: the guide steps are printed (no browser)" "$OUT" "NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY = the publishable key"
209
+ has "database: the guide page is named" "$OUT" "databases/supabase/guide.html"
210
+ t "git: one commit" "$(git -C "$shop" rev-list --count HEAD)" "1"
211
+ t "git: the env file is not in the commit" "$(git -C "$shop" ls-files .env.local)" ""
212
+ t "git: the working tree is clean after the first commit" "$(git -C "$shop" status --porcelain)" ""
213
+ t "git: checked out on develop" "$(git -C "$shop" symbolic-ref --short HEAD)" "develop"
214
+ t "GitHub: main and develop were pushed" "$(git -C "$GHS/git/tester/my-shop.git" for-each-ref --format='%(refname:short)' refs/heads | tr '\n' ' ')" "develop main "
215
+ has "GitHub: repository created PRIVATE" "$(cat "$GHS/writes.log")" "repo create tester/my-shop --private"
216
+ has "GitHub: default branch set to develop" "$(cat "$GHS/writes.log")" "--default-branch develop"
217
+ has "GitHub: head branches deleted on merge" "$(cat "$GHS/writes.log")" "repo patch tester/my-shop delete_branch_on_merge"
218
+ has "GitHub: develop protected" "$(cat "$GHS/writes.log")" "protect tester/my-shop develop"
219
+ has "GitHub: labels created" "$(cat "$GHS/writes.log")" "label create tester/my-shop priority:p1"
220
+ has "GitHub: milestones created" "$(cat "$GHS/writes.log")" "milestone create tester/my-shop"
221
+ has "report: the plan is listed before the steps" "$OUT" "Create the PRIVATE repository tester/my-shop"
222
+ has "report: totals" "$OUT" "0 failed"
223
+ hasnt "report: no secret placeholder value echoed as a step detail" "$OUT" "your-publishable-key"
224
+
225
+ # ── 3. idempotent re-run ────────────────────────────────────────────────────────────────────────
226
+ w0="$(writes)"; s0="$(tree_sum "$shop")"; h0="$(git -C "$shop" rev-parse HEAD)"
227
+ run "$shop" --yes
228
+ t "re-run: rc 0" "$RC" "0"
229
+ t "re-run: no GitHub write" "$(writes)" "$w0"
230
+ t "re-run: no file changed" "$(tree_sum "$shop")" "$s0"
231
+ t "re-run: no new commit" "$(git -C "$shop" rev-parse HEAD)" "$h0"
232
+ hasnt "re-run: no step reports done" "$OUT" "[done"
233
+ has "re-run: says the kit files are already there" "$OUT" "cckit files — already there"
234
+ has "re-run: says the labels are there" "$OUT" "labels — all"
235
+ run "$shop" --database supabase --yes
236
+ t "re-run with --database: rc 0, still no write" "$RC:$(writes)" "0:$w0"
237
+ t "re-run with --database: no file changed" "$(tree_sum "$shop")" "$s0"
238
+
239
+ run "$shop" --dry-run
240
+ t "re-run --dry-run: rc 0, no write" "$RC:$(writes):$(tree_sum "$shop")" "0:$w0:$s0"
241
+ has "re-run --dry-run: says the kit files stay" "$OUT" "cckit files: already there"
242
+ has "re-run --dry-run: lists the setup steps" "$OUT" "Use the repository this folder is already connected to"
243
+
244
+ # ── 4. --upgrade is not part of the flow ────────────────────────────────────────────────────────
245
+ run "$shop" --upgrade --yes
246
+ hasnt "--upgrade: no project setup" "$OUT" "Project setup"
247
+ t "--upgrade: no GitHub write" "$(writes)" "$w0"
248
+
249
+ # ── 5. empty folder, named on the command line ──────────────────────────────────────────────────
250
+ printf '{"recipe":"none","profile":"minimal"}\n' > "$tmp/a-empty.json"
251
+ : > "$GHS/writes.log"
252
+ run "$tmp" "$tmp/p/blank" --answers "$tmp/a-empty.json" --yes --public
253
+ t "empty folder: rc 0" "$RC" "0"
254
+ has "empty folder: asked whether it is a new project" "$OUT" "Is this a new project?"
255
+ yes_if "empty folder: kit installed, no recipe" '[ -f "$tmp/p/blank/.claude/kit.config.json" ] && [ ! -f "$tmp/p/blank/package.json" ]'
256
+ t "no recipe: the config gets no tasks.check" "$(jq -r '.tasks.check // "absent"' "$tmp/p/blank/.claude/kit.config.json")" "absent"
257
+ # A recipe's config keys merge with the profile's (#496): marketing sets tasks.default, the recipe tasks.check.
258
+ run "$tmp" "$tmp/p/mk-site" --profile marketing --recipe demo --no-github
259
+ t "marketing + recipe: rc 0" "$RC" "0"
260
+ t "marketing + recipe: tasks.default and tasks.check are both written" "$(jq -c .tasks "$(ls "$tmp/p/mk-site/.claude/kit.config.json" "$tmp/p/mk-site/cckit.config.json" 2>/dev/null | sed -n 1p)")" '{"default":"light","check":"pnpm build && pnpm lint"}'
261
+ # A recipe whose config sets tasks.design installs the page-design skill and offers the three
262
+ # third-party design skills as integrations; nothing third-party is installed by init (#504).
263
+ jq '.id = "demopage" | .recommended = false | .config.tasks.design = true' "$fx/demo.json" > "$fx/demopage.json"
264
+ run "$tmp" "$tmp/p/pg-site" --profile minimal --recipe demopage --no-github
265
+ t "recipe with tasks.design: rc 0" "$RC" "0"
266
+ t "recipe with tasks.design: the key is written" "$(jq -r '.tasks.design' "$tmp/p/pg-site/.claude/kit.config.json")" "true"
267
+ yes_if "recipe with tasks.design: page-design is installed with its references" '[ -f "$tmp/p/pg-site/.claude/skills/page-design/SKILL.md" ] && [ -f "$tmp/p/pg-site/.claude/skills/page-design/references/minimum-rules.md" ]'
268
+ has "recipe with tasks.design: the three integrations are offered" "$OUT" "cckit add impeccable && cckit add emil-design-eng && cckit add web-design-guidelines && cckit doctor --fix"
269
+ yes_if "recipe with tasks.design: no third-party skill is installed" '[ ! -e "$tmp/p/pg-site/.claude/skills/impeccable" ] && [ ! -e "$tmp/p/pg-site/.claude/skills/emil-design-eng" ] && [ ! -e "$tmp/p/pg-site/.claude/skills/web-design-guidelines" ]'
270
+ yes_if "a recipe without tasks.design installs no page-design" '[ ! -e "$tmp/p/blank/.claude/skills/page-design" ]'
271
+ rm -f "$fx/demopage.json"
272
+ has "--public: the repository is created public" "$(cat "$GHS/writes.log")" "repo create tester/blank --public"
273
+ t "empty folder: git init used main, not the user's init.defaultBranch" "$(git -C "$GHS/git/tester/blank.git" for-each-ref --format='%(refname:short)' refs/heads | tr '\n' ' ')" "develop main "
274
+
275
+ # ── 6. files without a project marker ───────────────────────────────────────────────────────────
276
+ mkdir -p "$tmp/p/loose"; echo "my notes" > "$tmp/p/loose/notes.txt"
277
+ printf '{"folder_use":"cancel"}\n' > "$tmp/a-cancel.json"
278
+ run "$tmp/p/loose" --answers "$tmp/a-cancel.json" --yes
279
+ t "files, cancel: rc 0, nothing written" "$RC:$(ls -A "$tmp/p/loose" | tr '\n' ' ')" "0:notes.txt "
280
+ printf '{"folder_use":"here","profile":"minimal"}\n' > "$tmp/a-here2.json"
281
+ run "$tmp/p/loose" --answers "$tmp/a-here2.json" --yes
282
+ t "files, set up here: rc 0" "$RC" "0"
283
+ t "files, set up here: the existing file is untouched" "$(cat "$tmp/p/loose/notes.txt")" "my notes"
284
+ yes_if "files, set up here: kit installed and committed" '[ -f "$tmp/p/loose/.claude/kit.config.json" ] && [ "$(git -C "$tmp/p/loose" rev-list --count HEAD)" = "1" ]'
285
+ printf '{"folder_use":"new","project_name":"Side Thing","profile":"minimal","recipe":"none"}\n' > "$tmp/a-new2.json"
286
+ mkdir -p "$tmp/p/loose2"; echo x > "$tmp/p/loose2/x.txt"
287
+ run "$tmp/p/loose2" --answers "$tmp/a-new2.json" --no-github
288
+ t "files, new project elsewhere: rc 0" "$RC" "0"
289
+ yes_if "files, new project elsewhere: made in a sub-folder, the original left alone" '[ -f "$tmp/p/loose2/side-thing/.claude/kit.config.json" ] && [ ! -e "$tmp/p/loose2/.claude" ]'
290
+
291
+ # ── 7. git repository without a remote ──────────────────────────────────────────────────────────
292
+ mkdir -p "$tmp/p/local"; git -C "$tmp/p/local" init -q
293
+ echo hi > "$tmp/p/local/README.md"; git -C "$tmp/p/local" add -A; git -C "$tmp/p/local" commit -q -m first
294
+ : > "$GHS/writes.log"
295
+ run "$tmp/p/local" --profile minimal --yes
296
+ t "git, no remote: rc 0" "$RC" "0"
297
+ has "git, no remote: first commit skipped" "$OUT" "first commit — the repository already has commits"
298
+ has "git, no remote: repository created" "$(cat "$GHS/writes.log")" "repo create tester/local --private"
299
+ # #487: a repository that already had a commit gets ONE more, holding the cckit files.
300
+ t "git, no remote: the existing commit plus the cckit files commit" "$(git -C "$tmp/p/local" rev-list --count HEAD)" "2"
301
+ has "git, no remote: the plan lists the cckit files commit" "$OUT" "Save the cckit files as one commit on 'develop'"
302
+ has "git, no remote: the commit step is reported" "$OUT" "[done ] cckit files commit"
303
+ t "git, no remote: the commit's subject" "$(git -C "$tmp/p/local" log -1 --format=%s)" "chore: add the cckit project files"
304
+ t "git, no remote: the working tree is clean" "$(git -C "$tmp/p/local" status --porcelain)" ""
305
+ t "git, no remote: the config is tracked" "$(git -C "$tmp/p/local" ls-files .claude/kit.config.json)" ".claude/kit.config.json"
306
+ t "git, no remote: an ignored file is not in the commit" "$(git -C "$tmp/p/local" ls-files .claude/settings.local.json .claude/kit.manifest.json)" ""
307
+ t "git, no remote: develop on GitHub carries the cckit files" "$(git -C "$GHS/git/tester/local.git" ls-tree -r --name-only develop -- CLAUDE.md)" "CLAUDE.md"
308
+ h7="$(git -C "$tmp/p/local" rev-parse HEAD)"; w7="$(writes)"
309
+ run "$tmp/p/local" --yes
310
+ t "git, no remote, re-run: rc 0, no new commit, no GitHub write" "$RC:$(git -C "$tmp/p/local" rev-parse HEAD):$(writes)" "0:$h7:$w7"
311
+ has "git, no remote, re-run: the commit step is skipped" "$OUT" "[skipped] cckit files commit — already committed"
312
+ yes_if "git, no remote: develop is on GitHub" 'git -C "$GHS/git/tester/local.git" show-ref --verify -q refs/heads/develop'
313
+
314
+ # ── 8. repository that already has a GitHub remote ──────────────────────────────────────────────
315
+ mkdir -p "$GHS/repos/tester__adopted" "$GHS/git/tester" "$tmp/p/adopted"
316
+ git init -q --bare "$GHS/git/tester/adopted.git"
317
+ git -C "$tmp/p/adopted" init -q; git -C "$tmp/p/adopted" symbolic-ref HEAD refs/heads/main
318
+ echo hi > "$tmp/p/adopted/README.md"; git -C "$tmp/p/adopted" add -A; git -C "$tmp/p/adopted" commit -q -m first
319
+ git -C "$tmp/p/adopted" remote add origin "$GHS/git/tester/adopted.git"; git -C "$tmp/p/adopted" push -q -u origin main
320
+ : > "$GHS/writes.log"
321
+ run "$tmp/p/adopted" --profile minimal --yes
322
+ t "existing remote: rc 0" "$RC" "0"
323
+ has "existing remote: adopted, not created" "$OUT" "GitHub repository — already connected to"
324
+ hasnt "existing remote: no repo create" "$(cat "$GHS/writes.log")" "repo create"
325
+ hasnt "existing remote: default branch not changed" "$(cat "$GHS/writes.log")" "repo edit"
326
+ t "existing remote: base branch is the repository's own" "$(jq -r .github.baseBranch "$tmp/p/adopted/.claude/kit.config.json")" "main"
327
+ has "existing remote: the missing steps still run" "$(cat "$GHS/writes.log")" "protect"
328
+ t "existing remote: the checkout was not moved" "$(git -C "$tmp/p/adopted" symbolic-ref --short HEAD)" "main"
329
+ # #487: the base branch is already on GitHub, so the cckit files commit is pushed to it.
330
+ has "existing remote: the cckit files commit is pushed" "$OUT" "[done ] branch main — pushed the cckit files commit"
331
+ t "existing remote: GitHub's main is the local main" "$(git -C "$GHS/git/tester/adopted.git" rev-parse main)" "$(git -C "$tmp/p/adopted" rev-parse main)"
332
+ t "existing remote: the working tree is clean" "$(git -C "$tmp/p/adopted" status --porcelain)" ""
333
+
334
+ # A project with its own untracked files, a staged change and an env file: none of them is in the
335
+ # cckit files commit.
336
+ mkdir -p "$GHS/repos/tester__mixed" "$tmp/p/mixed/scripts"
337
+ git init -q --bare "$GHS/git/tester/mixed.git"
338
+ git -C "$tmp/p/mixed" init -q; git -C "$tmp/p/mixed" symbolic-ref HEAD refs/heads/main
339
+ echo hi > "$tmp/p/mixed/README.md"; git -C "$tmp/p/mixed" add -A; git -C "$tmp/p/mixed" commit -q -m first
340
+ git -C "$tmp/p/mixed" remote add origin "$GHS/git/tester/mixed.git"; git -C "$tmp/p/mixed" push -q -u origin main
341
+ echo "SECRET=1" > "$tmp/p/mixed/.env"; echo "SECRET=2" > "$tmp/p/mixed/scripts/.env.local"
342
+ echo "mine" > "$tmp/p/mixed/scripts/my-own.sh"; echo "notes" > "$tmp/p/mixed/notes.txt"
343
+ echo "staged" > "$tmp/p/mixed/staged.txt"; git -C "$tmp/p/mixed" add staged.txt
344
+ run "$tmp/p/mixed" --profile minimal --yes
345
+ t "mixed project: rc 0" "$RC" "0"
346
+ in_commit="$(git -C "$tmp/p/mixed" show --name-only --format= HEAD)"
347
+ has "mixed project: the commit holds the cckit files" "$in_commit" ".claude/kit.config.json"
348
+ has "mixed project: a kit script is in it" "$in_commit" "scripts/setup-labels.sh"
349
+ hasnt "mixed project: no env file" "$in_commit" ".env"
350
+ hasnt "mixed project: the project's own script is left out" "$in_commit" "scripts/my-own.sh"
351
+ hasnt "mixed project: an unrelated file is left out" "$in_commit" "notes.txt"
352
+ hasnt "mixed project: a change the project had staged is left out" "$in_commit" "staged.txt"
353
+ t "mixed project: the staged change is still staged" "$(git -C "$tmp/p/mixed" diff --cached --name-only)" "staged.txt"
354
+
355
+ # A folder parked on another branch while the base branch exists: the commit is not made there.
356
+ mkdir -p "$GHS/repos/tester__parked" "$tmp/p/parked"
357
+ git init -q --bare "$GHS/git/tester/parked.git"
358
+ git -C "$tmp/p/parked" init -q; git -C "$tmp/p/parked" symbolic-ref HEAD refs/heads/main
359
+ echo hi > "$tmp/p/parked/README.md"; git -C "$tmp/p/parked" add -A; git -C "$tmp/p/parked" commit -q -m first
360
+ git -C "$tmp/p/parked" remote add origin "$GHS/git/tester/parked.git"; git -C "$tmp/p/parked" push -q -u origin main
361
+ git -C "$tmp/p/parked" checkout -q -b side
362
+ run "$tmp/p/parked" --profile minimal --yes
363
+ t "parked on another branch: rc 1" "$RC" "1"
364
+ has "parked on another branch: says which branch the files belong on" "$OUT" "this folder is on 'side' and the files belong on 'main'"
365
+ t "parked on another branch: no commit was made" "$(git -C "$tmp/p/parked" rev-list --count side)" "1"
366
+
367
+ # ── 9. --dry-run writes nothing ─────────────────────────────────────────────────────────────────
368
+ : > "$GHS/writes.log"
369
+ run "$tmp" "$tmp/p/dry" --profile minimal --recipe demo --database supabase --dry-run
370
+ t "dry run: rc 0" "$RC" "0"
371
+ yes_if "dry run: the folder was not created" '[ ! -e "$tmp/p/dry" ]'
372
+ t "dry run: no GitHub write" "$(writes)" "0"
373
+ has "dry run: lists the GitHub steps" "$OUT" "Create the PRIVATE repository tester/dry"
374
+ has "dry run: lists the recipe commands" "$OUT" "app/page.tsx"
375
+ has "dry run: lists the database files" "$OUT" "lib/supabase/client.ts"
376
+
377
+ # ── 10. no terminal and no --yes: the setup needs a confirmation it cannot get ──────────────────
378
+ run "$tmp" "$tmp/p/zzbravo" --profile minimal
379
+ t "no --yes, no terminal: rc 0 (the files are written)" "$RC" "0"
380
+ has "no --yes, no terminal: says the setup did not run and how to run it" "$OUT" "cckit init --yes"
381
+ has "no --yes, no terminal: says no task can be started yet" "$OUT" "is not a git repository yet, so no task can be started in it"
382
+ # #487: a repository with a commit, no terminal, no --yes. The base branch is one the repository
383
+ # has, and the closing lines name what was left undone with the command that does it.
384
+ mkdir -p "$tmp/p/quiet"; git -C "$tmp/p/quiet" init -q; git -C "$tmp/p/quiet" symbolic-ref HEAD refs/heads/trunk
385
+ echo hi > "$tmp/p/quiet/README.md"; git -C "$tmp/p/quiet" add -A; git -C "$tmp/p/quiet" commit -q -m first
386
+ run "$tmp/p/quiet" --profile marketing
387
+ t "commits, no --yes: rc 0" "$RC" "0"
388
+ t "commits, no --yes: the base branch is the one the repository has" "$(jq -r .github.baseBranch "$tmp/p/quiet/.claude/kit.config.json")" "trunk"
389
+ has "commits, no --yes: says the cckit files are not committed" "$OUT" "Not done: the cckit files are not committed."
390
+ has "commits, no --yes: names the command" "$OUT" "To commit them on 'trunk' and push: cckit init --yes"
391
+ hasnt "commits, no --yes: no missing-branch notice, the branch exists" "$OUT" "does not exist in this repository"
392
+ hasnt "marketing next steps: no label or milestone script" "$OUT" "setup-labels.sh"
393
+ has "marketing next steps: the first task" "$OUT" 'cckit task new "<title>"'
394
+ t "commits, no --yes: nothing was committed" "$(git -C "$tmp/p/quiet" rev-list --count HEAD)" "1"
395
+ jq '.github.baseBranch = "develop"' "$tmp/p/quiet/.claude/kit.config.json" > "$tmp/q.json" && mv "$tmp/q.json" "$tmp/p/quiet/.claude/kit.config.json"
396
+ run "$tmp/p/quiet" --profile marketing --force
397
+ has "a base branch the repository lacks: said before exiting" "$OUT" "Not done: the branch 'develop' (github.baseBranch in .claude/kit.config.json) does not exist in this repository."
398
+ has "a base branch the repository lacks: names the command" "$OUT" "To create it and push it: cckit init --yes"
399
+ yes_if "no --yes, no terminal: no git repository, no GitHub write" '[ ! -e "$tmp/p/zzbravo/.git" ] && [ "$(writes)" = "0" ]'
400
+
401
+ # ── 11. --no-github is the scaffold-only run ────────────────────────────────────────────────────
402
+ run "$tmp" "$tmp/p/zzalpha" --profile minimal --no-github
403
+ t "--no-github: rc 0" "$RC" "0"
404
+ yes_if "--no-github: no git repository, no GitHub write" '[ ! -e "$tmp/p/zzalpha/.git" ] && [ "$(writes)" = "0" ]'
405
+ has "--no-github: prints the manual next steps" "$OUT" "./scripts/setup-labels.sh && ./scripts/setup-milestones.sh"
406
+ # #487: cckit's local state and the worktrees are ignored in every scaffolded project.
407
+ t "--no-github: .cckit/ is gitignored" "$(grep -cxF '.cckit/' "$tmp/p/zzalpha/.gitignore")" "1"
408
+ t "--no-github: .claude/worktrees/ is gitignored" "$(grep -cxF '.claude/worktrees/' "$tmp/p/zzalpha/.gitignore")" "1"
409
+ hasnt "--no-github: no setup notice" "$OUT" "Git and GitHub setup"
410
+ t "--no-github: base branch as before (main)" "$(jq -r .github.baseBranch "$tmp/p/zzalpha/.claude/kit.config.json")" "main"
411
+ # The same files as the unconfirmed run above, which is the scaffold init has always written.
412
+ norm() { ( cd "$1" && find . -type f ! -name kit.manifest.json | sort | while read -r f; do printf '%s %s\n' "$f" "$(sed -e "s#$2#NAME#g" "$f" | cksum)"; done ) }
413
+ t "--no-github: the same file list as a run with no setup" "$(cd "$tmp/p/zzalpha" && find . -type f | sort)" "$(cd "$tmp/p/zzbravo" && find . -type f | sort)"
414
+ t "--no-github: the same file contents (project name aside)" "$(norm "$tmp/p/zzalpha" zzalpha)" "$(norm "$tmp/p/zzbravo" zzbravo)"
415
+ run "$tmp" --target "$tmp/p/zzalpha" --profile minimal --no-github
416
+ t "--no-github on an initialized project: refused as before (rc 1)" "$RC" "1"
417
+ has "--no-github on an initialized project: the same message" "$OUT" "already initialized"
418
+
419
+ # ── 12. a plan that refuses branch protection is a skip, not a failure ──────────────────────────
420
+ : > "$GHS/plan-refuses"; : > "$GHS/writes.log"
421
+ run "$tmp" "$tmp/p/free" --profile minimal --yes
422
+ t "protection refused by the plan: rc 0" "$RC" "0"
423
+ has "protection refused by the plan: skipped, with the reason" "$OUT" "[skipped] protect develop"
424
+ has "protection refused by the plan: names HTTP 403" "$OUT" "HTTP 403"
425
+ hasnt "protection refused by the plan: no protect write" "$(cat "$GHS/writes.log")" "protect "
426
+ rm -f "$GHS/plan-refuses"
427
+
428
+ # ── 13. a failed step does not hide the ones after it ───────────────────────────────────────────
429
+ : > "$GHS/fail-labels"; : > "$GHS/writes.log"
430
+ run "$tmp" "$tmp/p/partial" --profile minimal --yes
431
+ t "failed step: rc 1" "$RC" "1"
432
+ has "failed step: labels reported failed" "$OUT" "[failed ] labels"
433
+ has "failed step: a later step still ran" "$(cat "$GHS/writes.log")" "protect tester/partial develop"
434
+ has "failed step: the result names the failure again" "$OUT" "1 failed"
435
+ rm -f "$GHS/fail-labels"
436
+ run "$tmp/p/partial" --yes
437
+ t "failed step, re-run: rc 0" "$RC" "0"
438
+ has "failed step, re-run: only the missing labels are created" "$OUT" "[done ] labels"
439
+ hasnt "failed step, re-run: the repository is not created twice" "$(grep -c 'repo create tester/partial' "$GHS/writes.log")" "2"
440
+
441
+ : > "$GHS/fail-create"
442
+ run "$tmp" "$tmp/p/nocreate" --profile minimal --yes
443
+ t "repository cannot be created: rc 1" "$RC" "1"
444
+ has "repository cannot be created: later steps are reported, not hidden" "$OUT" "[skipped] labels — needs the GitHub repository"
445
+ rm -f "$GHS/fail-create"
446
+
447
+ # ── 14. refusals before anything is written ─────────────────────────────────────────────────────
448
+ printf '{"new_project":"maybe"}\n' > "$tmp/a-bad.json"
449
+ run "$tmp" "$tmp/p/bad" --answers "$tmp/a-bad.json" --yes
450
+ t "an answer that is not an option: rc 2" "$RC" "2"
451
+ has "an answer that is not an option: lists the options" "$OUT" "Choose one of: yes no"
452
+ run "$tmp" "$tmp/p/bad" --profile minimal --recipe nope --no-github
453
+ t "unknown recipe: rc 2" "$RC" "2"
454
+ run "$tmp" --target "$tmp/p/loose" --recipe demo --force --no-github
455
+ t "recipe on a folder with files: rc 2" "$RC" "2"
456
+ run "$tmp" "$tmp/p/Bad_Name" --profile minimal --recipe demo --no-github
457
+ t "recipe with a folder name it cannot use: rc 2" "$RC" "2"
458
+ run "$tmp" "$tmp/p/bad" --answers "$tmp/nope.json"
459
+ t "answers file missing: rc 2" "$RC" "2"
460
+ yes_if "refusals: nothing was created" '[ ! -e "$tmp/p/bad" ] && [ ! -e "$tmp/p/Bad_Name" ]'
461
+
462
+ # ── 15. the advisor: every question has exactly one recommended answer ──────────────────────────
463
+ : > "$tmp/a-none.json"; echo '{}' > "$tmp/a-none.json"
464
+ run "$tmp" "$tmp/p/defaults" --answers "$tmp/a-none.json" --no-github
465
+ t "empty answers file: rc 0" "$RC" "0"
466
+ has "empty answers file: the recommended answer is taken and said so" "$OUT" '(recommended; "recipe" is not in the answers file)'
467
+ yes_if "empty answers file: the recommended recipe and database ran" '[ -f "$tmp/p/defaults/app/page.tsx" ] && [ -f "$tmp/p/defaults/lib/supabase/client.ts" ]'
468
+ ask_out="$( { printf '\n' | KIT_INIT_TTY=1 INIT_ANSWERS="" init_ask k "Question?" "why" "a|A|first" "b|B|second|R" "c|C|third"; } 2>&1 >/dev/null )"
469
+ t "terminal: Enter alone takes the recommended option" "$( { printf '\n' | KIT_INIT_TTY=1 INIT_ANSWERS="" init_ask k "Question?" "why" "a|A|first" "b|B|second|R" "c|C|third"; } 2>/dev/null)" "b"
470
+ t "terminal: exactly one option is marked recommended" "$(printf '%s\n' "$ask_out" | grep -c '(Recommended)')" "1"
471
+ t "terminal: a number picks that option" "$( { printf '3\n' | KIT_INIT_TTY=1 INIT_ANSWERS="" init_ask k "Q?" "" "a|A|x" "b|B|y|R" "c|C|z"; } 2>/dev/null)" "c"
472
+
473
+ [ "$fail" -eq 0 ] && echo "init-guided-test: PASS" || echo "init-guided-test: FAIL"
474
+ exit "$fail"
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # init-recipes-test.sh — consistency of the recipe and database registries (#456).
4
+ #
5
+ # recipes/*.json and databases/*.json are data that `cckit init` offers to a person who cannot
6
+ # check them. This test is what keeps the data honest:
7
+ # - every shipped descriptor is valid, and each list has exactly ONE recommended entry;
8
+ # - every database option has its guide page AND its setup test — one without the other fails;
9
+ # - the env variable names agree in three places: the descriptor, the guide page, and the client
10
+ # code the option adds (every declared name is read, and no undeclared name is read);
11
+ # - the guide page carries the descriptor's "last verified" date and one step per descriptor step;
12
+ # - an option missing its guide or its test is not offered at run time.
13
+ # Offline. Run: bash scripts/init-recipes-test.sh
14
+ # errors: strict — a test runner: rc 1 on any failed assertion
15
+ set -u
16
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
17
+ # shellcheck source=/dev/null
18
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
19
+ fail=0
20
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
21
+ yes_if() { if eval "$2"; then echo "ok: $1"; else echo "FAIL: $1 -> not true: $2"; fail=1; fi; }
22
+
23
+ command -v jq >/dev/null 2>&1 || { echo "init-recipes-test: jq absent — skipping (dependency-light gate)"; exit 0; }
24
+ # shellcheck source=/dev/null
25
+ . "$ROOT/scripts/lib/init-guide.sh"
26
+
27
+ # ── recipes ─────────────────────────────────────────────────────────────────────────────────────
28
+ t "there is a recipe to offer" "$([ -n "$(recipes_list)" ] && echo yes)" "yes"
29
+ rec=0
30
+ for id in $(recipes_list); do
31
+ f="$(recipe_file "$id")"
32
+ t "recipe $id: valid" "$(recipe_validate "$f" 2>&1; echo "rc=$?")" "rc=0"
33
+ [ "$(jq -r .recommended "$f")" = "true" ] && rec=$((rec + 1))
34
+ t "recipe $id: its profile exists" "$([ -f "$ROOT/profiles/$(jq -r .profile "$f").json" ] && echo yes)" "yes"
35
+ t "recipe $id: lists its sources" "$(jq -r '(.sources // []) | length > 0' "$f")" "true"
36
+ done
37
+ t "recipes: exactly one is recommended" "$rec" "1"
38
+ # A recipe may carry project config keys (#496): the web recipe names the gate `cckit task run` uses.
39
+ t "recipe nextjs-shadcn: sets tasks.check" "$(jq -r '.config.tasks.check' "$(recipe_file nextjs-shadcn)")" "pnpm build && pnpm lint"
40
+ # …and that its tasks are page tasks, which is also what installs the page-design skill (#504).
41
+ t "recipe nextjs-shadcn: sets tasks.design" "$(jq -r '.config.tasks.design' "$(recipe_file nextjs-shadcn)")" "true"
42
+ bad="$(mktemp -d)"; jq '.config = "pnpm build"' "$(recipe_file nextjs-shadcn)" > "$bad/nextjs-shadcn.json"
43
+ t "a recipe whose config is not an object is invalid" "$(recipe_validate "$bad/nextjs-shadcn.json" 2>&1)" "nextjs-shadcn: config: an object of project config keys"
44
+ rm -rf "$bad"
45
+
46
+ # ── databases ───────────────────────────────────────────────────────────────────────────────────
47
+ t "there is a database option to offer" "$([ -n "$(databases_list)" ] && echo yes)" "yes"
48
+ rec=0
49
+ for id in $(databases_list); do
50
+ f="$(database_file "$id")"
51
+ t "database $id: valid" "$(database_validate "$f" 2>&1; echo "rc=$?")" "rc=0"
52
+ [ "$(jq -r .recommended "$f")" = "true" ] && rec=$((rec + 1))
53
+ guide="$(database_path "$f" "$(jq -r .guide "$f")")"; test_file="$(database_path "$f" "$(jq -r .test "$f")")"
54
+ t "database $id: has its guide page" "$([ -f "$guide" ] && echo yes)" "yes"
55
+ t "database $id: has its setup test" "$([ -f "$test_file" ] && echo yes)" "yes"
56
+ t "database $id: the setup test is one the runner discovers" "$(case "$test_file" in */scripts/*-test.sh) echo yes ;; esac)" "yes"
57
+ t "database $id: offered" "$(database_offered "$f"; echo "rc=$?")" "rc=0"
58
+ [ -f "$guide" ] || continue
59
+ # The guide: self-contained, dated, one step per descriptor step, the env file named.
60
+ t "database $id: the guide loads nothing from elsewhere" "$(grep -cE '<(script|link|img|iframe)[^>]*(src|href)=' "$guide")" "0"
61
+ yes_if "database $id: the guide carries the last-verified date" 'grep -q "Last verified: <strong id=\"last-verified\">$(jq -r .lastVerified "$f")</strong>" "$guide"'
62
+ t "database $id: one guide step per descriptor step" "$(grep -c '<li class="step">' "$guide")" "$(jq '.steps | length' "$f")"
63
+ yes_if "database $id: the guide names the env file" 'grep -qF "$(jq -r .envFile "$f")" "$guide"'
64
+ for n in $(jq -r '.env[].name' "$f"); do
65
+ yes_if "database $id: the guide names $n" 'grep -qF "$n" "$guide"'
66
+ yes_if "database $id: the terminal steps name $n" 'grep -qF "$n" <<<"$(database_steps "$f" /p)"'
67
+ yes_if "database $id: the placeholder of $n is not a real key" '! grep -qE "sb_(publishable|secret)_|eyJ" <<<"$(jq -r --arg n "$n" ".env[] | select(.name == \$n) | .placeholder" "$f")"'
68
+ done
69
+ # Guide and descriptor name the same variables: no name in the guide's file sample is undeclared.
70
+ t "database $id: the guide's file sample declares the same names" \
71
+ "$(grep -oE '(^|<pre>)[A-Z][A-Z0-9_]+=' "$guide" | sed 's/<pre>//' | tr -d '=' | sort -u | tr '\n' ' ')" "$(jq -r '.env[].name' "$f" | sort -u | tr '\n' ' ')"
72
+ for s in $(jq -r '.stacks | keys[]' "$f"); do
73
+ read_names=""
74
+ for from in $(jq -r --arg s "$s" '.stacks[$s].files[].from' "$f"); do
75
+ src="$(database_path "$f" "$from")"
76
+ t "database $id/$s: ships $from" "$([ -f "$src" ] && echo yes)" "yes"
77
+ [ -f "$src" ] && read_names="$read_names $(grep -oE 'process\.env\.[A-Z][A-Z0-9_]*' "$src" | sed 's/process\.env\.//' | tr '\n' ' ')"
78
+ done
79
+ t "database $id/$s: the client code reads exactly the declared names" \
80
+ "$(printf '%s\n' $read_names | sort -u | tr '\n' ' ')" "$(jq -r '.env[].name' "$f" | sort -u | tr '\n' ' ')"
81
+ for pk in $(jq -r --arg s "$s" '.stacks[$s].packages[]' "$f"); do
82
+ yes_if "database $id/$s: the install command installs $pk" 'grep -qF -- "$pk" <<<"$(jq -r --arg s "$s" ".stacks[\$s].install" "$f")"'
83
+ done
84
+ done
85
+ done
86
+ t "databases: exactly one is recommended" "$rec" "1"
87
+
88
+ # ── an option without its guide or its test is not offered ──────────────────────────────────────
89
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
90
+ fx="$tmp/databases"; mkdir -p "$fx/demo"
91
+ jq '.id = "demo" | .guide = "demo/guide.html" | .test = "demo-test.sh"' "$ROOT/databases/supabase.json" > "$fx/demo.json"
92
+ t "fixture: neither guide nor test -> not offered" "$(database_offered "$fx/demo.json"; echo "rc=$?")" "rc=1"
93
+ : > "$fx/demo/guide.html"
94
+ t "fixture: guide without test -> not offered" "$(database_offered "$fx/demo.json"; echo "rc=$?")" "rc=1"
95
+ rm "$fx/demo/guide.html"; : > "$fx/demo-test.sh"
96
+ t "fixture: test without guide -> not offered" "$(database_offered "$fx/demo.json"; echo "rc=$?")" "rc=1"
97
+ : > "$fx/demo/guide.html"
98
+ t "fixture: both -> offered" "$(database_offered "$fx/demo.json"; echo "rc=$?")" "rc=0"
99
+ t "fixture: the registry directory is replaceable" "$(KIT_DATABASES_DIR="$fx" databases_list)" "demo"
100
+ jq 'del(.env)' "$fx/demo.json" > "$fx/bad.json"
101
+ t "fixture: a descriptor without env is invalid" "$(database_validate "$fx/bad.json" >/dev/null 2>&1; echo "rc=$?")" "rc=1"
102
+
103
+ [ "$fail" -eq 0 ] && echo "init-recipes-test: PASS" || echo "init-recipes-test: FAIL"
104
+ exit "$fail"