@@ -14,6 +14,62 @@ teardown() {
1414 rm -rf " $BATS_TMPDIR /gtr-init-cache-$$ "
1515}
1616
17+ run_generated_bash_wrapper_completion () {
18+ local wrapper_name=" $1 "
19+ local comp_line=" $2 "
20+ local comp_cword=" $3 "
21+ local comp_point=" $4 "
22+ shift 4
23+
24+ bash -s -- " $PROJECT_ROOT " " $XDG_CACHE_HOME " " $wrapper_name " " $comp_line " " $comp_cword " " $comp_point " " $@ " << 'BASH '
25+ set -euo pipefail
26+
27+ PROJECT_ROOT="$1"
28+ XDG_CACHE_HOME="$2"
29+ wrapper_name="$3"
30+ comp_line="$4"
31+ comp_cword="$5"
32+ comp_point="$6"
33+ shift 6
34+ words=("$@")
35+
36+ export XDG_CACHE_HOME
37+ export GTR_VERSION="test"
38+
39+ log_info() { :; }
40+ log_warn() { :; }
41+ log_error() { :; }
42+ show_command_help() { :; }
43+
44+ # shellcheck disable=SC1090
45+ . "$PROJECT_ROOT/lib/commands/init.sh"
46+
47+ if [ "$wrapper_name" = "gtr" ]; then
48+ eval "$(cmd_init bash)"
49+ else
50+ eval "$(cmd_init bash --as "$wrapper_name")"
51+ fi
52+
53+ _git_gtr() {
54+ printf 'WORDS=%s\n' "${COMP_WORDS[*]}"
55+ printf 'CWORD=%s\n' "$COMP_CWORD"
56+ printf 'LINE=%s\n' "$COMP_LINE"
57+ printf 'POINT=%s\n' "$COMP_POINT"
58+ COMPREPLY=(--from)
59+ }
60+
61+ completion_fn="_${wrapper_name}_completion"
62+ COMP_WORDS=("${words[@]}")
63+ COMP_CWORD="$comp_cword"
64+ COMP_LINE="$comp_line"
65+ COMP_POINT="$comp_point"
66+ COMPREPLY=()
67+ "$completion_fn"
68+
69+ printf 'REPLY=%s\n' "${COMPREPLY[*]}"
70+ BASH
71+ }
72+
1773# ── Default function name ────────────────────────────────────────────────────
1874
1975@test " bash output defines gtr() function by default" {
@@ -211,6 +267,39 @@ teardown() {
211267 [[ "$output" == *' compgen -W " --cd" ' * ]]
212268}
213269
270+ @test "bash wrapper completion rewrites delegated context for ai targets" {
271+ run run_generated_bash_wrapper_completion gtr "gtr ai fe" 2 9 gtr ai fe
272+
273+ [ "$status" -eq 0 ]
274+ [[ "$output" == *"WORDS=git gtr ai fe"* ]]
275+ [[ "$output" == *"CWORD=3"* ]]
276+ [[ "$output" == *"LINE=git gtr ai fe"* ]]
277+ [[ "$output" == *"POINT=13"* ]]
278+ [[ "$output" == *"REPLY=--from"* ]]
279+ }
280+
281+ @test "bash wrapper completion rewrites delegated context for custom wrapper names" {
282+ run run_generated_bash_wrapper_completion gwtr "gwtr ai fe" 2 10 gwtr ai fe
283+
284+ [ "$status" -eq 0 ]
285+ [[ "$output" == *"WORDS=git gtr ai fe"* ]]
286+ [[ "$output" == *"CWORD=3"* ]]
287+ [[ "$output" == *"LINE=git gtr ai fe"* ]]
288+ [[ "$output" == *"POINT=13"* ]]
289+ [[ "$output" == *"REPLY=--from"* ]]
290+ }
291+
292+ @test "bash wrapper completion preserves delegated replies and appends --cd for new flags" {
293+ run run_generated_bash_wrapper_completion gtr "gtr new --c" 2 11 gtr new --c
294+
295+ [ "$status" -eq 0 ]
296+ [[ "$output" == *"WORDS=git gtr new --c"* ]]
297+ [[ "$output" == *"CWORD=3"* ]]
298+ [[ "$output" == *"LINE=git gtr new --c"* ]]
299+ [[ "$output" == *"POINT=15"* ]]
300+ [[ "$output" == *"REPLY=--from --cd"* ]]
301+ }
302+
214303@test "zsh wrapper completions include --cd for new" {
215304 run cmd_init zsh
216305 [ "$status" -eq 0 ]
0 commit comments