@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,175 @@
1
+ #!/usr/bin/env bash
2
+ # qa-lanes-test.sh — `cckit qa lanes` is a read of what other verbs recorded (#301): one row per
3
+ # lane with its branch, worktree, ports, whether something listens on them, and how its verdict
4
+ # reads against the local tip of its branch. It writes nothing and calls neither gh nor curl.
5
+ #
6
+ # Hermetic: a scratch repo, a hand-written port-slot ledger, `gh` and `curl` stubs that only log
7
+ # (the log must stay empty across every `lanes` call). One section listens on a loopback port the
8
+ # kernel picked; it skips with a printed reason when perl, or both lsof and ss, are absent.
9
+ #
10
+ # Run: bash scripts/lib/qa-lanes-test.sh
11
+ # errors: strict — a test runner: rc 1 on any failed assertion
12
+ # shellcheck shell=bash
13
+ set -u
14
+
15
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
16
+ command -v jq >/dev/null 2>&1 || { echo "qa-lanes-test: jq absent — skipping"; exit 0; }
17
+ # shellcheck source=/dev/null
18
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
19
+
20
+ TMP="$(cd "$(mktemp -d)" && pwd -P)" || exit 1
21
+ PIDS=""
22
+ cleanup() { local p; for p in $PIDS; do kill "$p" 2>/dev/null; done; rm -rf "$TMP"; }
23
+ trap cleanup EXIT
24
+
25
+ fail=0
26
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
27
+ yes() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> missing '$3' in [$2]"; fail=1 ;; esac; }
28
+ no() { case "$2" in *"$3"*) echo "FAIL: $1 -> found '$3' in [$2]"; fail=1 ;; *) echo "ok: $1" ;; esac; }
29
+
30
+ # ── gh and curl: log every call and fail. `lanes` must never reach either. ─────────────────────
31
+ STUB="$TMP/stub"; mkdir -p "$STUB"
32
+ NET_LOG="$TMP/net.log"; export NET_LOG; : > "$NET_LOG"
33
+ for o in gh curl; do
34
+ cat > "$STUB/$o" <<'SH'
35
+ #!/usr/bin/env bash
36
+ printf '%s %s\n' "${0##*/}" "$*" >> "$NET_LOG"
37
+ exit 1
38
+ SH
39
+ chmod +x "$STUB/$o"
40
+ done
41
+ PATH="$STUB:$PATH"; export PATH
42
+
43
+ # ── the project: three lane branches, one of them checked out in its own worktree ──────────────
44
+ P="$TMP/proj"; mkdir -p "$P"
45
+ (
46
+ cd "$P" && git init -q . && git config user.email t@t && git config user.name t &&
47
+ git commit -q --allow-empty -m base &&
48
+ git branch task/11-alpha && git branch task/12-beta && git branch task/15-gamma &&
49
+ git worktree add -q "$TMP/wt12" task/12-beta
50
+ ) || { echo "qa-lanes-test: could not build the fixture repo"; exit 1; }
51
+ jq -n '{qa: {command: "sleep 60", route: "/", credentialEnv: [],
52
+ ports: [{env: "WEB_PORT", base: 3000}, {env: "API_PORT", base: 4000}],
53
+ readiness: [{env: "WEB_PORT", path: "/"}]}}' > "$P/cckit.config.json"
54
+
55
+ KIT_STATE_DIR="$TMP/state"; export KIT_STATE_DIR
56
+ KIT_CONFIG="$P/cckit.config.json"; export KIT_CONFIG
57
+ QA_PORT_TOOL=none; export QA_PORT_TOOL
58
+ cd "$P" || exit 1
59
+ # shellcheck source=/dev/null
60
+ . "$ROOT/scripts/lib/qa-lane.sh"
61
+
62
+ lanes() { qa_cli lanes 2>/dev/null; }
63
+ jlanes() { CCKIT_OUTPUT=json qa_cli lanes 2>/dev/null; }
64
+ row() { jlanes | jq -c --arg l "$1" '.[] | select(.lane == $l)'; }
65
+ field() { row "$1" | jq -r "$2"; }
66
+
67
+ # ── nothing recorded: no lane, rc 0, an empty array ────────────────────────────────────────────
68
+ out="$(qa_cli lanes 2>"$TMP/e")"; rc=$?
69
+ t "no lane is rc 0" "$rc" "0"
70
+ t "no lane prints no table" "$out" ""
71
+ yes "no lane says so on stderr" "$(cat "$TMP/e")" "no QA lanes"
72
+ t "--llm with no lane is an empty array" "$(jlanes)" "[]"
73
+ t "listing created no state directory" "$([ -e "$KIT_STATE_DIR" ] && echo yes || echo no)" "no"
74
+
75
+ # ── the ledger gives a lane its slot; a row whose worktree is gone is nobody's ─────────────────
76
+ mkdir -p "$TMP/wt11"
77
+ LEDGER="$P/.git/kit-portslots.tsv"
78
+ printf '11\t3\t%s\n12\t5\t%s\n13\t6\t%s\n' "$TMP/wt11" "$TMP/wt12" "$TMP/gone" > "$LEDGER"
79
+ t "one lane per ledger row with a live worktree" "$(jlanes | jq -r '[.[].lane] | join(" ")')" "11 12"
80
+ t "the lane's branch is the local head carrying its number" "$(field 11 .branch)" "task/11-alpha"
81
+ t "a branch checked out nowhere falls back to the ledger's worktree" "$(field 11 .worktree)" "$TMP/wt11"
82
+ t "a checked-out branch names its worktree" "$(field 12 .worktree)" "$TMP/wt12"
83
+ t "ports with no launch record come from qa.ports and the slot" "$(field 11 '"\(.ports.WEB_PORT) \(.ports.API_PORT)"')" "3030 4030"
84
+ t "the second lane's ports are its own slot's" "$(field 12 '"\(.ports.WEB_PORT) \(.ports.API_PORT)"')" "3050 4050"
85
+ t "with no tool to read listeners, up is unknown" "$(field 11 .up)" "unknown"
86
+ t "a lane nobody reviewed reads none" "$(field 11 .verdict)" "none"
87
+
88
+ # ── the verdict column: qa_verdict_state against the LOCAL tip of the lane's branch ────────────
89
+ tip="$(git -C "$P" rev-parse task/11-alpha)"
90
+ qa_cli verdict pass --lane 11 --head "$tip" >/dev/null 2>&1
91
+ qa_cli verdict pass --lane 12 --head "$tip" >/dev/null 2>&1
92
+ qa_cli verdict fail --lane 15 --head "$tip" --note "the save button stays disabled" >/dev/null 2>&1
93
+ qa_cli verdict pass --lane 14 --head "$tip" >/dev/null 2>&1
94
+ git -C "$TMP/wt12" commit -q --allow-empty -m "a later push"
95
+ : > "$NET_LOG"
96
+ t "a receipt alone makes a lane" "$(jlanes | jq -r '[.[].lane] | join(" ")')" "11 12 14 15"
97
+ t "a pass on the branch tip reads pass" "$(field 11 .verdict)" "pass"
98
+ t "a commit after the verdict reads stale" "$(field 12 .verdict)" "stale"
99
+ t "a fail on the branch tip reads fail" "$(field 15 .verdict)" "fail"
100
+ t "a verdict with no local branch to compare reads unknown" "$(field 14 .verdict)" "unknown"
101
+ t "a lane with no local branch has a null branch and worktree" "$(field 14 '"\(.branch) \(.worktree)"')" "null null"
102
+ t "a lane with no slot has no ports" "$(field 15 '.ports | length')" "0"
103
+ t "a lane with no ports is up unknown" "$(field 15 .up)" "unknown"
104
+
105
+ # ── the table: a header, one line per lane, the same words ─────────────────────────────────────
106
+ out="$(lanes)"
107
+ t "the table has a header and one line per lane" "$(printf '%s\n' "$out" | grep -c .)" "5"
108
+ t "the header names the columns" "$(printf '%s\n' "$out" | sed -n 1p | tr -s ' ')" "LANE BRANCH PORTS UP VERDICT WORKTREE"
109
+ t "a row reads lane, branch, ports, up, verdict, worktree" \
110
+ "$(printf '%s\n' "$out" | grep '^11 ' | tr -s ' ')" "11 task/11-alpha WEB_PORT=3030 API_PORT=4030 unknown pass $TMP/wt11"
111
+ t "an empty cell is a dash" "$(printf '%s\n' "$out" | grep '^14 ' | tr -s ' ')" "14 - - unknown unknown -"
112
+
113
+ # ── read-only: no file changes, no event, no gh, no curl ───────────────────────────────────────
114
+ snap() { { find "$KIT_STATE_DIR" "$LEDGER" "$P/.git/kit-events.jsonl" -type f -exec cksum {} + 2>/dev/null; git -C "$P" worktree list; } | sort; }
115
+ before="$(snap)"
116
+ lanes >/dev/null; jlanes >/dev/null
117
+ t "listing changes no state, ledger or event file" "$(snap)" "$before"
118
+ t "listing calls neither gh nor curl" "$(cat "$NET_LOG")" ""
119
+ t "the dead ledger row is left for cckit start to reclaim" "$(grep -c '^13 ' "$LEDGER")" "1"
120
+ t "listing allocates no slot for a lane that has none" "$(grep -c '^15 ' "$LEDGER")" "0"
121
+
122
+ # ── arguments ──────────────────────────────────────────────────────────────────────────────────
123
+ qa_cli lanes --lane 11 >/dev/null 2>"$TMP/e"; t "lanes takes no argument" "$?" "2"
124
+ yes "the refusal names the argument" "$(cat "$TMP/e")" "unknown argument '--lane'"
125
+ yes "the help lists lanes" "$(qa_cli help 2>&1)" "cckit qa lanes"
126
+ yes "an unknown subcommand names lanes" "$(qa_cli nope 2>&1)" "verdict|lanes"
127
+
128
+ # ── up: who listens on the lane's ports ────────────────────────────────────────────────────────
129
+ free_port() { perl -MIO::Socket::INET -e 'my $s = IO::Socket::INET->new(Listen => 1, LocalAddr => "127.0.0.1", LocalPort => 0) or exit 1; print $s->sockport' 2>/dev/null; }
130
+ unset QA_PORT_TOOL
131
+ if ! command -v perl >/dev/null 2>&1; then
132
+ echo "skip: up — perl is absent, so the fixture cannot open a listener"
133
+ elif ! qa_port_tool >/dev/null 2>&1; then
134
+ echo "skip: up — neither lsof nor ss is installed, so a port's listener cannot be read"
135
+ else
136
+ cat > "$TMP/listen.pl" <<'PL'
137
+ use IO::Socket::INET;
138
+ my $s = IO::Socket::INET->new(Listen => 5, LocalAddr => "127.0.0.1", LocalPort => $ARGV[0], ReuseAddr => 1) or exit 1;
139
+ sleep 600;
140
+ PL
141
+ held="$(free_port)"
142
+ perl "$TMP/listen.pl" "$held" & lpid=$!; PIDS="$PIDS $lpid"
143
+ i=0; while [ -z "$(qa_port_pids "$held")" ] && [ "$i" -lt 100 ]; do sleep 0.1; i=$((i+1)); done
144
+ idle="$(free_port)"
145
+ # The record `qa up` writes: the ports the lane was launched with win over the computed ones.
146
+ mkdir -p "$KIT_STATE_DIR/qa/11"
147
+ printf 'WEB_PORT=%s\n' "$held" > "$KIT_STATE_DIR/qa/11/ports"
148
+ t "recorded ports replace the computed ones" "$(field 11 '.ports | tostring')" "{\"WEB_PORT\":$held}"
149
+ t "every port listened on is up" "$(field 11 .up)" "up"
150
+ printf 'WEB_PORT=%s\nAPI_PORT=%s\n' "$held" "$idle" > "$KIT_STATE_DIR/qa/11/ports"
151
+ t "some ports listened on is partial" "$(field 11 .up)" "partial"
152
+ printf 'WEB_PORT=%s\n' "$idle" > "$KIT_STATE_DIR/qa/11/ports"
153
+ t "no port listened on is down" "$(field 11 .up)" "down"
154
+ yes "the table carries the same word" "$(lanes | grep '^11 ')" " down "
155
+ lanes >/dev/null
156
+ t "listing leaves the listener it found running" "$(kill -0 "$lpid" 2>/dev/null && echo yes || echo no)" "yes"
157
+ rm -rf "$KIT_STATE_DIR/qa"
158
+ fi
159
+ QA_PORT_TOOL=none; export QA_PORT_TOOL
160
+
161
+ # ── zsh reads the same table; the verb is wired ────────────────────────────────────────────────
162
+ want="$(jlanes)"
163
+ if command -v zsh >/dev/null 2>&1; then
164
+ got="$(zsh -c "cd '$P'; . '$ROOT/scripts/lib/qa-lane.sh'; CCKIT_OUTPUT=json qa_cli lanes" 2>&1)"
165
+ t "zsh: lanes prints the same array" "$got" "$want"
166
+ t "zsh: the table has the same lines" "$(zsh -c "cd '$P'; . '$ROOT/scripts/lib/qa-lane.sh'; qa_cli lanes" 2>&1)" "$(lanes)"
167
+ else
168
+ echo "ok: zsh absent — skipping the zsh lanes pass (dependency-light gate)"
169
+ fi
170
+ t "cckit qa lanes --llm dispatches to the lib" "$("$ROOT/bin/cckit" qa lanes --llm 2>/dev/null)" "$want"
171
+ t "cckit qa lanes prints the table" "$("$ROOT/bin/cckit" qa lanes 2>/dev/null)" "$(lanes)"
172
+ t "nothing in this run reached gh or curl" "$(cat "$NET_LOG")" ""
173
+
174
+ [ "$fail" -eq 0 ] && echo "ALL OK (qa-lanes)" || echo "qa-lanes: FAILURES"
175
+ exit "$fail"
@@ -19,7 +19,7 @@ react_detect() {
19
19
 
20
20
  # merged dependency name list (deps + devDeps); tolerate malformed JSON
21
21
  deps="$(jq -r '((.dependencies // {}) + (.devDependencies // {})) | keys[]?' "$pkg" 2>/dev/null)" || return 0
22
- _has() { printf '%s\n' "$deps" | grep -qx "$1"; }
22
+ _has() { grep -qx "$1" <<<"$deps"; }
23
23
 
24
24
  _has react || return 0
25
25
  REACT_DETECTED="true"
@@ -16,7 +16,7 @@ if [ -n "${RND_TEST_INNER:-}" ]; then
16
16
  eq "width clamps high" "$(COLUMNS=999 render_width)" "120"
17
17
  eq "width clamps low" "$(COLUMNS=5 render_width)" "40"
18
18
  eq "width passes mid" "$(COLUMNS=90 render_width)" "90"
19
- eq "width junk -> safe" "$( (COLUMNS=abc; unset TERM; render_width) | grep -qE '^[0-9]+$' && echo ok)" "ok"
19
+ eq "width junk -> safe" "$(grep -qE '^[0-9]+$' <<<"$(COLUMNS=abc; unset TERM; render_width)" && echo ok)" "ok"
20
20
 
21
21
  # table composers.
22
22
  eq "table row" "$(render_table_row '#76' 'M' 'plan')" "| #76 | M | plan |"
@@ -0,0 +1,318 @@
1
+ #!/usr/bin/env bash
2
+ # review-page-test.sh — a page opens only where a reader can see it, the fallback never fails, and
3
+ # an answer is written to the issue or to a file (#451).
4
+ #
5
+ # Hermetic: `lavish-axi`, `npx`, `gh` and `uname` are stubs on a sealed PATH that log their
6
+ # arguments; no browser starts and no network is touched. Every file lands under one mktemp dir.
7
+ # Each case names the whole session environment it runs in, because the host's own (CI on the
8
+ # runner, CLAUDECODE in an agent's shell) would otherwise decide the outcome.
9
+ #
10
+ # Run: bash scripts/lib/review-page-test.sh
11
+ # errors: strict — a test runner: rc 1 on any failed assertion
12
+ # shellcheck shell=bash
13
+ set -u
14
+
15
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
16
+ LIBF="$ROOT/scripts/lib/review-page.sh"
17
+ command -v jq >/dev/null 2>&1 || { echo "review-page-test: jq absent — skipping"; exit 0; }
18
+ command -v git >/dev/null 2>&1 || { echo "review-page-test: git absent — skipping"; exit 0; }
19
+ # shellcheck source=/dev/null
20
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
21
+
22
+ TMP="$(cd "$(mktemp -d)" && pwd -P)" || exit 1
23
+ trap 'rm -rf "$TMP"' EXIT
24
+
25
+ fail=0
26
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
27
+ yes() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> missing '$3' in [$2]"; fail=1 ;; esac; }
28
+ no() { case "$2" in *"$3"*) echo "FAIL: $1 -> found '$3' in [$2]"; fail=1 ;; *) echo "ok: $1" ;; esac; }
29
+
30
+ # ── a sealed PATH: the tools the lib needs, and nothing that could be a real page tool ─────────
31
+ SEALED="$TMP/sealed"; mkdir -p "$SEALED"
32
+ for tool in sh bash jq git grep sed awk sort cat mkdir rm dirname basename chmod ls pwd env tr head tail find mktemp cut cp mv date cksum; do
33
+ src="$(command -v "$tool" 2>/dev/null)" || continue
34
+ case "$src" in /*) ln -s "$src" "$SEALED/$tool" ;; esac
35
+ done
36
+ STUB="$TMP/stub"; mkdir -p "$STUB" # lavish-axi + gh + uname
37
+ NPXONLY="$TMP/npxonly"; mkdir -p "$NPXONLY"
38
+ LOG="$TMP/calls.log"; : > "$LOG"
39
+ printf '0\n' > "$TMP/lavish-rc"
40
+ printf 'Darwin\n' > "$TMP/os"
41
+ : > "$TMP/gh-comments"
42
+ printf '0\n' > "$TMP/gh-rc"
43
+
44
+ cat > "$STUB/lavish-axi" <<EOF
45
+ #!/bin/sh
46
+ echo "lavish-axi \$*" >> "$LOG"
47
+ echo "stub page output"
48
+ exit "\$(cat "$TMP/lavish-rc")"
49
+ EOF
50
+ cat > "$NPXONLY/npx" <<EOF
51
+ #!/bin/sh
52
+ echo "npx \$*" >> "$LOG"
53
+ exit 0
54
+ EOF
55
+ cat > "$STUB/uname" <<EOF
56
+ #!/bin/sh
57
+ cat "$TMP/os"
58
+ EOF
59
+ cat > "$NPXONLY/uname" <<EOF
60
+ #!/bin/sh
61
+ cat "$TMP/os"
62
+ EOF
63
+ # gh: `issue view` answers the comment bodies recorded so far; `issue comment` records the body
64
+ # file and prints a URL, or fails with the code in gh-rc.
65
+ cat > "$STUB/gh" <<EOF
66
+ #!/bin/sh
67
+ echo "gh \$*" >> "$LOG"
68
+ case "\$1 \$2" in
69
+ "issue view") cat "$TMP/gh-comments" ;;
70
+ "issue comment")
71
+ rc="\$(cat "$TMP/gh-rc")"
72
+ [ "\$rc" = 0 ] || { echo "stub gh: refused" >&2; exit "\$rc"; }
73
+ bf=""; prev=""
74
+ for a in "\$@"; do [ "\$prev" = "--body-file" ] && bf="\$a"; prev="\$a"; done
75
+ cat "\$bf" >> "$TMP/gh-comments"; cp "\$bf" "$TMP/gh-last-body"
76
+ echo "https://example.invalid/o/r/issues/\$3#issuecomment-1" ;;
77
+ esac
78
+ exit 0
79
+ EOF
80
+ chmod +x "$STUB"/* "$NPXONLY"/*
81
+
82
+ # ── projects ───────────────────────────────────────────────────────────────────────────────────
83
+ project() { # <name> <config-json> -> a git repo with that config; echoes its dir
84
+ mkdir -p "$TMP/$1/.claude" "$TMP/$1/.lavish"
85
+ git -C "$TMP/$1" init -q 2>/dev/null
86
+ printf '%s\n' "$2" > "$TMP/$1/.claude/kit.config.json"
87
+ printf '<!DOCTYPE html><title>p</title>\n' > "$TMP/$1/.lavish/plan.html"
88
+ printf '# The plan\n\nstep one\n' > "$TMP/$1/.lavish/plan.md"
89
+ printf '%s\n' "$TMP/$1"
90
+ }
91
+ GH="$(project gh '{"github":{"repo":"o/r"}}')"
92
+ NOGH="$(project nogh '{"project":{"name":"x"}}')"
93
+ OFF="$(project off '{"github":{"repo":"o/r"},"reviewPages":{"enabled":false}}')"
94
+
95
+ # page <project> [VAR=value …] -- <args…>
96
+ # Runs the verb in an ATTENDED Claude Code session on a machine with a display and the page tool on
97
+ # PATH; the VAR=value pairs change that one fact at a time. stdin/stdout/stderr are never a TTY.
98
+ # stdout is the result; stderr lands in $TMP/err; the exit code is the verb's.
99
+ page() {
100
+ local proj="$1"; shift
101
+ local envs=()
102
+ while [ $# -gt 0 ] && [ "$1" != "--" ]; do envs+=("$1"); shift; done
103
+ shift
104
+ ( cd "$proj" && env -i HOME="$TMP/home" PATH="$STUB:$SEALED" KIT_CONFIG="$proj/.claude/kit.config.json" \
105
+ CLAUDECODE=1 CLAUDE_CODE_ENTRYPOINT=cli CLAUDE_CODE_SESSION_ATTENDED=1 DISPLAY=:0 \
106
+ ${envs[@]+"${envs[@]}"} bash "$LIBF" "$@" </dev/null 2> "$TMP/err" )
107
+ }
108
+ calls() { tr '\n' '|' < "$LOG"; }
109
+ reset() { : > "$LOG"; : > "$TMP/gh-comments"; rm -f "$TMP/gh-last-body"; printf '0\n' > "$TMP/gh-rc"; printf '0\n' > "$TMP/lavish-rc"; printf 'Darwin\n' > "$TMP/os"; }
110
+
111
+ # ── 1. mode: the attended session gets a page ──────────────────────────────────────────────────
112
+ t "attended session, tool on PATH -> page" "$(page "$GH" -- mode)" "page"
113
+ t "on by default: a config with no reviewPages key -> page" "$(page "$NOGH" -- mode)" "page"
114
+ t "--llm mode is one JSON object" "$(page "$GH" CCKIT_OUTPUT=json -- mode)" '{"mode":"page"}'
115
+
116
+ # ── 2. mode: every no-browser session falls back, and says why ─────────────────────────────────
117
+ yes "CI -> terminal" "$(page "$GH" CI=true -- mode)" "terminal: CI is set"
118
+ t "CI=false is not CI" "$(page "$GH" CI=false -- mode)" "page"
119
+ yes "unattended run -> terminal" "$(page "$GH" CCKIT_HEADLESS=1 -- mode)" "terminal: CCKIT_HEADLESS is set"
120
+ yes "claude -p (sdk-cli) -> terminal" "$(page "$GH" CLAUDE_CODE_ENTRYPOINT=sdk-cli -- mode)" "terminal: a headless Claude Code session (CLAUDE_CODE_ENTRYPOINT=sdk-cli)"
121
+ yes "unattended Claude session -> terminal" "$(page "$GH" CLAUDE_CODE_SESSION_ATTENDED=0 -- mode)" "terminal: a headless Claude Code session (CLAUDE_CODE_SESSION_ATTENDED=0)"
122
+ yes "SSH -> terminal" "$(page "$GH" SSH_CONNECTION=1.2.3.4 -- mode)" "terminal: an SSH session"
123
+ printf 'Linux\n' > "$TMP/os"
124
+ yes "Linux with no display -> terminal" "$(page "$GH" DISPLAY= -- mode)" "terminal: no display"
125
+ t "Linux with WAYLAND_DISPLAY -> page" "$(page "$GH" DISPLAY= WAYLAND_DISPLAY=wayland-0 -- mode)" "page"
126
+ printf 'Darwin\n' > "$TMP/os"
127
+ t "macOS needs no DISPLAY" "$(page "$GH" DISPLAY= -- mode)" "page"
128
+ yes "no agent session and no TTY -> terminal" "$(page "$GH" CLAUDECODE= -- mode)" "terminal: no terminal and no attended agent session"
129
+ yes "the off switch -> terminal" "$(page "$OFF" -- mode)" "terminal: review pages are off (reviewPages.enabled is false in $OFF/.claude/kit.config.json)"
130
+ yes "CCKIT_PAGES=terminal -> terminal" "$(page "$GH" CCKIT_PAGES=terminal -- mode)" "terminal: CCKIT_PAGES=terminal"
131
+ t "CCKIT_PAGES=page overrides the session checks" "$(page "$GH" CCKIT_PAGES=page CI=true CLAUDECODE= -- mode)" "page"
132
+ yes "CCKIT_PAGES=page does not override the off switch" "$(page "$OFF" CCKIT_PAGES=page -- mode)" "terminal: review pages are off"
133
+ yes "no lavish-axi and no npx -> terminal" "$(page "$GH" PATH="$SEALED" -- mode)" "terminal: neither lavish-axi nor npx is on PATH"
134
+ t "--llm terminal mode carries the reason" "$(page "$GH" CI=1 CCKIT_OUTPUT=json -- mode | jq -r '.mode + "|" + .reason')" "terminal|CI is set: a CI job has no reader"
135
+ for e in CI=true CCKIT_HEADLESS=1 CLAUDE_CODE_ENTRYPOINT=sdk-cli SSH_TTY=/dev/pts/1 CCKIT_PAGES=terminal; do
136
+ page "$GH" "$e" -- mode >/dev/null; t "mode exits 0 under $e" "$?" "0"
137
+ done
138
+
139
+ # ── 3. open: page mode runs the tool with the file ─────────────────────────────────────────────
140
+ reset
141
+ out="$(page "$GH" -- open .lavish/plan.html --fallback .lavish/plan.md)"; rc=$?
142
+ t "open rc" "$rc" "0"
143
+ t "open ran the tool with the html file, once" "$(calls)" "lavish-axi .lavish/plan.html|"
144
+ yes "open passes the tool's output through" "$out" "stub page output"
145
+ no "open in page mode does not print the fallback" "$out" "step one"
146
+ t "open keeps .lavish/ out of git status" "$(git -C "$GH" status --porcelain --untracked-files=all | grep -c '\.lavish' )" "0"
147
+ t "…through the local exclude file, written once" "$(grep -c '^\.lavish/$' "$GH/.git/info/exclude")" "1"
148
+ page "$GH" -- open .lavish/plan.html >/dev/null
149
+ t "…and a second open adds no second line" "$(grep -c '^\.lavish/$' "$GH/.git/info/exclude")" "1"
150
+ reset
151
+ out="$(page "$GH" PATH="$NPXONLY:$SEALED" -- open .lavish/plan.html)"
152
+ t "without the binary, open goes through npx -y" "$(calls)" "npx -y lavish-axi .lavish/plan.html|"
153
+ reset
154
+ page "$GH" -- open .lavish/plan.html --fallback .lavish/plan.md -- --reopen >/dev/null
155
+ t "flags after -- reach the tool" "$(calls)" "lavish-axi .lavish/plan.html --reopen|"
156
+ reset
157
+ out="$(page "$GH" CCKIT_OUTPUT=json -- open .lavish/plan.html)"
158
+ t "--llm open: stdout is one JSON object" "$out" '{"mode":"page","file":".lavish/plan.html"}'
159
+
160
+ # ── 4. open: the fallback prints the markdown, runs no tool and exits 0 ────────────────────────
161
+ reset
162
+ out="$(page "$GH" CI=true -- open .lavish/plan.html --fallback .lavish/plan.md)"; rc=$?
163
+ t "fallback rc" "$rc" "0"
164
+ t "fallback runs no tool" "$(calls)" ""
165
+ yes "fallback prints the markdown" "$out" "step one"
166
+ yes "fallback says why, on stderr" "$(cat "$TMP/err")" "page: terminal output — CI is set"
167
+ out="$(page "$GH" CCKIT_HEADLESS=1 -- open .lavish/plan.html)"; rc=$?
168
+ t "fallback with no markdown rc" "$rc" "0"
169
+ yes "fallback with no markdown tells the agent to print" "$out" "terminal: no page was opened (CCKIT_HEADLESS is set"
170
+ out="$(page "$OFF" -- open .lavish/plan.html --fallback .lavish/plan.md)"; rc=$?
171
+ t "integration off: open rc" "$rc" "0"
172
+ yes "integration off: the markdown is printed" "$out" "step one"
173
+ t "integration off: no tool ran" "$(calls)" ""
174
+ out="$(page "$GH" CI=true CCKIT_OUTPUT=json -- open .lavish/plan.html --fallback .lavish/plan.md)"
175
+ t "--llm fallback names mode, reason and fallback file" "$(printf '%s' "$out" | jq -r '.mode + "|" + .fallback')" "terminal|.lavish/plan.md"
176
+
177
+ # ── 5. open: a tool that fails falls back instead of failing ───────────────────────────────────
178
+ reset; printf '7\n' > "$TMP/lavish-rc"
179
+ out="$(page "$GH" -- open .lavish/plan.html --fallback .lavish/plan.md)"; rc=$?
180
+ t "tool exits 7 -> open still exits 0" "$rc" "0"
181
+ yes "tool exits 7 -> the markdown is printed" "$out" "step one"
182
+ yes "tool exits 7 -> stderr names the exit code" "$(cat "$TMP/err")" "lavish-axi exited 7"
183
+
184
+ # ── 6. open: usage errors are the only non-zero exits ──────────────────────────────────────────
185
+ reset
186
+ page "$GH" -- open >/dev/null; t "open with no file -> rc 2" "$?" "2"
187
+ page "$GH" -- open .lavish/absent.html >/dev/null; t "open with a missing file -> rc 2" "$?" "2"
188
+ page "$GH" -- open .lavish/plan.html --fallback .lavish/absent.md >/dev/null; t "open with a missing fallback -> rc 2" "$?" "2"
189
+ t "a usage error runs no tool" "$(calls)" ""
190
+ page "$GH" -- frobnicate >/dev/null; t "unknown subcommand -> rc 2" "$?" "2"
191
+
192
+ # ── 7. poll / reply / end: handed to the tool in page mode, a no-op in terminal mode ───────────
193
+ reset
194
+ page "$GH" -- poll .lavish/plan.html --agent-reply "done" >/dev/null; t "poll rc" "$?" "0"
195
+ page "$GH" -- end .lavish/plan.html >/dev/null
196
+ t "poll and end reach the tool with their arguments" "$(calls)" "lavish-axi poll .lavish/plan.html --agent-reply done|lavish-axi end .lavish/plan.html|"
197
+ printf '3\n' > "$TMP/lavish-rc"
198
+ page "$GH" -- poll .lavish/plan.html >/dev/null; t "poll returns the tool's own exit code" "$?" "3"
199
+ reset
200
+ page "$GH" CI=true -- poll .lavish/plan.html >/dev/null; t "poll in terminal mode -> rc 0" "$?" "0"
201
+ t "poll in terminal mode runs no tool" "$(calls)" ""
202
+
203
+ # ── 8. answer: a GitHub project with an issue gets ONE comment ─────────────────────────────────
204
+ reset
205
+ printf 'Chose option B: one PR.\n' > "$TMP/answer.md"
206
+ out="$(page "$GH" -- answer --kind decision --title "Ship as one PR" --issue 42 --body-file "$TMP/answer.md")"; rc=$?
207
+ t "answer rc" "$rc" "0"
208
+ yes "answer commented on the issue, in the configured repo" "$(calls)" "gh issue comment 42 --repo o/r --body-file "
209
+ yes "answer prints where it went" "$out" "issue #42 https://example.invalid/o/r/issues/42#issuecomment-1"
210
+ body="$(cat "$TMP/gh-last-body")"
211
+ yes "comment: kind and title in the heading" "$body" "### Decision answer: Ship as one PR"
212
+ yes "comment: the answer text" "$body" "Chose option B: one PR."
213
+ yes "comment: the marker that makes a re-run a no-op" "$body" "<!-- cckit:page-answer kind=decision id="
214
+ t "answer wrote no file in a GitHub project" "$([ -e "$GH/docs/answers" ] && echo made || echo none)" "none"
215
+ : > "$LOG"
216
+ out="$(page "$GH" -- answer --kind decision --title "Ship as one PR" --issue 42 --body-file "$TMP/answer.md")"; rc=$?
217
+ t "same answer again: rc 0" "$rc" "0"
218
+ no "same answer again: no second comment" "$(calls)" "issue comment"
219
+ yes "same answer again: says so" "$out" "issue #42 (already recorded)"
220
+ : > "$LOG"
221
+ # page() feeds /dev/null on stdin, so an answer with no --body-file has an empty body.
222
+ page "$GH" -- answer --kind decision --title "Ship as one PR" --issue '#42' >/dev/null
223
+ t "an empty body is refused" "$?" "2"
224
+ no "an empty body posts nothing" "$(calls)" "issue comment"
225
+ printf 'Chose option A instead.\n' > "$TMP/answer2.md"
226
+ page "$GH" -- answer --kind decision --title "Ship as one PR" --issue '#42' --body-file "$TMP/answer2.md" >/dev/null
227
+ yes "a different answer on the same issue is a new comment" "$(calls)" "gh issue comment 42"
228
+ out="$(page "$GH" CCKIT_OUTPUT=json -- answer --kind grill --title "Round 1" --issue 42 --body-file "$TMP/answer.md")"
229
+ t "--llm answer is one JSON object" "$(printf '%s' "$out" | jq -c '[.ok, .where, .issue, .written]')" '[true,"issue",42,true]'
230
+ reset; printf '1\n' > "$TMP/gh-rc"
231
+ page "$GH" -- answer --kind plan --title "Plan" --issue 42 --body-file "$TMP/answer.md" >/dev/null; rc=$?
232
+ t "a refused comment -> rc 1" "$rc" "1"
233
+ yes "a refused comment names the cause" "$(cat "$TMP/err")" "could not comment on #42"
234
+ reset
235
+ page "$GH" CI=true -- answer --kind plan --title "Approved in the terminal" --issue 7 --body-file "$TMP/answer.md" >/dev/null
236
+ yes "terminal mode writes the answer back too" "$(calls)" "gh issue comment 7 --repo o/r"
237
+
238
+ # ── 9. answer: no GitHub (or no issue) writes a versioned file ─────────────────────────────────
239
+ reset
240
+ today="$(date +%Y-%m-%d)"
241
+ out="$(page "$NOGH" -- answer --kind decision --title "Launch: week 12, not 14!" --body-file "$TMP/answer.md")"; rc=$?
242
+ want="$NOGH/docs/answers/$today-decision-launch-week-12-not-14.md"
243
+ t "file answer rc" "$rc" "0"
244
+ t "file answer prints the path" "$out" "file $want"
245
+ t "file answer made no gh call" "$(calls)" ""
246
+ f="$(cat "$want" 2>/dev/null)"
247
+ yes "file: heading" "$f" "# Decision answer: Launch: week 12, not 14!"
248
+ yes "file: date" "$f" "- Recorded: $today"
249
+ yes "file: the answer text" "$f" "Chose option B: one PR."
250
+ t "file is untracked-but-visible to git, so it can be committed" "$(git -C "$NOGH" status --porcelain --untracked-files=all | grep -c 'docs/answers/')" "1"
251
+ yes "file answer tells the agent to commit it" "$(cat "$TMP/err")" "commit it with the change"
252
+ out="$(page "$NOGH" -- answer --kind decision --title "Launch: week 12, not 14!" --body-file "$TMP/answer.md")"
253
+ yes "same file answer again: nothing written" "$out" "(already recorded)"
254
+ t "same file answer again: still one file" "$(find "$NOGH/docs/answers" -type f | wc -l | tr -d ' ')" "1"
255
+ page "$NOGH" -- answer --kind decision --title "Launch: week 12, not 14!" --body-file "$TMP/answer2.md" >/dev/null
256
+ t "a different answer under the same title gets its own file" "$([ -f "${want%.md}-2.md" ] && echo yes || echo no)" "yes"
257
+ # The file name starts with the date: the same answer on a later day is still one record.
258
+ mv "$want" "$NOGH/docs/answers/2020-01-01-decision-launch-week-12-not-14.md"
259
+ out="$(page "$NOGH" -- answer --kind decision --title "Launch: week 12, not 14!" --body-file "$TMP/answer.md")"
260
+ yes "same file answer on a later day: nothing written" "$out" "docs/answers/2020-01-01-decision-launch-week-12-not-14.md (already recorded)"
261
+ t "…and no file dated today appears" "$([ -e "$want" ] && echo made || echo none)" "none"
262
+ out="$(page "$NOGH" -- answer --kind plan --title "Q3 plan" --issue 9 --body-file "$TMP/answer.md")"
263
+ yes "no GitHub repo in the config: an --issue still goes to a file" "$out" "file $NOGH/docs/answers/$today-plan-q3-plan.md"
264
+ yes "…and the file records the issue" "$(cat "$NOGH/docs/answers/$today-plan-q3-plan.md")" "- Issue: #9"
265
+ out="$(page "$GH" -- answer --kind plan --title "Before the issue exists" --body-file "$TMP/answer.md")"
266
+ yes "a GitHub project with no --issue writes a file" "$out" "file $GH/docs/answers/$today-plan-before-the-issue-exists.md"
267
+ t "…and makes no gh call" "$(calls)" ""
268
+
269
+ # ── 10. answer: reviewPages.answers / answersDir decide when they are set ──────────────────────
270
+ FORCEF="$(project forcef '{"github":{"repo":"o/r"},"reviewPages":{"answers":"file","answersDir":"knowledge/decisions"}}')"
271
+ reset
272
+ out="$(page "$FORCEF" -- answer --kind decision --title "Pick" --issue 5 --body-file "$TMP/answer.md")"
273
+ yes "answers=file wins over a GitHub issue, in answersDir" "$out" "file $FORCEF/knowledge/decisions/$today-decision-pick.md"
274
+ t "answers=file makes no gh call" "$(calls)" ""
275
+ FORCEI="$(project forcei '{"reviewPages":{"answers":"issue"}}')"
276
+ page "$FORCEI" -- answer --kind decision --title "Pick" --body-file "$TMP/answer.md" >/dev/null
277
+ t "answers=issue with no --issue -> rc 2" "$?" "2"
278
+ ESC="$(project esc '{"reviewPages":{"answersDir":"../outside"}}')"
279
+ page "$ESC" -- answer --kind decision --title "Pick" --body-file "$TMP/answer.md" >/dev/null
280
+ t "an answersDir that leaves the repo -> rc 2" "$?" "2"
281
+ t "…and nothing is written outside" "$([ -e "$TMP/outside" ] && echo made || echo none)" "none"
282
+
283
+ # ── 11. answer: usage errors ───────────────────────────────────────────────────────────────────
284
+ page "$GH" -- answer --kind verdict --title x --body-file "$TMP/answer.md" >/dev/null; t "unknown kind -> rc 2" "$?" "2"
285
+ page "$GH" -- answer --kind plan --body-file "$TMP/answer.md" >/dev/null; t "no title -> rc 2" "$?" "2"
286
+ page "$GH" -- answer --kind plan --title x --issue abc --body-file "$TMP/answer.md" >/dev/null; t "non-numeric issue -> rc 2" "$?" "2"
287
+ page "$GH" -- answer --kind plan --title x --body-file "$TMP/absent.md" >/dev/null; t "missing body file -> rc 2" "$?" "2"
288
+ page "$GH" -- answer --title x --kind >/dev/null; t "a flag with no value -> rc 2" "$?" "2"
289
+ ABS="$(project abs "{\"reviewPages\":{\"answersDir\":\"$TMP/abs-out\"}}")"
290
+ page "$ABS" -- answer --kind decision --title "Pick" --body-file "$TMP/answer.md" >/dev/null
291
+ t "an absolute answersDir -> rc 2" "$?" "2"
292
+ t "…and nothing is written there" "$([ -e "$TMP/abs-out" ] && echo made || echo none)" "none"
293
+ reset
294
+ page "$GH" -- reply .lavish/plan.html --agent-reply "noted" >/dev/null
295
+ t "reply reaches the tool with its arguments" "$(calls)" "lavish-axi reply .lavish/plan.html --agent-reply noted|"
296
+
297
+ # ── 12. the same answers under zsh (scripts/lib is sourced by both shells) ─────────────────────
298
+ if command -v zsh >/dev/null 2>&1; then
299
+ ZSH="$(command -v zsh)"
300
+ zmode() { ( cd "$GH" && env -i HOME="$TMP/home" PATH="$STUB:$SEALED" KIT_CONFIG="$GH/.claude/kit.config.json" \
301
+ CLAUDECODE=1 CLAUDE_CODE_ENTRYPOINT=cli DISPLAY=:0 "$@" "$ZSH" -c ". '$LIBF'; rp_mode" </dev/null 2>/dev/null ); }
302
+ t "zsh: attended -> page" "$(zmode)" "page"
303
+ yes "zsh: CI -> terminal" "$(zmode CI=true)" "terminal CI is set"
304
+ reset
305
+ ( cd "$GH" && env -i HOME="$TMP/home" PATH="$STUB:$SEALED" KIT_CONFIG="$GH/.claude/kit.config.json" \
306
+ CLAUDECODE=1 CLAUDE_CODE_ENTRYPOINT=cli DISPLAY=:0 "$ZSH" -c ". '$LIBF'; rp_open .lavish/plan.html; rp_answer --kind plan --title 'Z plan' --issue 3 --body-file '$TMP/answer.md'" </dev/null >/dev/null 2>&1 )
307
+ yes "zsh: open runs the tool" "$(calls)" "lavish-axi .lavish/plan.html|"
308
+ yes "zsh: answer comments on the issue" "$(calls)" "gh issue comment 3 --repo o/r"
309
+ zerr="$( cd "$NOGH" && env -i HOME="$TMP/home" PATH="$STUB:$SEALED" KIT_CONFIG="$NOGH/.claude/kit.config.json" \
310
+ "$ZSH" -c ". '$LIBF'; rp_answer --kind grill --title 'Z round' --body-file '$TMP/answer.md'; rp_answer --title x --kind" </dev/null 2>&1 >/dev/null )"
311
+ t "zsh: a file answer is written" "$([ -f "$NOGH/docs/answers/$today-grill-z-round.md" ] && echo yes || echo no)" "yes"
312
+ no "zsh: a flag with no value prints no shell error" "$zerr" "shift count"
313
+ else
314
+ echo "ok: zsh absent — the zsh cases are skipped"
315
+ fi
316
+
317
+ if [ "$fail" -eq 0 ]; then echo "PASS review-page-test"; else echo "FAIL review-page-test"; fi
318
+ exit "$fail"