@@ -23,8 +23,9 @@ class Tmux:
2323 "-y" , "$ height " ,
2424 shell ,
2525 ]
26- // Wait for the shell to initialize.
27- sleep --ms = 500
26+ // Wait for the shell to initialize by echoing a marker.
27+ send-line "echo tmux-ready"
28+ wait-for "tmux-ready"
2829
2930 /**
3031 Sends keystrokes to the tmux session.
@@ -41,9 +42,13 @@ class Tmux:
4142 send-line text / string -> none :
4243 send-keys [ text , "Enter" ]
4344
44- /** Sends Ctrl-C to cancel the current line. */
45+ /** Sends Ctrl-C to cancel the current line, then waits for the shell to be ready . */
4546 cancel -> none :
4647 send-keys [ "C-c" ]
48+ // Echo a marker and wait for it so we know the shell is ready.
49+ marker := "ready-$ Time.monotonic-us "
50+ send-line "echo $ marker "
51+ wait-for marker
4752
4853 /** Captures the current pane content as a string. */
4954 capture -> string :
@@ -112,8 +117,9 @@ test-bash:
112117 tmux := Tmux ( next-session-name_ ) --shell = "bash --norc --noprofile"
113118 try:
114119 // Source the completion script.
115- tmux .send-line "source <($ binary_ completion bash)"
116- sleep --ms = 500
120+ tmux .send-line "source <($ binary_ completion bash); echo sourced"
121+ expect ( tmux .wait-for "sourced" )
122+ --message = "bash: sourcing completion script"
117123
118124 // Test 1: Subcommand completion (double Tab for ambiguous matches).
119125 tmux .send-keys [ "$ binary_ " , "Tab" , "Tab" ]
@@ -127,17 +133,13 @@ test-bash:
127133 expect ( content .contains "completion" )
128134 --message = "bash: subcommand 'completion' should appear"
129135 tmux .cancel
130- sleep --ms = 300
131136
132137 // Test 2: Unique prefix auto-completes inline.
133138 tmux .send-keys [ "$ binary_ dep" , "Tab" ]
134- sleep --ms = 1000
135- content = tmux .capture
136139 // With a single match, bash auto-completes inline.
137- expect ( content . contains "deploy" )
140+ expect ( tmux . wait-for "deploy" )
138141 --message = "bash: 'dep' should auto-complete to 'deploy'"
139142 tmux .cancel
140- sleep --ms = 300
141143
142144 // Test 3: Enum value completion.
143145 tmux .send-keys [ "$ binary_ deploy --channel " , "Tab" , "Tab" ]
@@ -149,14 +151,12 @@ test-bash:
149151 expect ( content .contains "dev" )
150152 --message = "bash: enum value 'dev' should appear"
151153 tmux .cancel
152- sleep --ms = 300
153154
154155 // Test 4: Short option -d triggers device completion.
155156 tmux .send-keys [ "$ binary_ deploy -d " , "Tab" , "Tab" ]
156157 expect ( tmux .wait-for "d3b07384" )
157158 --message = "bash: short option -d should show device UUID"
158159 tmux .cancel
159- sleep --ms = 300
160160
161161 print " All bash tests passed."
162162 finally:
@@ -168,10 +168,12 @@ test-zsh:
168168 tmux := Tmux ( next-session-name_ ) --shell = "zsh -f"
169169 try:
170170 // Initialize zsh completion system.
171- tmux .send-line "autoload -U compinit && compinit -u"
172- sleep --ms = 500
173- tmux .send-line "source <($ binary_ completion zsh)"
174- sleep --ms = 500
171+ tmux .send-line "autoload -U compinit && compinit -u && echo ready"
172+ expect ( tmux .wait-for "ready" )
173+ --message = "zsh: compinit"
174+ tmux .send-line "source <($ binary_ completion zsh) && echo sourced"
175+ expect ( tmux .wait-for "sourced" )
176+ --message = "zsh: sourcing completion script"
175177
176178 // Test 1: Subcommand completion.
177179 tmux .send-keys [ "$ binary_ " , "Tab" ]
@@ -181,7 +183,6 @@ test-zsh:
181183 expect ( content .contains "status" )
182184 --message = "zsh: subcommand 'status' should appear"
183185 tmux .cancel
184- sleep --ms = 300
185186
186187 // Test 2: Enum value completion.
187188 tmux .send-keys [ "$ binary_ deploy --channel " , "Tab" ]
@@ -191,14 +192,12 @@ test-zsh:
191192 expect ( content .contains "beta" )
192193 --message = "zsh: enum value 'beta' should appear"
193194 tmux .cancel
194- sleep --ms = 300
195195
196196 // Test 3: Device completion with descriptions.
197197 tmux .send-keys [ "$ binary_ deploy --device " , "Tab" ]
198198 expect ( tmux .wait-for "Living Room Sensor" )
199199 --message = "zsh: device completion should show description"
200200 tmux .cancel
201- sleep --ms = 300
202201
203202 print " All zsh tests passed."
204203 finally:
@@ -216,8 +215,9 @@ test-fish:
216215 tmux := Tmux ( next-session-name_ ) --shell = "fish --no-config"
217216 try:
218217 // Source the completion script.
219- tmux .send-line "$ binary_ completion fish | source"
220- sleep --ms = 500
218+ tmux .send-line "$ binary_ completion fish | source; echo sourced"
219+ expect ( tmux .wait-for "sourced" )
220+ --message = "fish: sourcing completion script"
221221
222222 // Test 1: Subcommand completion.
223223 tmux .send-keys [ "$ binary_ " , "Tab" ]
@@ -227,7 +227,6 @@ test-fish:
227227 expect ( content .contains "status" )
228228 --message = "fish: subcommand 'status' should appear"
229229 tmux .cancel
230- sleep --ms = 300
231230
232231 // Test 2: Enum value completion.
233232 tmux .send-keys [ "$ binary_ deploy --channel " , "Tab" ]
@@ -237,14 +236,12 @@ test-fish:
237236 expect ( content .contains "beta" )
238237 --message = "fish: enum value 'beta' should appear"
239238 tmux .cancel
240- sleep --ms = 300
241239
242240 // Test 3: Device completion with descriptions.
243241 tmux .send-keys [ "$ binary_ deploy --device " , "Tab" ]
244242 expect ( tmux .wait-for "Living Room Sensor" )
245243 --message = "fish: device completion should show description"
246244 tmux .cancel
247- sleep --ms = 300
248245
249246 print " All fish tests passed."
250247 finally:
0 commit comments