Skip to content

Commit d31da74

Browse files
authored
feat(test-classifier): own arg defaulting in dispatcher (bare ref / no-arg) (#62)
Move the ergonomic defaulting out of the hand-pasted ~/.zshrc wrapper and into the versioned dispatcher, so the wrapper can be a dumb one-line passthrough that never drifts on a re-vendor: • bare ref (e.g. origin/main) → --against <ref> • no range/PR selector at all → --unpushed (local report-only backstop) • all other flags pass through unchanged Defaulting runs before discover_pr_context so the injected --against/--unpushed correctly suppresses PR auto-discovery.
1 parent 3c15a29 commit d31da74

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

testing/classifier/.skills/test-classifier/scripts/test-classifier-dispatcher.sh

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
# is posted when nothing was triaged.
2828
#
2929
# Usage:
30-
# test-classifier-dispatcher.sh # auto-discover PR; print only
30+
# test-classifier-dispatcher.sh # no args → --unpushed (local committed+staged, report-only)
31+
# test-classifier-dispatcher.sh origin/main # bare ref → --against origin/main
3132
# test-classifier-dispatcher.sh --pr 1234 --post-comment # post the PR comment
3233
# test-classifier-dispatcher.sh --pr 1234 --submit # post + prompt "helpful?" + append a Testing Events row
3334
# test-classifier-dispatcher.sh --against origin/main # explicit base ref
@@ -154,6 +155,49 @@ while [[ $# -gt 0 ]]; do
154155
esac
155156
done
156157

158+
# ── Convenience defaulting (so callers/wrappers stay dumb) ──────────────────
159+
# The shell wrapper that fronts this dispatcher is a one-line passthrough; the
160+
# ergonomic defaults live HERE so they're versioned with the bundle and never
161+
# drift out of a hand-pasted ~/.zshrc function. Applied only when the caller
162+
# gave no diff-range/PR selector (--against / --unpushed / --pr) of its own:
163+
#
164+
# • a bare ref (e.g. `origin/main`) → --against <ref> (classify <ref>..HEAD)
165+
# • otherwise → --unpushed (committed + staged,
166+
# local report-only backstop)
167+
#
168+
# Other flags (--dry-run, --json-only, --post-comment, …) pass through unchanged.
169+
#
170+
# We detect "did the caller already choose a range/PR?" by scanning the args
171+
# bound for the lib for --against/--unpushed, plus our own --pr. If any is
172+
# present we add nothing. This runs BEFORE discover_pr_context, which inspects
173+
# REMAINING_FOR_LIB for --against/--unpushed to decide whether to skip PR lookup.
174+
ai_classifier::has_range_selector() {
175+
[[ -n "${PR_NUMBER}" ]] && return 0
176+
local a
177+
for a in "${REMAINING_FOR_LIB[@]+"${REMAINING_FOR_LIB[@]}"}"; do
178+
case "$a" in
179+
--against|--against=*|--unpushed) return 0 ;;
180+
esac
181+
done
182+
return 1
183+
}
184+
185+
if ! ai_classifier::has_range_selector; then
186+
# A bare positional (doesn't start with '-') is a base ref; the lib would
187+
# otherwise drop it into AI_REVIEW_REMAINING and ignore it. Rewrite it to
188+
# --against and keep any other flags (--dry-run, --json-only, …) intact.
189+
bare_ref="" rest=()
190+
for a in "${REMAINING_FOR_LIB[@]+"${REMAINING_FOR_LIB[@]}"}"; do
191+
if [[ -z "${bare_ref}" && "${a#-}" == "${a}" ]]; then bare_ref="$a"; else rest+=("$a"); fi
192+
done
193+
if [[ -n "${bare_ref}" ]]; then
194+
REMAINING_FOR_LIB=("--against" "${bare_ref}" "${rest[@]+"${rest[@]}"}")
195+
else
196+
# No range/PR/ref anywhere → default to the local unpushed backstop.
197+
REMAINING_FOR_LIB+=("--unpushed")
198+
fi
199+
fi
200+
157201
# ── PR / base-ref discovery (mirrors the security dispatcher) ───────────────
158202
require_gh_cli() {
159203
local why="$1"

0 commit comments

Comments
 (0)