@jeiemgi/cckit 0.7.0 → 0.8.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 +15 -4
- package/README.md +11 -3
- package/bin/cckit +86 -7
- package/cckit.config.json +1 -1
- package/kit.config.schema.json +43 -2
- package/package.json +1 -1
- package/scripts/autopilot-test.sh +68 -0
- package/scripts/autopilot.sh +16 -10
- package/scripts/check.sh +14 -1
- package/scripts/copilot-loop-test.sh +3 -0
- package/scripts/guard-raw-git-ops-test.sh +65 -0
- package/scripts/init.sh +68 -8
- package/scripts/lib/agent-profile-test.sh +151 -0
- package/scripts/lib/agent-profile.sh +195 -0
- package/scripts/lib/agent-resolve-test.sh +156 -0
- package/scripts/lib/agent-resolve.sh +177 -0
- package/scripts/lib/branch-owner-test.sh +99 -0
- package/scripts/lib/branch-owner.sh +194 -0
- package/scripts/lib/captain-test.sh +86 -0
- package/scripts/lib/captain.sh +142 -7
- package/scripts/lib/contribute-root-test.sh +40 -0
- package/scripts/lib/contribute-root.sh +22 -0
- package/scripts/lib/effort-ops-test.sh +42 -2
- package/scripts/lib/effort-ops.sh +157 -14
- package/scripts/lib/effort-parity-test.sh +5 -3
- package/scripts/lib/effort.sh +38 -14
- package/scripts/lib/hook-refresh-test.sh +65 -0
- package/scripts/lib/hook-refresh.sh +62 -0
- package/scripts/lib/kit-config.sh +6 -0
- package/scripts/lib/kit-gc-test.sh +178 -1
- package/scripts/lib/kit-gc.sh +233 -55
- package/scripts/lib/kit-task-ops-test.sh +15 -0
- package/scripts/lib/kit-task-ops.sh +65 -21
- package/scripts/lib/kto-task-pr-merge-test.sh +72 -0
- package/scripts/lib/kto-task-pr-test.sh +59 -0
- package/scripts/lib/orchestration-runtime-test.sh +142 -0
- package/scripts/lib/orchestration-runtime.sh +171 -0
- package/scripts/lib/review-stage-test.sh +241 -0
- package/scripts/lib/review-stage.sh +259 -0
- package/scripts/lib/stage-receipt-test.sh +252 -0
- package/scripts/lib/stage-receipt.sh +442 -0
- package/scripts/lib/test-env-test.sh +25 -0
- package/scripts/lib/test-env.sh +30 -0
- package/scripts/lib/worker-brief-test.sh +120 -0
- package/scripts/lib/worker-brief.sh +185 -0
- package/scripts/lib/worktree-ports-test.sh +146 -0
- package/scripts/lib/worktree-start.sh +137 -7
- package/scripts/lib/zsh-safety-test.sh +67 -0
- package/scripts/orchestrate.sh +124 -22
- package/scripts/portable-test.sh +22 -1
- package/scripts/review-lint-baseline.txt +28 -0
- package/scripts/review-lint-test.sh +271 -0
- package/scripts/review-lint.sh +259 -0
- package/scripts/review-rules.conf +55 -0
- package/scripts/setup-labels.sh +21 -1
- package/scripts/skill-frontmatter-baseline.txt +24 -0
- package/scripts/skill-frontmatter-lint-test.sh +156 -0
- package/scripts/skill-frontmatter-lint.sh +182 -0
- package/scripts/task-sync.sh +8 -0
- package/scripts/test.sh +10 -1
- package/skills/kit-autopilot/SKILL.md +13 -1
- package/skills/kit-cleanup/SKILL.md +5 -3
- package/skills/kit-contribute/SKILL.md +6 -5
- package/skills/kit-effort-close/SKILL.md +8 -3
- package/skills/kit-effort-pr/SKILL.md +16 -95
- package/skills/kit-gc/SKILL.md +15 -10
- package/skills/kit-security-sweep/SKILL.md +4 -6
- package/skills/kit-ship/SKILL.md +1 -1
- package/skills/kit-task-pr/SKILL.md +2 -0
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +180 -0
- package/templates/rules/branch-naming.md +6 -0
- package/templates/rules/effort-model.md +3 -0
- package/templates/rules/naming-and-ids.md +4 -1
- package/templates/settings/settings.json.tmpl +4 -2
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# orchestration-runtime.sh — terminal-runtime adapters for cckit orchestrate.
|
|
3
|
+
#
|
|
4
|
+
# cckit owns the work: issue selection, worktrees, branches, pull requests. A runtime owns only the
|
|
5
|
+
# terminal the agent runs in. Everything here is that second half — validate the runtime name,
|
|
6
|
+
# refuse an agent kind the runtime cannot start, and build the Herdr topology (workspace → tab →
|
|
7
|
+
# pane → agent) that tmux gets for free from `tmux new-session`.
|
|
8
|
+
# errors: strict — an invalid runtime, an unsupported agent kind, a missing binary or a failed
|
|
9
|
+
# herdr call propagates its rc; the caller must not create worktrees after a non-zero preflight.
|
|
10
|
+
# shellcheck shell=bash
|
|
11
|
+
|
|
12
|
+
or_runtime_validate() {
|
|
13
|
+
case "${1:-}" in
|
|
14
|
+
tmux|herdr) return 0 ;;
|
|
15
|
+
*) echo "orchestrate: --runtime must be tmux or herdr (got '${1:-}')" >&2; return 2 ;;
|
|
16
|
+
esac
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# The kinds Herdr can start. Read from the INSTALLED binary rather than a copy kept here: a
|
|
20
|
+
# hand-written list drifts silently against the runtime, and it already had — it carried `letta`,
|
|
21
|
+
# which herdr 0.9.0 does not support, so `--agent letta` passed preflight and then failed at
|
|
22
|
+
# `agent start`, after the worktree existed. The fallback list is only for when herdr is absent
|
|
23
|
+
# (a dry run) or its help output changes shape; it is deliberately the 0.9.0 set.
|
|
24
|
+
_OR_HERDR_KINDS_FALLBACK="pi claude codex gemini cursor devin agy cline omp mastracode opencode copilot kimi kiro droid amp grok hermes kilo qodercli qwen maki muse"
|
|
25
|
+
_OR_HERDR_KINDS=""
|
|
26
|
+
|
|
27
|
+
or_herdr_kinds() {
|
|
28
|
+
[ -n "$_OR_HERDR_KINDS" ] && { printf '%s\n' "$_OR_HERDR_KINDS"; return 0; }
|
|
29
|
+
local live=""
|
|
30
|
+
if command -v herdr >/dev/null 2>&1; then
|
|
31
|
+
live="$(herdr agent start --help 2>&1 \
|
|
32
|
+
| tr -d '\n' \
|
|
33
|
+
| sed -n 's/.*\[possible values:\([^]]*\)\].*/\1/p' \
|
|
34
|
+
| tr -d ' ' | tr ',' ' ')"
|
|
35
|
+
fi
|
|
36
|
+
case "$live" in
|
|
37
|
+
*claude*) _OR_HERDR_KINDS="$live" ;; # sanity: a parse that lost `claude` is a bad parse
|
|
38
|
+
*) _OR_HERDR_KINDS="$_OR_HERDR_KINDS_FALLBACK" ;;
|
|
39
|
+
esac
|
|
40
|
+
printf '%s\n' "$_OR_HERDR_KINDS"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
or_herdr_kind_supported() {
|
|
44
|
+
local want="${1:-}" k
|
|
45
|
+
[ -n "$want" ] || return 1
|
|
46
|
+
for k in $(or_herdr_kinds); do
|
|
47
|
+
[ "$k" = "$want" ] && return 0
|
|
48
|
+
done
|
|
49
|
+
return 1
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
or_runtime_preflight() {
|
|
53
|
+
local runtime="$1" agent="$2" dryrun="${3:-0}"
|
|
54
|
+
or_runtime_validate "$runtime" || return $?
|
|
55
|
+
|
|
56
|
+
if [ "$runtime" = "herdr" ] && ! or_herdr_kind_supported "$agent"; then
|
|
57
|
+
echo "orchestrate: Herdr needs a supported agent kind, not '$agent'" >&2
|
|
58
|
+
echo " supported here: $(or_herdr_kinds)" >&2
|
|
59
|
+
return 2
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
[ "$dryrun" -eq 1 ] && return 0
|
|
63
|
+
command -v "$runtime" >/dev/null 2>&1 || {
|
|
64
|
+
case "$runtime" in
|
|
65
|
+
tmux) echo "orchestrate: tmux not installed (brew install tmux)" >&2 ;;
|
|
66
|
+
herdr) echo "orchestrate: Herdr not installed (see https://herdr.dev/install)" >&2 ;;
|
|
67
|
+
esac
|
|
68
|
+
return 1
|
|
69
|
+
}
|
|
70
|
+
command -v "$agent" >/dev/null 2>&1 || {
|
|
71
|
+
echo "orchestrate: agent '$agent' not on PATH" >&2
|
|
72
|
+
return 1
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
or_herdr_agent_name() {
|
|
77
|
+
local project="$1" issue="$2" base room
|
|
78
|
+
base="cckit-${project:-project}"
|
|
79
|
+
base="$(printf '%s' "$base" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9_-' '-')"
|
|
80
|
+
base="${base#-}"
|
|
81
|
+
[ -n "$base" ] || base="cckit-project"
|
|
82
|
+
case "$base" in [a-z]*) ;; *) base="cckit-$base" ;; esac
|
|
83
|
+
room=$((31 - ${#issue}))
|
|
84
|
+
[ "$room" -gt 0 ] || room=1
|
|
85
|
+
printf '%.*s-%s' "$room" "$base" "$issue"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# or_tmux_agent_cmd <kind> <agent-args-nl> — echo the command LINE tmux types into a pane.
|
|
89
|
+
#
|
|
90
|
+
# The two runtimes receive a profile's argv differently, and the difference is the whole reason this
|
|
91
|
+
# exists. Herdr takes an argv array and never meets a shell; tmux `send-keys` writes a command line
|
|
92
|
+
# INTO the pane's shell, so every argument must be single-quoted here or that shell re-splits it.
|
|
93
|
+
#
|
|
94
|
+
# Skipping this dropped a profile's args on the DEFAULT runtime while orchestrate still printed the
|
|
95
|
+
# resolved profile — a profile selecting a model ran on the CLI's default model with no warning.
|
|
96
|
+
or_tmux_agent_cmd() {
|
|
97
|
+
local kind="${1:-}" args_nl="${2:-}" cmd="${1:-}" a esc
|
|
98
|
+
[ -n "$args_nl" ] || { printf '%s\n' "$kind"; return 0; }
|
|
99
|
+
while IFS= read -r a; do
|
|
100
|
+
[ -n "$a" ] || continue
|
|
101
|
+
# Escape in its OWN assignment, not inline in the concatenation: the `'\''` idiom needs one
|
|
102
|
+
# level of quoting and doing it inside a double-quoted string silently adds another. The
|
|
103
|
+
# seed prompt a few lines down in orchestrate.sh uses this exact two-step form for the same
|
|
104
|
+
# reason — it was arrived at by a bug, not by taste.
|
|
105
|
+
esc=${a//\'/\'\\\'\'}
|
|
106
|
+
cmd="$cmd '$esc'"
|
|
107
|
+
done <<EOF
|
|
108
|
+
$args_nl
|
|
109
|
+
EOF
|
|
110
|
+
printf '%s\n' "$cmd"
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
# or_herdr_launch <session> <kind> <seed?> <detach?> <project> <agent-args-nl> <entry>...
|
|
114
|
+
#
|
|
115
|
+
# <agent-args-nl> is the profile's extra CLI argv, ONE PER LINE (empty for none). They are handed to
|
|
116
|
+
# `herdr agent start ... -- <args>`, which is Herdr's documented passthrough to the agent process.
|
|
117
|
+
# One-per-line, then rebuilt into an array, so an argument containing spaces stays one argument —
|
|
118
|
+
# a flat string would be re-split by the shell and silently change what the agent was asked to do.
|
|
119
|
+
or_herdr_launch() {
|
|
120
|
+
local session="$1" agent="$2" seed_enabled="$3" detach="$4" project="$5" args_nl="${6:-}"
|
|
121
|
+
shift 6
|
|
122
|
+
local entries=("$@") first entry wt rest branch num created workspace pane tab name seed
|
|
123
|
+
local aargs=() _a
|
|
124
|
+
if [ -n "$args_nl" ]; then
|
|
125
|
+
while IFS= read -r _a; do [ -n "$_a" ] && aargs+=("$_a"); done <<EOF
|
|
126
|
+
$args_nl
|
|
127
|
+
EOF
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
first=1
|
|
131
|
+
workspace=""
|
|
132
|
+
for entry in "${entries[@]}"; do
|
|
133
|
+
wt="${entry%%|*}"; rest="${entry#*|}"; branch="${rest%%|*}"; num="${rest##*|}"
|
|
134
|
+
if [ "$first" -eq 1 ]; then
|
|
135
|
+
created="$(herdr workspace create --cwd "$wt" --label "cckit:${project:-project}:$session" --no-focus)" || return $?
|
|
136
|
+
workspace="$(printf '%s\n' "$created" | jq -r '.result.workspace.workspace_id // empty')"
|
|
137
|
+
pane="$(printf '%s\n' "$created" | jq -r '.result.root_pane.pane_id // empty')"
|
|
138
|
+
[ -n "$workspace" ] && [ -n "$pane" ] || {
|
|
139
|
+
echo "orchestrate: Herdr workspace response did not include workspace and pane IDs" >&2
|
|
140
|
+
return 1
|
|
141
|
+
}
|
|
142
|
+
first=0
|
|
143
|
+
else
|
|
144
|
+
tab="$(herdr tab create --workspace "$workspace" --cwd "$wt" --label "issue-$num" --no-focus)" || return $?
|
|
145
|
+
pane="$(printf '%s\n' "$tab" | jq -r '.result.root_pane.pane_id // empty')"
|
|
146
|
+
[ -n "$pane" ] || {
|
|
147
|
+
echo "orchestrate: Herdr tab response did not include a pane ID for issue #$num" >&2
|
|
148
|
+
return 1
|
|
149
|
+
}
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
name="$(or_herdr_agent_name "$project" "$num")"
|
|
153
|
+
if [ "${#aargs[@]}" -gt 0 ]; then
|
|
154
|
+
herdr agent start "$name" --kind "$agent" --pane "$pane" -- "${aargs[@]}" >/dev/null || return $?
|
|
155
|
+
else
|
|
156
|
+
herdr agent start "$name" --kind "$agent" --pane "$pane" >/dev/null || return $?
|
|
157
|
+
fi
|
|
158
|
+
if [ "$seed_enabled" -eq 1 ]; then
|
|
159
|
+
seed="$(seed_for "$num" "$branch" "$wt")"
|
|
160
|
+
herdr agent prompt "$name" "$seed" >/dev/null || return $?
|
|
161
|
+
fi
|
|
162
|
+
echo " #$num Herdr agent '$name' in $wt"
|
|
163
|
+
done
|
|
164
|
+
|
|
165
|
+
if [ "$detach" -eq 1 ]; then
|
|
166
|
+
echo "orchestrate: Herdr workspace '$workspace' built. Open: herdr workspace focus $workspace && herdr"
|
|
167
|
+
else
|
|
168
|
+
herdr workspace focus "$workspace" >/dev/null
|
|
169
|
+
exec herdr
|
|
170
|
+
fi
|
|
171
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# review-stage-test.sh — the review DISPATCH contract (#346).
|
|
3
|
+
#
|
|
4
|
+
# Hermetic. The configured `review.command` is a shell script in a temp dir, so a real dispatch runs
|
|
5
|
+
# end to end — brief on stdin, report on stdout, receipt on disk — with no agent, no gh and no
|
|
6
|
+
# network. The one thing stubbed is ap_pr_context, which is the gh-touching half of resolution and
|
|
7
|
+
# already has its own coverage in agent-resolve-test.sh.
|
|
8
|
+
# Run: bash scripts/lib/review-stage-test.sh
|
|
9
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
10
|
+
# shellcheck shell=bash
|
|
11
|
+
set -u
|
|
12
|
+
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
13
|
+
|
|
14
|
+
command -v jq >/dev/null 2>&1 || { echo "review-stage-test: jq absent — skipping"; exit 0; }
|
|
15
|
+
|
|
16
|
+
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
|
17
|
+
# Point the receipt store at the temp dir BEFORE sourcing, so nothing writes into the real .cckit/.
|
|
18
|
+
export KIT_STATE_DIR="$tmp/state"
|
|
19
|
+
# shellcheck source=/dev/null
|
|
20
|
+
source "$ROOT/scripts/lib/review-stage.sh"
|
|
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
|
+
rc() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> rc '[$2]' want '[$3]'"; fail=1; fi; }
|
|
25
|
+
has(){ case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> '[$2]' lacks '$3'"; fail=1 ;; esac; }
|
|
26
|
+
|
|
27
|
+
CFG="$tmp/kit.config.json"
|
|
28
|
+
cat > "$CFG" <<'JSON'
|
|
29
|
+
{
|
|
30
|
+
"review": { "command": "cat > /dev/null; printf 'outcome: pr-open\nurl: u\ngate: pass — read the diff\nblocker: none\nnext stage: none\n'" },
|
|
31
|
+
"agents": {
|
|
32
|
+
"default": "builder",
|
|
33
|
+
"profiles": {
|
|
34
|
+
"builder": { "kind": "claude", "stages": ["build"], "write": true },
|
|
35
|
+
"critic": { "kind": "codex", "stages": ["review"], "tier": "low" },
|
|
36
|
+
"writer": { "kind": "claude", "stages": ["review"], "write": true }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
JSON
|
|
41
|
+
|
|
42
|
+
# ── the off switch ─────────────────────────────────────────────────────────────────────────────
|
|
43
|
+
echo '{}' > "$tmp/none.json"
|
|
44
|
+
t "no review.command is empty" "$(rs_command "$tmp/none.json")" ""
|
|
45
|
+
rs_enabled "$tmp/none.json"; rc "a config with no review.command is off" "$?" "1"
|
|
46
|
+
rs_enabled "$CFG"; rc "a configured command is on" "$?" "0"
|
|
47
|
+
t "a missing config file is empty" "$(rs_command "$tmp/absent.json")" ""
|
|
48
|
+
|
|
49
|
+
# ── when a PR earns a reviewer (pure) ──────────────────────────────────────────────────────────
|
|
50
|
+
rs_needs_dispatch CLEAN merge 0; rc "a mergeable PR with no receipt gets one" "$?" "0"
|
|
51
|
+
rs_needs_dispatch CLEAN merge 1; rc "a PR already reviewed does not" "$?" "1"
|
|
52
|
+
rs_needs_dispatch CHECKS_MISSING verify 0; rc "a PR still verifying does not" "$?" "1"
|
|
53
|
+
rs_needs_dispatch HELD hold 0; rc "a PR held by a policy floor does not" "$?" "1"
|
|
54
|
+
rs_needs_dispatch CONFLICTING rebase 0; rc "a conflicting PR does not" "$?" "1"
|
|
55
|
+
rs_needs_dispatch '' '' 0; rc "an empty state and action does not" "$?" "1"
|
|
56
|
+
|
|
57
|
+
# The deadlock (#351 review). REVIEW_MISSING is `verify`, not `merge`: a merge-only predicate meant
|
|
58
|
+
# that once review.command turned the requirement on, the FIRST pass classified every unreviewed PR
|
|
59
|
+
# REVIEW_MISSING, the reviewer never ran, and the PR sat at `verify` for good.
|
|
60
|
+
rs_needs_dispatch REVIEW_MISSING verify 0; rc "a PR blocked ON the missing review gets one" "$?" "0"
|
|
61
|
+
# Unless it already has a verdict — then REVIEW_MISSING means the verdict is stale, and a receipt
|
|
62
|
+
# the head check rejected sets have=0, so this case only arises from a caller that lost track.
|
|
63
|
+
rs_needs_dispatch REVIEW_MISSING verify 1; rc "but never twice for the same verdict" "$?" "1"
|
|
64
|
+
# A recorded FAIL is not re-reviewed on its own: the author acts on it and pushes, which changes the
|
|
65
|
+
# head, which makes the verdict stale, which is what earns the next review.
|
|
66
|
+
rs_needs_dispatch REVIEW_FAILING fix 1; rc "a failing review is not re-run" "$?" "1"
|
|
67
|
+
|
|
68
|
+
# The display placeholder must never reach receipt storage.
|
|
69
|
+
t "a real issue number passes through" "$(rs_issue_num 42)" "42"
|
|
70
|
+
t "the em-dash placeholder is empty" "$(rs_issue_num '—')" ""
|
|
71
|
+
t "an empty field stays empty" "$(rs_issue_num '')" ""
|
|
72
|
+
t "a non-numeric field is empty" "$(rs_issue_num 'main')" ""
|
|
73
|
+
|
|
74
|
+
# ── the brief carries its three invariants ─────────────────────────────────────────────────────
|
|
75
|
+
b="$(rs_brief 'o/r' 7 42)"
|
|
76
|
+
has "the brief says no human is there" "$b" "HEADLESS"
|
|
77
|
+
has "the brief forbids writing" "$b" "READ ONLY"
|
|
78
|
+
has "the brief names the PR" "$b" "pull request #7"
|
|
79
|
+
has "the brief names the issue" "$b" "issue #42"
|
|
80
|
+
# Without the closing block in sr_parse's shape, sr_record finds no outcome: and refuses the report.
|
|
81
|
+
for f in "outcome:" "gate:" "blocker:" "next stage:"; do
|
|
82
|
+
has "the brief spells out '$f'" "$b" "$f"
|
|
83
|
+
done
|
|
84
|
+
# The brief must offer words sr_invalid_fields accepts. Telling a reviewer to say `shipped` records
|
|
85
|
+
# a receipt flagged invalid — recorded, but carrying a flag the captain then has to interpret.
|
|
86
|
+
for w in pr-open blocked pass fail; do
|
|
87
|
+
has "the brief offers the real vocabulary word '$w'" "$b" "$w"
|
|
88
|
+
done
|
|
89
|
+
|
|
90
|
+
# ── dispatch ───────────────────────────────────────────────────────────────────────────────────
|
|
91
|
+
# The mirror is a network call. Off for the run so nothing here touches GitHub; the cases at the end
|
|
92
|
+
# assert that a dispatch still records a verdict with the mirror unavailable.
|
|
93
|
+
export CCKIT_RECEIPT_REMOTE=0
|
|
94
|
+
# ap_pr_context is the gh half; agent-resolve-test.sh covers it. Here it is fixed so the rest is real.
|
|
95
|
+
FX_CTX="42\t\t"
|
|
96
|
+
ap_pr_context() { printf "$FX_CTX\n"; }
|
|
97
|
+
|
|
98
|
+
rs_dispatch "$tmp/none.json" 'o/r' 7 42 >/dev/null 2>&1
|
|
99
|
+
rc "no configured command dispatches nothing" "$?" "4"
|
|
100
|
+
|
|
101
|
+
rs_dispatch "$CFG" 'o/r' 7 '' >/dev/null 2>&1
|
|
102
|
+
rc "a PR with no linked issue is refused" "$?" "2"
|
|
103
|
+
|
|
104
|
+
# agents.default is `builder`, which does not list the review stage — a build agent must not be
|
|
105
|
+
# handed a review just because it is the default.
|
|
106
|
+
rs_dispatch "$CFG" 'o/r' 7 42 >/dev/null 2>&1
|
|
107
|
+
rc "a default barred from the review stage refuses" "$?" "2"
|
|
108
|
+
|
|
109
|
+
# An agent: label naming a review profile that CAN write is refused before it ever runs.
|
|
110
|
+
FX_CTX="42\tagent:writer\t"
|
|
111
|
+
rs_dispatch "$CFG" 'o/r' 7 42 >/dev/null 2>&1
|
|
112
|
+
rc "a write:true review profile is refused" "$?" "2"
|
|
113
|
+
|
|
114
|
+
# The real path: a read-only review profile, the configured command, a receipt on disk.
|
|
115
|
+
FX_CTX="42\tagent:critic\t"
|
|
116
|
+
p="$(rs_dispatch "$CFG" 'o/r' 7 42)"
|
|
117
|
+
rc "a read-only review profile dispatches" "$?" "0"
|
|
118
|
+
[ -f "$p" ] && echo "ok: the receipt exists on disk" || { echo "FAIL: no receipt at '$p'"; fail=1; }
|
|
119
|
+
t "the receipt is at stage review" "$(jq -r .stage "$p")" "review"
|
|
120
|
+
t "the receipt names the profile" "$(jq -r .profile "$p")" "critic"
|
|
121
|
+
t "the receipt records the verdict" "$(jq -r .outcome "$p")" "pr-open"
|
|
122
|
+
t "the receipt records the gate" "$(jq -r .gate "$p" | cut -d' ' -f1)" "pass"
|
|
123
|
+
t "the receipt records read-only" "$(jq -r .permissions "$p")" "read-only"
|
|
124
|
+
t "the receipt names the issue" "$(jq -r .issue "$p")" "42"
|
|
125
|
+
t "nothing is flagged invalid" "$(jq -r '.invalid | length' "$p")" "0"
|
|
126
|
+
|
|
127
|
+
# The receipt is now findable, which is what closes the dispatch loop: a second pass must not
|
|
128
|
+
# re-review a PR that already has a verdict.
|
|
129
|
+
rs_have_receipt 42; rc "the verdict is findable afterwards" "$?" "0"
|
|
130
|
+
rs_have_receipt 99; rc "an unreviewed issue has none" "$?" "1"
|
|
131
|
+
have=0; rs_have_receipt 42 && have=1
|
|
132
|
+
rs_needs_dispatch CLEAN merge "$have"; rc "a reviewed PR is not dispatched twice" "$?" "1"
|
|
133
|
+
|
|
134
|
+
# A command that exits non-zero writes NO receipt — a failed reviewer must not look like a verdict.
|
|
135
|
+
cat > "$tmp/fail.json" <<'JSON'
|
|
136
|
+
{ "review": { "command": "exit 9" },
|
|
137
|
+
"agents": { "default": "critic",
|
|
138
|
+
"profiles": { "critic": { "kind": "codex", "stages": ["review"] } } } }
|
|
139
|
+
JSON
|
|
140
|
+
before="$(ls "$KIT_STATE_DIR/receipts" 2>/dev/null | wc -l | tr -d ' ')"
|
|
141
|
+
rs_dispatch "$tmp/fail.json" 'o/r' 8 55 >/dev/null 2>&1
|
|
142
|
+
rc "a failing review command is rc 3" "$?" "3"
|
|
143
|
+
t "a failing review command writes no receipt" \
|
|
144
|
+
"$(ls "$KIT_STATE_DIR/receipts" 2>/dev/null | wc -l | tr -d ' ')" "$before"
|
|
145
|
+
|
|
146
|
+
# A command that succeeds but reports nothing parseable is sr_record's refusal, not a silent pass.
|
|
147
|
+
cat > "$tmp/mute.json" <<'JSON'
|
|
148
|
+
{ "review": { "command": "cat > /dev/null; echo 'looks fine to me'" },
|
|
149
|
+
"agents": { "default": "critic",
|
|
150
|
+
"profiles": { "critic": { "kind": "codex", "stages": ["review"] } } } }
|
|
151
|
+
JSON
|
|
152
|
+
rs_dispatch "$tmp/mute.json" 'o/r' 8 55 >/dev/null 2>&1
|
|
153
|
+
rc "a report with no outcome: line is refused" "$?" "2"
|
|
154
|
+
t "and it writes no receipt either" \
|
|
155
|
+
"$(ls "$KIT_STATE_DIR/receipts" 2>/dev/null | wc -l | tr -d ' ')" "$before"
|
|
156
|
+
|
|
157
|
+
# ── the mirror never costs the verdict (#347) ──────────────────────────────────────────────────
|
|
158
|
+
# sr_mirror is best-effort: an unmirrored receipt is still the receipt the merge gate reads. Failing
|
|
159
|
+
# a dispatch on an offline mirror would stall every PR at `verify` over a visibility problem.
|
|
160
|
+
FX_CTX="42\tagent:critic\t"
|
|
161
|
+
# NOT a command substitution: SR_MIRROR_LAST_RESULT is set by sr_mirror in whatever shell runs it,
|
|
162
|
+
# and `$(rs_dispatch …)` would set it in a subshell that then exits. Redirect to a file instead.
|
|
163
|
+
rs_dispatch "$CFG" 'o/r' 7 42 > "$tmp/p2"
|
|
164
|
+
rc "a dispatch succeeds with the mirror off" "$?" "0"
|
|
165
|
+
p2="$(cat "$tmp/p2")"
|
|
166
|
+
t "sr_mirror reported why it did not post" "$SR_MIRROR_LAST_RESULT" "no-remote"
|
|
167
|
+
[ -f "$p2" ] && echo "ok: the receipt is on disk anyway" || { echo "FAIL: no receipt at '$p2'"; fail=1; }
|
|
168
|
+
t "and it is a second attempt, not an overwrite" "$(jq -r .attempt "$p2")" "2"
|
|
169
|
+
[ "$p2" != "$p" ] && echo "ok: the two attempts are separate files" || { echo "FAIL: attempt 2 reused $p"; fail=1; }
|
|
170
|
+
|
|
171
|
+
# ── the PR review findings (#351) ──────────────────────────────────────────────────────────────
|
|
172
|
+
|
|
173
|
+
# The timeout bound. review.timeoutSeconds, with a default and a refusal to honour "no limit".
|
|
174
|
+
t "the default bound is 900s" "$(rs_timeout "$CFG")" "900"
|
|
175
|
+
cat > "$tmp/to.json" <<'JSON'
|
|
176
|
+
{ "review": { "command": "true", "timeoutSeconds": 30 } }
|
|
177
|
+
JSON
|
|
178
|
+
t "a configured bound is used" "$(rs_timeout "$tmp/to.json")" "30"
|
|
179
|
+
cat > "$tmp/tobad.json" <<'JSON'
|
|
180
|
+
{ "review": { "command": "true", "timeoutSeconds": "none" } }
|
|
181
|
+
JSON
|
|
182
|
+
# "none" reads like a request for NO limit. Honouring it would hand an unattended captain the hang
|
|
183
|
+
# the bound exists to prevent, so it falls back to the default instead.
|
|
184
|
+
t "a non-numeric bound falls back" "$(rs_timeout "$tmp/tobad.json" 2>/dev/null)" "900"
|
|
185
|
+
cat > "$tmp/tozero.json" <<'JSON'
|
|
186
|
+
{ "review": { "command": "true", "timeoutSeconds": 0 } }
|
|
187
|
+
JSON
|
|
188
|
+
t "a zero bound falls back" "$(rs_timeout "$tmp/tozero.json" 2>/dev/null)" "900"
|
|
189
|
+
|
|
190
|
+
# _rs_run actually kills a hung command, on whichever path this system takes.
|
|
191
|
+
start=$(date +%s)
|
|
192
|
+
printf 'ignored
|
|
193
|
+
' | _rs_run 2 'sleep 60' >/dev/null 2>&1
|
|
194
|
+
rc "a command past its bound is rc 124" "$?" "124"
|
|
195
|
+
elapsed=$(( $(date +%s) - start ))
|
|
196
|
+
[ "$elapsed" -lt 30 ] && echo "ok: it was killed in ${elapsed}s, not left running" \
|
|
197
|
+
|| { echo "FAIL: still ran ${elapsed}s after a 2s bound"; fail=1; }
|
|
198
|
+
t "a command inside its bound returns its output" "$(printf '' | _rs_run 10 'echo alive' 2>/dev/null)" "alive"
|
|
199
|
+
printf '' | _rs_run 10 'exit 7' >/dev/null 2>&1
|
|
200
|
+
rc "a command's own exit code survives" "$?" "7"
|
|
201
|
+
|
|
202
|
+
# A dispatch whose reviewer hangs writes NO receipt — a killed reviewer is not a verdict.
|
|
203
|
+
cat > "$tmp/hang.json" <<'JSON'
|
|
204
|
+
{ "review": { "command": "sleep 60", "timeoutSeconds": 2 },
|
|
205
|
+
"agents": { "default": "critic",
|
|
206
|
+
"profiles": { "critic": { "kind": "codex", "stages": ["review"] } } } }
|
|
207
|
+
JSON
|
|
208
|
+
FX_CTX="77\t\t"
|
|
209
|
+
before2="$(ls "$KIT_STATE_DIR/receipts" 2>/dev/null | wc -l | tr -d ' ')"
|
|
210
|
+
rs_dispatch "$tmp/hang.json" 'o/r' 9 77 >/dev/null 2>&1
|
|
211
|
+
rc "a hung reviewer is rc 3" "$?" "3"
|
|
212
|
+
t "a hung reviewer writes no receipt" \
|
|
213
|
+
"$(ls "$KIT_STATE_DIR/receipts" 2>/dev/null | wc -l | tr -d ' ')" "$before2"
|
|
214
|
+
|
|
215
|
+
# The resolved profile reaches the command. Without this an agent: label named a profile that only
|
|
216
|
+
# labelled the receipt, while the fixed command ran something else.
|
|
217
|
+
cat > "$tmp/env.json" <<'JSON'
|
|
218
|
+
{ "review": { "command": "cat > /dev/null; printf 'outcome: pr-open\nurl: u\ngate: pass — %s/%s\nblocker: none\nnext stage: none\n' $CCKIT_REVIEW_PROFILE $CCKIT_REVIEW_KIND" },
|
|
219
|
+
"agents": { "default": "critic",
|
|
220
|
+
"profiles": { "critic": { "kind": "codex", "stages": ["review"] } } } }
|
|
221
|
+
JSON
|
|
222
|
+
FX_CTX="78\t\t"
|
|
223
|
+
pe="$(rs_dispatch "$tmp/env.json" 'o/r' 9 78)"
|
|
224
|
+
t "the command sees the resolved profile and kind" \
|
|
225
|
+
"$(jq -r .gate "$pe" | sed 's/^pass — //')" "critic/codex"
|
|
226
|
+
|
|
227
|
+
# head_sha binds a verdict to a revision (the stale-PASS hole).
|
|
228
|
+
FX_CTX="80\tagent:critic\t"
|
|
229
|
+
ph="$(rs_dispatch "$CFG" 'o/r' 9 80 'abc123')"
|
|
230
|
+
t "the receipt records the head it reviewed" "$(jq -r .head_sha "$ph")" "abc123"
|
|
231
|
+
rs_have_receipt 80 'abc123'; rc "the verdict counts for that head" "$?" "0"
|
|
232
|
+
rs_have_receipt 80 'def456'; rc "it does NOT count for a later commit" "$?" "1"
|
|
233
|
+
rs_have_receipt 80; rc "with no head given, the issue alone counts" "$?" "0"
|
|
234
|
+
|
|
235
|
+
# A receipt written before head_sha existed has an empty field. Asked about a head it cannot match,
|
|
236
|
+
# it reads as absent — which is correct, and is why the gate skips the check on an empty head.
|
|
237
|
+
rs_have_receipt 42 'abc123'; rc "a head-less receipt does not cover a head" "$?" "1"
|
|
238
|
+
rs_have_receipt 42; rc "but still counts when no head is asked" "$?" "0"
|
|
239
|
+
|
|
240
|
+
[ "$fail" -eq 0 ] && echo "review-stage-test: PASS" || echo "review-stage-test: FAILED"
|
|
241
|
+
exit "$fail"
|