@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.
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +169 -21
- package/README.md +505 -35
- package/SECURITY.md +5 -0
- package/bin/cckit +189 -20
- package/cckit.config.json +1 -1
- package/commands/kit-doctor.md +13 -5
- package/commands/kit-export-project.md +0 -2
- package/commands/kit-export-training.md +6 -9
- package/commands/kit-init.md +43 -13
- package/commands/kit-routines.md +1 -1
- package/commands/kit-update.md +11 -6
- package/databases/supabase/guide.html +106 -0
- package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
- package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
- package/databases/supabase.json +70 -0
- package/integrations/emil-design-eng.json +41 -0
- package/integrations/graft.json +81 -0
- package/integrations/impeccable.json +42 -0
- package/integrations/integration.schema.json +215 -0
- package/integrations/lavish.json +43 -0
- package/integrations/mempalace.json +28 -0
- package/integrations/mlx-lm.json +32 -0
- package/integrations/web-design-guidelines.json +42 -0
- package/kit.config.schema.json +183 -5
- package/package.json +4 -1
- package/profiles/automation.json +7 -1
- package/profiles/content.json +10 -2
- package/profiles/marketing.json +57 -0
- package/profiles/minimal.json +7 -1
- package/profiles/research.json +7 -1
- package/profiles/software.json +7 -1
- package/recipes/nextjs-shadcn.json +49 -0
- package/scripts/agent-skills-external.txt +45 -0
- package/scripts/agent-skills-lint-test.sh +131 -0
- package/scripts/agent-skills-lint.sh +115 -0
- package/scripts/agent-template-lint-test.sh +42 -0
- package/scripts/agent-template-lint.sh +58 -0
- package/scripts/annotate-setup.sh +1 -1
- package/scripts/autopilot-run-test.sh +338 -0
- package/scripts/autopilot-run.sh +448 -0
- package/scripts/autopilot-test.sh +8 -0
- package/scripts/autopilot.sh +10 -1
- package/scripts/benchmark/benchmark-test.sh +85 -0
- package/scripts/benchmark/checkpoint-test.sh +314 -0
- package/scripts/benchmark/checkpoint.sh +408 -0
- package/scripts/benchmark/lib/model.sh +31 -6
- package/scripts/benchmark/report.sh +17 -2
- package/scripts/benchmark/run-quality.sh +36 -10
- package/scripts/benchmark/verb-timings-test.sh +124 -0
- package/scripts/benchmark/verb-timings.sh +149 -0
- package/scripts/check.sh +29 -19
- package/scripts/content-skills-test.sh +144 -0
- package/scripts/copilot-loop-test.sh +25 -0
- package/scripts/database-supabase-test.sh +121 -0
- package/scripts/docs-marketing-words-test.sh +73 -0
- package/scripts/docs-record-tables-test.sh +72 -0
- package/scripts/guard-raw-git-ops-test.sh +8 -0
- package/scripts/hook-adapter-test.sh +193 -0
- package/scripts/init-content-test.sh +225 -0
- package/scripts/init-guided-test.sh +474 -0
- package/scripts/init-recipes-test.sh +104 -0
- package/scripts/init-upgrade-test.sh +341 -2
- package/scripts/init.sh +746 -95
- package/scripts/instruction-budget-baseline.txt +8 -0
- package/scripts/instruction-budget-lint-test.sh +166 -0
- package/scripts/instruction-budget-lint.sh +219 -0
- package/scripts/integrations-check-test.sh +200 -0
- package/scripts/integrations-check.sh +157 -0
- package/scripts/kit-add-test.sh +214 -0
- package/scripts/kit-add.sh +305 -5
- package/scripts/kit-adopt-test.sh +16 -0
- package/scripts/kit-adopt.sh +3 -2
- package/scripts/kit-digest.sh +2 -2
- package/scripts/kit-doctor-test.sh +293 -0
- package/scripts/kit-doctor.sh +272 -140
- package/scripts/kit-export-project-test.sh +3 -3
- package/scripts/kit-remove-test.sh +19 -0
- package/scripts/kit-routines.sh +2 -2
- package/scripts/kit-self-update.sh +1 -1
- package/scripts/kit-version-check-test.sh +4 -0
- package/scripts/kit-version-check.sh +4 -2
- package/scripts/knowledge-lint.sh +4 -4
- package/scripts/leak-fence-test.sh +89 -0
- package/scripts/lib/adapter-select-test.sh +136 -0
- package/scripts/lib/adapter-select.sh +158 -0
- package/scripts/lib/agent-def-test.sh +69 -0
- package/scripts/lib/agent-def.sh +106 -0
- package/scripts/lib/agent-launch-test.sh +212 -0
- package/scripts/lib/agent-launch.sh +335 -0
- package/scripts/lib/board-view-test.sh +11 -0
- package/scripts/lib/board-view.sh +42 -26
- package/scripts/lib/branch-owner-test.sh +26 -0
- package/scripts/lib/branch-owner.sh +16 -9
- package/scripts/lib/captain-test.sh +105 -0
- package/scripts/lib/captain.sh +87 -8
- package/scripts/lib/codex-hooks-test.sh +100 -0
- package/scripts/lib/codex-hooks.sh +69 -0
- package/scripts/lib/commitlint.sh +1 -1
- package/scripts/lib/content-kinds-gc-test.sh +88 -0
- package/scripts/lib/copilot-test.sh +70 -4
- package/scripts/lib/copilot.sh +66 -14
- package/scripts/lib/effort-dispatch-test.sh +3 -3
- package/scripts/lib/effort-metrics-test.sh +178 -1
- package/scripts/lib/effort-metrics.sh +188 -35
- package/scripts/lib/effort-ops-test.sh +217 -7
- package/scripts/lib/effort-ops.sh +281 -49
- package/scripts/lib/effort-parity-test.sh +49 -13
- package/scripts/lib/effort-plan-test.sh +337 -0
- package/scripts/lib/effort-plan.sh +200 -23
- package/scripts/lib/effort-slug.sh +16 -2
- package/scripts/lib/effort.sh +67 -12
- package/scripts/lib/errors-header-test.sh +1 -1
- package/scripts/lib/gh-project-test.sh +35 -1
- package/scripts/lib/gh-project.sh +37 -16
- package/scripts/lib/gh-rest-test.sh +330 -0
- package/scripts/lib/gh-rest.sh +304 -0
- package/scripts/lib/hook-refresh.sh +1 -1
- package/scripts/lib/init-github.sh +412 -0
- package/scripts/lib/init-guide.sh +630 -0
- package/scripts/lib/integration-install-test.sh +343 -0
- package/scripts/lib/integration-install.sh +257 -0
- package/scripts/lib/integrations-test.sh +366 -0
- package/scripts/lib/integrations.sh +244 -0
- package/scripts/lib/kinds-test.sh +125 -0
- package/scripts/lib/kinds.sh +66 -0
- package/scripts/lib/kit-brief-test.sh +22 -3
- package/scripts/lib/kit-brief.sh +45 -5
- package/scripts/lib/kit-config-resolve.sh +2 -2
- package/scripts/lib/kit-config-test.sh +64 -1
- package/scripts/lib/kit-config.sh +37 -1
- package/scripts/lib/kit-events.sh +7 -0
- package/scripts/lib/kit-gc-test.sh +173 -1
- package/scripts/lib/kit-gc.sh +244 -37
- package/scripts/lib/kit-hotfix.sh +216 -0
- package/scripts/lib/kit-interview-test.sh +93 -0
- package/scripts/lib/kit-interview.sh +117 -8
- package/scripts/lib/kit-lib-test.sh +1 -1
- package/scripts/lib/kit-lib.sh +3 -3
- package/scripts/lib/kit-local.sh +2 -2
- package/scripts/lib/kit-manifest.sh +33 -1
- package/scripts/lib/kit-profile-test.sh +3 -3
- package/scripts/lib/kit-status-test.sh +112 -4
- package/scripts/lib/kit-status.sh +246 -16
- package/scripts/lib/kit-task-ops-test.sh +37 -0
- package/scripts/lib/kit-task-ops.sh +362 -89
- package/scripts/lib/kto-hotfix-test.sh +232 -0
- package/scripts/lib/kto-task-close-test.sh +83 -0
- package/scripts/lib/kto-task-new-test.sh +95 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
- package/scripts/lib/kto-task-pr-test.sh +70 -0
- package/scripts/lib/leak-fence.sh +89 -0
- package/scripts/lib/light-task-run-test.sh +255 -0
- package/scripts/lib/light-task-test.sh +309 -0
- package/scripts/lib/light-task.sh +706 -0
- package/scripts/lib/next-test.sh +99 -0
- package/scripts/lib/next.sh +9 -3
- package/scripts/lib/orchestration-runtime-test.sh +72 -0
- package/scripts/lib/orchestration-runtime.sh +57 -5
- package/scripts/lib/plan-machine-test.sh +15 -2
- package/scripts/lib/plan-machine.sh +20 -7
- package/scripts/lib/plan-next-test.sh +1 -1
- package/scripts/lib/plan-next.sh +4 -4
- package/scripts/lib/pr-evidence-test.sh +3 -3
- package/scripts/lib/pr-evidence.sh +1 -1
- package/scripts/lib/qa-lane-test.sh +626 -0
- package/scripts/lib/qa-lane.sh +1357 -0
- package/scripts/lib/qa-lanes-test.sh +175 -0
- package/scripts/lib/react-detect.sh +1 -1
- package/scripts/lib/render-test.sh +1 -1
- package/scripts/lib/review-page-test.sh +318 -0
- package/scripts/lib/review-page.sh +369 -0
- package/scripts/lib/review-stage-test.sh +62 -11
- package/scripts/lib/review-stage.sh +42 -60
- package/scripts/lib/role-identity-test.sh +65 -0
- package/scripts/lib/role-identity.sh +25 -2
- package/scripts/lib/secret-guard.sh +3 -3
- package/scripts/lib/session-registry-test.sh +111 -0
- package/scripts/lib/session-registry.sh +233 -0
- package/scripts/lib/stage-receipt-test.sh +14 -1
- package/scripts/lib/stage-receipt.sh +13 -8
- package/scripts/lib/task-source-file.sh +309 -0
- package/scripts/lib/task-source.sh +130 -0
- package/scripts/lib/test-env-test.sh +3 -3
- package/scripts/lib/test-env.sh +7 -4
- package/scripts/lib/upgrade-report-test.sh +120 -0
- package/scripts/lib/upgrade-report.sh +138 -0
- package/scripts/lib/version-bump.sh +3 -3
- package/scripts/lib/wave-result-test.sh +80 -0
- package/scripts/lib/wave-result.sh +127 -0
- package/scripts/lib/worker-brief-test.sh +5 -0
- package/scripts/lib/worker-brief.sh +2 -2
- package/scripts/lib/worktree-issue-test.sh +30 -1
- package/scripts/lib/worktree-issue.sh +93 -9
- package/scripts/lib/worktree-ports-test.sh +57 -4
- package/scripts/lib/worktree-start-test.sh +197 -0
- package/scripts/lib/worktree-start.sh +169 -32
- package/scripts/lib/zsh-safety-test.sh +19 -3
- package/scripts/marketing-walkthrough-test.sh +152 -0
- package/scripts/night-grant-test.sh +37 -0
- package/scripts/night-grant.sh +448 -0
- package/scripts/night-run-test.sh +8 -0
- package/scripts/night-run.mjs +275 -0
- package/scripts/night-run.test.mjs +324 -0
- package/scripts/orchestrate-test.sh +190 -0
- package/scripts/orchestrate.sh +79 -8
- package/scripts/portable-test.sh +11 -2
- package/scripts/publish.sh +28 -3
- package/scripts/review-lint-test.sh +7 -7
- package/scripts/review-lint.sh +2 -2
- package/scripts/review-rules.conf +8 -0
- package/scripts/rule-recipes-test.sh +96 -0
- package/scripts/self-install-test.sh +39 -9
- package/scripts/setup-labels.sh +18 -1
- package/scripts/setup-milestones.sh +1 -1
- package/scripts/showcase.sh +1 -1
- package/scripts/skill-frontmatter-lint-test.sh +4 -4
- package/scripts/skill-frontmatter-lint.sh +1 -1
- package/scripts/status-test.sh +113 -2
- package/scripts/status.sh +16 -3
- package/scripts/task-sync-test.sh +154 -0
- package/scripts/task-sync.sh +243 -32
- package/scripts/test-runner-test.sh +158 -0
- package/scripts/test.sh +131 -23
- package/scripts/update-path-test.sh +279 -0
- package/scripts/ux-ds-audit.sh +1 -1
- package/scripts/ux-graph-scan.sh +6 -6
- package/scripts/wave-worker.sh +54 -0
- package/skills/kit-add/SKILL.md +77 -0
- package/skills/kit-autopilot/SKILL.md +123 -12
- package/skills/kit-cleanup/SKILL.md +5 -2
- package/skills/kit-contribute/SKILL.md +4 -4
- package/skills/kit-docs-writer/SKILL.md +16 -6
- package/skills/kit-effort-close/SKILL.md +17 -8
- package/skills/kit-effort-new/SKILL.md +15 -9
- package/skills/kit-effort-pr/SKILL.md +15 -7
- package/skills/kit-effort-start/SKILL.md +5 -2
- package/skills/kit-gc/SKILL.md +5 -2
- package/skills/kit-next/SKILL.md +5 -1
- package/skills/kit-onboard/SKILL.md +3 -3
- package/skills/kit-page/SKILL.md +93 -0
- package/skills/kit-plan-next/SKILL.md +8 -4
- package/skills/kit-security-sweep/SKILL.md +1 -3
- package/skills/kit-ship/SKILL.md +2 -3
- package/skills/kit-status/SKILL.md +35 -4
- package/skills/kit-task-new/SKILL.md +3 -3
- package/skills/kit-task-pr/SKILL.md +7 -2
- package/skills/kit-task-pr-merge/SKILL.md +7 -2
- package/skills/kit-task-start/SKILL.md +7 -7
- package/skills/kit-task-sync/SKILL.md +19 -3
- package/skills/kit-ux-audit/SKILL.md +3 -2
- package/templates/agents/auto-dev.md +5 -4
- package/templates/agents/backend.md +1 -1
- package/templates/agents/designer.md +2 -0
- package/templates/agents/devops.md +1 -1
- package/templates/agents/editor.md +9 -1
- package/templates/agents/frontend.md +1 -1
- package/templates/agents/local-delegate.md +1 -1
- package/templates/agents/pm.md +5 -5
- package/templates/agents/tech-lead.md +1 -1
- package/templates/benchmarks/SCHEMA.md +9 -3
- package/templates/codex/hooks.json.tmpl +89 -0
- package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +27 -14
- package/templates/hooks/mempal_followup.sh.tmpl +2 -2
- package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
- package/templates/hooks/prepush_gate.sh.tmpl +4 -2
- package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
- package/templates/instructions.md.tmpl +174 -0
- package/templates/kit.config.json.tmpl +3 -3
- package/templates/knowledge-INDEX.md.tmpl +1 -1
- package/templates/lib/kit-sigil.sh.tmpl +1 -1
- package/templates/rules/authoring.md +106 -0
- package/templates/rules/branch-naming.md +40 -4
- package/templates/rules/code-retrieval.md +63 -0
- package/templates/rules/delegation-brief.md +0 -3
- package/templates/rules/design-routing.md +3 -3
- package/templates/rules/effort-model.md +14 -10
- package/templates/rules/gate-and-review.md +94 -0
- package/templates/rules/issue-lifecycle.md +88 -0
- package/templates/rules/knowledge-base.md +1 -1
- package/templates/rules/mempalace.md +1 -1
- package/templates/rules/merge-safety.md +108 -0
- package/templates/rules/naming-and-ids.md +23 -17
- package/templates/rules/plain-language.md +59 -0
- package/templates/rules/plan-next.md +9 -11
- package/templates/rules/react-annotate.md +6 -0
- package/templates/rules/review-pages.md +49 -0
- package/templates/rules/risk-tiered-review.md +13 -4
- package/templates/rules/shared-checkout.md +106 -0
- package/templates/rules/skill-gaps.md +2 -7
- package/templates/rules/task-management.md +13 -1
- package/templates/skills/brand-voice/SKILL.md +91 -0
- package/templates/skills/brand-voice/references/voice-template.md +61 -0
- package/templates/skills/campaign/SKILL.md +123 -0
- package/templates/skills/campaign/references/plan-template.md +55 -0
- package/templates/skills/concrete/SKILL.md +2 -2
- package/templates/skills/copywriting/SKILL.md +8 -1
- package/templates/skills/feature-build-refine/SKILL.md +2 -4
- package/templates/skills/morning-briefing/SKILL.md +2 -2
- package/templates/skills/page-design/SKILL.md +145 -0
- package/templates/skills/page-design/add.json +5 -0
- package/templates/skills/page-design/references/design-file-template.md +40 -0
- package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
- package/templates/skills/page-design/references/minimum-rules.md +42 -0
- package/templates/skills/speckit/SKILL.md +4 -5
- package/templates/skills/supabase-patterns/SKILL.md +1 -1
- package/commands/kit-add.md +0 -42
- package/templates/CLAUDE.md.tmpl +0 -106
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
# RECORDED under the git-common-dir, so uniqueness is by construction and an issue keeps its
|
|
18
18
|
# slot for as long as its worktree lives.
|
|
19
19
|
#
|
|
20
|
+
# 4. A LOCK THAT DID NOT EXCLUDE (#449). The ledger lock was `mkdir`. The `mkdir` of uutils
|
|
21
|
+
# coreutils 0.10.0 (Ubuntu 26.04, GitHub's `ubuntu-latest`) exits 0 for the loser of a race, so
|
|
22
|
+
# two allocations ran together and took the same slot: 4 of 70 runs of this file on that
|
|
23
|
+
# runner, 52 of 100 runs of section 6 in an Ubuntu 26.04 container. Section 7 races the
|
|
24
|
+
# primitive itself.
|
|
25
|
+
#
|
|
20
26
|
# The bar: N worktrees over arbitrary issue numbers, in either config layout, produce N disjoint
|
|
21
27
|
# port sets — and re-running for a live issue never renumbers it.
|
|
22
28
|
#
|
|
@@ -85,6 +91,20 @@ wt_assign_ports "$W" 7 "$P" >/dev/null 2>&1
|
|
|
85
91
|
after="$(ports_of "$W" | tr '\n' ' ')"
|
|
86
92
|
[ "$before" = "$after" ] && ok || bad "re-run renumbered a live lane: '$before' -> '$after'"
|
|
87
93
|
|
|
94
|
+
# ── 4b. the public readers agree with the allocation (#295) ───────────────────────────────────
|
|
95
|
+
# The QA lane derives its ports from wt_port_slot + wt_port_stride. If either disagreed with what
|
|
96
|
+
# wt_assign_ports wrote, a lane's stack would boot off the worktree's own port block.
|
|
97
|
+
slot7="$(wt_port_slot "$P" 7 "$W" 2>/dev/null)"
|
|
98
|
+
stride7="$(wt_port_stride "$P/cckit.config.json")"
|
|
99
|
+
[ "$stride7" = 10 ] && ok || bad "wt_port_stride default: got '$stride7', want 10"
|
|
100
|
+
first7="$(ports_of "$W" | sed -n 1p)"
|
|
101
|
+
[ "$first7" = "$(( 3001 + slot7 * stride7 ))" ] && ok || bad "wt_port_slot disagrees with the assigned port: slot '$slot7' stride '$stride7' port '$first7'"
|
|
102
|
+
[ "$(wt_port_slot "$P" 7 "$W" 2>/dev/null)" = "$slot7" ] && ok || bad "wt_port_slot renumbered a live issue"
|
|
103
|
+
printf '%s' '{"worktree":{"devPortStride":25}}' > "$TMP/stride.json"
|
|
104
|
+
[ "$(wt_port_stride "$TMP/stride.json")" = 25 ] && ok || bad "wt_port_stride ignored worktree.devPortStride"
|
|
105
|
+
printf '%s' '{"worktree":{"devPortStride":"wide"}}' > "$TMP/stride.json"
|
|
106
|
+
[ "$(wt_port_stride "$TMP/stride.json")" = 10 ] && ok || bad "wt_port_stride accepted a non-integer stride"
|
|
107
|
+
|
|
88
108
|
# ── 5. a freed slot is reclaimed, not leaked ──────────────────────────────────────────────────
|
|
89
109
|
slots="$(git -C "$P" rev-parse --git-common-dir 2>/dev/null)"
|
|
90
110
|
case "$slots" in /*) : ;; *) slots="$(cd "$P" && cd "$slots" && pwd)" ;; esac
|
|
@@ -119,7 +139,7 @@ for num in $RACE_NUMS; do
|
|
|
119
139
|
while [ "$(lines_in "$barrier")" -lt "$RACE_N" ] && [ "$waited" -lt 50 ]; do
|
|
120
140
|
sleep 0.1; waited=$(( waited + 1 ))
|
|
121
141
|
done
|
|
122
|
-
wt_assign_ports "$W" "$num" "$P" >/dev/null 2
|
|
142
|
+
wt_assign_ports "$W" "$num" "$P" >/dev/null 2>"$P/.err.$num"
|
|
123
143
|
) &
|
|
124
144
|
pids="$pids $!"
|
|
125
145
|
done
|
|
@@ -134,13 +154,46 @@ race_uniq="$(printf '%s' "$race" | sort -u | grep -c .)"
|
|
|
134
154
|
[ "$race_total" = 24 ] && ok || bad "parallel: expected 24 ports over 8 concurrent worktrees, got $race_total"
|
|
135
155
|
if [ "$race_total" = "$race_uniq" ]; then ok; else
|
|
136
156
|
bad "parallel port collision: $race_total ports but only $race_uniq distinct ($(printf '%s' "$race" | sort | uniq -d | tr '\n' ' '))"
|
|
157
|
+
# The evidence, not only the verdict: what the ledger recorded and what the allocator said on
|
|
158
|
+
# stderr (a lock that timed out warns there). Without these a collision cannot be traced (#449).
|
|
159
|
+
echo " ledger:"; sed 's/^/ /' "$P/.git/kit-portslots.tsv" 2>&1
|
|
160
|
+
echo " allocator stderr:"; cat "$P"/.err.* 2>/dev/null | grep -v ' PORT=' | sed 's/^/ /'
|
|
137
161
|
fi
|
|
138
162
|
|
|
139
|
-
# The lock is released on the way out — a leftover lock
|
|
140
|
-
#
|
|
163
|
+
# The lock is released on the way out — a leftover lock wedges every later start until the
|
|
164
|
+
# one-minute abandonment window elapses.
|
|
141
165
|
race_gcd="$(git -C "$P" rev-parse --git-common-dir 2>/dev/null)"
|
|
142
166
|
case "$race_gcd" in /*) : ;; *) race_gcd="$(cd "$P" && cd "$race_gcd" && pwd)" ;; esac
|
|
143
|
-
[ ! -
|
|
167
|
+
[ ! -e "$race_gcd/kit-portslots.tsv.lock" ] && ok || bad "the port-slot lock was left behind after allocation"
|
|
168
|
+
|
|
169
|
+
# ── 7. the lock primitive excludes: of N simultaneous attempts exactly one wins (#449) ────────
|
|
170
|
+
# Section 6 only fails when two allocations happen to overlap. This one asks the primitive
|
|
171
|
+
# directly: eight processes make ONE attempt each on the same lock, released together by a start
|
|
172
|
+
# file, and the winners are counted. A primitive that checks and then creates (uutils `mkdir`)
|
|
173
|
+
# reports several winners in most rounds, so 25 rounds do not pass by luck.
|
|
174
|
+
LOCK_ROUNDS=25; lock_bad=0; lock_detail=""
|
|
175
|
+
L="$TMP/prim.lock"; go="$TMP/prim.go"; won="$TMP/prim.won"
|
|
176
|
+
r=0
|
|
177
|
+
while [ "$r" -lt "$LOCK_ROUNDS" ]; do
|
|
178
|
+
r=$((r+1)); rm -rf "$L" "$go"; : > "$won"; pids=""
|
|
179
|
+
for k in 1 2 3 4 5 6 7 8; do
|
|
180
|
+
(
|
|
181
|
+
waited=0
|
|
182
|
+
while [ ! -e "$go" ] && [ "$waited" -lt 20000 ]; do waited=$((waited+1)); done # spin: a sleep would spread the attempts out
|
|
183
|
+
_wt_lock_try "$L" && echo "$k" >> "$won"
|
|
184
|
+
) &
|
|
185
|
+
pids="$pids $!"
|
|
186
|
+
done
|
|
187
|
+
: > "$go"
|
|
188
|
+
for pid in $pids; do wait "$pid"; done
|
|
189
|
+
winners="$(lines_in "$won")"
|
|
190
|
+
[ "$winners" = 1 ] || { lock_bad=$((lock_bad+1)); lock_detail="$lock_detail $winners"; }
|
|
191
|
+
done
|
|
192
|
+
[ "$lock_bad" = 0 ] && ok || bad "the lock primitive let $lock_bad of $LOCK_ROUNDS rounds end without exactly one winner (winners per bad round:$lock_detail)"
|
|
193
|
+
_wt_unlock "$L"; [ ! -e "$L" ] && ok || bad "_wt_unlock left the lock in place"
|
|
194
|
+
# A cckit from before #449 leaves a lock DIRECTORY at the same path: it must still block.
|
|
195
|
+
mkdir "$L"; if _wt_lock_try "$L"; then bad "a lock directory from an older cckit did not block"; else ok; fi
|
|
196
|
+
_wt_unlock "$L"; [ ! -e "$L" ] && ok || bad "_wt_unlock left an older lock directory in place"
|
|
144
197
|
|
|
145
198
|
echo "worktree-ports-test: $n assertion(s), $([ "$fail" = 0 ] && echo "all passed" || echo "FAILURES")"
|
|
146
199
|
exit "$fail"
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# worktree-start-test.sh — wt_start sees live session claims (#384).
|
|
3
|
+
#
|
|
4
|
+
# The bug: a second `cckit start <N>` from another session got "reusing worktree" and rc 0, so two
|
|
5
|
+
# agents wrote one tree. The bar: a LIVE claim by another session refuses the start before any
|
|
6
|
+
# fetch, branch or worktree; `--force` / KIT_FORCE=1 proceeds; a dead session's claim is reaped;
|
|
7
|
+
# the claimant's own re-run stays a no-op; `cckit claims` lists and writes nothing.
|
|
8
|
+
#
|
|
9
|
+
# Hermetic: a throwaway repo with a local bare origin, a stubbed `gh` (no network, no auth) and a
|
|
10
|
+
# stubbed `zoxide` (so no temp path lands in the developer's jump database). A "session" is a
|
|
11
|
+
# background `sleep` whose pid is handed to wt_start through KIT_SESSION_PID.
|
|
12
|
+
#
|
|
13
|
+
# Run: bash scripts/lib/worktree-start-test.sh
|
|
14
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
15
|
+
set -u
|
|
16
|
+
LIB="$(cd "$(dirname "$0")" && pwd)"
|
|
17
|
+
ROOT="$(cd "$LIB/../.." && pwd)"
|
|
18
|
+
# shellcheck source=/dev/null
|
|
19
|
+
. "$LIB/test-env.sh" && test_env_seal
|
|
20
|
+
command -v jq >/dev/null 2>&1 || { echo "worktree-start-test: jq required" >&2; exit 1; }
|
|
21
|
+
|
|
22
|
+
fail=0
|
|
23
|
+
t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
|
|
24
|
+
has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> missing '$3' in [$2]"; fail=1 ;; esac; }
|
|
25
|
+
|
|
26
|
+
tmp="$(cd "$(mktemp -d 2>/dev/null || mktemp -d -t wst)" && pwd -P)"
|
|
27
|
+
SESS_A=""; SESS_B=""
|
|
28
|
+
cleanup() {
|
|
29
|
+
[ -n "$SESS_A" ] && kill "$SESS_A" 2>/dev/null
|
|
30
|
+
[ -n "$SESS_B" ] && kill "$SESS_B" 2>/dev/null
|
|
31
|
+
rm -rf "$tmp"
|
|
32
|
+
}
|
|
33
|
+
trap cleanup EXIT INT TERM
|
|
34
|
+
|
|
35
|
+
# ── fixture: stubs, a bare origin with `main`, and a clone to start worktrees from ─────────────
|
|
36
|
+
mkdir -p "$tmp/bin"
|
|
37
|
+
cat > "$tmp/bin/gh" <<'SH'
|
|
38
|
+
#!/usr/bin/env bash
|
|
39
|
+
# Every call is logged, so a test can assert a refusal made NO GitHub read.
|
|
40
|
+
printf '%s\n' "$*" >> "${GH_CALL_LOG:-/dev/null}"
|
|
41
|
+
case "$*" in
|
|
42
|
+
*"issue view"*) echo '{"title":"Claimed thing","labels":[{"name":"kind:task"}]}' ;;
|
|
43
|
+
*graphql*) echo '{"data":{}}' ;;
|
|
44
|
+
*) echo '[]' ;;
|
|
45
|
+
esac
|
|
46
|
+
SH
|
|
47
|
+
printf '#!/bin/sh\nexit 0\n' > "$tmp/bin/zoxide"
|
|
48
|
+
chmod +x "$tmp/bin/gh" "$tmp/bin/zoxide"
|
|
49
|
+
PATH="$tmp/bin:$PATH"; export PATH
|
|
50
|
+
export GH_CALL_LOG="$tmp/gh.calls"; : > "$GH_CALL_LOG"
|
|
51
|
+
|
|
52
|
+
git init -q --bare "$tmp/origin.git"
|
|
53
|
+
git init -q "$tmp/repo"
|
|
54
|
+
(
|
|
55
|
+
cd "$tmp/repo" || exit 1
|
|
56
|
+
git config user.email t@example.invalid; git config user.name t; git config commit.gpgsign false
|
|
57
|
+
git checkout -q -b main
|
|
58
|
+
printf '{ "kitVersion":"9.9.9", "project":{"name":"fx","slug":"fx"},\n "github":{"repo":"octo/fx","owner":"octo","baseBranch":"main","projectsV2":false} }\n' > cckit.config.json
|
|
59
|
+
git add cckit.config.json && git commit -q -m init
|
|
60
|
+
git remote add origin "$tmp/origin.git" && git push -q origin main
|
|
61
|
+
) || { echo "FAIL: fixture repo setup"; exit 1; }
|
|
62
|
+
REPO="$tmp/repo"
|
|
63
|
+
REG="$REPO/.git/kit-sessions"
|
|
64
|
+
|
|
65
|
+
export WT_START_REPO="octo/fx" KIT_BASE_BRANCH="main" KIT_WT_INSTALL=0
|
|
66
|
+
# shellcheck source=/dev/null
|
|
67
|
+
. "$LIB/worktree-start.sh"
|
|
68
|
+
|
|
69
|
+
sleep 600 & SESS_A=$!
|
|
70
|
+
sleep 600 & SESS_B=$!
|
|
71
|
+
|
|
72
|
+
# start_as <session-pid> <args…> — wt_start from the main checkout, as that session.
|
|
73
|
+
start_as() { local sp="$1"; shift; ( cd "$REPO" && KIT_SESSION_PID="$sp" wt_start "$@" ); }
|
|
74
|
+
branches() { git -C "$REPO" for-each-ref --format='%(refname:short)' refs/heads | sort | tr '\n' ' '; }
|
|
75
|
+
worktrees() { git -C "$REPO" worktree list --porcelain | grep -c '^worktree '; }
|
|
76
|
+
|
|
77
|
+
# ── 1. first start: creates the worktree and writes the claim ──────────────────────────────────
|
|
78
|
+
out="$(start_as "$SESS_A" 7 2>/dev/null)"; rc=$?
|
|
79
|
+
t "first start succeeds" "$rc" "0"
|
|
80
|
+
WT7="$REPO/.claude/worktrees/task+7-claimed-thing"
|
|
81
|
+
t "first start prints path|branch|issue" "$out" "$WT7|task/7-claimed-thing|7"
|
|
82
|
+
t "claim file written" "$([ -f "$REG/issue-7.json" ] && echo yes || echo no)" "yes"
|
|
83
|
+
t "claim records the session pid" "$(jq -r .pid "$REG/issue-7.json" 2>/dev/null)" "$SESS_A"
|
|
84
|
+
t "claim records the worktree" "$(jq -r .worktree "$REG/issue-7.json" 2>/dev/null)" "$WT7"
|
|
85
|
+
t "claim records the branch" "$(jq -r .branch "$REG/issue-7.json" 2>/dev/null)" "task/7-claimed-thing"
|
|
86
|
+
t "claim records the issue" "$(jq -r .issue "$REG/issue-7.json" 2>/dev/null)" "7"
|
|
87
|
+
t "claim records a start time" "$(jq -r '.started | type' "$REG/issue-7.json" 2>/dev/null)" "number"
|
|
88
|
+
|
|
89
|
+
# ── 6. the EXISTING reader sees the claim (it reads .pid + .cwd, skips cache-*) ────────────────
|
|
90
|
+
_wt_session_owns "$REPO" "$WT7"; t "_wt_session_owns sees the wt_start claim" "$?" "0"
|
|
91
|
+
_wt_session_owns "$REPO" "$REPO/.claude/worktrees/task+8-nope"; t "_wt_session_owns is false for an unclaimed path" "$?" "1"
|
|
92
|
+
|
|
93
|
+
# ── 1. a second session is refused — and nothing is created, nothing is fetched or read ────────
|
|
94
|
+
# A second issue number makes "no new worktree, no new branch" observable: 7 already has both, so
|
|
95
|
+
# the refusal case that proves it is a claim on an issue whose worktree does NOT exist yet.
|
|
96
|
+
mkdir -p "$REG"
|
|
97
|
+
jq -n --argjson pid "$SESS_A" --arg host "$(hostname)" --arg wt "$REPO/.claude/worktrees/task+9-claimed-thing" \
|
|
98
|
+
--argjson started "$(date +%s)" \
|
|
99
|
+
'{issue:9, branch:"task/9-claimed-thing", worktree:$wt, cwd:$wt, pid:$pid, host:$host, started:$started}' \
|
|
100
|
+
> "$REG/issue-9.json"
|
|
101
|
+
b_before="$(branches)"; w_before="$(worktrees)"; : > "$GH_CALL_LOG"
|
|
102
|
+
fetch_before="$(stat -c %Y "$REPO/.git/FETCH_HEAD" 2>/dev/null || stat -f %m "$REPO/.git/FETCH_HEAD" 2>/dev/null)"
|
|
103
|
+
err="$(start_as "$SESS_B" 9 2>&1 >/dev/null)"; rc=$?
|
|
104
|
+
t "second session on a claimed issue is refused (rc 1)" "$rc" "1"
|
|
105
|
+
has "refusal names the claimant pid" "$err" "pid $SESS_A"
|
|
106
|
+
has "refusal names the escape hatch" "$err" "--force"
|
|
107
|
+
t "refusal creates no branch" "$(branches)" "$b_before"
|
|
108
|
+
t "refusal creates no worktree" "$(worktrees)" "$w_before"
|
|
109
|
+
t "refusal creates no worktree dir" "$([ -e "$REPO/.claude/worktrees/task+9-claimed-thing" ] && echo yes || echo no)" "no"
|
|
110
|
+
t "refusal makes no gh call (it runs before the issue read)" "$(wc -l < "$GH_CALL_LOG" | tr -d ' ')" "0"
|
|
111
|
+
t "refusal runs before the fetch (FETCH_HEAD untouched)" \
|
|
112
|
+
"$(stat -c %Y "$REPO/.git/FETCH_HEAD" 2>/dev/null || stat -f %m "$REPO/.git/FETCH_HEAD" 2>/dev/null)" "$fetch_before"
|
|
113
|
+
t "refusal leaves the claim with its owner" "$(jq -r .pid "$REG/issue-9.json")" "$SESS_A"
|
|
114
|
+
|
|
115
|
+
# The same refusal on the issue that already has a worktree: no "reusing worktree" success.
|
|
116
|
+
out="$(start_as "$SESS_B" 7 2>/dev/null)"; rc=$?
|
|
117
|
+
t "second session on a claimed, existing worktree is refused" "$rc" "1"
|
|
118
|
+
t "refused start prints no worktree line" "$out" ""
|
|
119
|
+
|
|
120
|
+
# ── 2. --force and KIT_FORCE=1 proceed ─────────────────────────────────────────────────────────
|
|
121
|
+
out="$(start_as "$SESS_B" --force 9 2>/dev/null)"; rc=$?
|
|
122
|
+
t "--force starts a claimed issue" "$rc" "0"
|
|
123
|
+
t "--force is not taken for the issue number" "$out" "$REPO/.claude/worktrees/task+9-claimed-thing|task/9-claimed-thing|9"
|
|
124
|
+
t "--force takes the claim over" "$(jq -r .pid "$REG/issue-9.json")" "$SESS_B"
|
|
125
|
+
out="$(start_as "$SESS_B" 7 --force 2>/dev/null)"; rc=$?
|
|
126
|
+
t "--force after the issue number also works" "$rc" "0"
|
|
127
|
+
t "claim 7 now belongs to the forcing session" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_B"
|
|
128
|
+
out="$( cd "$REPO" && KIT_FORCE=1 KIT_SESSION_PID="$SESS_A" wt_start 7 2>/dev/null )"; rc=$?
|
|
129
|
+
t "KIT_FORCE=1 starts a claimed issue" "$rc" "0"
|
|
130
|
+
t "KIT_FORCE=1 takes the claim over" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_A"
|
|
131
|
+
err="$(start_as "$SESS_A" --bogus 7 2>&1 >/dev/null)"; rc=$?
|
|
132
|
+
t "an unknown flag is refused, not read as the issue" "$rc" "1"
|
|
133
|
+
|
|
134
|
+
# ── 4. the claimant's own re-run is a no-op success ────────────────────────────────────────────
|
|
135
|
+
before="$(cat "$REG/issue-7.json")"
|
|
136
|
+
out="$(start_as "$SESS_A" 7 2>/dev/null)"; rc=$?
|
|
137
|
+
t "re-run by the claiming session succeeds" "$rc" "0"
|
|
138
|
+
t "re-run by the claiming session leaves the claim untouched" "$(cat "$REG/issue-7.json")" "$before"
|
|
139
|
+
# From inside the claim's own worktree, as a session with a DIFFERENT pid (an agent's fresh shell).
|
|
140
|
+
out="$( cd "$WT7" && KIT_SESSION_PID="$SESS_B" wt_start 7 2>/dev/null )"; rc=$?
|
|
141
|
+
t "re-run from the claim's own worktree succeeds" "$rc" "0"
|
|
142
|
+
t "re-run from the claim's own worktree prints the same line" "$out" "$WT7|task/7-claimed-thing|7"
|
|
143
|
+
t "re-run from the claim's own worktree leaves the claim untouched" "$(cat "$REG/issue-7.json")" "$before"
|
|
144
|
+
t "re-run added no worktree" "$(worktrees)" "3"
|
|
145
|
+
|
|
146
|
+
# ── 5. `cckit claims` lists the live claims and writes nothing ─────────────────────────────────
|
|
147
|
+
snap() { ( cd "$REG" && ls -la . && cat issue-*.json ) 2>/dev/null; }
|
|
148
|
+
before="$(snap)"
|
|
149
|
+
human="$( cd "$REPO" && "$ROOT/bin/cckit" claims 2>/dev/null )"; rc=$?
|
|
150
|
+
t "cckit claims exits 0" "$rc" "0"
|
|
151
|
+
has "cckit claims lists issue 7" "$human" "#7"
|
|
152
|
+
has "cckit claims lists the branch" "$human" "task/7-claimed-thing"
|
|
153
|
+
json="$( cd "$REPO" && "$ROOT/bin/cckit" claims --llm 2>/dev/null )"
|
|
154
|
+
t "cckit claims --llm is a JSON array of both live claims" "$(printf '%s' "$json" | jq -c '[.[].issue]' 2>/dev/null)" "[7,9]"
|
|
155
|
+
t "cckit claims --llm carries the pid" "$(printf '%s' "$json" | jq -r '.[0].pid' 2>/dev/null)" "$SESS_A"
|
|
156
|
+
t "cckit claims works from inside a worktree" "$( cd "$WT7" && "$ROOT/bin/cckit" claims --llm 2>/dev/null | jq -c '[.[].issue]' )" "[7,9]"
|
|
157
|
+
t "cckit claims writes nothing" "$(snap)" "$before"
|
|
158
|
+
|
|
159
|
+
# ── 3. a dead session's claim is reaped and the start proceeds ─────────────────────────────────
|
|
160
|
+
kill "$SESS_A" 2>/dev/null; wait "$SESS_A" 2>/dev/null; DEAD="$SESS_A"; SESS_A=""
|
|
161
|
+
before="$(snap)"
|
|
162
|
+
t "cckit claims hides a dead session's claim" "$( cd "$REPO" && "$ROOT/bin/cckit" claims --llm 2>/dev/null | jq -c '[.[].issue]' )" "[9]"
|
|
163
|
+
t "cckit claims does not reap it (read-only)" "$(snap)" "$before"
|
|
164
|
+
_wt_session_owns "$REPO" "$WT7"; t "_wt_session_owns is false once the session died" "$?" "1"
|
|
165
|
+
out="$(start_as "$SESS_B" 7 2>/dev/null)"; rc=$?
|
|
166
|
+
t "start over a dead session's claim proceeds" "$rc" "0"
|
|
167
|
+
t "the dead claim was replaced by the new session's" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_B"
|
|
168
|
+
t "the dead pid is gone from the registry" "$(grep -l "\"pid\": *$DEAD\b" "$REG"/issue-*.json 2>/dev/null | wc -l | tr -d ' ')" "0"
|
|
169
|
+
|
|
170
|
+
# A claim whose worktree was removed (the PR merged, cleanup ran) is dead even with a live pid,
|
|
171
|
+
# once it is older than the grace that covers the claim→`worktree add` window.
|
|
172
|
+
jq -n --argjson pid "$SESS_B" --arg host "$(hostname)" --arg wt "$tmp/gone" --argjson started "$(( $(date +%s) - 4000 ))" \
|
|
173
|
+
'{issue:11, branch:"task/11-x", worktree:$wt, cwd:$wt, pid:$pid, host:$host, started:$started}' > "$REG/issue-11.json"
|
|
174
|
+
start_as "$$" 11 >/dev/null 2>&1; rc=$?
|
|
175
|
+
t "a claim whose worktree is long gone does not block" "$rc" "0"
|
|
176
|
+
|
|
177
|
+
# ── a failed start does not leave a claim behind ───────────────────────────────────────────────
|
|
178
|
+
# `git worktree add -B` fails when the branch is checked out in the main checkout.
|
|
179
|
+
git -C "$REPO" checkout -q -b task/12-claimed-thing
|
|
180
|
+
start_as "$SESS_B" 12 >/dev/null 2>&1; rc=$?
|
|
181
|
+
t "a start whose worktree add fails returns 1" "$rc" "1"
|
|
182
|
+
t "…and releases the claim it had just taken" "$([ -e "$REG/issue-12.json" ] && echo yes || echo no)" "no"
|
|
183
|
+
git -C "$REPO" checkout -q main
|
|
184
|
+
|
|
185
|
+
# ── 7. the CLI reports the ISSUE, not the flag ─────────────────────────────────────────────────
|
|
186
|
+
json="$( cd "$REPO" && KIT_SESSION_PID="$$" "$ROOT/bin/cckit" start --force 9 --llm 2>/dev/null )"
|
|
187
|
+
t "cckit start --force N --llm reports issue N" "$(printf '%s' "$json" | jq -r '.issue' 2>/dev/null)" "9"
|
|
188
|
+
t "cckit start --force N --llm is ok" "$(printf '%s' "$json" | jq -r '.ok' 2>/dev/null)" "true"
|
|
189
|
+
json="$( cd "$REPO" && KIT_SESSION_PID="$SESS_B" "$ROOT/bin/cckit" start 9 --llm 2>/dev/null )"; rc=$?
|
|
190
|
+
t "cckit start on a claimed issue exits 1" "$rc" "1"
|
|
191
|
+
t "cckit start on a claimed issue reports ok:false" "$(printf '%s' "$json" | jq -r '.ok' 2>/dev/null)" "false"
|
|
192
|
+
err="$( cd "$REPO" && KIT_SESSION_PID="$SESS_B" "$ROOT/bin/cckit" start 9 2>&1 >/dev/null )"; rc=$?
|
|
193
|
+
t "cckit start (human mode) on a claimed issue exits 1" "$rc" "1"
|
|
194
|
+
has "cckit start (human mode) prints the refusal" "$err" "refused: a live session already claims this issue"
|
|
195
|
+
|
|
196
|
+
[ "$fail" -eq 0 ] && echo "ALL OK (worktree-start)" || echo "worktree-start: FAILURES"
|
|
197
|
+
exit "$fail"
|