@feigi/fleet-ctl 0.0.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 +9 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/agents/fleet-finisher.agent.md +7 -0
- package/agents/fleet-implementer-alt.agent.md +210 -0
- package/agents/fleet-implementer.agent.md +210 -0
- package/agents/fleet-merge-bot.agent.md +7 -0
- package/agents/fleet-review-comments.agent.md +40 -0
- package/agents/fleet-review-correctness.agent.md +43 -0
- package/agents/fleet-review-runner.agent.md +73 -0
- package/agents/fleet-review-silent-failure.agent.md +49 -0
- package/agents/fleet-review-simplify.agent.md +46 -0
- package/agents/fleet-review-snapshot.agent.md +24 -0
- package/agents/fleet-review-tests.agent.md +46 -0
- package/agents/fleet-review-types.agent.md +41 -0
- package/agents/fleet-review-verifier.agent.md +29 -0
- package/commands/review-and-fix.md +98 -0
- package/commands/run-merge-bot.md +357 -0
- package/commands/run-team-help.md +17 -0
- package/package.json +23 -0
- package/scripts/agent-test-dir-prose.test.mjs +59 -0
- package/scripts/agent-test.test.mjs +1636 -0
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
- package/scripts/ambient-git-vars-prose.test.mjs +192 -0
- package/scripts/ancestry-check-position-prose.test.mjs +175 -0
- package/scripts/apply-ruleset.test.mjs +420 -0
- package/scripts/arg-header-probes-prose.test.mjs +393 -0
- package/scripts/arg.mjs +600 -0
- package/scripts/arg.test.mjs +1354 -0
- package/scripts/board-cli.test.mjs +694 -0
- package/scripts/board-identity.test.mjs +429 -0
- package/scripts/board-liveness-banner.test.mjs +119 -0
- package/scripts/board-prev-shape.test.mjs +229 -0
- package/scripts/board-tryparse-null.test.mjs +119 -0
- package/scripts/board.html +471 -0
- package/scripts/board.mjs +2037 -0
- package/scripts/board.test.mjs +3086 -0
- package/scripts/brief-after-cut-prose.test.mjs +53 -0
- package/scripts/candidates-exit3-prose.test.mjs +302 -0
- package/scripts/candidates.mjs +674 -0
- package/scripts/candidates.test.mjs +2101 -0
- package/scripts/caveat-unification-prose.test.mjs +98 -0
- package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
- package/scripts/ci-completes-premise-prose.test.mjs +257 -0
- package/scripts/ci-state-prose.test.mjs +113 -0
- package/scripts/ci-state.mjs +761 -0
- package/scripts/ci-state.test.mjs +1640 -0
- package/scripts/ci-vacuous-green.test.mjs +368 -0
- package/scripts/citation-sweep-prose.test.mjs +1572 -0
- package/scripts/claim-lifecycle.test.mjs +185 -0
- package/scripts/claim-ticket.sh +417 -0
- package/scripts/claim-ticket.test.mjs +1121 -0
- package/scripts/closing-keyword-prose.test.mjs +193 -0
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
- package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
- package/scripts/compute-board.mjs +579 -0
- package/scripts/compute-board.test.mjs +1060 -0
- package/scripts/compute-spend.mjs +329 -0
- package/scripts/compute-spend.test.mjs +451 -0
- package/scripts/cross-repo-citation-prose.test.mjs +156 -0
- package/scripts/cwd-isolation-pins.mjs +83 -0
- package/scripts/dedupe-guard-prose.test.mjs +243 -0
- package/scripts/derive-testcmd.sh +239 -0
- package/scripts/derive-testcmd.test.mjs +380 -0
- package/scripts/diff-stats.mjs +231 -0
- package/scripts/diff-stats.test.mjs +408 -0
- package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
- package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
- package/scripts/drop-merged-label.sh +173 -0
- package/scripts/drop-merged-label.test.mjs +480 -0
- package/scripts/expected-jobs-prose.test.mjs +80 -0
- package/scripts/filing-bar-seat-prose.test.mjs +242 -0
- package/scripts/filing-claim-bar-prose.test.mjs +166 -0
- package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
- package/scripts/finisher-halt-prose.test.mjs +106 -0
- package/scripts/finisher-name-prose.test.mjs +134 -0
- package/scripts/finisher-own-tree-prose.test.mjs +285 -0
- package/scripts/finisher-pin-race-prose.test.mjs +339 -0
- package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
- package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
- package/scripts/fleet-bootstrap +155 -0
- package/scripts/fleet-heartbeat.mjs +272 -0
- package/scripts/fleet-heartbeat.test.mjs +450 -0
- package/scripts/fleet-provenance +207 -0
- package/scripts/fleet-provenance.test.mjs +64 -0
- package/scripts/fleet-run +148 -0
- package/scripts/fleet-run.test.mjs +90 -0
- package/scripts/fleet-state.mjs +400 -0
- package/scripts/fleet-state.test.mjs +373 -0
- package/scripts/fleet-tick-prose.test.mjs +299 -0
- package/scripts/fleet-tick.mjs +832 -0
- package/scripts/fleet-tick.test.mjs +1332 -0
- package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
- package/scripts/frontmatter-allowlist.json +64 -0
- package/scripts/frontmatter-check.mjs +256 -0
- package/scripts/frontmatter-check.test.mjs +436 -0
- package/scripts/git-env.mjs +124 -0
- package/scripts/git-env.test.mjs +149 -0
- package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
- package/scripts/gone-walk.test.mjs +213 -0
- package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
- package/scripts/head-moved-after-label-prose.test.mjs +233 -0
- package/scripts/immutable-body-claim-prose.test.mjs +413 -0
- package/scripts/implementer-model-tier.test.mjs +643 -0
- package/scripts/inflight-citation-prose.test.mjs +144 -0
- package/scripts/inflight-exit2-prose.test.mjs +81 -0
- package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
- package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
- package/scripts/inflight.sh +1106 -0
- package/scripts/inflight.test.mjs +2984 -0
- package/scripts/injection-control-prose.test.mjs +404 -0
- package/scripts/install-root-audit.test.mjs +464 -0
- package/scripts/instrument-check-prose.test.mjs +235 -0
- package/scripts/instruments.sh +394 -0
- package/scripts/instruments.test.mjs +787 -0
- package/scripts/issue-tracker-prose.test.mjs +71 -0
- package/scripts/json.sh +248 -0
- package/scripts/json.test.mjs +364 -0
- package/scripts/ledger-dispatch.test.mjs +516 -0
- package/scripts/ledger-grammar.mjs +85 -0
- package/scripts/ledger-grammar.test.mjs +142 -0
- package/scripts/ledger-read-require-file.test.mjs +197 -0
- package/scripts/ledger.mjs +1753 -0
- package/scripts/ledger.test.mjs +3554 -0
- package/scripts/line-distance-prose.test.mjs +245 -0
- package/scripts/liveness-rationale-prose.test.mjs +83 -0
- package/scripts/locale-pin-prose.test.mjs +189 -0
- package/scripts/member-outcome-prose.test.mjs +167 -0
- package/scripts/member-outcomes-header.test.mjs +148 -0
- package/scripts/member-outcomes-prose.test.mjs +63 -0
- package/scripts/member-outcomes.mjs +231 -0
- package/scripts/member-outcomes.test.mjs +507 -0
- package/scripts/member-prompt-prose.test.mjs +161 -0
- package/scripts/member-record.mjs +605 -0
- package/scripts/member-record.test.mjs +516 -0
- package/scripts/member-write-guard.mjs +279 -0
- package/scripts/member-write-guard.test.mjs +211 -0
- package/scripts/merge-commit-probe-prose.test.mjs +122 -0
- package/scripts/merge-gate.mjs +262 -0
- package/scripts/merge-gate.test.mjs +613 -0
- package/scripts/muted-git-guard-sweep.test.mjs +493 -0
- package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
- package/scripts/net-watchdog-prose.test.mjs +79 -0
- package/scripts/net.sh +409 -0
- package/scripts/net.test.mjs +211 -0
- package/scripts/no-ci-gate-prose.test.mjs +108 -0
- package/scripts/no-undo-audit.sh +1134 -0
- package/scripts/no-undo-audit.test.mjs +3965 -0
- package/scripts/no-wave.test.mjs +138 -0
- package/scripts/node-floor-sweep.test.mjs +611 -0
- package/scripts/pointer-target-prose.test.mjs +186 -0
- package/scripts/pr-overlap.mjs +417 -0
- package/scripts/pr-overlap.test.mjs +695 -0
- package/scripts/printf-die-sweep.test.mjs +384 -0
- package/scripts/prompt-renderer.mjs +39 -0
- package/scripts/prompt-renderer.test.mjs +68 -0
- package/scripts/prose-pin.mjs +808 -0
- package/scripts/prose-pin.test.mjs +1034 -0
- package/scripts/prove-merge.sh +228 -0
- package/scripts/prove-merge.test.mjs +995 -0
- package/scripts/pull-table-relabel-prose.test.mjs +60 -0
- package/scripts/quiet-payload-prose.test.mjs +222 -0
- package/scripts/reap.sh +1768 -0
- package/scripts/reap.test.mjs +4395 -0
- package/scripts/reaping-prose.test.mjs +159 -0
- package/scripts/refuter-scratch-prose.test.mjs +135 -0
- package/scripts/release-label-required-prose.test.mjs +71 -0
- package/scripts/release-label-split-prose.test.mjs +169 -0
- package/scripts/release-ticket.sh +1716 -0
- package/scripts/release-ticket.test.mjs +5106 -0
- package/scripts/renovate-release-contract.test.mjs +379 -0
- package/scripts/repo-root.mjs +544 -0
- package/scripts/repo-root.test.mjs +873 -0
- package/scripts/reporter-output-rule-prose.test.mjs +208 -0
- package/scripts/review-agent-report-only.test.mjs +49 -0
- package/scripts/review-core-cwd-isolation.test.mjs +374 -0
- package/scripts/review-core-reads.test.mjs +478 -0
- package/scripts/review-core-refuter-scratch.test.mjs +148 -0
- package/scripts/review-core-snapshot-path.test.mjs +777 -0
- package/scripts/review-core-specialist-scratch.test.mjs +189 -0
- package/scripts/review-core-testcmd.test.mjs +288 -0
- package/scripts/review-core-unrun.test.mjs +530 -0
- package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
- package/scripts/review-core.mjs +1028 -0
- package/scripts/review-eval-resolver-path.test.mjs +55 -0
- package/scripts/review-eval.mjs +197 -0
- package/scripts/review-host-fixture.mjs +73 -0
- package/scripts/review-in-run-retry.test.mjs +187 -0
- package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
- package/scripts/review-path-default.test.mjs +796 -0
- package/scripts/review-runner-spawns.test.mjs +93 -0
- package/scripts/review-runner.test.mjs +155 -0
- package/scripts/review-tier-audit.test.mjs +140 -0
- package/scripts/run-artifact-pr-prose.test.mjs +341 -0
- package/scripts/run-merge-bot-prose.test.mjs +1391 -0
- package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
- package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
- package/scripts/section-between-guard-prose.test.mjs +378 -0
- package/scripts/select-dimensions.test.mjs +674 -0
- package/scripts/shared-refusal.test.mjs +388 -0
- package/scripts/shell-traps-prose.test.mjs +507 -0
- package/scripts/shortlist.mjs +355 -0
- package/scripts/shortlist.test.mjs +366 -0
- package/scripts/slow-transport.mjs +72 -0
- package/scripts/snapshot-repo.test.mjs +772 -0
- package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
- package/scripts/spend-view.test.mjs +312 -0
- package/scripts/staleness-qualifier-prose.test.mjs +251 -0
- package/scripts/staleness-verdict-prose.test.mjs +142 -0
- package/scripts/staleness.mjs +414 -0
- package/scripts/staleness.test.mjs +893 -0
- package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
- package/scripts/stash-prohibition-prose.test.mjs +313 -0
- package/scripts/strip-comments.mjs +44 -0
- package/scripts/tier-check.mjs +468 -0
- package/scripts/tier-check.test.mjs +726 -0
- package/scripts/tier-guard-gate-prose.test.mjs +216 -0
- package/scripts/tier-outcomes-header.test.mjs +586 -0
- package/scripts/tier-outcomes.mjs +441 -0
- package/scripts/tier-outcomes.test.mjs +342 -0
- package/scripts/tier-roles.mjs +250 -0
- package/scripts/tier-roles.test.mjs +316 -0
- package/scripts/tracker-block-copy-prose.test.mjs +288 -0
- package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
- package/scripts/unattended-git-sweep.test.mjs +142 -0
- package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
- package/scripts/verify-sha.sh +117 -0
- package/scripts/verify-sha.test.mjs +693 -0
- package/scripts/watcher-degraded-block.test.mjs +372 -0
- package/scripts/watcher-key-prose.test.mjs +106 -0
- package/scripts/within-run-pair-prose.test.mjs +208 -0
- package/scripts/worktree-audit.sh +482 -0
- package/scripts/worktree-audit.test.mjs +1407 -0
- package/scripts/worktree-head-prose.test.mjs +276 -0
- package/scripts/worktree-listing-sweep.test.mjs +217 -0
- package/scripts/worktree-model-prose.test.mjs +216 -0
- package/scripts/worktree.sh +470 -0
- package/skills/next-ticket/SKILL.md +138 -0
- package/skills/run-team/SKILL.md +3603 -0
- package/skills/run-team/references/ci-and-staleness.md +75 -0
- package/skills/run-team/references/correction-tickets.md +37 -0
- package/skills/run-team/references/isolation.md +23 -0
- package/skills/run-team/references/member-lifecycle.md +73 -0
- package/skills/run-team/references/reaping.md +73 -0
- package/skills/sizing-a-ticket/SKILL.md +39 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Drop `in-progress` from every issue a merged PR closes. claim-ticket.sh adds
|
|
3
|
+
# the label, release-ticket.sh drops it on a bail (CONTEXT.md's Release: "a
|
|
4
|
+
# claim that never became" a PR). This is neither Release nor Reap
|
|
5
|
+
# (CONTEXT.md's Reap is branches and worktrees, not the label) — a third,
|
|
6
|
+
# merge-triggered step in the claim lifecycle CONTEXT.md does not yet name.
|
|
7
|
+
# #170.
|
|
8
|
+
#
|
|
9
|
+
# Single writer, per the #170 ruling: the merge is the only moment the ticket
|
|
10
|
+
# number and the fact of completion are known together, so only a PROVEN merge
|
|
11
|
+
# triggers this — never reap (branches, not tickets), never a repo automation
|
|
12
|
+
# (no attribution). Call this from run-merge-bot.md's step 4, after
|
|
13
|
+
# prove-merge.sh, never before: the claim has not ended until the merge lands.
|
|
14
|
+
#
|
|
15
|
+
# #1617: `closingIssuesReferences` reflects `Closes #N` syntax in the PR's own
|
|
16
|
+
# title/body, but NOT a commit-message-only reference — GitHub's real
|
|
17
|
+
# merge-time closer honors the latter (confirmed via the issue's own
|
|
18
|
+
# timeline), this field never does, even after the merge. This script unions
|
|
19
|
+
# both signals (see the commit-message scan below) so a real close is never
|
|
20
|
+
# missed just because the keyword only ever lived in a commit message.
|
|
21
|
+
#
|
|
22
|
+
# Dry-run by default; --apply mutates the tracker. Exit 0 done (or dry run),
|
|
23
|
+
# 1 one or more removals failed — REPORT THIS, never swallow it: a merged
|
|
24
|
+
# ticket that keeps the label is a future invisible ticket, 2 could not even
|
|
25
|
+
# tell what this PR closes.
|
|
26
|
+
set -eu
|
|
27
|
+
|
|
28
|
+
NAME=drop-merged-label
|
|
29
|
+
die() { printf '%s: %s\n' "$NAME" "$1" >&2; exit 2; }
|
|
30
|
+
|
|
31
|
+
[ $# -ge 1 ] && [ $# -le 2 ] || die "usage: drop-merged-label.sh <pr> [--apply]"
|
|
32
|
+
pr=$1
|
|
33
|
+
case "$pr" in ''|*[!0-9]*|0?*) die "pr must be a number, got '$pr'";; esac
|
|
34
|
+
case "${2:-}" in
|
|
35
|
+
''|--apply) ;;
|
|
36
|
+
*) die "unknown argument '$2' — the only option is --apply";;
|
|
37
|
+
esac
|
|
38
|
+
apply=false
|
|
39
|
+
[ "${2:-}" = "--apply" ] && apply=true
|
|
40
|
+
|
|
41
|
+
# MERGED, not just "closed" — a PR closed without merging must never reach the
|
|
42
|
+
# loop below. Reading state before closingIssuesReferences means this refusal
|
|
43
|
+
# fires before either call that follows can hand the caller anything to act on.
|
|
44
|
+
echo "\$ gh pr view $pr --json state --jq .state" >&2
|
|
45
|
+
if ! state=$(gh pr view "$pr" --json state --jq .state); then
|
|
46
|
+
die "gh pr view $pr failed — cannot tell whether it merged"
|
|
47
|
+
fi
|
|
48
|
+
[ "$state" = "MERGED" ] || die "PR #$pr is not merged (state=$state) — refusing to touch its issues"
|
|
49
|
+
|
|
50
|
+
echo "\$ gh pr view $pr --json closingIssuesReferences --jq '.closingIssuesReferences[].number'" >&2
|
|
51
|
+
if ! issues=$(gh pr view "$pr" --json closingIssuesReferences --jq '.closingIssuesReferences[].number'); then
|
|
52
|
+
die "gh pr view $pr failed — cannot read which issues it closes"
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# #1617: the query above misses a commit-message-only close. Scan every
|
|
56
|
+
# commit's own headline+body for the same close/fix/resolve keyword forms
|
|
57
|
+
# GitHub's real closer recognizes, and union the result into `$issues` — the
|
|
58
|
+
# set of issues this PR is proven to close, so the check below acts on
|
|
59
|
+
# either signal.
|
|
60
|
+
echo "\$ gh pr view $pr --json commits --jq '[.commits[]|(.messageHeadline//\"\")+\"\\n\"+(.messageBody//\"\")]|join(\"\\n\")'" >&2
|
|
61
|
+
if ! commit_text=$(gh pr view "$pr" --json commits --jq '[.commits[] | (.messageHeadline // "") + "\n" + (.messageBody // "")] | join("\n")'); then
|
|
62
|
+
die "gh pr view $pr failed — cannot scan its commit messages for issue closes"
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
# Same three-outcome discipline as the label scan below (#1543): rc 1 (no
|
|
66
|
+
# keyword anywhere in any commit) must read as zero commit-closed issues,
|
|
67
|
+
# never conflated with rc 2+ (the scan itself broke), which must halt loudly
|
|
68
|
+
# instead of silently behaving like "commits close nothing".
|
|
69
|
+
# The leading `(^|[^[:alnum:]_])` requires a non-word character (or line
|
|
70
|
+
# start) immediately before the keyword, so "bugfix #77" or "prefix #88"
|
|
71
|
+
# never read as closing #77/#88 just because "fix" is a substring of a
|
|
72
|
+
# larger word — only a real close/fix/resolve keyword counts.
|
|
73
|
+
if matched=$(printf '%s\n' "$commit_text" | grep -Eio '(^|[^[:alnum:]_])(close[sd]?|fix(e[sd])?|resolve[sd]?)[[:space:]]*#[0-9]+'); then
|
|
74
|
+
commit_grep_rc=0
|
|
75
|
+
else
|
|
76
|
+
commit_grep_rc=$?
|
|
77
|
+
fi
|
|
78
|
+
case $commit_grep_rc in
|
|
79
|
+
0)
|
|
80
|
+
if commit_issues=$(printf '%s\n' "$matched" | grep -Eo '[0-9]+'); then
|
|
81
|
+
commit_num_rc=0
|
|
82
|
+
else
|
|
83
|
+
commit_num_rc=$?
|
|
84
|
+
fi
|
|
85
|
+
[ "$commit_num_rc" = 0 ] || die "could not extract issue numbers from PR #$pr's matched commit text (grep exited $commit_num_rc)"
|
|
86
|
+
;;
|
|
87
|
+
1) commit_issues="" ;;
|
|
88
|
+
*) die "could not scan PR #$pr's commit messages for issue closes (grep exited $commit_grep_rc)" ;;
|
|
89
|
+
esac
|
|
90
|
+
|
|
91
|
+
# Union both signals through the SAME three-outcome discipline, never a bare
|
|
92
|
+
# `grep | sort`: command substitution reports only the LAST pipe stage's
|
|
93
|
+
# exit status, so `sort`'s own rc 0 would otherwise mask a grep 2+ break
|
|
94
|
+
# entirely — the exact "commits close nothing" misreading #1543 already
|
|
95
|
+
# guards against elsewhere in this file. `awk '{print $0+0}'` strips any
|
|
96
|
+
# leading zeros (#121's defect class) before the final sort, so a
|
|
97
|
+
# commit-message "#007" reaches the JSON payload below as the bare,
|
|
98
|
+
# valid-JSON integer `7` — and correctly dedupes against a plain `7` named
|
|
99
|
+
# by the other signal.
|
|
100
|
+
if union=$(printf '%s\n%s\n' "$issues" "$commit_issues" | grep -Eo '[0-9]+'); then
|
|
101
|
+
union_rc=0
|
|
102
|
+
else
|
|
103
|
+
union_rc=$?
|
|
104
|
+
fi
|
|
105
|
+
case $union_rc in
|
|
106
|
+
0) issues=$(printf '%s\n' "$union" | awk '{print $0+0}' | sort -n -u) ;;
|
|
107
|
+
1) issues="" ;;
|
|
108
|
+
*) die "could not union PR #$pr's closing issues (grep exited $union_rc)" ;;
|
|
109
|
+
esac
|
|
110
|
+
|
|
111
|
+
if [ -z "$issues" ]; then
|
|
112
|
+
echo "$NAME: PR #$pr closes no issues — nothing to drop" >&2
|
|
113
|
+
printf '{"pr":%s,"merged":true,"issues":[],"applied":%s,"failed":[]}\n' "$pr" "$apply"
|
|
114
|
+
exit 0
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
results=""
|
|
118
|
+
failed=""
|
|
119
|
+
for n in $issues; do
|
|
120
|
+
echo "\$ gh issue view $n --json labels --jq '.labels[].name'" >&2
|
|
121
|
+
if ! labels=$(gh issue view "$n" --json labels --jq '.labels[].name'); then
|
|
122
|
+
echo " #$n: could not read labels — gh issue view failed" >&2
|
|
123
|
+
failed="${failed}${n},"
|
|
124
|
+
results="${results}{\"issue\":$n,\"hadLabel\":null,\"removed\":false},"
|
|
125
|
+
continue
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
# grep's OWN scan failing (rc 2+) must not read as "no in-progress label":
|
|
129
|
+
# the same defect PR #1519 fixed in reap.sh's grep_probe (#1543). A bare
|
|
130
|
+
# `if … grep -qx …; then had=true; else had=false; fi` has room for only two
|
|
131
|
+
# of grep's three `-q` outcomes — rc 0 matched, rc 1 none did, rc 2+ the
|
|
132
|
+
# scan itself broke — so a scan that could not look would read here exactly
|
|
133
|
+
# like a measurement that looked and found the label already gone, and the
|
|
134
|
+
# loop below would skip the removal a merged ticket still needs.
|
|
135
|
+
if printf '%s\n' "$labels" | grep -qx in-progress; then gp_rc=0; else gp_rc=$?; fi
|
|
136
|
+
case $gp_rc in
|
|
137
|
+
0) had=true ;;
|
|
138
|
+
1) had=false ;;
|
|
139
|
+
*)
|
|
140
|
+
echo " #$n: could not scan its labels for in-progress (grep exited $gp_rc)" >&2
|
|
141
|
+
failed="${failed}${n},"
|
|
142
|
+
results="${results}{\"issue\":$n,\"hadLabel\":null,\"removed\":false},"
|
|
143
|
+
continue
|
|
144
|
+
;;
|
|
145
|
+
esac
|
|
146
|
+
if [ "$had" = false ]; then
|
|
147
|
+
echo " #$n: no in-progress label — already clear" >&2
|
|
148
|
+
results="${results}{\"issue\":$n,\"hadLabel\":false,\"removed\":false},"
|
|
149
|
+
continue
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
if [ "$apply" = false ]; then
|
|
153
|
+
echo " would: gh issue edit $n --remove-label in-progress" >&2
|
|
154
|
+
results="${results}{\"issue\":$n,\"hadLabel\":true,\"removed\":false},"
|
|
155
|
+
continue
|
|
156
|
+
fi
|
|
157
|
+
|
|
158
|
+
echo "\$ gh issue edit $n --remove-label in-progress" >&2
|
|
159
|
+
if gh issue edit "$n" --remove-label in-progress >/dev/null; then
|
|
160
|
+
echo " #$n: dropped in-progress" >&2
|
|
161
|
+
results="${results}{\"issue\":$n,\"hadLabel\":true,\"removed\":true},"
|
|
162
|
+
else
|
|
163
|
+
echo " #$n: FAILED to drop in-progress — invisible on reopen until retried" >&2
|
|
164
|
+
failed="${failed}${n},"
|
|
165
|
+
results="${results}{\"issue\":$n,\"hadLabel\":true,\"removed\":false},"
|
|
166
|
+
fi
|
|
167
|
+
done
|
|
168
|
+
|
|
169
|
+
printf '{"pr":%s,"merged":true,"issues":[%s],"applied":%s,"failed":[%s]}\n' \
|
|
170
|
+
"$pr" "${results%,}" "$apply" "${failed%,}"
|
|
171
|
+
|
|
172
|
+
[ -z "$failed" ] || exit 1
|
|
173
|
+
exit 0
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
// Regression gate for drop-merged-label.sh, the merge-triggered third step in
|
|
2
|
+
// the claim lifecycle (#170) — neither CONTEXT.md's Release (a claim that
|
|
3
|
+
// never became a PR) nor its Reap (branches and worktrees): claim-ticket.sh
|
|
4
|
+
// adds the label, release-ticket.sh drops it on a bail, this drops it on a
|
|
5
|
+
// merge.
|
|
6
|
+
//
|
|
7
|
+
// Zero deps: `node --test plugin/scripts/drop-merged-label.test.mjs`.
|
|
8
|
+
// No git repo needed — the script never touches git, only `gh`, so `gh` is the
|
|
9
|
+
// only thing stubbed, on PATH.
|
|
10
|
+
//
|
|
11
|
+
// Each precondition gets a case that proves it blocks ON ITS OWN, same
|
|
12
|
+
// discipline as release-ticket.test.mjs: deleting a check must fail the case
|
|
13
|
+
// named after it, not merely turn the suite red somewhere.
|
|
14
|
+
|
|
15
|
+
import { test } from "node:test";
|
|
16
|
+
import assert from "node:assert/strict";
|
|
17
|
+
import { readFileSync, mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { spawnSync, execFileSync } from "node:child_process";
|
|
19
|
+
import { tmpdir } from "node:os";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
|
|
23
|
+
const SCRIPT = fileURLToPath(new URL("./drop-merged-label.sh", import.meta.url));
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A `gh` stub on PATH answering the four calls this script makes, tuned per
|
|
27
|
+
* test through env vars. Returns a call log and an env() builder, same shape
|
|
28
|
+
* as release-ticket.test.mjs's fixture.
|
|
29
|
+
*/
|
|
30
|
+
function stub(t) {
|
|
31
|
+
const root = mktemp(t);
|
|
32
|
+
const bin = join(root, "bin");
|
|
33
|
+
mkdirSync(bin);
|
|
34
|
+
const log = join(root, "gh.log");
|
|
35
|
+
writeFileSync(log, "");
|
|
36
|
+
writeFileSync(
|
|
37
|
+
join(bin, "gh"),
|
|
38
|
+
`#!/bin/sh
|
|
39
|
+
printf '%s\\n' "$*" >> "${log}"
|
|
40
|
+
case "$1 $2" in
|
|
41
|
+
"pr view")
|
|
42
|
+
pr=\$3
|
|
43
|
+
case "$*" in
|
|
44
|
+
*"--json state --jq .state")
|
|
45
|
+
[ "\${PR_STATE_FAIL:-0}" = 0 ] || { echo "gh: simulated failure" >&2; exit 1; }
|
|
46
|
+
echo "\${PR_STATE:-MERGED}"
|
|
47
|
+
;;
|
|
48
|
+
*"--json closingIssuesReferences --jq"*)
|
|
49
|
+
[ "\${CLOSES_FAIL:-0}" = 0 ] || { echo "gh: simulated failure" >&2; exit 1; }
|
|
50
|
+
[ -z "\${CLOSES:-}" ] || printf '%s\\n' \${CLOSES}
|
|
51
|
+
;;
|
|
52
|
+
*"--json commits --jq"*)
|
|
53
|
+
[ "\${COMMITS_FAIL:-0}" = 0 ] || { echo "gh: simulated failure" >&2; exit 1; }
|
|
54
|
+
# Quoted, unlike CLOSES above: commit text carries real spaces
|
|
55
|
+
# ("Closes #1512") that unquoted word-splitting would scatter across
|
|
56
|
+
# separate printf lines and break the keyword+number adjacency the
|
|
57
|
+
# script's own scan depends on.
|
|
58
|
+
[ -z "\${COMMITS:-}" ] || printf '%s\\n' "\${COMMITS}"
|
|
59
|
+
;;
|
|
60
|
+
*) echo "gh: unstubbed pr view call: $*" >&2; exit 1 ;;
|
|
61
|
+
esac
|
|
62
|
+
;;
|
|
63
|
+
"issue view")
|
|
64
|
+
n=\$3
|
|
65
|
+
case ",\${ISSUE_VIEW_FAIL:-}," in *",\$n,"*) echo "gh: simulated failure" >&2; exit 1;; esac
|
|
66
|
+
eval "labels=\\\${LABELS_\$n:-}"
|
|
67
|
+
[ -z "\$labels" ] || printf '%s\\n' \$labels
|
|
68
|
+
;;
|
|
69
|
+
"issue edit")
|
|
70
|
+
n=\$3
|
|
71
|
+
case ",\${EDIT_FAIL:-}," in *",\$n,"*) echo "gh: simulated failure" >&2; exit 1;; esac
|
|
72
|
+
;;
|
|
73
|
+
*) echo "gh: unstubbed call: $*" >&2; exit 1 ;;
|
|
74
|
+
esac
|
|
75
|
+
exit 0
|
|
76
|
+
`,
|
|
77
|
+
{ mode: 0o755 },
|
|
78
|
+
);
|
|
79
|
+
return {
|
|
80
|
+
log,
|
|
81
|
+
calls: () => readFileSync(log, "utf8").trim().split("\n").filter(Boolean),
|
|
82
|
+
env: (extra = {}) => ({ ...process.env, PATH: `${bin}:${process.env.PATH}`, ...extra }),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function mktemp(t) {
|
|
87
|
+
const root = mkdtempSync(join(tmpdir(), "drop-merged-label-"));
|
|
88
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
89
|
+
return root;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function run(pr, { apply = false, env = {} } = {}) {
|
|
93
|
+
const argv = apply ? [String(pr), "--apply"] : [String(pr)];
|
|
94
|
+
const res = spawnSync("sh", [SCRIPT, ...argv], { env, encoding: "utf8" });
|
|
95
|
+
return {
|
|
96
|
+
code: res.status,
|
|
97
|
+
json: res.stdout.trim() ? JSON.parse(res.stdout) : null,
|
|
98
|
+
stderr: res.stderr,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
test("usage: rejects a non-numeric PR", (t) => {
|
|
103
|
+
const s = stub(t);
|
|
104
|
+
const { code, stderr } = run("abc", { env: s.env() });
|
|
105
|
+
assert.equal(code, 2);
|
|
106
|
+
assert.match(stderr, /pr must be a number/);
|
|
107
|
+
assert.deepEqual(s.calls(), [], "must refuse before calling gh at all");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("usage: rejects a zero-padded PR number", (t) => {
|
|
111
|
+
// The same defect #121 names for `"issue":%s`, in this script's `"pr":%s`
|
|
112
|
+
// slot: all-digits is not a JSON number, so `007` cleared the guard and the
|
|
113
|
+
// payload emitted `{"pr":007,…}` — unparseable at exit 0. Refused before gh
|
|
114
|
+
// is reached, like every other usage error here. Two widths, because one does
|
|
115
|
+
// not pin the guard: `0?*` narrowed to `0??*` still refuses `007` and
|
|
116
|
+
// re-admits `01`, which is the same bug back.
|
|
117
|
+
const s = stub(t);
|
|
118
|
+
for (const padded of ["007", "01"]) {
|
|
119
|
+
const { code, stderr } = run(padded, { env: s.env() });
|
|
120
|
+
assert.equal(code, 2, padded);
|
|
121
|
+
assert.match(stderr, /pr must be a number/);
|
|
122
|
+
}
|
|
123
|
+
assert.deepEqual(s.calls(), [], "must refuse before calling gh at all");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("usage: a bare 0 clears the numeric guard", (t) => {
|
|
127
|
+
// `0?*`, not `0*`: #121 lists `sh inflight.sh 0 -> parses` among its PASSING
|
|
128
|
+
// cases, beside `42`. A bare `0` is a valid RFC 8259 number and `$((0))` is
|
|
129
|
+
// `0`, so neither hazard the guard exists to close applies to it. Widening
|
|
130
|
+
// the arm would refuse a value the ticket's own worked example shows working.
|
|
131
|
+
const s = stub(t);
|
|
132
|
+
const { code, stderr } = run("0", { env: s.env() });
|
|
133
|
+
assert.doesNotMatch(stderr, /pr must be a number/);
|
|
134
|
+
assert.equal(code, 0, "0 clears the guard and runs to completion");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("usage: rejects an unknown second argument", (t) => {
|
|
138
|
+
const s = stub(t);
|
|
139
|
+
const { code, stderr } = run(9, { apply: false, env: s.env() });
|
|
140
|
+
const res = spawnSync("sh", [SCRIPT, "9", "--wat"], { env: s.env(), encoding: "utf8" });
|
|
141
|
+
assert.equal(res.status, 2);
|
|
142
|
+
assert.match(res.stderr, /unknown argument/);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("a PR whose state query fails halts before anything else", (t) => {
|
|
146
|
+
const s = stub(t);
|
|
147
|
+
const { code, stderr } = run(9, { env: s.env({ PR_STATE_FAIL: "1" }) });
|
|
148
|
+
assert.equal(code, 2);
|
|
149
|
+
assert.match(stderr, /cannot tell whether it merged/);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("a PR that is not merged is refused, not silently skipped", (t) => {
|
|
153
|
+
const s = stub(t);
|
|
154
|
+
const { code, stderr } = run(9, { env: s.env({ PR_STATE: "CLOSED" }) });
|
|
155
|
+
assert.equal(code, 2);
|
|
156
|
+
assert.match(stderr, /not merged \(state=CLOSED\)/);
|
|
157
|
+
// Never reaches the closingIssuesReferences call — a closed-not-merged PR
|
|
158
|
+
// is nothing this script may touch, so nothing past state should ever run.
|
|
159
|
+
assert.ok(!s.calls().some((c) => c.includes("closingIssuesReferences")));
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("closingIssuesReferences query failing after a confirmed merge still halts", (t) => {
|
|
163
|
+
const s = stub(t);
|
|
164
|
+
const { code, stderr } = run(9, { env: s.env({ CLOSES_FAIL: "1" }) });
|
|
165
|
+
assert.equal(code, 2);
|
|
166
|
+
assert.match(stderr, /cannot read which issues it closes/);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("a merged PR that closes nothing is a clean no-op", (t) => {
|
|
170
|
+
const s = stub(t);
|
|
171
|
+
const { code, json } = run(9, { apply: true, env: s.env({ CLOSES: "" }) });
|
|
172
|
+
assert.equal(code, 0);
|
|
173
|
+
assert.deepEqual(json, { pr: 9, merged: true, issues: [], applied: true, failed: [] });
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("dry run reports what it would drop and touches nothing", (t) => {
|
|
177
|
+
const s = stub(t);
|
|
178
|
+
const { code, json } = run(9, { apply: false, env: s.env({ CLOSES: "41", LABELS_41: "in-progress ready-for-agent" }) });
|
|
179
|
+
assert.equal(code, 0);
|
|
180
|
+
assert.deepEqual(json.issues, [{ issue: 41, hadLabel: true, removed: false }]);
|
|
181
|
+
assert.ok(!s.calls().some((c) => c.startsWith("issue edit")), "dry run must never call issue edit");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("--apply drops in-progress from a merged PR's closed issue", (t) => {
|
|
185
|
+
const s = stub(t);
|
|
186
|
+
const { code, json } = run(9, { apply: true, env: s.env({ CLOSES: "41", LABELS_41: "in-progress ready-for-agent" }) });
|
|
187
|
+
assert.equal(code, 0);
|
|
188
|
+
assert.deepEqual(json.issues, [{ issue: 41, hadLabel: true, removed: true }]);
|
|
189
|
+
assert.ok(s.calls().includes("issue edit 41 --remove-label in-progress"));
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("an issue that already lost the label is reported clear, not re-edited", (t) => {
|
|
193
|
+
const s = stub(t);
|
|
194
|
+
const { code, json } = run(9, { apply: true, env: s.env({ CLOSES: "41", LABELS_41: "ready-for-agent" }) });
|
|
195
|
+
assert.equal(code, 0);
|
|
196
|
+
assert.deepEqual(json.issues, [{ issue: 41, hadLabel: false, removed: false }]);
|
|
197
|
+
assert.ok(!s.calls().some((c) => c.startsWith("issue edit")));
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("a failed label read is reported, never swallowed", (t) => {
|
|
201
|
+
const s = stub(t);
|
|
202
|
+
const { code, json } = run(9, {
|
|
203
|
+
apply: true,
|
|
204
|
+
env: s.env({ CLOSES: "41", ISSUE_VIEW_FAIL: "41" }),
|
|
205
|
+
});
|
|
206
|
+
assert.equal(code, 1);
|
|
207
|
+
assert.deepEqual(json.failed, [41]);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// #1543. Same defect class PR #1519 fixed in reap.sh's grep_probe: `grep -q`
|
|
211
|
+
// has THREE outcomes and the bare `if … grep -qx …; then had=true; else
|
|
212
|
+
// had=false; fi` this script used to run had room for only two — rc 0
|
|
213
|
+
// matched, rc 1 none did, rc 2+ the scan itself broke — so grep's OWN failure
|
|
214
|
+
// used to fold into `had=false`, reading exactly like the "already clear"
|
|
215
|
+
// case two tests up and letting a merged ticket keep the label with nothing
|
|
216
|
+
// reported.
|
|
217
|
+
// Generalized over a `trigger` substring so the same shim can target either
|
|
218
|
+
// this script's label scan (`-qx`) or its #1617 commit-message scan
|
|
219
|
+
// (`-Eio`) in isolation — passthrough to the real `grep` for every other
|
|
220
|
+
// invocation, so only the targeted call site ever sees the simulated break.
|
|
221
|
+
function grepFailShim(t, trigger) {
|
|
222
|
+
const bin = mkdtempSync(join(tmpdir(), "drop-merged-label-grep-shim-"));
|
|
223
|
+
t.after(() => rmSync(bin, { recursive: true, force: true }));
|
|
224
|
+
const realGrep = execFileSync("/bin/sh", ["-c", "command -v grep"], { encoding: "utf8" }).trim();
|
|
225
|
+
writeFileSync(
|
|
226
|
+
join(bin, "grep"),
|
|
227
|
+
`#!/bin/sh\ncase "$*" in\n *${trigger}*) echo "grep: illegal byte sequence" >&2; exit 2 ;;\nesac\nexec ${realGrep} "$@"\n`,
|
|
228
|
+
{ mode: 0o755 },
|
|
229
|
+
);
|
|
230
|
+
return bin;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
test("a grep scan failure over an issue's labels is reported failed, never read as already clear", (t) => {
|
|
234
|
+
const s = stub(t);
|
|
235
|
+
const bin = grepFailShim(t, "-qx");
|
|
236
|
+
const base = s.env({ CLOSES: "41", LABELS_41: "in-progress" });
|
|
237
|
+
const { code, json } = run(9, { apply: true, env: { ...base, PATH: `${bin}:${base.PATH}` } });
|
|
238
|
+
assert.equal(code, 1, "a swallowed scan failure would read as success (exit 0)");
|
|
239
|
+
assert.deepEqual(json.issues, [{ issue: 41, hadLabel: null, removed: false }],
|
|
240
|
+
"hadLabel must be null (unknown), not false — false is the reading a completed, genuinely-empty scan earns");
|
|
241
|
+
assert.deepEqual(json.failed, [41]);
|
|
242
|
+
assert.ok(!s.calls().some((c) => c.startsWith("issue edit")),
|
|
243
|
+
"an unscanned label must not be removed on a guess either");
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("a failed removal is reported loudly, not swallowed — the acceptance criterion", (t) => {
|
|
247
|
+
const s = stub(t);
|
|
248
|
+
const { code, json, stderr } = run(9, {
|
|
249
|
+
apply: true,
|
|
250
|
+
env: s.env({ CLOSES: "41", LABELS_41: "in-progress", EDIT_FAIL: "41" }),
|
|
251
|
+
});
|
|
252
|
+
assert.equal(code, 1, "a swallowed failure would read as success (exit 0)");
|
|
253
|
+
assert.deepEqual(json.issues, [{ issue: 41, hadLabel: true, removed: false }]);
|
|
254
|
+
assert.deepEqual(json.failed, [41]);
|
|
255
|
+
assert.match(stderr, /FAILED to drop in-progress/);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("one failure among several issues does not stop the rest from being processed", (t) => {
|
|
259
|
+
const s = stub(t);
|
|
260
|
+
const { code, json } = run(9, {
|
|
261
|
+
apply: true,
|
|
262
|
+
env: s.env({
|
|
263
|
+
CLOSES: "41\n42",
|
|
264
|
+
LABELS_41: "in-progress",
|
|
265
|
+
LABELS_42: "in-progress",
|
|
266
|
+
EDIT_FAIL: "41",
|
|
267
|
+
}),
|
|
268
|
+
});
|
|
269
|
+
assert.equal(code, 1);
|
|
270
|
+
assert.deepEqual(json.issues, [
|
|
271
|
+
{ issue: 41, hadLabel: true, removed: false },
|
|
272
|
+
{ issue: 42, hadLabel: true, removed: true },
|
|
273
|
+
]);
|
|
274
|
+
assert.deepEqual(json.failed, [41]);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// The acceptance criterion is "reopening a previously-merged ticket makes it a
|
|
278
|
+
// candidate again" — verified against the real consumer, not against this
|
|
279
|
+
// file's idea of one. candidates.mjs excludes on the literal string
|
|
280
|
+
// `-label:in-progress`; this proves this script issues the exact `gh issue
|
|
281
|
+
// edit --remove-label in-progress` call that clears the one flag that clause
|
|
282
|
+
// keys on, so a reopened issue this script has touched no longer matches it.
|
|
283
|
+
test("the label this script drops is the exact one candidates.mjs excludes on", (t) => {
|
|
284
|
+
const candidates = readFileSync(
|
|
285
|
+
fileURLToPath(new URL("./candidates.mjs", import.meta.url)),
|
|
286
|
+
"utf8",
|
|
287
|
+
);
|
|
288
|
+
assert.match(candidates, /-label:in-progress/, "candidates.mjs moved its exclusion — update this test");
|
|
289
|
+
|
|
290
|
+
const s = stub(t);
|
|
291
|
+
const { code } = run(9, { apply: true, env: s.env({ CLOSES: "41", LABELS_41: "in-progress" }) });
|
|
292
|
+
assert.equal(code, 0);
|
|
293
|
+
assert.ok(s.calls().includes("issue edit 41 --remove-label in-progress"));
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// #1617. `closingIssuesReferences` reflects `Closes #N` syntax only when it
|
|
297
|
+
// lives in the PR's own title/body. PR #1614 (ticket #1512) had an EMPTY PR
|
|
298
|
+
// body but a commit message (`52a68b4`) carrying `Closes #1512` — GitHub's
|
|
299
|
+
// real merge-time closer honored it and closed #1512, but this script read
|
|
300
|
+
// back an empty `closingIssuesReferences` array and left `in-progress`
|
|
301
|
+
// stuck. This reproduces that exact shape.
|
|
302
|
+
test("PR #1614's exact shape: an empty closingIssuesReferences with a commit-message-only Closes #N still drops the label", (t) => {
|
|
303
|
+
const s = stub(t);
|
|
304
|
+
const { code, json } = run(1614, {
|
|
305
|
+
apply: true,
|
|
306
|
+
env: s.env({
|
|
307
|
+
CLOSES: "",
|
|
308
|
+
COMMITS: "fix(run-merge-bot): verify the fallback worktree against the branch ref\n\nCloses #1512",
|
|
309
|
+
LABELS_1512: "in-progress ready-for-agent",
|
|
310
|
+
}),
|
|
311
|
+
});
|
|
312
|
+
assert.equal(code, 0);
|
|
313
|
+
assert.deepEqual(json.issues, [{ issue: 1512, hadLabel: true, removed: true }]);
|
|
314
|
+
assert.ok(s.calls().includes("issue edit 1512 --remove-label in-progress"));
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test("commit-message scan recognizes every close/fix/resolve keyword form, case-insensitively", (t) => {
|
|
318
|
+
const s = stub(t);
|
|
319
|
+
const { code, json } = run(9, {
|
|
320
|
+
apply: true,
|
|
321
|
+
env: s.env({
|
|
322
|
+
CLOSES: "",
|
|
323
|
+
COMMITS: "Fixes #10\n\nsome body text\n\nresolved #20\n\nRESOLVES #30",
|
|
324
|
+
LABELS_10: "in-progress",
|
|
325
|
+
LABELS_20: "in-progress",
|
|
326
|
+
LABELS_30: "in-progress",
|
|
327
|
+
}),
|
|
328
|
+
});
|
|
329
|
+
assert.equal(code, 0);
|
|
330
|
+
assert.deepEqual(json.issues, [
|
|
331
|
+
{ issue: 10, hadLabel: true, removed: true },
|
|
332
|
+
{ issue: 20, hadLabel: true, removed: true },
|
|
333
|
+
{ issue: 30, hadLabel: true, removed: true },
|
|
334
|
+
]);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("a commit message merely mentioning an issue without a close keyword does not close it", (t) => {
|
|
338
|
+
const s = stub(t);
|
|
339
|
+
const { code, json } = run(9, {
|
|
340
|
+
apply: true,
|
|
341
|
+
env: s.env({ CLOSES: "", COMMITS: "Related to #99, see also #100 for background" }),
|
|
342
|
+
});
|
|
343
|
+
assert.equal(code, 0);
|
|
344
|
+
assert.deepEqual(json, { pr: 9, merged: true, issues: [], applied: true, failed: [] });
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test("closingIssuesReferences and a commit-message reference union, without processing a shared issue twice", (t) => {
|
|
348
|
+
const s = stub(t);
|
|
349
|
+
const { code, json } = run(9, {
|
|
350
|
+
apply: true,
|
|
351
|
+
env: s.env({
|
|
352
|
+
CLOSES: "41",
|
|
353
|
+
COMMITS: "Closes #41\n\nCloses #55",
|
|
354
|
+
LABELS_41: "in-progress",
|
|
355
|
+
LABELS_55: "in-progress",
|
|
356
|
+
}),
|
|
357
|
+
});
|
|
358
|
+
assert.equal(code, 0);
|
|
359
|
+
assert.deepEqual(json.issues, [
|
|
360
|
+
{ issue: 41, hadLabel: true, removed: true },
|
|
361
|
+
{ issue: 55, hadLabel: true, removed: true },
|
|
362
|
+
]);
|
|
363
|
+
const viewsOf41 = s.calls().filter((c) => c === "issue view 41 --json labels --jq .labels[].name");
|
|
364
|
+
assert.equal(viewsOf41.length, 1, "an issue named by both signals must be looked up once, not once per signal");
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test("the commit-message query failing after a confirmed merge still halts", (t) => {
|
|
368
|
+
const s = stub(t);
|
|
369
|
+
const { code, stderr } = run(9, { env: s.env({ CLOSES: "", COMMITS_FAIL: "1" }) });
|
|
370
|
+
assert.equal(code, 2);
|
|
371
|
+
assert.match(stderr, /cannot scan its commit messages for issue closes/);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// Same discipline as #1543's label-scan fix, applied to the new commit scan:
|
|
375
|
+
// rc 1 (no keyword anywhere) is zero commit-closed issues, but rc 2+ (the
|
|
376
|
+
// scan itself broke) must halt loudly, never silently read as "commits close
|
|
377
|
+
// nothing" — a swallowed break here would look exactly like the previous
|
|
378
|
+
// test's `Related to #99` case even though the scan never actually ran.
|
|
379
|
+
test("a grep scan failure over commit messages halts loudly, never read as commits closing nothing", (t) => {
|
|
380
|
+
const s = stub(t);
|
|
381
|
+
const bin = grepFailShim(t, "-Eio");
|
|
382
|
+
const base = s.env({ CLOSES: "", COMMITS: "Closes #1512" });
|
|
383
|
+
const { code, stderr } = run(9, { apply: true, env: { ...base, PATH: `${bin}:${base.PATH}` } });
|
|
384
|
+
assert.equal(code, 2, "a swallowed scan failure would read as a clean no-op (exit 0)");
|
|
385
|
+
assert.match(stderr, /could not scan PR #9's commit messages for issue closes \(grep exited 2\)/);
|
|
386
|
+
assert.ok(!s.calls().some((c) => c.startsWith("issue view") || c.startsWith("issue edit")),
|
|
387
|
+
"an unscanned commit history must never be treated as having resolved to zero issues");
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// The digit-extraction step that turns a matched commit line into a bare
|
|
391
|
+
// issue number is guarded the same way, so a broken extraction halts with
|
|
392
|
+
// this script's own branded die() message instead of raw, unbranded grep
|
|
393
|
+
// stderr and no diagnosis of which step failed.
|
|
394
|
+
test("a grep scan failure extracting issue numbers from matched commit text halts loudly with a branded die() message", (t) => {
|
|
395
|
+
const s = stub(t);
|
|
396
|
+
const bin = grepFailShim(t, "-Eo");
|
|
397
|
+
const base = s.env({ CLOSES: "", COMMITS: "Closes #1512" });
|
|
398
|
+
const { code, stderr } = run(9, { apply: true, env: { ...base, PATH: `${bin}:${base.PATH}` } });
|
|
399
|
+
assert.equal(code, 2, "a swallowed extraction failure must not read as success (exit 0)");
|
|
400
|
+
assert.match(stderr, /drop-merged-label: could not extract issue numbers from PR #9's matched commit text \(grep exited 2\)/);
|
|
401
|
+
assert.ok(!s.calls().some((c) => c.startsWith("issue view") || c.startsWith("issue edit")),
|
|
402
|
+
"an unextracted commit match must never be treated as resolving to zero issues");
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// #1543's own discipline, generalized to the LAST step of the scan: unioning
|
|
406
|
+
// `$issues` and `$commit_issues` used to run a bare `grep | sort`, and
|
|
407
|
+
// command substitution reports only the LAST pipe stage's exit status —
|
|
408
|
+
// `sort`'s own rc 0 silently masked a grep 2+ break, reading exactly like
|
|
409
|
+
// the PR closing zero issues even though the union scan itself never ran.
|
|
410
|
+
// A keyword-free COMMITS means the earlier commit-message scan (its own,
|
|
411
|
+
// already-guarded grep) legitimately returns rc 1 and skips straight past
|
|
412
|
+
// the digit-extraction grep, so this is the ONLY grep call the union step
|
|
413
|
+
// reaches — isolating the exact call this fix guards.
|
|
414
|
+
test("a grep scan failure in the final issue-number union halts loudly, never silently unions to zero issues", (t) => {
|
|
415
|
+
const s = stub(t);
|
|
416
|
+
const bin = grepFailShim(t, "-Eo");
|
|
417
|
+
const base = s.env({ CLOSES: "41", COMMITS: "Related to #99, see also #100 for background" });
|
|
418
|
+
const { code, stderr } = run(9, { apply: true, env: { ...base, PATH: `${bin}:${base.PATH}` } });
|
|
419
|
+
assert.equal(code, 2, "a swallowed union failure would read as the PR closing zero issues (exit 0)");
|
|
420
|
+
assert.match(stderr, /could not union PR #9's closing issues \(grep exited 2\)/);
|
|
421
|
+
assert.ok(!s.calls().some((c) => c.startsWith("issue view") || c.startsWith("issue edit")),
|
|
422
|
+
"issue #41 already carrying in-progress must never be silently skipped because the union step broke");
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// The keyword regex used to have no boundary before it, so it matched
|
|
426
|
+
// "fix"/"close(d)" as a bare SUBSTRING of an unrelated word. Each of these
|
|
427
|
+
// three commit lines contains one of the keyword strings glued to a longer
|
|
428
|
+
// word with no non-word character in front of it, so none of them may close
|
|
429
|
+
// anything.
|
|
430
|
+
test("a keyword regex requires a word boundary — 'bugfix', 'prefix', and 'unclosed' as substrings do not trigger a close", (t) => {
|
|
431
|
+
const s = stub(t);
|
|
432
|
+
const { code, json } = run(9, {
|
|
433
|
+
apply: true,
|
|
434
|
+
env: s.env({
|
|
435
|
+
CLOSES: "",
|
|
436
|
+
COMMITS: "chore: bugfix #77 rolled forward\n\nrefactor: prefix #88 handling\n\nnote: left unclosed #99 for later",
|
|
437
|
+
}),
|
|
438
|
+
});
|
|
439
|
+
assert.equal(code, 0);
|
|
440
|
+
assert.deepEqual(json, { pr: 9, merged: true, issues: [], applied: true, failed: [] });
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// The boundary fix must not regress a real keyword that follows punctuation
|
|
444
|
+
// or a space mid-line (not just one that opens the line) — the alternation's
|
|
445
|
+
// `[^[:alnum:]_]` branch, not only its `^` branch.
|
|
446
|
+
test("a real close keyword preceded by punctuation, not just line-start, still closes", (t) => {
|
|
447
|
+
const s = stub(t);
|
|
448
|
+
const { code, json } = run(9, {
|
|
449
|
+
apply: true,
|
|
450
|
+
env: s.env({ CLOSES: "", COMMITS: "See other work; closes #77 too", LABELS_77: "in-progress" }),
|
|
451
|
+
});
|
|
452
|
+
assert.equal(code, 0);
|
|
453
|
+
assert.deepEqual(json.issues, [{ issue: 77, hadLabel: true, removed: true }]);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
// #121's defect class: a bare zero-padded digit string flowed unnormalized
|
|
457
|
+
// into the JSON payload as an illegal leading-zero JSON number. Verified by
|
|
458
|
+
// actually parsing the script's stdout as JSON (run()'s own JSON.parse),
|
|
459
|
+
// exactly like this file's other JSON-payload-validity assertions.
|
|
460
|
+
test("a zero-padded commit-message issue number normalizes to a valid JSON integer", (t) => {
|
|
461
|
+
const s = stub(t);
|
|
462
|
+
const { code, json } = run(9, {
|
|
463
|
+
apply: true,
|
|
464
|
+
env: s.env({ CLOSES: "", COMMITS: "Closes #007", LABELS_7: "in-progress" }),
|
|
465
|
+
});
|
|
466
|
+
assert.equal(code, 0);
|
|
467
|
+
assert.deepEqual(json.issues, [{ issue: 7, hadLabel: true, removed: true }]);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
test("a zero-padded commit-message reference dedupes against the same issue named by closingIssuesReferences", (t) => {
|
|
471
|
+
const s = stub(t);
|
|
472
|
+
const { code, json } = run(9, {
|
|
473
|
+
apply: true,
|
|
474
|
+
env: s.env({ CLOSES: "7", COMMITS: "Closes #007", LABELS_7: "in-progress" }),
|
|
475
|
+
});
|
|
476
|
+
assert.equal(code, 0);
|
|
477
|
+
assert.deepEqual(json.issues, [{ issue: 7, hadLabel: true, removed: true }]);
|
|
478
|
+
const viewsOf7 = s.calls().filter((c) => c === "issue view 7 --json labels --jq .labels[].name");
|
|
479
|
+
assert.equal(viewsOf7.length, 1, "'007' and '7' name the same issue and must be looked up once, not twice");
|
|
480
|
+
});
|