@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
@@ -1,33 +1,257 @@
1
1
  #!/usr/bin/env bash
2
2
  # Read-only board status, grouped by role. Pure gh + jq. bash 3.2 compatible.
3
3
  # Reads repo from .claude/kit.config.json. Run from project root.
4
- # ./scripts/task-sync.sh [--role <Name>] [--milestone <label>]
4
+ # ./scripts/task-sync.sh [--role <Name>] [--milestone <label>] [--plan]
5
5
  # --raw-json: original issue objects for shell consumers; --llm stays TOON-first.
6
+ # The dashboard layer (#383) — one cached JSON document a TUI or statusline polls:
7
+ # --json one JSON summary: per role, merge queue, stale flags (schema below)
8
+ # --write write that document atomically to <git-common-dir>/kit-sync-cache.json;
9
+ # a failed or partial fetch never touches the file
10
+ # --cached [TTL] print the cache when it is younger than TTL seconds (default 60) — no gh
11
+ # call — otherwise refresh it, write it, print it
12
+ # --watch [SECS] refresh + write every SECS seconds (default 30); a failed refresh keeps the
13
+ # last good cache. KIT_SYNC_WATCH_MAX=<n> stops after n refreshes
14
+ # --plan inline `effort plan` (a "### Effort plan" section; `plan` in the document)
15
+ # Every fetch emits op.start / op.done (op "sync") on the kit-events.jsonl bus.
16
+ # --json document: { schema, repo, generatedAt, generatedEpoch, open,
17
+ # roles:[{role, slug, issues:[{number,title,status,priority,milestone,blocked}]}],
18
+ # unassigned:[same rows — issues carrying none of the configured role: labels; [] under --role],
19
+ # blocked:[n], notOnBoard:[n]|null (null = no Projects v2 board), stale:{days, issues:[{number,days}]},
20
+ # mergeQueue:[{number,title,risk,size,state,blocked,draft,agent,conflict,approved}], plan? }
6
21
  set -euo pipefail
7
22
  source "$(dirname "$0")/lib/kit-config.sh" && load_kit_config
8
- # Pure board-view render helpers (merge queue, stale flag, not-on-board flag, Project Status).
23
+ # Pure board-view helpers (merge queue, stale flag, not-on-board flag, Project Status).
9
24
  source "$(dirname "$0")/lib/board-view.sh"
10
25
  # The rendering seam (#82): the human board is markdown, routed through cckit_render — rich via glow
11
26
  # in a TTY, verbatim markdown otherwise (renders natively in Claude Code, pipe-safe).
12
27
  source "$(dirname "$0")/lib/ui.sh" 2>/dev/null || true
13
28
  source "$(dirname "$0")/lib/render.sh" 2>/dev/null || true
29
+ # The event bus is best-effort: a scaffold without the lib still syncs, it just emits nothing.
30
+ source "$(dirname "$0")/lib/kit-events.sh" 2>/dev/null || true
31
+ command -v emit_event >/dev/null 2>&1 || emit_event() { :; }
14
32
 
15
33
  ROLE_FILTER=""; MS_FILTER=""
34
+ # OUT is what goes to stdout: human | json (TOON, the --llm form) | raw-json | doc (--json) | none.
35
+ OUT="${CCKIT_OUTPUT:-human}"; OUT_SET=0
36
+ case "$OUT" in json|raw-json) ;; *) OUT=human ;; esac
37
+ WRITE=0; PLAN=0; CACHED_TTL=""; WATCH_SECS=""
38
+ _is_int() { case "${1:-}" in ''|*[!0-9]*) return 1 ;; *) return 0 ;; esac; }
16
39
  while [[ $# -gt 0 ]]; do
17
40
  case "$1" in
18
41
  --role) ROLE_FILTER="$2"; shift 2 ;;
19
42
  --milestone) MS_FILTER="$2"; shift 2 ;;
20
- --llm|--output=json) CCKIT_OUTPUT=json; shift ;;
21
- --raw-json) CCKIT_OUTPUT=raw-json; shift ;;
43
+ --llm|--output=json) OUT=json; OUT_SET=1; shift ;;
44
+ --raw-json) OUT=raw-json; OUT_SET=1; shift ;;
45
+ --json) OUT=doc; OUT_SET=1; shift ;;
46
+ --write) WRITE=1; shift ;;
47
+ --plan) PLAN=1; shift ;;
48
+ --cached) CACHED_TTL=60; shift; if _is_int "${1:-}"; then CACHED_TTL="$1"; shift; fi ;;
49
+ --watch) WATCH_SECS=30; shift; if _is_int "${1:-}"; then WATCH_SECS="$1"; shift; fi ;;
22
50
  *) echo "unknown flag: $1" >&2; exit 1 ;;
23
51
  esac
24
52
  done
25
53
 
26
- ISSUES=$(gh issue list --repo "$KIT_REPO" --state open --limit 200 \
27
- --json number,title,labels,milestone,assignees,updatedAt,body)
54
+ # --cached / --watch both maintain the cache; --cached also prints the document.
55
+ if [ -n "$CACHED_TTL" ]; then WRITE=1; OUT=doc; fi
56
+ if [ -n "$WATCH_SECS" ]; then WRITE=1; [ "$OUT" = doc ] || OUT=none; fi
57
+ # A bare --write is a cache refresh, not a board print.
58
+ if [ "$WRITE" = 1 ] && [ "$OUT_SET" = 0 ] && [ "$OUT" = human ]; then OUT=none; fi
59
+ # The cache is ONE file every reader shares, so a filtered document must never land in it.
60
+ if [ "$WRITE" = 1 ] && [ -n "$ROLE_FILTER$MS_FILTER" ]; then
61
+ echo "sync: --write / --cached / --watch cache the whole board — drop --role / --milestone" >&2
62
+ exit 2
63
+ fi
64
+
65
+ # <git-common-dir>/kit-sync-cache.json — worktree-durable, the same home as kit-events.jsonl.
66
+ sync_cache_path() {
67
+ local gcd
68
+ gcd="$(git rev-parse --git-common-dir 2>/dev/null)" || return 1
69
+ case "$gcd" in /*) : ;; *) gcd="$(cd "$gcd" 2>/dev/null && pwd)" || return 1 ;; esac
70
+ printf '%s/kit-sync-cache.json\n' "$gcd"
71
+ }
72
+
73
+ ISSUES="[]"; STATUS_MAP="{}"; PRS_JSON="[]"; PLAN_TEXT=""; DOC=""
74
+
75
+ # sync_fetch <strict|lenient> — read the board into ISSUES / STATUS_MAP / PRS_JSON. Returns non-zero
76
+ # when the issue list cannot be read. `strict` is the data path (--json / --write): there an
77
+ # unreadable PR list or Project board fails the fetch too, because a document with an empty merge
78
+ # queue it could not read is a partial result. `lenient` is the human board: it degrades to an
79
+ # empty queue / "—" Status and still renders, as it always has.
80
+ sync_fetch() {
81
+ local mode="${1:-lenient}" raw
82
+ raw="$(gh issue list --repo "$KIT_REPO" --state open --limit 200 \
83
+ --json number,title,labels,milestone,assignees,updatedAt,body)" || return 1
84
+ # Only the data path validates: --raw-json hands gh's bytes to its caller verbatim, and the
85
+ # caller (autopilot) owns the "invalid board data" diagnosis.
86
+ if [ "$mode" = strict ]; then
87
+ printf '%s' "$raw" | jq -e 'type == "array"' >/dev/null 2>&1 || return 1
88
+ fi
89
+ ISSUES="$raw"
90
+ # The two shell-consumer forms read the issue list and nothing else.
91
+ case "$OUT" in raw-json|json) [ "$WRITE" = 1 ] || return 0 ;; esac
92
+
93
+ # Project Status map {"<number>":"<status>"} — from the Projects v2 board when it is enabled, so
94
+ # each issue row shows its board Status and we can flag issues that never got added
95
+ # (no-board-entry). Config-guarded: with projectsV2 off the map stays {} and every row shows "—".
96
+ STATUS_MAP="{}"
97
+ if [ "${KIT_PROJECTS_V2:-false}" = "true" ] && [ -n "${KIT_PROJECT_NUMBER:-}" ] && [ -n "${KIT_OWNER:-}" ]; then
98
+ local root map
99
+ case "${KIT_PROJECT_OWNER_TYPE:-user}" in org|organization) root=organization ;; *) root=user ;; esac
100
+ map="$(gh api graphql -f query="
101
+ query(\$login:String!,\$number:Int!){
102
+ $root(login:\$login){ projectV2(number:\$number){ items(first:200){ nodes{
103
+ content{ ... on Issue { number } ... on PullRequest { number } }
104
+ fieldValueByName(name:\"Status\"){ ... on ProjectV2ItemFieldSingleSelectValue { name } }
105
+ }}}}}" -f login="$KIT_OWNER" -F number="$KIT_PROJECT_NUMBER" 2>/dev/null \
106
+ | jq -c "[.data.${root}.projectV2.items.nodes[]
107
+ | select(.content.number != null)
108
+ | {key:(.content.number|tostring), value:(.fieldValueByName.name // \"—\")}]
109
+ | from_entries" 2>/dev/null)" || map=""
110
+ if [ -n "$map" ]; then STATUS_MAP="$map"; elif [ "$mode" = strict ]; then return 1; fi
111
+ fi
112
+
113
+ # Open PRs for the merge queue (fetched once; risk/size labels + draft/review state drive the order).
114
+ if raw="$(gh pr list --repo "$KIT_REPO" --state open --limit 100 \
115
+ --json number,title,labels,isDraft,headRefName,reviewDecision,mergeable 2>/dev/null)" \
116
+ && printf '%s' "$raw" | jq -e 'type == "array"' >/dev/null 2>&1; then
117
+ PRS_JSON="$raw"
118
+ elif [ "$mode" = strict ]; then
119
+ return 1
120
+ else
121
+ PRS_JSON="[]"
122
+ fi
123
+ return 0
124
+ }
125
+
126
+ # sync_plan — fill PLAN_TEXT with `effort plan` output. Non-zero when the plan cannot be produced.
127
+ sync_plan() {
128
+ local lib; lib="$(dirname "$0")/lib/effort-plan.sh"
129
+ [ -f "$lib" ] || { echo "sync: --plan needs scripts/lib/effort-plan.sh" >&2; return 1; }
130
+ # shellcheck source=/dev/null
131
+ source "$lib" || return 1
132
+ PLAN_TEXT="$(effort_plan)" || return 1
133
+ }
134
+
135
+ # sync_doc — build the --json document into DOC from the fetched state. Non-zero on any jq failure,
136
+ # so a malformed input can never become a cached document.
137
+ sync_doc() {
138
+ local roles mq stale
139
+ roles="$(printf '%s\n' "${ROLE_FILTER:-$KIT_ROLES}" | jq -Rn '[inputs | select(length > 0)]')" || return 1
140
+ mq="$(board_merge_queue_data "$PRS_JSON")" || return 1
141
+ stale="$(board_stale_data "$ISSUES" 14)" || return 1
142
+ [ -n "$mq" ] && [ -n "$stale" ] || return 1
143
+ DOC="$(printf '%s' "$ISSUES" | jq -c \
144
+ --arg repo "$KIT_REPO" --arg ms "$MS_FILTER" --arg at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
145
+ --argjson epoch "$(date -u +%s)" --argjson roles "$roles" --argjson st "$STATUS_MAP" \
146
+ --argjson mq "$mq" --argjson stale "$stale" \
147
+ --argjson board "$([ "${KIT_PROJECTS_V2:-false}" = "true" ] && echo true || echo false)" \
148
+ --argjson filtered "$([ -n "$ROLE_FILTER" ] && echo true || echo false)" \
149
+ --argjson withplan "$PLAN" --arg plan "$PLAN_TEXT" '
150
+ . as $all
151
+ | def row: { number, title,
152
+ status: ($st[(.number|tostring)] // "—"),
153
+ priority: ([.labels[].name | select(startswith("priority:")) | sub("priority:";"")][0] // ""),
154
+ milestone: (.milestone.title // ""),
155
+ blocked: ((.body // "") | test("Blocked by")) };
156
+ { schema: 1, repo: $repo, generatedAt: $at, generatedEpoch: $epoch,
157
+ open: ($all | length),
158
+ roles: [ $roles[] as $r
159
+ | ($r | ascii_downcase | gsub(" "; "-")) as $slug
160
+ | { role: $r, slug: $slug,
161
+ issues: [ $all[]
162
+ | select(any(.labels[]; .name == ("role:" + $slug)))
163
+ | select($ms == "" or (.milestone.title // "") == $ms)
164
+ | row ] } ],
165
+ unassigned: [ $all[]
166
+ | select($filtered | not)
167
+ | select(([.labels[].name] - ($roles | map("role:" + (ascii_downcase | gsub(" "; "-"))))) == [.labels[].name])
168
+ | select($ms == "" or (.milestone.title // "") == $ms)
169
+ | row ],
170
+ blocked: [ $all[] | select((.body // "") | test("Blocked by")) | .number ],
171
+ notOnBoard: (if $board
172
+ then [ $all[] | select(($st[(.number|tostring)] // null) == null) | .number ]
173
+ else null end),
174
+ stale: { days: 14, issues: $stale },
175
+ mergeQueue: $mq }
176
+ + (if $withplan == 1 then { plan: $plan } else {} end)')" || return 1
177
+ [ -n "$DOC" ]
178
+ }
179
+
180
+ # sync_write — put DOC in the cache atomically: write a sibling temp file, re-validate it as one
181
+ # JSON object, then rename over the cache. A reader sees the old document or the new one, never half.
182
+ sync_write() {
183
+ local cache tmpf
184
+ cache="$(sync_cache_path)" || { echo "sync: --write needs a git repository (no git-common-dir)" >&2; return 1; }
185
+ tmpf="$cache.$$.tmp"
186
+ printf '%s\n' "$DOC" > "$tmpf" 2>/dev/null || { rm -f "$tmpf"; return 1; }
187
+ jq -e 'type == "object" and (.mergeQueue | type == "array")' "$tmpf" >/dev/null 2>&1 \
188
+ || { rm -f "$tmpf"; return 1; }
189
+ mv -f "$tmpf" "$cache" || { rm -f "$tmpf"; return 1; }
190
+ }
191
+
192
+ # sync_refresh — one full data refresh: fetch (strict), plan if asked, build DOC, write if asked.
193
+ # Emits op.start / op.done around it. Non-zero leaves the cache exactly as it was.
194
+ sync_refresh() {
195
+ local ok=1
196
+ emit_event op.start sync "{\"mode\":\"$OUT\",\"write\":$WRITE}"
197
+ sync_fetch strict || ok=0
198
+ if [ "$ok" = 1 ] && [ "$PLAN" = 1 ]; then sync_plan || ok=0; fi
199
+ if [ "$ok" = 1 ]; then sync_doc || ok=0; fi
200
+ if [ "$ok" = 1 ] && [ "$WRITE" = 1 ]; then sync_write || ok=0; fi
201
+ if [ "$ok" = 1 ]; then
202
+ emit_event op.done sync "{\"ok\":true,\"open\":$(printf '%s' "$ISSUES" | jq 'length' 2>/dev/null || echo 0)}"
203
+ return 0
204
+ fi
205
+ emit_event op.done sync '{"ok":false}'
206
+ return 1
207
+ }
208
+
209
+ # ── --watch: refresh in a loop; a failed refresh keeps the last good cache ──────────────────────
210
+ if [ -n "$WATCH_SECS" ]; then
211
+ _n=0; _last=0
212
+ while :; do
213
+ _n=$((_n + 1))
214
+ if sync_refresh; then
215
+ _last=0
216
+ [ "$OUT" = doc ] && printf '%s\n' "$DOC"
217
+ echo "sync: watch refresh $_n ok ($(date -u +%H:%M:%SZ))" >&2
218
+ else
219
+ _last=1
220
+ echo "sync: watch refresh $_n failed — kept the last good cache" >&2
221
+ fi
222
+ if _is_int "${KIT_SYNC_WATCH_MAX:-}" && [ "$_n" -ge "$KIT_SYNC_WATCH_MAX" ]; then exit "$_last"; fi
223
+ sleep "$WATCH_SECS"
224
+ done
225
+ fi
226
+
227
+ # ── --cached: serve the cache inside its TTL with no gh call, else refresh ──────────────────────
228
+ if [ -n "$CACHED_TTL" ]; then
229
+ _cache="$(sync_cache_path)" || { echo "sync: --cached needs a git repository (no git-common-dir)" >&2; exit 1; }
230
+ if [ -f "$_cache" ]; then
231
+ # Fresh = younger than the TTL, and carrying a plan when one was asked for.
232
+ _epoch="$(jq -r --argjson p "$PLAN" 'if $p == 1 and (has("plan") | not) then 0 else (.generatedEpoch // 0) end' "$_cache" 2>/dev/null || echo 0)"
233
+ if _is_int "$_epoch" && [ $(( $(date -u +%s) - _epoch )) -lt "$CACHED_TTL" ]; then
234
+ cat "$_cache"; exit 0
235
+ fi
236
+ fi
237
+ sync_refresh || { echo "sync: refresh failed — the cache at $_cache was left as it was" >&2; exit 1; }
238
+ printf '%s\n' "$DOC"; exit 0
239
+ fi
240
+
241
+ # ── --json / --write: one strict refresh ────────────────────────────────────────────────────────
242
+ if [ "$OUT" = doc ] || [ "$WRITE" = 1 ]; then
243
+ sync_refresh || { echo "sync: could not read the board — no document written" >&2; exit 1; }
244
+ if [ "$WRITE" = 1 ]; then echo "sync: wrote $(sync_cache_path)" >&2; fi
245
+ [ "$OUT" = doc ] && { printf '%s\n' "$DOC"; exit 0; }
246
+ [ "$OUT" = none ] && exit 0
247
+ else
248
+ emit_event op.start sync "{\"mode\":\"$OUT\",\"write\":0}"
249
+ sync_fetch lenient || { emit_event op.done sync '{"ok":false}'; echo "sync: could not read the board" >&2; exit 1; }
250
+ emit_event op.done sync "{\"ok\":true,\"open\":$(printf '%s' "$ISSUES" | jq 'length' 2>/dev/null || echo 0)}"
251
+ fi
28
252
 
29
253
  # Keep shell consumers out of the agent-oriented TOON encoding and flattened label shape.
30
- if [ "${CCKIT_OUTPUT:-human}" = "raw-json" ]; then
254
+ if [ "$OUT" = "raw-json" ]; then
31
255
  printf '%s\n' "$ISSUES"
32
256
  exit 0
33
257
  fi
@@ -36,7 +260,7 @@ fi
36
260
  # uniform list, so it goes out as TOON — far cheaper in tokens than JSON — via the shared encoder,
37
261
  # which falls back to JSON for a non-uniform/empty result. labels + assignees are flattened to
38
262
  # space-joined strings (and priority is lifted out) so every row is scalar-only and TOON-eligible.
39
- if [ "${CCKIT_OUTPUT:-human}" = "json" ]; then
263
+ if [ "$OUT" = "json" ]; then
40
264
  board="$(echo "$ISSUES" | jq -c '[.[] | {
41
265
  number,
42
266
  title,
@@ -52,30 +276,6 @@ if [ "${CCKIT_OUTPUT:-human}" = "json" ]; then
52
276
  exit 0
53
277
  fi
54
278
 
55
- # Project Status map {"<number>":"<status>"} — from the Projects v2 board when it is enabled, so each
56
- # issue row shows its board Status and we can flag issues that never got added (no-board-entry). A
57
- # best-effort, config-guarded read: with projectsV2 off (or any hiccup) the map stays {} and every
58
- # row shows "—" — the board view still renders, just without Status.
59
- STATUS_MAP="{}"
60
- if [ "${KIT_PROJECTS_V2:-false}" = "true" ] && [ -n "${KIT_PROJECT_NUMBER:-}" ] && [ -n "${KIT_OWNER:-}" ]; then
61
- case "${KIT_PROJECT_OWNER_TYPE:-user}" in org|organization) _ROOT=organization ;; *) _ROOT=user ;; esac
62
- STATUS_MAP="$(gh api graphql -f query="
63
- query(\$login:String!,\$number:Int!){
64
- $_ROOT(login:\$login){ projectV2(number:\$number){ items(first:200){ nodes{
65
- content{ ... on Issue { number } ... on PullRequest { number } }
66
- fieldValueByName(name:\"Status\"){ ... on ProjectV2ItemFieldSingleSelectValue { name } }
67
- }}}}}" -f login="$KIT_OWNER" -F number="$KIT_PROJECT_NUMBER" 2>/dev/null \
68
- | jq -c "[.data.${_ROOT}.projectV2.items.nodes[]
69
- | select(.content.number != null)
70
- | {key:(.content.number|tostring), value:(.fieldValueByName.name // \"—\")}]
71
- | from_entries" 2>/dev/null || printf '{}')"
72
- [ -n "$STATUS_MAP" ] || STATUS_MAP="{}"
73
- fi
74
-
75
- # Open PRs for the merge queue (fetched once; risk/size labels + draft/review state drive the order).
76
- PRS_JSON="$(gh pr list --repo "$KIT_REPO" --state open --limit 100 \
77
- --json number,title,labels,isDraft,headRefName,reviewDecision,mergeable 2>/dev/null || echo '[]')"
78
-
79
279
  # All human output is composed as markdown inside this function, then piped once through
80
280
  # cckit_render (below) so the whole board — tables, headings, flags — renders as one document.
81
281
  _board_human() {
@@ -127,6 +327,17 @@ echo ""
127
327
  # ── Merge Queue: open PRs ordered ready → draft → blocked (risk asc, size asc) ───────────────────
128
328
  board_merge_queue "$PRS_JSON"
129
329
 
330
+ # ── Effort plan (--plan): `effort plan` inline, fenced so its column layout survives markdown ────
331
+ if [ "$PLAN" = 1 ]; then
332
+ echo ""
333
+ echo "### Effort plan"
334
+ if sync_plan 2>/dev/null && [ -n "$PLAN_TEXT" ]; then
335
+ printf '```text\n%s\n```\n' "$PLAN_TEXT"
336
+ else
337
+ echo "_(no effort plan — no open efforts, or \`effort plan\` could not read them)_"
338
+ fi
339
+ fi
340
+
130
341
  # ── Optional local-model digest — only when the local endpoint is alive (zero API cost) ──────────
131
342
  # A 3–5 line executive read of the board (merge order, blockers, staleness). Best-effort: absent or
132
343
  # offline local model → nothing appended, the board view above stands on its own.
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env bash
2
+ # test-runner-test.sh — scripts/test.sh runs files in parallel and still reports correctly (#455).
3
+ #
4
+ # Copies the runner and scripts/lib/test-env.sh into a throwaway tree with fixture `*-test.sh`
5
+ # files, then asserts on the copy's exit code and output:
6
+ # - a failing file fails the run, and its output is printed whole, in one block
7
+ # - two files really run at the same time under -j 2 (each waits for the other's marker file)
8
+ # - a file marked `# test-runner: serial` is held back and run after the parallel phase
9
+ # - --serial, a path pattern, and a bad job count behave as the header of test.sh says
10
+ # - every test is sealed from KIT_* variables and runs with commit signing off
11
+ # Run: bash scripts/test-runner-test.sh
12
+ # errors: strict — a test runner: rc 1 on any failed assertion
13
+ set -u
14
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
15
+ fail=0
16
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
17
+ has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> '[$2]' lacks '[$3]'"; fail=1 ;; esac; }
18
+ no() { case "$2" in *"$3"*) echo "FAIL: $1 -> '[$2]' contains '[$3]'"; fail=1 ;; *) echo "ok: $1" ;; esac; }
19
+
20
+ tmp="$(cd "$(mktemp -d)" && pwd -P)"; trap 'rm -rf "$tmp"' EXIT
21
+ # The caller's own runner settings must not steer the copy under test.
22
+ unset TEST_JOBS TEST_TIMINGS TEST_RUN_DIR
23
+ # shellcheck source=/dev/null
24
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
25
+
26
+ # fixture <name> — a fresh tree holding the runner; echoes its path.
27
+ fixture() {
28
+ local d="$tmp/$1"
29
+ mkdir -p "$d/scripts/lib" "$d/bin" "$d/shared"
30
+ cp "$ROOT/scripts/test.sh" "$d/scripts/test.sh"
31
+ cp "$ROOT/scripts/lib/test-env.sh" "$d/scripts/lib/test-env.sh"
32
+ printf '%s' "$d"
33
+ }
34
+ run() { # run <fixture dir> [runner args…] -> OUT (stdout+stderr), RC
35
+ local d="$1"; shift
36
+ OUT="$(bash "$d/scripts/test.sh" "$@" 2>&1)"; RC=$?
37
+ }
38
+
39
+ # ── 1. pass, fail, and a failing file's output in one block ────────────────────────────────────
40
+ F="$(fixture basic)"
41
+ printf '#!/usr/bin/env bash\necho "a says ok"\n' > "$F/scripts/a-pass-test.sh"
42
+ printf '#!/usr/bin/env bash\necho "b line one"; echo "b line two" >&2; echo "b line three"; exit 3\n' > "$F/scripts/b-fail-test.sh"
43
+ printf '#!/usr/bin/env bash\nexit 0\n' > "$F/scripts/lib/c-pass-test.sh"
44
+ printf '#!/usr/bin/env bash\necho "not a test"; exit 9\n' > "$F/scripts/helper.sh"
45
+
46
+ run "$F" -j 3
47
+ t "a failing file fails the run" "$RC" "1"
48
+ has "the header states the file and job count" "$OUT" "3 file(s), 3 at a time"
49
+ has "a passing file gets an ok line" "$OUT" " ok scripts/a-pass-test.sh"
50
+ has "the failing file gets a FAIL line + rc" "$OUT" " FAIL scripts/b-fail-test.sh (rc=3)"
51
+ has "the summary counts both" "$OUT" "2 passed, 1 failed"
52
+ has "the failed list names the file" "$OUT" " - scripts/b-fail-test.sh"
53
+ no "a passing file's output is not printed" "$OUT" "a says ok"
54
+ no "a script that is not *-test.sh never runs" "$OUT" "not a test"
55
+ block="$(printf '%s\n' "$OUT" | grep -A3 -- '^---- FAIL scripts/b-fail-test.sh (rc=3)$' | sed 's/^ *//' | tr '\n' '|')"
56
+ t "the failing output is whole, in order, stdout and stderr together" "$block" \
57
+ "---- FAIL scripts/b-fail-test.sh (rc=3)|b line one|b line two|b line three|"
58
+
59
+ run "$F" --serial
60
+ t "--serial: the failure still fails the run" "$RC" "1"
61
+ has "--serial runs one at a time" "$OUT" "3 file(s), 1 at a time"
62
+ order="$(printf '%s\n' "$OUT" | grep -E '^ (ok|FAIL) ' | awk '{print $2}' | tr '\n' ' ')"
63
+ t "--serial runs in sorted order" "$order" "scripts/a-pass-test.sh scripts/b-fail-test.sh scripts/lib/c-pass-test.sh "
64
+
65
+ run "$F" 'a-pass|c-pass'
66
+ t "a pattern that skips the failing file passes" "$RC" "0"
67
+ has "the pattern is named in the header" "$OUT" "2 file(s) (filter: a-pass|c-pass)"
68
+ has "an all-green run says so" "$OUT" "PASS all tests"
69
+
70
+ run "$F" no-such-file
71
+ t "a pattern matching nothing exits 0" "$RC" "0"
72
+ has "…and says nothing was found" "$OUT" "no *-test.sh found matching 'no-such-file'"
73
+
74
+ run "$F" --timings a-pass
75
+ has "--timings prints the per-file table" "$OUT" "wall seconds per file, slowest first"
76
+
77
+ TEST_JOBS=1 run "$F" a-pass
78
+ has "TEST_JOBS sets the job count" "$OUT" "1 at a time"
79
+
80
+ for bad in 0 x -3; do
81
+ run "$F" -j "$bad"
82
+ t "-j $bad is refused with rc 2" "$RC" "2"
83
+ done
84
+ run "$F" --frobnicate
85
+ t "an unknown option is refused with rc 2" "$RC" "2"
86
+
87
+ # ── 2. files really overlap under -j 2 ─────────────────────────────────────────────────────────
88
+ # Each file drops its own marker and waits (up to 20 s) for the other's. Run one after the other,
89
+ # the first would time out and fail.
90
+ F="$(fixture overlap)"
91
+ for pair in "one two" "two one"; do
92
+ set -- $pair
93
+ cat > "$F/scripts/$1-test.sh" <<EOF
94
+ #!/usr/bin/env bash
95
+ : > "$F/shared/$1"
96
+ i=0; while [ ! -e "$F/shared/$2" ] && [ "\$i" -lt 200 ]; do sleep 0.1; i=\$((i+1)); done
97
+ [ -e "$F/shared/$2" ] || { echo "$1 never saw $2"; exit 1; }
98
+ EOF
99
+ done
100
+ run "$F" -j 2
101
+ t "two files run at the same time under -j 2" "$RC" "0"
102
+
103
+ # ── 3. the serial marker ───────────────────────────────────────────────────────────────────────
104
+ # `late` is marked serial and sorts FIRST; it passes only when every unmarked file has finished.
105
+ F="$(fixture marker)"
106
+ cat > "$F/scripts/a-late-test.sh" <<EOF
107
+ #!/usr/bin/env bash
108
+ # test-runner: serial
109
+ [ -e "$F/shared/p1" ] && [ -e "$F/shared/p2" ] || { echo "ran before the parallel phase ended"; exit 1; }
110
+ EOF
111
+ for p in p1 p2; do
112
+ printf '#!/usr/bin/env bash\nsleep 0.3\n: > "%s/shared/%s"\n' "$F" "$p" > "$F/scripts/$p-test.sh"
113
+ done
114
+ run "$F" -j 2
115
+ t "a marked file runs after the parallel phase" "$RC" "0"
116
+ has "the runner says how many files were held back" "$OUT" "1 file(s) marked serial, run alone"
117
+ last="$(printf '%s\n' "$OUT" | grep -E '^ (ok|FAIL) ' | tail -1)"
118
+ t "the marked file reports last" "$last" " ok scripts/a-late-test.sh"
119
+ rm -f "$F/shared/p1" "$F/shared/p2"
120
+ run "$F" --serial
121
+ no "--serial has no separate serial phase" "$OUT" "marked serial"
122
+ t "…so the marked file runs in sorted order, first, and fails this fixture" "$RC" "1"
123
+
124
+ # A marked file that fails still fails the run.
125
+ F="$(fixture markerfail)"
126
+ printf '#!/usr/bin/env bash\n# test-runner: serial\necho "serial broke"; exit 4\n' > "$F/scripts/s-test.sh"
127
+ printf '#!/usr/bin/env bash\nexit 0\n' > "$F/scripts/p-test.sh"
128
+ run "$F" -j 2
129
+ t "a failing marked file fails the run" "$RC" "1"
130
+ has "…with its rc and output" "$OUT" "---- FAIL scripts/s-test.sh (rc=4)"
131
+
132
+ # ── 4. what every test inherits ────────────────────────────────────────────────────────────────
133
+ F="$(fixture env)"
134
+ cat > "$F/scripts/env-test.sh" <<'EOF'
135
+ #!/usr/bin/env bash
136
+ rc=0
137
+ [ -z "${KIT_CONFIG:-}" ] || { echo "KIT_CONFIG leaked: $KIT_CONFIG"; rc=1; }
138
+ [ -z "${TEST_RUN_DIR:-}" ] || { echo "TEST_RUN_DIR leaked"; rc=1; }
139
+ [ "${KEEP_ME:-}" = 1 ] || { echo "KEEP_ME was dropped"; rc=1; }
140
+ if command -v git >/dev/null 2>&1; then
141
+ [ "$(git config --get commit.gpgsign)" = false ] || { echo "commit.gpgsign is not off"; rc=1; }
142
+ [ "$(git config --get tag.gpgsign)" = false ] || { echo "tag.gpgsign is not off"; rc=1; }
143
+ [ "$(git config --get test.kept)" = yes ] || { echo "the caller's own GIT_CONFIG pair was lost"; rc=1; }
144
+ fi
145
+ exit "$rc"
146
+ EOF
147
+ OUT="$(KIT_CONFIG=/elsewhere KEEP_ME=1 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=test.kept GIT_CONFIG_VALUE_0=yes \
148
+ bash "$F/scripts/test.sh" 2>&1)"; RC=$?
149
+ t "a test is sealed, unsigned, and keeps the rest of its environment" "$RC" "0"
150
+ [ "$RC" -eq 0 ] || printf '%s\n' "$OUT"
151
+ has "the runner reports what it sealed" "$OUT" "sealed 1 inherited"
152
+
153
+ # ── 5. the result directory is removed ─────────────────────────────────────────────────────────
154
+ left="$(TMPDIR="$tmp/td" bash -c 'mkdir -p "$TMPDIR" && bash "$0/scripts/test.sh" >/dev/null 2>&1; ls "$TMPDIR" | wc -l' "$F" | tr -d ' ')"
155
+ t "the runner leaves nothing in TMPDIR" "$left" "0"
156
+
157
+ [ "$fail" -eq 0 ] && echo "test-runner: all passed" || echo "test-runner: FAILURES"
158
+ exit "$fail"