@jeiemgi/cckit 0.9.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 (305) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +491 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +182 -17
  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/hook-adapter-test.sh +193 -0
  59. package/scripts/init-content-test.sh +225 -0
  60. package/scripts/init-guided-test.sh +474 -0
  61. package/scripts/init-recipes-test.sh +104 -0
  62. package/scripts/init-upgrade-test.sh +341 -2
  63. package/scripts/init.sh +746 -95
  64. package/scripts/instruction-budget-baseline.txt +8 -0
  65. package/scripts/instruction-budget-lint-test.sh +166 -0
  66. package/scripts/instruction-budget-lint.sh +219 -0
  67. package/scripts/integrations-check-test.sh +200 -0
  68. package/scripts/integrations-check.sh +157 -0
  69. package/scripts/kit-add-test.sh +214 -0
  70. package/scripts/kit-add.sh +305 -5
  71. package/scripts/kit-adopt-test.sh +16 -0
  72. package/scripts/kit-adopt.sh +3 -2
  73. package/scripts/kit-digest.sh +2 -2
  74. package/scripts/kit-doctor-test.sh +293 -0
  75. package/scripts/kit-doctor.sh +272 -140
  76. package/scripts/kit-export-project-test.sh +3 -3
  77. package/scripts/kit-remove-test.sh +19 -0
  78. package/scripts/kit-routines.sh +2 -2
  79. package/scripts/kit-self-update.sh +1 -1
  80. package/scripts/kit-version-check-test.sh +4 -0
  81. package/scripts/kit-version-check.sh +4 -2
  82. package/scripts/knowledge-lint.sh +4 -4
  83. package/scripts/leak-fence-test.sh +89 -0
  84. package/scripts/lib/adapter-select-test.sh +136 -0
  85. package/scripts/lib/adapter-select.sh +158 -0
  86. package/scripts/lib/agent-def-test.sh +69 -0
  87. package/scripts/lib/agent-def.sh +106 -0
  88. package/scripts/lib/agent-launch-test.sh +212 -0
  89. package/scripts/lib/agent-launch.sh +335 -0
  90. package/scripts/lib/board-view-test.sh +11 -0
  91. package/scripts/lib/board-view.sh +42 -26
  92. package/scripts/lib/branch-owner-test.sh +26 -0
  93. package/scripts/lib/branch-owner.sh +16 -9
  94. package/scripts/lib/captain-test.sh +105 -0
  95. package/scripts/lib/captain.sh +87 -8
  96. package/scripts/lib/codex-hooks-test.sh +100 -0
  97. package/scripts/lib/codex-hooks.sh +69 -0
  98. package/scripts/lib/commitlint.sh +1 -1
  99. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  100. package/scripts/lib/copilot-test.sh +70 -4
  101. package/scripts/lib/copilot.sh +66 -14
  102. package/scripts/lib/effort-dispatch-test.sh +3 -3
  103. package/scripts/lib/effort-metrics-test.sh +178 -1
  104. package/scripts/lib/effort-metrics.sh +175 -35
  105. package/scripts/lib/effort-ops-test.sh +205 -7
  106. package/scripts/lib/effort-ops.sh +198 -43
  107. package/scripts/lib/effort-parity-test.sh +49 -13
  108. package/scripts/lib/effort-plan-test.sh +337 -0
  109. package/scripts/lib/effort-plan.sh +200 -23
  110. package/scripts/lib/effort.sh +56 -11
  111. package/scripts/lib/errors-header-test.sh +1 -1
  112. package/scripts/lib/gh-project-test.sh +35 -1
  113. package/scripts/lib/gh-project.sh +23 -16
  114. package/scripts/lib/gh-rest-test.sh +32 -3
  115. package/scripts/lib/gh-rest.sh +17 -2
  116. package/scripts/lib/hook-refresh.sh +1 -1
  117. package/scripts/lib/init-github.sh +412 -0
  118. package/scripts/lib/init-guide.sh +630 -0
  119. package/scripts/lib/integration-install-test.sh +343 -0
  120. package/scripts/lib/integration-install.sh +257 -0
  121. package/scripts/lib/integrations-test.sh +366 -0
  122. package/scripts/lib/integrations.sh +244 -0
  123. package/scripts/lib/kinds-test.sh +125 -0
  124. package/scripts/lib/kinds.sh +66 -0
  125. package/scripts/lib/kit-brief-test.sh +22 -3
  126. package/scripts/lib/kit-brief.sh +45 -5
  127. package/scripts/lib/kit-config-resolve.sh +2 -2
  128. package/scripts/lib/kit-config-test.sh +64 -1
  129. package/scripts/lib/kit-config.sh +37 -1
  130. package/scripts/lib/kit-events.sh +7 -0
  131. package/scripts/lib/kit-gc-test.sh +173 -1
  132. package/scripts/lib/kit-gc.sh +226 -37
  133. package/scripts/lib/kit-hotfix.sh +216 -0
  134. package/scripts/lib/kit-interview-test.sh +93 -0
  135. package/scripts/lib/kit-interview.sh +117 -8
  136. package/scripts/lib/kit-lib-test.sh +1 -1
  137. package/scripts/lib/kit-lib.sh +3 -3
  138. package/scripts/lib/kit-local.sh +2 -2
  139. package/scripts/lib/kit-manifest.sh +33 -1
  140. package/scripts/lib/kit-profile-test.sh +3 -3
  141. package/scripts/lib/kit-status-test.sh +112 -4
  142. package/scripts/lib/kit-status.sh +246 -16
  143. package/scripts/lib/kit-task-ops-test.sh +37 -0
  144. package/scripts/lib/kit-task-ops.sh +175 -31
  145. package/scripts/lib/kto-hotfix-test.sh +232 -0
  146. package/scripts/lib/kto-task-close-test.sh +1 -1
  147. package/scripts/lib/kto-task-new-test.sh +95 -0
  148. package/scripts/lib/kto-task-pr-merge-test.sh +37 -3
  149. package/scripts/lib/kto-task-pr-test.sh +70 -0
  150. package/scripts/lib/leak-fence.sh +89 -0
  151. package/scripts/lib/light-task-run-test.sh +255 -0
  152. package/scripts/lib/light-task-test.sh +309 -0
  153. package/scripts/lib/light-task.sh +706 -0
  154. package/scripts/lib/next-test.sh +99 -0
  155. package/scripts/lib/next.sh +9 -3
  156. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  157. package/scripts/lib/orchestration-runtime.sh +57 -5
  158. package/scripts/lib/plan-machine-test.sh +15 -2
  159. package/scripts/lib/plan-machine.sh +20 -7
  160. package/scripts/lib/plan-next-test.sh +1 -1
  161. package/scripts/lib/plan-next.sh +4 -4
  162. package/scripts/lib/pr-evidence-test.sh +3 -3
  163. package/scripts/lib/pr-evidence.sh +1 -1
  164. package/scripts/lib/qa-lane-test.sh +626 -0
  165. package/scripts/lib/qa-lane.sh +1357 -0
  166. package/scripts/lib/qa-lanes-test.sh +175 -0
  167. package/scripts/lib/react-detect.sh +1 -1
  168. package/scripts/lib/render-test.sh +1 -1
  169. package/scripts/lib/review-page-test.sh +318 -0
  170. package/scripts/lib/review-page.sh +369 -0
  171. package/scripts/lib/review-stage-test.sh +62 -11
  172. package/scripts/lib/review-stage.sh +42 -60
  173. package/scripts/lib/role-identity-test.sh +65 -0
  174. package/scripts/lib/role-identity.sh +25 -2
  175. package/scripts/lib/secret-guard.sh +3 -3
  176. package/scripts/lib/session-registry-test.sh +111 -0
  177. package/scripts/lib/session-registry.sh +233 -0
  178. package/scripts/lib/stage-receipt-test.sh +14 -1
  179. package/scripts/lib/stage-receipt.sh +13 -8
  180. package/scripts/lib/task-source-file.sh +309 -0
  181. package/scripts/lib/task-source.sh +130 -0
  182. package/scripts/lib/upgrade-report-test.sh +120 -0
  183. package/scripts/lib/upgrade-report.sh +138 -0
  184. package/scripts/lib/version-bump.sh +3 -3
  185. package/scripts/lib/wave-result-test.sh +80 -0
  186. package/scripts/lib/wave-result.sh +127 -0
  187. package/scripts/lib/worker-brief-test.sh +5 -0
  188. package/scripts/lib/worker-brief.sh +2 -2
  189. package/scripts/lib/worktree-issue-test.sh +30 -1
  190. package/scripts/lib/worktree-issue.sh +82 -12
  191. package/scripts/lib/worktree-ports-test.sh +57 -4
  192. package/scripts/lib/worktree-start-test.sh +197 -0
  193. package/scripts/lib/worktree-start.sh +153 -31
  194. package/scripts/lib/zsh-safety-test.sh +19 -3
  195. package/scripts/marketing-walkthrough-test.sh +152 -0
  196. package/scripts/night-grant-test.sh +37 -0
  197. package/scripts/night-grant.sh +448 -0
  198. package/scripts/night-run-test.sh +8 -0
  199. package/scripts/night-run.mjs +275 -0
  200. package/scripts/night-run.test.mjs +324 -0
  201. package/scripts/orchestrate-test.sh +190 -0
  202. package/scripts/orchestrate.sh +79 -8
  203. package/scripts/portable-test.sh +11 -2
  204. package/scripts/publish.sh +28 -3
  205. package/scripts/review-lint-test.sh +7 -7
  206. package/scripts/review-lint.sh +2 -2
  207. package/scripts/review-rules.conf +8 -0
  208. package/scripts/rule-recipes-test.sh +96 -0
  209. package/scripts/self-install-test.sh +39 -9
  210. package/scripts/setup-labels.sh +18 -1
  211. package/scripts/setup-milestones.sh +1 -1
  212. package/scripts/showcase.sh +1 -1
  213. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  214. package/scripts/skill-frontmatter-lint.sh +1 -1
  215. package/scripts/status-test.sh +113 -2
  216. package/scripts/status.sh +16 -3
  217. package/scripts/task-sync-test.sh +154 -0
  218. package/scripts/task-sync.sh +243 -32
  219. package/scripts/test-runner-test.sh +158 -0
  220. package/scripts/test.sh +131 -23
  221. package/scripts/update-path-test.sh +279 -0
  222. package/scripts/ux-ds-audit.sh +1 -1
  223. package/scripts/ux-graph-scan.sh +6 -6
  224. package/scripts/wave-worker.sh +54 -0
  225. package/skills/kit-add/SKILL.md +77 -0
  226. package/skills/kit-autopilot/SKILL.md +123 -12
  227. package/skills/kit-cleanup/SKILL.md +5 -2
  228. package/skills/kit-contribute/SKILL.md +4 -4
  229. package/skills/kit-docs-writer/SKILL.md +16 -6
  230. package/skills/kit-effort-close/SKILL.md +17 -8
  231. package/skills/kit-effort-new/SKILL.md +15 -9
  232. package/skills/kit-effort-pr/SKILL.md +15 -7
  233. package/skills/kit-effort-start/SKILL.md +5 -2
  234. package/skills/kit-gc/SKILL.md +5 -2
  235. package/skills/kit-next/SKILL.md +5 -1
  236. package/skills/kit-onboard/SKILL.md +3 -3
  237. package/skills/kit-page/SKILL.md +93 -0
  238. package/skills/kit-plan-next/SKILL.md +8 -4
  239. package/skills/kit-security-sweep/SKILL.md +1 -3
  240. package/skills/kit-ship/SKILL.md +2 -3
  241. package/skills/kit-status/SKILL.md +35 -4
  242. package/skills/kit-task-new/SKILL.md +3 -3
  243. package/skills/kit-task-pr/SKILL.md +7 -2
  244. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  245. package/skills/kit-task-start/SKILL.md +7 -7
  246. package/skills/kit-task-sync/SKILL.md +19 -3
  247. package/skills/kit-ux-audit/SKILL.md +3 -2
  248. package/templates/agents/auto-dev.md +5 -4
  249. package/templates/agents/backend.md +1 -1
  250. package/templates/agents/designer.md +2 -0
  251. package/templates/agents/devops.md +1 -1
  252. package/templates/agents/editor.md +9 -1
  253. package/templates/agents/frontend.md +1 -1
  254. package/templates/agents/local-delegate.md +1 -1
  255. package/templates/agents/pm.md +5 -5
  256. package/templates/agents/tech-lead.md +1 -1
  257. package/templates/benchmarks/SCHEMA.md +9 -3
  258. package/templates/codex/hooks.json.tmpl +89 -0
  259. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  260. package/templates/hooks/guard-raw-git-ops.sh.tmpl +12 -12
  261. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  262. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  263. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  264. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  265. package/templates/instructions.md.tmpl +174 -0
  266. package/templates/kit.config.json.tmpl +3 -3
  267. package/templates/knowledge-INDEX.md.tmpl +1 -1
  268. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  269. package/templates/rules/authoring.md +106 -0
  270. package/templates/rules/branch-naming.md +40 -4
  271. package/templates/rules/code-retrieval.md +63 -0
  272. package/templates/rules/delegation-brief.md +0 -3
  273. package/templates/rules/design-routing.md +3 -3
  274. package/templates/rules/effort-model.md +14 -10
  275. package/templates/rules/gate-and-review.md +94 -0
  276. package/templates/rules/issue-lifecycle.md +88 -0
  277. package/templates/rules/knowledge-base.md +1 -1
  278. package/templates/rules/mempalace.md +1 -1
  279. package/templates/rules/merge-safety.md +108 -0
  280. package/templates/rules/naming-and-ids.md +23 -17
  281. package/templates/rules/plain-language.md +59 -0
  282. package/templates/rules/plan-next.md +9 -11
  283. package/templates/rules/react-annotate.md +6 -0
  284. package/templates/rules/review-pages.md +49 -0
  285. package/templates/rules/risk-tiered-review.md +13 -4
  286. package/templates/rules/shared-checkout.md +106 -0
  287. package/templates/rules/skill-gaps.md +2 -7
  288. package/templates/rules/task-management.md +13 -1
  289. package/templates/skills/brand-voice/SKILL.md +91 -0
  290. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  291. package/templates/skills/campaign/SKILL.md +123 -0
  292. package/templates/skills/campaign/references/plan-template.md +55 -0
  293. package/templates/skills/concrete/SKILL.md +2 -2
  294. package/templates/skills/copywriting/SKILL.md +8 -1
  295. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  296. package/templates/skills/morning-briefing/SKILL.md +2 -2
  297. package/templates/skills/page-design/SKILL.md +145 -0
  298. package/templates/skills/page-design/add.json +5 -0
  299. package/templates/skills/page-design/references/design-file-template.md +40 -0
  300. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  301. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  302. package/templates/skills/speckit/SKILL.md +4 -5
  303. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  304. package/commands/kit-add.md +0 -42
  305. package/templates/CLAUDE.md.tmpl +0 -106
@@ -0,0 +1,626 @@
1
+ #!/usr/bin/env bash
2
+ # qa-lane-test.sh — launched and usable are different facts (#295); the review route comes from
3
+ # the work (#297); a stop leaves the ports with no listener (#298); a verdict is bound to the
4
+ # commit that was reviewed and a later commit reads it stale (#299).
5
+ #
6
+ # Hermetic: `curl` is a stub on PATH that answers from a table, the "stack" is a `sleep`, and every
7
+ # file lands in a scratch repo. `open`, `xdg-open` and `gh` are stubs too: no browser starts and no
8
+ # network is touched. Only the stop sections listen on a port — a loopback port the kernel picked —
9
+ # and they skip with a printed reason when perl, or both lsof and ss, are absent.
10
+ #
11
+ # Run: bash scripts/lib/qa-lane-test.sh
12
+ # errors: strict — a test runner: rc 1 on any failed assertion
13
+ # shellcheck shell=bash
14
+ set -u
15
+
16
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
17
+ command -v jq >/dev/null 2>&1 || { echo "qa-lane-test: jq absent — skipping"; exit 0; }
18
+ # Sealed from the caller's KIT_*/CCKIT_* (#369): the suite builds its own project.
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
+ PIDS=""
24
+ cleanup() { local p; for p in $PIDS; do kill "$p" 2>/dev/null; done; rm -rf "$TMP"; }
25
+ trap cleanup EXIT
26
+
27
+ fail=0
28
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
29
+ yes() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> missing '$3' in [$2]"; fail=1 ;; esac; }
30
+ no() { case "$2" in *"$3"*) echo "FAIL: $1 -> found '$3' in [$2]"; fail=1 ;; *) echo "ok: $1" ;; esac; }
31
+
32
+ # ── the curl stub: status per URL substring, first match wins; no match is a refused connection ──
33
+ STUB="$TMP/stub"; mkdir -p "$STUB"
34
+ CURL_TABLE="$TMP/curl.table"; export CURL_TABLE
35
+ CURL_LOG="$TMP/curl.log"; export CURL_LOG
36
+ cat > "$STUB/curl" <<'SH'
37
+ #!/usr/bin/env bash
38
+ url=""; for a in "$@"; do url="$a"; done
39
+ printf '%s\n' "$*" >> "$CURL_LOG"
40
+ while read -r needle code; do
41
+ [ -n "$needle" ] || continue
42
+ case "$url" in *"$needle"*) printf '%s' "$code"; [ "$code" = 000 ] && exit 7; exit 0 ;; esac
43
+ done < "$CURL_TABLE"
44
+ printf '000'; exit 7
45
+ SH
46
+ chmod +x "$STUB/curl"
47
+ # ── the browser openers and gh: each logs its arguments; gh answers a PR body from a file ──────
48
+ OPEN_LOG="$TMP/open.log"; export OPEN_LOG; : > "$OPEN_LOG"
49
+ for o in open xdg-open; do
50
+ cat > "$STUB/$o" <<'SH'
51
+ #!/usr/bin/env bash
52
+ printf '%s %s\n' "${0##*/}" "$*" >> "$OPEN_LOG"
53
+ SH
54
+ chmod +x "$STUB/$o"
55
+ done
56
+ GH_LOG="$TMP/gh.log"; export GH_LOG; : > "$GH_LOG"
57
+ PR_BODY="$TMP/pr.body"; export PR_BODY
58
+ PR_META="$TMP/pr.meta"; export PR_META
59
+ GH_COMMENTS="$TMP/gh.comments"; export GH_COMMENTS; : > "$GH_COMMENTS"
60
+ cat > "$STUB/gh" <<'SH'
61
+ #!/usr/bin/env bash
62
+ # stub: `gh pr view <ref> --json body --jq …` prints the body file; no file means no PR (rc 1).
63
+ # For the verdict (#299) it also answers the PR's number/url/head/branch from $PR_META and keeps
64
+ # the PR's comments in $GH_COMMENTS as `<id><TAB><json body>` rows: list, create, edit in place.
65
+ printf '%s\n' "$*" >> "$GH_LOG"
66
+ case "$*" in
67
+ *"--json number,url,headRefOid,headRefName"*)
68
+ [ -f "$PR_META" ] || { echo "no pull requests found" >&2; exit 1; }
69
+ cat "$PR_META"; exit 0 ;;
70
+ "api --paginate "*) cat "$GH_COMMENTS" 2>/dev/null; exit 0 ;;
71
+ "api --method PATCH "*)
72
+ id="${4##*/}"; f="${6#body=@}"
73
+ grep -v "^$id " "$GH_COMMENTS" > "$GH_COMMENTS.tmp"
74
+ printf '%s\t%s\n' "$id" "$(jq -Rs . < "$f")" >> "$GH_COMMENTS.tmp"
75
+ mv "$GH_COMMENTS.tmp" "$GH_COMMENTS"; exit 0 ;;
76
+ "pr comment "*)
77
+ n=$(( $(wc -l < "$GH_COMMENTS" 2>/dev/null || echo 0) + 9001 ))
78
+ printf '%s\t%s\n' "$n" "$(jq -Rs . < "$5")" >> "$GH_COMMENTS"; exit 0 ;;
79
+ esac
80
+ [ -f "$PR_BODY" ] || { echo "no pull requests found" >&2; exit 1; }
81
+ cat "$PR_BODY"
82
+ SH
83
+ chmod +x "$STUB/gh"
84
+ PATH="$STUB:$PATH"; export PATH
85
+ answers() { printf '%s\n' "$@" > "$CURL_TABLE"; }
86
+
87
+ # ── a project that declared its stack the way `kit-add.sh qa` records it (#294) ────────────────
88
+ P="$TMP/proj"; mkdir -p "$P"
89
+ (
90
+ cd "$P" && git init -q . && git config user.email t@t && git config user.name t &&
91
+ git commit -q --allow-empty -m base && git checkout -q -b task/7-review-stack
92
+ ) || { echo "qa-lane-test: could not build the fixture repo"; exit 1; }
93
+ DEF_PORTS='[{"env":"WEB_PORT","base":3000},{"env":"API_PORT","base":4000}]'
94
+ DEF_READY='[{"env":"WEB_PORT","path":"/"},{"env":"API_PORT","path":"/health"}]'
95
+ write_cfg() { # <command> [<ports-json>] [<readiness-json>]
96
+ local ports="${2:-$DEF_PORTS}" ready="${3:-$DEF_READY}"
97
+ jq -n --arg c "$1" --argjson ports "$ports" --argjson ready "$ready" \
98
+ '{qa: {command: $c, ports: $ports, readiness: $ready, route: "/", credentialEnv: []}}' \
99
+ > "$P/cckit.config.json"
100
+ }
101
+ write_cfg 'env > "env.$LANE_TAG.dump"; exec sleep 60'
102
+
103
+ KIT_STATE_DIR="$TMP/state"; export KIT_STATE_DIR
104
+ KIT_CONFIG="$P/cckit.config.json"; export KIT_CONFIG
105
+ QA_READY_INTERVAL=0.1; export QA_READY_INTERVAL
106
+ EVENTS="$P/.git/kit-events.jsonl"
107
+ events() { local c; c="$(grep -c "\"op\":\"$1\"" "$EVENTS" 2>/dev/null)"; [ -n "$c" ] || c=0; printf '%s' "$c"; }
108
+
109
+ cd "$P" || exit 1
110
+ # shellcheck source=/dev/null
111
+ . "$ROOT/scripts/lib/qa-lane.sh"
112
+
113
+ # The sections that launch on the default bases (3000, 4000) answer their probes from the curl stub
114
+ # and bind nothing. `up` refuses a lane port somebody already listens on, and this machine may run
115
+ # a dev server there, so the holder lookup is off until the stop sections, which pick free ports.
116
+ QA_PORT_TOOL=none; export QA_PORT_TOOL
117
+
118
+ # ── one probe: what counts as up ───────────────────────────────────────────────────────────────
119
+ answers "/ok 200" "/login-wall 302" "/missing 404" "/broken 503"
120
+ qa_probe "http://localhost:1/ok" >/dev/null; t "a 200 is up" "$?" "0"
121
+ qa_probe "http://localhost:1/login-wall" >/dev/null; t "a 302 to sign-in is up" "$?" "0"
122
+ qa_probe "http://localhost:1/missing" >/dev/null; t "a 404 is not up" "$?" "1"
123
+ qa_probe "http://localhost:1/broken" >/dev/null; t "a 503 is not up" "$?" "1"
124
+ qa_probe "http://localhost:1/nothing" >/dev/null; t "a refused connection is not up" "$?" "1"
125
+ t "a refused connection reads as 000" "$(qa_probe "http://localhost:1/nothing")" "000"
126
+ : > "$CURL_LOG"; qa_probe "http://localhost:1/login-wall" >/dev/null
127
+ no "redirects are not followed" "$(cat "$CURL_LOG")" " -L"
128
+
129
+ # ── the lane id ────────────────────────────────────────────────────────────────────────────────
130
+ t "the lane is the branch's issue number" "$(qa_lane_id)" "7"
131
+ t "--lane overrides the branch" "$(qa_lane_id 12)" "12"
132
+ qa_lane_id abc >/dev/null 2>&1; t "a non-numeric lane is refused" "$?" "2"
133
+
134
+ # ── launch: the command's environment holds the project's OWN port variables ───────────────────
135
+ answers ":3 200" ":4 200"
136
+ out7="$(LANE_TAG=7 qa_cli up --timeout 5 2>"$TMP/up7.err")"; rc=$?
137
+ PIDS="$PIDS $(cat "$KIT_STATE_DIR/qa/7/pid" 2>/dev/null)"
138
+ t "up returns 0 once every probe answers" "$rc" "0"
139
+ yes "up prints the usable line" "$out7" "lane 7 usable"
140
+ waited=0; while [ ! -s "$P/env.7.dump" ] && [ "$waited" -lt 50 ]; do sleep 0.1; waited=$((waited+1)); done
141
+ web7="$(sed -n 's/^WEB_PORT=//p' "$P/env.7.dump" 2>/dev/null)"
142
+ api7="$(sed -n 's/^API_PORT=//p' "$P/env.7.dump" 2>/dev/null)"
143
+ t "WEB_PORT in the command's env is the recorded lane port" "$web7" "$(sed -n 's/^WEB_PORT=//p' "$KIT_STATE_DIR/qa/7/ports")"
144
+ t "API_PORT in the command's env is the recorded lane port" "$api7" "$(sed -n 's/^API_PORT=//p' "$KIT_STATE_DIR/qa/7/ports")"
145
+ slot7="$(awk -F'\t' '$1==7 {print $2}' "$P/.git/kit-portslots.tsv")"
146
+ t "the web port is base + slot * stride" "$web7" "$(( 3000 + slot7 * 10 ))"
147
+ t "the api port is base + slot * stride" "$api7" "$(( 4000 + slot7 * 10 ))"
148
+ yes "the probes hit the lane's own ports" "$(cat "$CURL_LOG")" "http://localhost:$api7/health"
149
+ t "launch appended one event" "$(events qa.launch)" "1"
150
+ t "ready appended one event" "$(events qa.ready)" "1"
151
+ t "the launch event is an op.start carrying the ports" \
152
+ "$(grep '"op":"qa.launch"' "$EVENTS" | jq -r '"\(.type) \(.payload.lane) \(.payload.ports.WEB_PORT)"')" "op.start 7 $web7"
153
+
154
+ # A second `up` on a live lane must not start a second stack.
155
+ pid_before="$(cat "$KIT_STATE_DIR/qa/7/pid")"
156
+ LANE_TAG=7 qa_cli up --timeout 5 >/dev/null 2>"$TMP/up7b.err"; rc=$?
157
+ t "a second up on a live lane still reports usable" "$rc" "0"
158
+ t "a second up keeps the running pid" "$(cat "$KIT_STATE_DIR/qa/7/pid")" "$pid_before"
159
+ yes "a second up says it did not relaunch" "$(cat "$TMP/up7b.err")" "already launched"
160
+ t "a second up emits no second launch event" "$(events qa.launch)" "1"
161
+
162
+ # ── two lanes get disjoint ports ───────────────────────────────────────────────────────────────
163
+ LANE_TAG=8 qa_cli up --lane 8 --timeout 5 >/dev/null 2>&1; rc=$?
164
+ PIDS="$PIDS $(cat "$KIT_STATE_DIR/qa/8/pid" 2>/dev/null)"
165
+ t "a second lane comes up" "$rc" "0"
166
+ all="$(cat "$KIT_STATE_DIR/qa/7/ports" "$KIT_STATE_DIR/qa/8/ports" | cut -d= -f2)"
167
+ t "two lanes hold four ports" "$(printf '%s\n' "$all" | grep -c .)" "4"
168
+ t "two lanes hold four DISTINCT ports" "$(printf '%s\n' "$all" | sort -u | grep -c .)" "4"
169
+
170
+ # ── usable needs EVERY probe: a web 200 with the API failing is not usable ─────────────────────
171
+ before_ready="$(events qa.ready)"
172
+ answers ":3 200" ":4 503"
173
+ err="$(qa_cli ready --timeout 1 2>&1 >/dev/null)"; rc=$?
174
+ t "web up + API failing is NOT usable" "$rc" "1"
175
+ yes "the failure names the probe that did not answer" "$err" "API_PORT http://localhost:$api7/health -> 503"
176
+ yes "the failure names the launch log" "$err" "$KIT_STATE_DIR/qa/7/launch.log"
177
+ t "a failed wait emits no ready event" "$(events qa.ready)" "$before_ready"
178
+ t "timeout appended one event" "$(events qa.timeout)" "1"
179
+ t "the timeout event carries the log path" \
180
+ "$(grep '"op":"qa.timeout"' "$EVENTS" | jq -r '.payload.log')" "$KIT_STATE_DIR/qa/7/launch.log"
181
+
182
+ # The API coming back flips the same lane to usable — the verdict is read, not remembered.
183
+ answers ":3 302" ":4 200"
184
+ qa_cli ready --timeout 5 >/dev/null 2>&1; t "a 302 on web plus a 200 on the API is usable" "$?" "0"
185
+
186
+ # --llm: one JSON object, usable is a boolean.
187
+ j="$(CCKIT_OUTPUT=json qa_cli ready --timeout 5 2>/dev/null)"
188
+ t "--llm reports usable + the lane's ports" "$(printf '%s' "$j" | jq -r '"\(.usable) \(.lane) \(.ports.API_PORT)"')" "true 7 $api7"
189
+ answers ":3 200"
190
+ j="$(CCKIT_OUTPUT=json qa_cli ready --timeout 1 2>/dev/null)"; rc=$?
191
+ t "--llm on a timeout still exits 1" "$rc" "1"
192
+ t "--llm on a timeout says usable false and names the log" \
193
+ "$(printf '%s' "$j" | jq -r '"\(.usable) \(.log)"')" "false $KIT_STATE_DIR/qa/7/launch.log"
194
+
195
+ # ── the route line: what counts as declared (#297) ─────────────────────────────────────────────
196
+ decl() { printf '%s\n' "$1" | qa_route_declared; }
197
+ t "a plain QA route line" "$(decl 'QA route: /settings/billing')" "/settings/billing"
198
+ t "a bulleted, backticked line" "$(decl '- QA route: `/orders/42?tab=items`')" "/orders/42?tab=items"
199
+ t "a bold label, any letter case" "$(decl '**qa Route:** /a')" "/a"
200
+ t "the first usable line wins" "$(decl "$(printf 'intro\nQA route: /one\nQA route: /two')")" "/one"
201
+ t "CRLF bodies are read" "$(printf 'QA route: /crlf\r\n' | qa_route_declared)" "/crlf"
202
+ t "an unfilled template placeholder is skipped" "$(decl "$(printf 'QA route: <path>\nQA route: /real')")" "/real"
203
+ decl 'QA route: settings' >/dev/null; t "a value with no leading slash is not a route" "$?" "1"
204
+ decl 'QA route: https://evil.example/x' >/dev/null; t "a full URL is not a route" "$?" "1"
205
+ decl 'the QA route: /x is mentioned mid-sentence' >/dev/null; t "a mid-sentence mention is not a declaration" "$?" "1"
206
+ decl 'no route here' >/dev/null; t "a body with no line declares nothing" "$?" "1"
207
+ qa_route_valid '/ok/path'; t "a path is a valid route" "$?" "0"
208
+ qa_route_valid '/a b'; t "a route with a space is refused" "$?" "1"
209
+ qa_route_valid '/a";rm'; t "a route with a quote is refused" "$?" "1"
210
+
211
+ # ── open: the screen the change touched, on the lane's own port ────────────────────────────────
212
+ write_cfg 'exec sleep 60'
213
+ jq '.qa.route = "/dashboard"' "$P/cckit.config.json" > "$TMP/cfg.tmp" && mv "$TMP/cfg.tmp" "$P/cckit.config.json"
214
+ answers ":3 200" ":4 200"
215
+ printf 'Summary of the change.\n\nQA route: /settings/billing\n' > "$PR_BODY"
216
+ : > "$OPEN_LOG"; : > "$GH_LOG"
217
+ url="$(qa_cli open 2>"$TMP/open.err")"; rc=$?
218
+ t "open on a usable lane returns 0" "$rc" "0"
219
+ t "a declared route opens on the lane's first port" "$url" "http://localhost:$web7/settings/billing"
220
+ t "the opener got exactly that URL, once" "$(cat "$OPEN_LOG")" "open http://localhost:$web7/settings/billing"
221
+ yes "the PR is looked up by the lane's branch" "$(cat "$GH_LOG")" "pr view task/7-review-stack"
222
+ yes "open says where the route came from" "$(cat "$TMP/open.err")" "declared route /settings/billing"
223
+ t "open appended one event" "$(events qa.open)" "1"
224
+ t "the open event carries the url and the source" \
225
+ "$(grep '"op":"qa.open"' "$EVENTS" | jq -r '"\(.type) \(.payload.source) \(.payload.opened) \(.payload.url)"')" \
226
+ "op.done declared true http://localhost:$web7/settings/billing"
227
+
228
+ # No declared line: the configured route is the fallback.
229
+ printf 'Summary only, no route line.\n' > "$PR_BODY"
230
+ : > "$OPEN_LOG"
231
+ t "with no declared route the configured one is used" "$(qa_cli open 2>/dev/null)" "http://localhost:$web7/dashboard"
232
+ t "the opener got the configured route" "$(cat "$OPEN_LOG")" "open http://localhost:$web7/dashboard"
233
+ # No PR at all (gh fails) reads the same as no declared line.
234
+ rm -f "$PR_BODY"
235
+ t "with no PR the configured route is used" "$(qa_cli open --print 2>/dev/null)" "http://localhost:$web7/dashboard"
236
+
237
+ # --pr reads another PR; --route overrides both; --port-env picks the port; --print opens nothing.
238
+ printf 'QA route: /from-pr-31\n' > "$PR_BODY"
239
+ : > "$GH_LOG"; : > "$OPEN_LOG"
240
+ t "--pr reads the named PR" "$(qa_cli open --pr 31 --print 2>/dev/null)" "http://localhost:$web7/from-pr-31"
241
+ yes "--pr is what gh was asked for" "$(cat "$GH_LOG")" "pr view 31"
242
+ t "--route overrides the declared route" "$(qa_cli open --route /override --print 2>/dev/null)" "http://localhost:$web7/override"
243
+ t "--port-env picks another port variable" "$(qa_cli open --port-env API_PORT --print 2>/dev/null)" "http://localhost:$api7/from-pr-31"
244
+ t "--print opens no browser" "$(cat "$OPEN_LOG")" ""
245
+ j="$(CCKIT_OUTPUT=json qa_cli open --print 2>/dev/null)"
246
+ t "--llm reports the url, the source and opened" \
247
+ "$(printf '%s' "$j" | jq -r '"\(.url) \(.source) \(.opened)"')" "http://localhost:$web7/from-pr-31 declared false"
248
+ # Another lane opens on ITS port.
249
+ web8="$(sed -n 's/^WEB_PORT=//p' "$KIT_STATE_DIR/qa/8/ports")"
250
+ t "another lane opens on its own port" "$(qa_cli open --lane 8 --route /x --print 2>/dev/null)" "http://localhost:$web8/x"
251
+ # QA_OPENER replaces the default opener.
252
+ : > "$OPEN_LOG"
253
+ QA_OPENER=xdg-open qa_cli open --route /via-env >/dev/null 2>&1
254
+ t "QA_OPENER names the opener" "$(cat "$OPEN_LOG")" "xdg-open http://localhost:$web7/via-env"
255
+
256
+ # ── open refuses a lane that is not ready ──────────────────────────────────────────────────────
257
+ opens="$(events qa.open)"
258
+ answers ":3 200" ":4 503"
259
+ : > "$OPEN_LOG"
260
+ err="$(qa_cli open 2>&1 >/dev/null)"; rc=$?
261
+ t "open on a lane that is not usable returns 1" "$rc" "1"
262
+ yes "the refusal says the lane is not usable" "$err" "NOT usable — refusing to open"
263
+ yes "the refusal names the probe that failed" "$err" "API_PORT http://localhost:$api7/health -> 503"
264
+ yes "the refusal names the launch log" "$err" "$KIT_STATE_DIR/qa/7/launch.log"
265
+ t "a refused open starts no browser" "$(cat "$OPEN_LOG")" ""
266
+ t "a refused open emits no open event" "$(events qa.open)" "$opens"
267
+ qa_cli open --lane 21 >/dev/null 2>&1; t "open on a lane never launched is rc 2" "$?" "2"
268
+ answers ":3 200" ":4 200"
269
+ qa_cli open --route 'no-slash' >/dev/null 2>&1; t "a --route that is not a route is rc 2" "$?" "2"
270
+ qa_cli open --port-env NOPE_PORT >/dev/null 2>&1; t "a --port-env the lane does not hold is rc 2" "$?" "2"
271
+ qa_cli open --pr abc >/dev/null 2>&1; t "a non-numeric --pr is rc 2" "$?" "2"
272
+ qa_cli open --timeout 5 >/dev/null 2>&1; t "--timeout on open is rc 2" "$?" "2"
273
+ qa_cli up --route /x >/dev/null 2>&1; t "--route on up is rc 2" "$?" "2"
274
+ jq '.qa.route = "bad route"' "$P/cckit.config.json" > "$TMP/cfg.tmp" && mv "$TMP/cfg.tmp" "$P/cckit.config.json"
275
+ rm -f "$PR_BODY"
276
+ err="$(qa_cli open --print 2>&1 >/dev/null)"; rc=$?
277
+ t "a configured route that is not a route is rc 2" "$rc" "2"
278
+ yes "that refusal names qa.route" "$err" "qa.route"
279
+ t "no refused open was recorded" "$(events qa.open)" "$opens"
280
+
281
+ # ── a command that exits is reported at once, not at the timeout ───────────────────────────────
282
+ write_cfg 'echo "boot failed: missing DATABASE_URL"; exit 3'
283
+ answers "nothing 200"
284
+ start="$(date +%s)"
285
+ err="$(qa_cli up --lane 9 --timeout 60 2>&1 >/dev/null)"; rc=$?
286
+ took=$(( $(date +%s) - start ))
287
+ t "a stack command that exits is not usable" "$rc" "1"
288
+ yes "the failure says the command exited" "$err" "exited before it was ready"
289
+ yes "the failure names that lane's log" "$err" "$KIT_STATE_DIR/qa/9/launch.log"
290
+ yes "the log holds the command's own output" "$(cat "$KIT_STATE_DIR/qa/9/launch.log")" "missing DATABASE_URL"
291
+ t "an exited command does not wait out the 60s timeout" "$([ "$took" -lt 30 ] && echo fast || echo "slow:$took")" "fast"
292
+ t "exited appended one event" "$(events qa.exited)" "1"
293
+
294
+ # ── refusals happen before anything launches ───────────────────────────────────────────────────
295
+ launches="$(events qa.launch)"
296
+ refuse() { # <label> <want-in-stderr> — expects rc 2, no lane 20 state, no launch event
297
+ local e rc
298
+ e="$(qa_cli up --lane 20 --timeout 1 2>&1 >/dev/null)"; rc=$?
299
+ t "$1: rc 2" "$rc" "2"
300
+ yes "$1: says why" "$e" "$2"
301
+ t "$1: no lane state is left" "$([ -e "$KIT_STATE_DIR/qa/20/ports" ] || [ -e "$KIT_STATE_DIR/qa/20/pid" ] && echo yes || echo no)" "no"
302
+ }
303
+ jq -n '{}' > "$P/cckit.config.json"
304
+ refuse "no qa.command" "no qa.command"
305
+ write_cfg 'exec sleep 60' '[]'
306
+ refuse "no port variables" "qa.ports is empty"
307
+ write_cfg 'exec sleep 60' '[{"env":"WEB_PORT","base":3000},{"env":"API_PORT","base":3100}]'
308
+ refuse "bases a stride multiple apart" "two lanes would share a port"
309
+ write_cfg 'exec sleep 60' '[{"env":"WEB_PORT","base":3000},{"env":"WEB_PORT","base":3001}]'
310
+ refuse "a port variable declared twice" "declares WEB_PORT twice"
311
+ write_cfg 'exec sleep 60' '[{"env":"WEB_PORT","base":3000}]' '[]'
312
+ refuse "no readiness probe" "qa.readiness is empty"
313
+ write_cfg 'exec sleep 60' '[{"env":"WEB_PORT","base":3000}]' '[{"env":"API_PORT","path":"/health"}]'
314
+ refuse "a probe on an undeclared variable" "not a port variable in qa.ports"
315
+ t "no refusal launched anything" "$(events qa.launch)" "$launches"
316
+
317
+ write_cfg 'exec sleep 60'
318
+ qa_cli ready --lane 21 --timeout 1 >/dev/null 2>&1; t "ready on a lane never launched is a refusal, not a timeout" "$?" "2"
319
+ qa_cli nope >/dev/null 2>&1; t "an unknown subcommand is rc 2" "$?" "2"
320
+ qa_cli up --wat >/dev/null 2>&1; t "an unknown argument is rc 2" "$?" "2"
321
+
322
+ # ── stop: the ports are free afterwards, and the report is what actually stopped (#298) ────────
323
+ # These sections run REAL processes: a supervisor shell that respawns a perl listener on a port
324
+ # the kernel just handed out. The curl stub still answers the readiness probes.
325
+ # A lane's base must leave room for 40 slots (qa_ports_check: base + 39 * stride <= 65535), and the
326
+ # kernel hands out ports up to 65535, so a pick above 65000 is drawn again.
327
+ free_port() { perl -MIO::Socket::INET -e 'for (1 .. 50) { my $s = IO::Socket::INET->new(Listen => 1, LocalAddr => "127.0.0.1", LocalPort => 0) or exit 1; my $p = $s->sockport; if ($p <= 65000) { print $p; exit 0 } } exit 1' 2>/dev/null; }
328
+ listening() { [ -n "$(qa_port_pids "$1")" ] && echo yes || echo no; }
329
+ wait_listen() { local i=0; while [ "$(listening "$1")" = no ] && [ "$i" -lt 100 ]; do sleep 0.1; i=$((i+1)); done; }
330
+ running() { _qa_alive "$1" && echo yes || echo no; }
331
+ # The supervisor: respawn the listener for as long as this shell lives.
332
+ cat > "$TMP/listen.pl" <<'PL'
333
+ use IO::Socket::INET;
334
+ my $s = IO::Socket::INET->new(Listen => 5, LocalAddr => "127.0.0.1", LocalPort => $ENV{WEB_PORT}, ReuseAddr => 1) or exit 1;
335
+ sleep 600;
336
+ PL
337
+ SUPERVISE="while :; do perl '$TMP/listen.pl'; sleep 0.1; done"
338
+
339
+ unset QA_PORT_TOOL
340
+ if ! command -v perl >/dev/null 2>&1; then
341
+ echo "skip: stop — perl is absent, so the fixture cannot open a listener"
342
+ elif ! qa_port_tool >/dev/null 2>&1; then
343
+ echo "skip: stop — neither lsof nor ss is installed, so a port's holder cannot be resolved"
344
+ else
345
+ # (1) through the verb: launch a respawning stack, stop it, and the port has no listener.
346
+ slot30="$(wt_port_slot "$P" 30 "$P")"
347
+ port30="$(free_port)"
348
+ write_cfg "$SUPERVISE" "[{\"env\":\"WEB_PORT\",\"base\":$(( port30 - slot30 * 10 ))}]" '[{"env":"WEB_PORT","path":"/"}]'
349
+ answers ":$port30 200"
350
+ qa_cli up --lane 30 --timeout 5 >/dev/null 2>&1; t "the respawning fixture stack comes up" "$?" "0"
351
+ sup30="$(cat "$KIT_STATE_DIR/qa/30/pid" 2>/dev/null)"; PIDS="$PIDS $sup30"
352
+ t "the lane was launched on the free port" "$(sed -n 's/^WEB_PORT=//p' "$KIT_STATE_DIR/qa/30/ports")" "$port30"
353
+ wait_listen "$port30"
354
+ lis30="$(qa_port_pids "$port30" | sed -n 1p)"
355
+ t "the fixture listener holds the port" "$(listening "$port30")" "yes"
356
+ # The supervisor really respawns: kill the listener alone and the port is held again.
357
+ kill "$lis30" 2>/dev/null; sleep 0.5; wait_listen "$port30"
358
+ t "killing the listener alone does not free the port" "$(listening "$port30")" "yes"
359
+ no "the respawned listener is a new process" " $(qa_port_pids "$port30" | tr '\n' ' ')" " $lis30 "
360
+ lis30="$(qa_port_pids "$port30" | sed -n 1p)"
361
+
362
+ stops="$(events qa.stop)"
363
+ err="$(qa_cli stop --lane 30 2>&1 >/dev/null)"; rc=$?
364
+ t "stop returns 0 once the port is free" "$rc" "0"
365
+ sleep 0.5
366
+ t "the port has no listener after stop" "$(listening "$port30")" "no"
367
+ t "the supervisor pid is gone" "$(running "$sup30")" "no"
368
+ t "the listener pid is gone" "$(running "$lis30")" "no"
369
+ yes "stop reports the supervisor it stopped" "$err" "$sup30"
370
+ yes "stop reports the listener it stopped" "$err" "$lis30"
371
+ yes "stop says the ports are free" "$err" "ports free: $port30"
372
+ t "stop appended one event" "$(events qa.stop)" "$(( stops + 1 ))"
373
+ t "the stop event says the ports were freed" "$(grep '"op":"qa.stop"' "$EVENTS" | tail -n 1 | jq -r '"\(.payload.lane) \(.payload.freed) \(.payload.held | length)"')" "30 true 0"
374
+ t "a stopped lane keeps no pid or ports record" "$([ -e "$KIT_STATE_DIR/qa/30/pid" ] || [ -e "$KIT_STATE_DIR/qa/30/ports" ] && echo yes || echo no)" "no"
375
+
376
+ # A second stop on the already-stopped lane: nothing stopped, rc 0.
377
+ err="$(qa_cli stop --lane 30 2>&1 >/dev/null)"; rc=$?
378
+ t "a second stop returns 0" "$rc" "0"
379
+ yes "a second stop reports nothing stopped" "$err" "nothing stopped"
380
+ no "a second stop claims no process" "$err" "stopped 1"
381
+ t "a second stop appends no event" "$(events qa.stop)" "$(( stops + 1 ))"
382
+ t "--llm on a stopped lane is an empty stop" "$(CCKIT_OUTPUT=json qa_cli stop --lane 30 2>/dev/null | jq -c '.stopped')" "[]"
383
+ qa_cli ready --lane 30 --timeout 1 >/dev/null 2>&1; t "ready on a stopped lane is a refusal" "$?" "2"
384
+ qa_cli stop --lane 30 --timeout 5 >/dev/null 2>&1; t "--timeout on stop is rc 2" "$?" "2"
385
+
386
+ # (2) the recorded pid is dead but its supervisor lives on: the port's holder names it.
387
+ port31="$(free_port)"
388
+ ( WEB_PORT="$port31" exec sh -c "$SUPERVISE" ) >/dev/null 2>&1 &
389
+ sup31=$!; PIDS="$PIDS $sup31"
390
+ ( exit 0 ) & gone=$!; wait "$gone" 2>/dev/null
391
+ mkdir -p "$KIT_STATE_DIR/qa/31"
392
+ printf '%s\n' "$gone" > "$KIT_STATE_DIR/qa/31/pid"
393
+ printf 'WEB_PORT=%s\n' "$port31" > "$KIT_STATE_DIR/qa/31/ports"
394
+ wait_listen "$port31"
395
+ t "the orphaned stack holds its port" "$(listening "$port31")" "yes"
396
+ # Nothing ties that listener to the lane: the recorded pid is dead and there is no group on
397
+ # record. An unforced stop leaves it running and says how to stop it.
398
+ err="$(qa_cli stop --lane 31 2>&1 >/dev/null)"; rc=$?
399
+ t "an unforced stop does not call a lane with a held port down" "$rc" "1"
400
+ t "an unforced stop leaves a listener it cannot tie to the lane" "$(running "$sup31")" "yes"
401
+ yes "an unforced stop names --force" "$err" "stop --lane 31 --force"
402
+ t "an unforced stop keeps the record for the retry" "$([ -f "$KIT_STATE_DIR/qa/31/ports" ] && echo yes || echo no)" "yes"
403
+ qa_cli up --lane 31 --force >/dev/null 2>&1; t "--force belongs to stop only" "$?" "2"
404
+ j="$(CCKIT_OUTPUT=json qa_cli stop --lane 31 --force 2>/dev/null)"; rc=$?
405
+ t "a forced stop finds a stack through its port when the recorded pid is dead" "$rc" "0"
406
+ sleep 0.5
407
+ t "that port has no listener after stop" "$(listening "$port31")" "no"
408
+ t "the supervisor behind the listener is gone" "$(running "$sup31")" "no"
409
+ t "--llm lists the supervisor among the stopped pids" "$(printf '%s' "$j" | jq -r --argjson p "$sup31" '"\(.freed) \(.stopped | index($p) != null)"')" "true true"
410
+ t "this shell survived the ancestor climb" "$(running "$$")" "yes"
411
+
412
+ # (3) a recycled pid is not the lane's stack: a start time that does not match is left alone.
413
+ sleep 60 & stranger=$!; PIDS="$PIDS $stranger"
414
+ mkdir -p "$KIT_STATE_DIR/qa/32"
415
+ printf '%s\n' "$stranger" > "$KIT_STATE_DIR/qa/32/pid"
416
+ printf 'Thu Jan 1 00:00:00 1970\n' > "$KIT_STATE_DIR/qa/32/started"
417
+ printf 'WEB_PORT=%s\n' "$(free_port)" > "$KIT_STATE_DIR/qa/32/ports"
418
+ err="$(qa_cli stop --lane 32 2>&1 >/dev/null)"; rc=$?
419
+ t "a recorded pid with another start time is not stopped" "$(running "$stranger")" "yes"
420
+ yes "that stop reports nothing stopped" "$err" "nothing stopped"
421
+ t "that stop still returns 0: the port is free" "$rc" "0"
422
+ kill "$stranger" 2>/dev/null
423
+
424
+ # (4) with no holder lookup the recorded tree is still stopped, and the ports are not called free.
425
+ ( exec sh -c 'sleep 60 & wait' ) >/dev/null 2>&1 &
426
+ sup33=$!; PIDS="$PIDS $sup33"
427
+ mkdir -p "$KIT_STATE_DIR/qa/33"
428
+ printf '%s\n' "$sup33" > "$KIT_STATE_DIR/qa/33/pid"
429
+ printf 'WEB_PORT=%s\n' "$(free_port)" > "$KIT_STATE_DIR/qa/33/ports"
430
+ err="$(QA_PORT_TOOL=none qa_cli stop --lane 33 2>&1 >/dev/null)"; rc=$?
431
+ t "without lsof or ss the recorded tree is still stopped" "$(running "$sup33")" "no"
432
+ t "without lsof or ss a clean stop is rc 0" "$rc" "0"
433
+ yes "without lsof or ss the ports are reported as not checked" "$err" "ports NOT checked"
434
+ no "without lsof or ss the ports are not called free" "$err" "ports free"
435
+
436
+ # (5) the same stop under zsh, where an unquoted list does not word-split.
437
+ if command -v zsh >/dev/null 2>&1; then
438
+ port35="$(free_port)"
439
+ ( WEB_PORT="$port35" exec sh -c "$SUPERVISE" ) >/dev/null 2>&1 &
440
+ sup35=$!; PIDS="$PIDS $sup35"
441
+ mkdir -p "$KIT_STATE_DIR/qa/35"
442
+ printf '%s\n' "$sup35" > "$KIT_STATE_DIR/qa/35/pid"
443
+ printf 'WEB_PORT=%s\n' "$port35" > "$KIT_STATE_DIR/qa/35/ports"
444
+ wait_listen "$port35"
445
+ lis35="$(qa_port_pids "$port35" | sed -n 1p)"
446
+ err="$(zsh -c "cd '$P'; . '$ROOT/scripts/lib/qa-lane.sh'; qa_stop 35" 2>&1 >/dev/null)"; rc=$?
447
+ t "zsh: stop returns 0" "$rc" "0"
448
+ sleep 0.5
449
+ t "zsh: the port has no listener after stop" "$(listening "$port35")" "no"
450
+ t "zsh: the supervisor pid is gone" "$(running "$sup35")" "no"
451
+ yes "zsh: stop reports both processes" "$err" "stopped 2 process(es): "
452
+ yes "zsh: the listener is in the report" "$err" "$lis35"
453
+ err="$(zsh -c "cd '$P'; . '$ROOT/scripts/lib/qa-lane.sh'; qa_stop 35" 2>&1 >/dev/null)"; rc=$?
454
+ t "zsh: a second stop returns 0" "$rc" "0"
455
+ yes "zsh: a second stop reports nothing stopped" "$err" "nothing stopped"
456
+ else
457
+ echo "ok: zsh absent — skipping the zsh stop pass (dependency-light gate)"
458
+ fi
459
+
460
+ # (6) a port somebody already listens on refuses the launch, before any record is written. The
461
+ # curl stub answers 200 on that port, so without the refusal the stranger makes the lane "usable".
462
+ slot36="$(wt_port_slot "$P" 36 "$P")"
463
+ port36="$(free_port)"
464
+ ( WEB_PORT="$port36" exec perl "$TMP/listen.pl" ) >/dev/null 2>&1 &
465
+ squat36=$!; PIDS="$PIDS $squat36"
466
+ wait_listen "$port36"
467
+ write_cfg 'exec sleep 60' "[{\"env\":\"WEB_PORT\",\"base\":$(( port36 - slot36 * 10 ))}]" '[{"env":"WEB_PORT","path":"/"}]'
468
+ answers ":$port36 200"
469
+ launches="$(events qa.launch)"
470
+ err="$(qa_cli up --lane 36 --timeout 5 2>&1 >/dev/null)"; rc=$?
471
+ t "up refuses a lane whose port is already in use" "$rc" "2"
472
+ yes "the refusal names the port" "$err" "WEB_PORT=$port36"
473
+ yes "the refusal names the listener" "$err" "pid $squat36"
474
+ t "a refused launch writes no ports or pid record" "$([ -e "$KIT_STATE_DIR/qa/36/ports" ] || [ -e "$KIT_STATE_DIR/qa/36/pid" ] && echo yes || echo no)" "no"
475
+ t "a refused launch emits no launch event" "$(events qa.launch)" "$launches"
476
+ qa_cli open --lane 36 --print >/dev/null 2>&1; t "open on the refused lane is a refusal" "$?" "2"
477
+ qa_cli stop --lane 36 >/dev/null 2>&1
478
+ t "the listener that was there first is still running" "$(running "$squat36")" "yes"
479
+ t "qa_port_held sees that listener" "$(qa_port_held "$port36" && echo yes || echo no)" "yes"
480
+ kill "$squat36" 2>/dev/null
481
+
482
+ # (7) a listener that takes the lane's port AFTER the launch is not the lane's: stop ends the
483
+ # launched command, leaves the stranger, and exits 1; --force stops the stranger too.
484
+ slot37="$(wt_port_slot "$P" 37 "$P")"
485
+ port37="$(free_port)"
486
+ write_cfg 'exec sleep 60' "[{\"env\":\"WEB_PORT\",\"base\":$(( port37 - slot37 * 10 ))}]" '[{"env":"WEB_PORT","path":"/"}]'
487
+ answers ":$port37 200"
488
+ qa_cli up --lane 37 --timeout 5 >/dev/null 2>&1; t "a lane on a free port comes up" "$?" "0"
489
+ own37="$(cat "$KIT_STATE_DIR/qa/37/pid" 2>/dev/null)"; PIDS="$PIDS $own37"
490
+ ( WEB_PORT="$port37" exec perl "$TMP/listen.pl" ) >/dev/null 2>&1 &
491
+ squat37=$!; PIDS="$PIDS $squat37"
492
+ wait_listen "$port37"
493
+ err="$(qa_cli stop --lane 37 2>&1 >/dev/null)"; rc=$?
494
+ t "stop ends the command the lane launched" "$(running "$own37")" "no"
495
+ t "stop leaves a listener the lane did not launch" "$(running "$squat37")" "yes"
496
+ t "stop is rc 1 while that listener holds the port" "$rc" "1"
497
+ yes "stop names the listener it left" "$err" "did not launch pid $squat37"
498
+ no "stop does not report the stranger as stopped" "$(printf '%s\n' "$err" | grep 'stopped ')" "$squat37"
499
+ err="$(qa_cli stop --lane 37 --force 2>&1 >/dev/null)"; rc=$?
500
+ t "stop --force stops that listener" "$(running "$squat37")" "no"
501
+ t "stop --force returns 0 once the port is free" "$rc" "0"
502
+ t "a forced stop clears the record" "$([ -e "$KIT_STATE_DIR/qa/37/ports" ] && echo yes || echo no)" "no"
503
+ write_cfg 'exec sleep 60'
504
+ fi
505
+ QA_PORT_TOOL=none; export QA_PORT_TOOL
506
+ QA_PORT_TOOL=none qa_port_tool >/dev/null 2>&1; t "QA_PORT_TOOL=none means no holder lookup" "$?" "1"
507
+ qa_cli stop --lane 34 >/dev/null 2>&1; t "stop on a lane never launched is rc 0" "$?" "0"
508
+
509
+ # ── the verdict: bound to the reviewed commit, upserted on the PR, a fail mailed back (#299) ────
510
+ KIT_MAIL_DIR="$TMP/mail"; export KIT_MAIL_DIR
511
+ sha1="$(git -C "$P" rev-parse HEAD)"
512
+ printf '31\nhttps://github.com/o/r/pull/31\n%s\ntask/7-review-stack\n' "$sha1" > "$PR_META"
513
+ : > "$GH_COMMENTS"
514
+ ncomments() { grep -c . "$GH_COMMENTS" 2>/dev/null || true; }
515
+ nreceipts() { ls "$KIT_STATE_DIR/receipts/7-qa-"*.json 2>/dev/null | grep -c . || true; }
516
+
517
+ t "a lane with no verdict reads none" "$(qa_cli verdict 2>/dev/null)" "none"
518
+ qa_cli verdict >/dev/null 2>&1; t "reading a lane with no verdict is rc 1" "$?" "1"
519
+
520
+ ev0="$(events qa.verdict)"
521
+ qa_cli verdict pass > "$TMP/v.out" 2> "$TMP/v.err"; rc=$?
522
+ t "a pass verdict returns 0" "$rc" "0"
523
+ t "the verdict prints the receipt path" "$(cat "$TMP/v.out")" "$KIT_STATE_DIR/receipts/7-qa-1.json"
524
+ t "the qa receipt's head_sha is the reviewed commit" "$(jq -r '.head_sha' "$KIT_STATE_DIR/receipts/7-qa-1.json")" "$sha1"
525
+ t "the qa receipt is a clean pass" \
526
+ "$(jq -r '"\(.stage) \(.outcome) \(.gate) \(.next_stage) \(.invalid | length)"' "$KIT_STATE_DIR/receipts/7-qa-1.json")" "qa pr-open pass none 0"
527
+ t "the first verdict creates the PR comment" "$PR_EVIDENCE_LAST_RESULT" "created"
528
+ t "one comment is on the PR" "$(ncomments)" "1"
529
+ yes "the comment carries the verdict marker" "$(cat "$GH_COMMENTS")" "cckit:pr-evidence key=qa-verdict"
530
+ yes "the comment names the reviewed commit" "$(cat "$GH_COMMENTS")" "commit: $sha1"
531
+ t "a verdict appends one event" "$(( $(events qa.verdict) - ev0 ))" "1"
532
+ t "the event carries the verdict, the commit and the PR" \
533
+ "$(grep '"op":"qa.verdict"' "$EVENTS" | tail -n 1 | jq -r '"\(.type) \(.payload.verdict) \(.payload.head) \(.payload.pr) \(.payload.comment) \(.payload.mailed)"')" \
534
+ "op.done pass $sha1 31 created false"
535
+ t "a pass mails nobody" "$(find "$KIT_MAIL_DIR" -name '*.md' 2>/dev/null | grep -c . || true)" "0"
536
+
537
+ qa_cli verdict pass >/dev/null 2>&1
538
+ t "the same verdict again edits the comment" "$PR_EVIDENCE_LAST_RESULT" "updated"
539
+ t "still one comment on the PR" "$(ncomments)" "1"
540
+ t "the same verdict on the same commit rewrites its attempt" "$(nreceipts)" "1"
541
+ t "the second verdict appended its own event" "$(( $(events qa.verdict) - ev0 ))" "2"
542
+
543
+ t "the verdict reads pass against the reviewed commit" "$(qa_verdict_state 7 "$sha1")" "pass"
544
+ qa_verdict_state 7 "$sha1" >/dev/null; t "a fresh pass is rc 0" "$?" "0"
545
+ t "the verb reads pass on the lane's head" "$(qa_cli verdict 2>/dev/null)" "pass"
546
+ t "receipt show prints the qa receipt" "$("$ROOT/bin/cckit" receipt show 7 qa | jq -r '.head_sha')" "$sha1"
547
+ t "the same receipt against another head reads stale" "$(qa_verdict_state 7 0000000000000000000000000000000000000000)" "stale"
548
+ t "a verdict with no head to compare reads stale" "$(qa_verdict_state 7 '')" "stale"
549
+ t "a lane nobody reviewed reads none" "$(qa_verdict_state 99 "$sha1")" "none"
550
+
551
+ # A later commit on the lane's branch: the recorded pass no longer covers what is there.
552
+ git -C "$P" commit -q --allow-empty -m "a later push"
553
+ sha2="$(git -C "$P" rev-parse HEAD)"
554
+ out="$(qa_cli verdict 2>"$TMP/v.err")"; rc=$?
555
+ t "after a later commit the verdict reads stale" "$out" "stale"
556
+ t "a stale verdict is rc 1" "$rc" "1"
557
+ yes "the stale report names the commit it was recorded against" "$(cat "$TMP/v.err")" "$sha1"
558
+ t "--llm reports the state and both commits" \
559
+ "$(CCKIT_OUTPUT=json qa_cli verdict 2>/dev/null | jq -r '"\(.state) \(.head) \(.verdict_head)"')" "stale $sha2 $sha1"
560
+ t "--head reads the verdict against a named commit" "$(qa_cli verdict --head "$sha1" 2>/dev/null)" "pass"
561
+
562
+ # A fail: notes are required, and they go back to the builder's branch as a steer.
563
+ qa_cli verdict fail >/dev/null 2>"$TMP/v.err"; t "a fail with no notes is refused" "$?" "2"
564
+ yes "the refusal says what is missing" "$(cat "$TMP/v.err")" "a fail needs its notes"
565
+ t "a refused verdict writes no receipt" "$(nreceipts)" "1"
566
+ qa_cli verdict pass --shot "$TMP/absent.png" >/dev/null 2>&1; t "a screenshot that is not a file is refused" "$?" "2"
567
+ qa_cli verdict maybe >/dev/null 2>&1; t "an unknown verdict word is refused" "$?" "2"
568
+ qa_cli verdict --note "orphan" >/dev/null 2>&1; t "notes with no verdict are refused" "$?" "2"
569
+ qa_cli up pass >/dev/null 2>&1; t "pass belongs to verdict only" "$?" "2"
570
+ t "none of the refusals wrote a receipt" "$(nreceipts)" "1"
571
+
572
+ printf 'png' > "$TMP/broken-save.png"
573
+ j="$(CCKIT_OUTPUT=json qa_cli verdict fail --note "Save does nothing on /settings/billing" --shot "$TMP/broken-save.png" 2>"$TMP/v.err")"; rc=$?
574
+ t "a fail verdict returns 0 once the notes are mailed" "$rc" "0"
575
+ t "--llm reports the fail, its commit and the mail" \
576
+ "$(printf '%s' "$j" | jq -r '"\(.verdict) \(.head) \(.pr) \(.attempt) \(.mailed)"')" "fail $sha2 31 2 true"
577
+ t "the fail is a new attempt bound to the later commit" "$(jq -r '.head_sha' "$KIT_STATE_DIR/receipts/7-qa-2.json")" "$sha2"
578
+ t "the fail receipt sends the work back to build" \
579
+ "$(jq -r '"\(.outcome)|\(.gate)|\(.blocker)|\(.next_stage)|\(.invalid | length)"' "$KIT_STATE_DIR/receipts/7-qa-2.json")" \
580
+ "blocked|fail — Save does nothing on /settings/billing|Save does nothing on /settings/billing|build|0"
581
+ mail="$(ls "$KIT_MAIL_DIR"/*/task+7-review-stack/new/*-steer-from-*.md 2>/dev/null)"
582
+ t "one steer mail is in the builder branch's mailbox" "$(printf '%s\n' "$mail" | grep -c .)" "1"
583
+ yes "the mail is a steer" "$(cat $mail 2>/dev/null)" "kind: steer"
584
+ yes "the mail carries the notes" "$(cat $mail 2>/dev/null)" "Save does nothing on /settings/billing"
585
+ yes "the mail names the reviewed commit" "$(cat $mail 2>/dev/null)" "$sha2"
586
+ yes "the verdict comment was edited in place" "$(grep 'qa-verdict' "$GH_COMMENTS")" "verdict: fail"
587
+ t "the screenshot is its own upserted comment" "$(grep -c 'key=qa-screenshot-1' "$GH_COMMENTS")" "1"
588
+ yes "the screenshot is a path reference" "$(grep 'qa-screenshot-1' "$GH_COMMENTS")" "$TMP/broken-save.png"
589
+ t "verdict and screenshot are the only comments" "$(ncomments)" "2"
590
+ t "the lane now reads fail" "$(qa_cli verdict 2>/dev/null)" "fail"
591
+ qa_cli verdict >/dev/null 2>&1; t "a fresh fail is rc 1" "$?" "1"
592
+ yes "a PR behind the reviewed commit is said out loud" "$(cat "$TMP/v.err")" "reads stale against it until $sha2 is pushed"
593
+
594
+ # --to names another mailbox; with no PR the verdict is still recorded, and nothing is posted.
595
+ rm -f "$PR_META"; before="$(ncomments)"
596
+ printf 'Still broken.\nSecond line.\n' > "$TMP/notes.txt"
597
+ qa_cli verdict fail --notes-file "$TMP/notes.txt" --to task/50-elsewhere >/dev/null 2>"$TMP/v.err"; rc=$?
598
+ t "a fail with no PR still records and mails" "$rc" "0"
599
+ t "--to names the mailbox" "$(ls "$KIT_MAIL_DIR"/*/task+50-elsewhere/new/*-steer-from-*.md 2>/dev/null | grep -c .)" "1"
600
+ t "with no PR nothing is posted" "$(ncomments)" "$before"
601
+ yes "the missing PR is said out loud" "$(cat "$TMP/v.err")" "no pull request found for lane 7"
602
+ t "the event records that nothing was posted" \
603
+ "$(grep '"op":"qa.verdict"' "$EVENTS" | tail -n 1 | jq -r '.payload.comment')" "no-pr"
604
+ # A lane with no branch and no PR has no commit to bind to: refused, nothing written.
605
+ qa_cli verdict pass --lane 77 >/dev/null 2>"$TMP/v.err"; t "a lane with no commit to bind is refused" "$?" "2"
606
+ yes "the refusal offers --head" "$(cat "$TMP/v.err")" "pass --head <sha>"
607
+ t "the refused lane has no receipt" "$([ -e "$KIT_STATE_DIR/receipts/77-qa-1.json" ] && echo yes || echo no)" "no"
608
+ if command -v zsh >/dev/null 2>&1; then
609
+ out="$(zsh -c "cd '$P'; . '$ROOT/scripts/lib/qa-lane.sh'; qa_cli verdict pass --lane 78 --head '$sha2' >/dev/null 2>&1; qa_verdict_state 78 '$sha2'; qa_verdict_state 78 '$sha1'" 2>&1)"
610
+ t "zsh: a verdict records and reads back pass, then stale" "$(printf '%s' "$out" | tr '\n' ' ')" "pass stale"
611
+ else
612
+ echo "ok: zsh absent — skipping the zsh verdict pass (dependency-light gate)"
613
+ fi
614
+
615
+ # ── the verb is wired ──────────────────────────────────────────────────────────────────────────
616
+ yes "cckit commands lists qa" " $("$ROOT/bin/cckit" commands) " " qa "
617
+ answers ":3 200" ":4 200"
618
+ "$ROOT/bin/cckit" qa ready --lane 7 --timeout 5 >/dev/null 2>&1; t "cckit qa ready dispatches to the lib" "$?" "0"
619
+ yes "cckit qa stop dispatches to the lib" "$("$ROOT/bin/cckit" qa stop --lane 34 2>&1)" "nothing stopped"
620
+ # Its own lane, recorded here: lane 78's pass exists only when zsh ran the pass above.
621
+ qa_cli verdict pass --lane 79 --head "$sha2" >/dev/null 2>&1
622
+ t "cckit qa verdict dispatches to the lib" "$("$ROOT/bin/cckit" qa verdict --lane 79 --head "$sha2" 2>/dev/null)" "pass"
623
+ t "cckit qa open dispatches to the lib" "$("$ROOT/bin/cckit" qa open --lane 7 --route /wired --print 2>/dev/null)" "http://localhost:$web7/wired"
624
+
625
+ [ "$fail" -eq 0 ] && echo "ALL OK (qa-lane)" || echo "qa-lane: FAILURES"
626
+ exit "$fail"