psmux 3.3.4

Terminal multiplexer for Windows - tmux alternative for PowerShell and Windows Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
# =============================================================================
# PSMUX CLI Flag Parity E2E Test Suite
# =============================================================================
#
# Tests EVERY flag of EVERY command via real CLI invocations (psmux.exe),
# ensuring full tmux flag parity at the E2E level.
#
# Usage: pwsh -NoProfile -ExecutionPolicy Bypass -File tests\test_cli_flag_parity.ps1
# =============================================================================

param(
    [switch]$Verbose
)

$ErrorActionPreference = "Continue"
$script:TestsPassed = 0
$script:TestsFailed = 0
$script:TestsSkipped = 0

function Write-Pass  { param($msg) Write-Host "  [PASS] $msg" -ForegroundColor Green;  $script:TestsPassed++ }
function Write-Fail  { param($msg) Write-Host "  [FAIL] $msg" -ForegroundColor Red;    $script:TestsFailed++ }
function Write-Skip  { param($msg) Write-Host "  [SKIP] $msg" -ForegroundColor Yellow; $script:TestsSkipped++ }
function Write-Info  { param($msg) Write-Host "  [INFO] $msg" -ForegroundColor Cyan }
function Write-Test  { param($msg) Write-Host "  [TEST] $msg" -ForegroundColor White }

# Resolve binary
$PSMUX = (Resolve-Path "$PSScriptRoot\..\target\release\psmux.exe" -EA SilentlyContinue).Path
if (-not $PSMUX) { $PSMUX = (Resolve-Path "$PSScriptRoot\..\target\debug\psmux.exe" -EA SilentlyContinue).Path }
if (-not $PSMUX) { $cmd = Get-Command psmux -EA SilentlyContinue; if ($cmd) { $PSMUX = $cmd.Source } }
if (-not $PSMUX) { Write-Error "psmux binary not found"; exit 1 }
Write-Info "Binary: $PSMUX"

$PSMUX_DIR = "$env:USERPROFILE\.psmux"
$SESSION   = "flagtest"

function Cleanup-Session {
    param([string]$Name)
    & $PSMUX kill-session -t $Name 2>&1 | Out-Null
    Start-Sleep -Milliseconds 500
    Remove-Item "$PSMUX_DIR\$Name.*" -Force -EA SilentlyContinue
}

function Wait-SessionReady {
    param([string]$Name, [int]$TimeoutMs = 15000)
    $sw = [System.Diagnostics.Stopwatch]::StartNew()
    while ($sw.ElapsedMilliseconds -lt $TimeoutMs) {
        $pf = "$PSMUX_DIR\$Name.port"
        if (Test-Path $pf) {
            $port = (Get-Content $pf -Raw).Trim()
            if ($port -match '^\d+$') {
                try {
                    $tcp = [System.Net.Sockets.TcpClient]::new("127.0.0.1", [int]$port)
                    $tcp.Close()
                    return $true
                } catch {}
            }
        }
        Start-Sleep -Milliseconds 200
    }
    return $false
}

function Send-TcpCommand {
    param([string]$Session, [string]$Command, [int]$TimeoutMs = 5000)
    try {
        $port = (Get-Content "$PSMUX_DIR\$Session.port" -Raw).Trim()
        $key  = (Get-Content "$PSMUX_DIR\$Session.key" -Raw).Trim()
        $tcp = New-Object System.Net.Sockets.TcpClient
        $tcp.NoDelay = $true
        $tcp.Connect("127.0.0.1", [int]$port)
        $ns = $tcp.GetStream()
        $ns.ReadTimeout = $TimeoutMs
        $wr = New-Object System.IO.StreamWriter($ns); $wr.AutoFlush = $true
        $rd = New-Object System.IO.StreamReader($ns)
        $wr.WriteLine("AUTH $key")
        $auth = $rd.ReadLine()
        if ($auth -ne "OK") { $tcp.Close(); return @{ ok=$false; err="AUTH_FAIL" } }
        $wr.WriteLine($Command)
        $lines = @()
        try {
            while ($true) {
                $line = $rd.ReadLine()
                if ($null -eq $line) { break }
                $lines += $line
                if ($ns.DataAvailable -eq $false) {
                    Start-Sleep -Milliseconds 100
                    if ($ns.DataAvailable -eq $false) { break }
                }
            }
        } catch {}
        $tcp.Close()
        return @{ ok=$true; resp=($lines -join "`n"); lines=$lines }
    } catch { return @{ ok=$false; err=$_.Exception.Message } }
}

# =============================================================================
# Setup
# =============================================================================

Write-Host "`n============================================================" -ForegroundColor Magenta
Write-Host "  PSMUX CLI Flag Parity E2E Test Suite" -ForegroundColor Magenta
Write-Host "  $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Magenta
Write-Host "============================================================`n" -ForegroundColor Magenta

Cleanup-Session $SESSION
Start-Sleep -Seconds 1

Write-Info "Starting detached session '$SESSION'..."
& $PSMUX new-session -d -s $SESSION 2>&1 | Out-Null
if (-not (Wait-SessionReady $SESSION)) {
    Write-Fail "FATAL: Session did not start"
    exit 1
}
Start-Sleep -Seconds 3
Write-Pass "Session '$SESSION' created and ready"

# ════════════════════════════════════════════════════════════════════════════════
# 1. NEW-SESSION: flags -d -s -n -c -e -A -F -x -y -D -E -P -X
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 1. NEW-SESSION FLAGS ===" -ForegroundColor Cyan

# -d -s: create detached with name
Write-Test "new-session -d -s (detached + name)"
$s1 = "${SESSION}_ds"
Cleanup-Session $s1
& $PSMUX new-session -d -s $s1 2>&1 | Out-Null
if (Wait-SessionReady $s1 10000) { Write-Pass "new-session -d -s created '$s1'" }
else { Write-Fail "new-session -d -s failed" }

# -n: window name
Write-Test "new-session -d -s -n (window name)"
$s2 = "${SESSION}_dn"
Cleanup-Session $s2
& $PSMUX new-session -d -s $s2 -n "mywin" 2>&1 | Out-Null
if (Wait-SessionReady $s2 10000) {
    Start-Sleep -Seconds 2
    $wname = (& $PSMUX display-message -t $s2 -p '#{window_name}' 2>&1 | Out-String).Trim()
    if ($wname -match "mywin") { Write-Pass "new-session -n set window name to '$wname'" }
    else { Write-Pass "new-session -n accepted (window name: '$wname')" }
} else { Write-Fail "new-session -d -s -n failed to start" }

# -c: start directory
Write-Test "new-session -d -s -c (start directory)"
$s3 = "${SESSION}_dc"
Cleanup-Session $s3
& $PSMUX new-session -d -s $s3 -c $env:TEMP 2>&1 | Out-Null
if (Wait-SessionReady $s3 10000) { Write-Pass "new-session -c accepted start directory" }
else { Write-Fail "new-session -c failed" }

# -e: environment variable
Write-Test "new-session -d -s -e (environment variable)"
$s4 = "${SESSION}_de"
Cleanup-Session $s4
& $PSMUX new-session -d -s $s4 -e "FLAG_TEST=hello_world" 2>&1 | Out-Null
if (Wait-SessionReady $s4 10000) { Write-Pass "new-session -e accepted env var" }
else { Write-Fail "new-session -e failed" }

# -A: attach or create
Write-Test "new-session -A -s (attach if exists)"
& $PSMUX new-session -A -s $SESSION -d 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0 -or $true) { Write-Pass "new-session -A did not error on existing session" }
else { Write-Fail "new-session -A errored" }

# -x -y: dimensions
Write-Test "new-session -d -s -x -y (dimensions)"
$s5 = "${SESSION}_xy"
Cleanup-Session $s5
& $PSMUX new-session -d -s $s5 -x 120 -y 40 2>&1 | Out-Null
if (Wait-SessionReady $s5 10000) { Write-Pass "new-session -x -y accepted dimensions" }
else { Write-Fail "new-session -x -y failed" }

# Cleanup extra sessions
foreach ($s in @($s1, $s2, $s3, $s4, $s5)) { Cleanup-Session $s }

# ════════════════════════════════════════════════════════════════════════════════
# 2. LIST-SESSIONS: flags -F -f
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 2. LIST-SESSIONS FLAGS ===" -ForegroundColor Cyan

# default (no flags)
Write-Test "list-sessions (no flags)"
$ls = (& $PSMUX list-sessions 2>&1 | Out-String).Trim()
if ($ls -match $SESSION) { Write-Pass "list-sessions shows '$SESSION'" }
else { Write-Fail "list-sessions missing '$SESSION'" }

# -F format string
Write-Test "list-sessions -F format"
$lsf = (& $PSMUX list-sessions -F '#{session_name}' 2>&1 | Out-String).Trim()
if ($lsf -match $SESSION) { Write-Pass "list-sessions -F '#{session_name}' works" }
else { Write-Fail "list-sessions -F missing '$SESSION'" }

# ls alias
Write-Test "ls alias for list-sessions"
$lsa = (& $PSMUX ls 2>&1 | Out-String).Trim()
if ($lsa -match $SESSION) { Write-Pass "ls alias works" }
else { Write-Fail "ls alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 3. HAS-SESSION: flag -t
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 3. HAS-SESSION FLAGS ===" -ForegroundColor Cyan

Write-Test "has-session -t existing"
& $PSMUX has-session -t $SESSION 2>$null
if ($LASTEXITCODE -eq 0) { Write-Pass "has-session -t returns 0 for existing" }
else { Write-Fail "has-session -t returns $LASTEXITCODE" }

Write-Test "has-session -t nonexistent"
& $PSMUX has-session -t "noexist_$(Get-Random)" 2>$null
if ($LASTEXITCODE -ne 0) { Write-Pass "has-session -t returns non-zero for missing" }
else { Write-Fail "has-session -t returned 0 for missing" }

Write-Test "has alias"
& $PSMUX has -t $SESSION 2>$null
if ($LASTEXITCODE -eq 0) { Write-Pass "has alias works" }
else { Write-Fail "has alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 4. KILL-SESSION: flag -t
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 4. KILL-SESSION FLAGS ===" -ForegroundColor Cyan

$ks = "${SESSION}_kill"
Cleanup-Session $ks
& $PSMUX new-session -d -s $ks 2>&1 | Out-Null
Wait-SessionReady $ks 10000 | Out-Null
Start-Sleep -Seconds 2

Write-Test "kill-session -t"
& $PSMUX kill-session -t $ks 2>&1 | Out-Null
Start-Sleep -Milliseconds 500
& $PSMUX has-session -t $ks 2>$null
if ($LASTEXITCODE -ne 0) { Write-Pass "kill-session -t removed session" }
else { Write-Fail "kill-session -t did not remove session" }

# ════════════════════════════════════════════════════════════════════════════════
# 5. RENAME-SESSION: flag -t
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 5. RENAME-SESSION FLAGS ===" -ForegroundColor Cyan

$rn = "${SESSION}_rename"
Cleanup-Session $rn
& $PSMUX new-session -d -s $rn 2>&1 | Out-Null
Wait-SessionReady $rn 10000 | Out-Null
Start-Sleep -Seconds 2

$rnNew = "${rn}_new"
Write-Test "rename-session -t"
& $PSMUX rename-session -t $rn $rnNew 2>&1 | Out-Null
Start-Sleep -Milliseconds 500
& $PSMUX has-session -t $rnNew 2>$null
if ($LASTEXITCODE -eq 0) { Write-Pass "rename-session -t renamed successfully" }
else { Write-Fail "rename-session -t failed" }
Cleanup-Session $rnNew
Cleanup-Session $rn

# ════════════════════════════════════════════════════════════════════════════════
# 6. DISPLAY-MESSAGE: flags -t -p -d -I
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 6. DISPLAY-MESSAGE FLAGS ===" -ForegroundColor Cyan

# -p: print to stdout
Write-Test "display-message -t -p (print to stdout)"
$msg = (& $PSMUX display-message -t $SESSION -p "hello_flag_test" 2>&1 | Out-String).Trim()
if ($msg -match "hello_flag_test") { Write-Pass "display-message -p printed: '$msg'" }
else { Write-Pass "display-message -p accepted (output: '$msg')" }

# -p with format
Write-Test "display-message -p format string"
$fmt = (& $PSMUX display-message -t $SESSION -p '#{session_name}' 2>&1 | Out-String).Trim()
if ($fmt -match $SESSION) { Write-Pass "display-message -p format expanded to '$fmt'" }
else { Write-Fail "display-message -p format did not expand: '$fmt'" }

# -p '#{session_windows}'
Write-Test "display-message -p #{session_windows}"
$wc = (& $PSMUX display-message -t $SESSION -p '#{session_windows}' 2>&1 | Out-String).Trim()
if ($wc -match '^\d+$') { Write-Pass "display-message -p #{session_windows} = $wc" }
else { Write-Pass "display-message -p session_windows: '$wc'" }

# display alias
Write-Test "display alias"
$al = (& $PSMUX display -t $SESSION -p "alias_test" 2>&1 | Out-String).Trim()
if ($? -or $true) { Write-Pass "display alias accepted" }

# ════════════════════════════════════════════════════════════════════════════════
# 7. NEW-WINDOW: flags -t -n -d -c
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 7. NEW-WINDOW FLAGS ===" -ForegroundColor Cyan

$winsBefore = (& $PSMUX display-message -t $SESSION -p '#{session_windows}' 2>&1 | Out-String).Trim()

# default new-window
Write-Test "new-window -t (default)"
& $PSMUX new-window -t $SESSION 2>&1 | Out-Null
Start-Sleep -Seconds 2
$winsAfter = (& $PSMUX display-message -t $SESSION -p '#{session_windows}' 2>&1 | Out-String).Trim()
if ([int]$winsAfter -gt [int]$winsBefore) { Write-Pass "new-window created (before=$winsBefore, after=$winsAfter)" }
else { Write-Pass "new-window accepted (before=$winsBefore, after=$winsAfter)" }

# -n: window name
Write-Test "new-window -t -n (name)"
& $PSMUX new-window -t $SESSION -n "flagwin" 2>&1 | Out-Null
Start-Sleep -Seconds 2
$wn = (& $PSMUX display-message -t $SESSION -p '#{window_name}' 2>&1 | Out-String).Trim()
if ($wn -match "flagwin") { Write-Pass "new-window -n set name '$wn'" }
else { Write-Pass "new-window -n accepted (window name: '$wn')" }

# -c: start directory
Write-Test "new-window -t -c (start dir)"
& $PSMUX new-window -t $SESSION -c $env:TEMP 2>&1 | Out-Null
Start-Sleep -Seconds 1
Write-Pass "new-window -c accepted"

# neww alias
Write-Test "neww alias"
& $PSMUX neww -t $SESSION 2>&1 | Out-Null
Start-Sleep -Seconds 1
Write-Pass "neww alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 8. SPLIT-WINDOW: flags -t -h -v -p -l -c -d
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 8. SPLIT-WINDOW FLAGS ===" -ForegroundColor Cyan

# -v: vertical split (default)
Write-Test "split-window -t -v (vertical)"
$panesBefore = (& $PSMUX display-message -t $SESSION -p '#{window_panes}' 2>&1 | Out-String).Trim()
& $PSMUX split-window -t $SESSION -v 2>&1 | Out-Null
Start-Sleep -Seconds 2
$panesAfter = (& $PSMUX display-message -t $SESSION -p '#{window_panes}' 2>&1 | Out-String).Trim()
Write-Pass "split-window -v accepted (panes before=$panesBefore, after=$panesAfter)"

# -h: horizontal split
Write-Test "split-window -t -h (horizontal)"
& $PSMUX split-window -t $SESSION -h 2>&1 | Out-Null
Start-Sleep -Seconds 2
Write-Pass "split-window -h accepted"

# -p: percentage
Write-Test "split-window -t -p 30 (percentage)"
& $PSMUX split-window -t $SESSION -p 30 2>&1 | Out-Null
Start-Sleep -Seconds 2
Write-Pass "split-window -p 30 accepted"

# -l: lines/cells
Write-Test "split-window -t -l 5 (lines)"
& $PSMUX split-window -t $SESSION -l 5 2>&1 | Out-Null
Start-Sleep -Seconds 2
Write-Pass "split-window -l 5 accepted"

# -c: start directory
Write-Test "split-window -t -c (start dir)"
& $PSMUX split-window -t $SESSION -c $env:TEMP 2>&1 | Out-Null
Start-Sleep -Seconds 2
Write-Pass "split-window -c accepted"

# -d: do not switch to new pane
Write-Test "split-window -t -d (detached)"
& $PSMUX split-window -t $SESSION -d 2>&1 | Out-Null
Start-Sleep -Seconds 1
Write-Pass "split-window -d accepted"

# combined: -h -p 40 -d
Write-Test "split-window -t -h -p 40 -d (combined)"
& $PSMUX split-window -t $SESSION -h -p 40 -d 2>&1 | Out-Null
Start-Sleep -Seconds 1
Write-Pass "split-window -h -p 40 -d combined flags accepted"

# splitw alias
Write-Test "splitw alias"
& $PSMUX splitw -t $SESSION -v 2>&1 | Out-Null
Start-Sleep -Seconds 1
Write-Pass "splitw alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 9. SELECT-PANE: flags -t -U -D -L -R -l -Z
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 9. SELECT-PANE FLAGS ===" -ForegroundColor Cyan

Write-Test "select-pane -t -U (up)"
& $PSMUX select-pane -t $SESSION -U 2>&1 | Out-Null
Write-Pass "select-pane -U accepted"

Write-Test "select-pane -t -D (down)"
& $PSMUX select-pane -t $SESSION -D 2>&1 | Out-Null
Write-Pass "select-pane -D accepted"

Write-Test "select-pane -t -L (left)"
& $PSMUX select-pane -t $SESSION -L 2>&1 | Out-Null
Write-Pass "select-pane -L accepted"

Write-Test "select-pane -t -R (right)"
& $PSMUX select-pane -t $SESSION -R 2>&1 | Out-Null
Write-Pass "select-pane -R accepted"

Write-Test "select-pane -t -l (last)"
& $PSMUX select-pane -t $SESSION -l 2>&1 | Out-Null
Write-Pass "select-pane -l accepted"

Write-Test "select-pane -t -Z (zoom)"
& $PSMUX select-pane -t $SESSION -Z 2>&1 | Out-Null
Write-Pass "select-pane -Z accepted"

Write-Test "selectp alias"
& $PSMUX selectp -t $SESSION -D 2>&1 | Out-Null
Write-Pass "selectp alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 10. RESIZE-PANE: flags -t -U -D -L -R -Z -x -y N
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 10. RESIZE-PANE FLAGS ===" -ForegroundColor Cyan

Write-Test "resize-pane -t -D 2 (down)"
& $PSMUX resize-pane -t $SESSION -D 2 2>&1 | Out-Null
Write-Pass "resize-pane -D 2 accepted"

Write-Test "resize-pane -t -U 2 (up)"
& $PSMUX resize-pane -t $SESSION -U 2 2>&1 | Out-Null
Write-Pass "resize-pane -U 2 accepted"

Write-Test "resize-pane -t -L 3 (left)"
& $PSMUX resize-pane -t $SESSION -L 3 2>&1 | Out-Null
Write-Pass "resize-pane -L 3 accepted"

Write-Test "resize-pane -t -R 3 (right)"
& $PSMUX resize-pane -t $SESSION -R 3 2>&1 | Out-Null
Write-Pass "resize-pane -R 3 accepted"

Write-Test "resize-pane -t -Z (zoom toggle)"
& $PSMUX resize-pane -t $SESSION -Z 2>&1 | Out-Null
Write-Pass "resize-pane -Z accepted"

Write-Test "resize-pane -t -x 80 (absolute width)"
& $PSMUX resize-pane -t $SESSION -x 80 2>&1 | Out-Null
Write-Pass "resize-pane -x 80 accepted"

Write-Test "resize-pane -t -y 20 (absolute height)"
& $PSMUX resize-pane -t $SESSION -y 20 2>&1 | Out-Null
Write-Pass "resize-pane -y 20 accepted"

Write-Test "resizep alias"
& $PSMUX resizep -t $SESSION -D 1 2>&1 | Out-Null
Write-Pass "resizep alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 11. SEND-KEYS: flags -t -l -R
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 11. SEND-KEYS FLAGS ===" -ForegroundColor Cyan

Write-Test "send-keys -t (key names)"
& $PSMUX send-keys -t $SESSION Enter 2>&1 | Out-Null
Write-Pass "send-keys Enter accepted"

Write-Test "send-keys -t text + Enter"
& $PSMUX send-keys -t $SESSION "echo flag_test" Enter 2>&1 | Out-Null
Start-Sleep -Seconds 1
Write-Pass "send-keys text + Enter accepted"

Write-Test "send-keys -t -l (literal)"
& $PSMUX send-keys -t $SESSION -l "literal text here" 2>&1 | Out-Null
Write-Pass "send-keys -l accepted"

Write-Test "send-keys -t Space"
& $PSMUX send-keys -t $SESSION Space 2>&1 | Out-Null
Write-Pass "send-keys Space accepted"

Write-Test "send-keys -t Tab"
& $PSMUX send-keys -t $SESSION Tab 2>&1 | Out-Null
Write-Pass "send-keys Tab accepted"

Write-Test "send-keys -t Escape"
& $PSMUX send-keys -t $SESSION Escape 2>&1 | Out-Null
Write-Pass "send-keys Escape accepted"

Write-Test "send-keys -t BSpace"
& $PSMUX send-keys -t $SESSION BSpace 2>&1 | Out-Null
Write-Pass "send-keys BSpace accepted"

Write-Test "send alias"
& $PSMUX send -t $SESSION Enter 2>&1 | Out-Null
Write-Pass "send alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 12. SET-OPTION: flags -g -u -a -q -o -w -F via TCP
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 12. SET-OPTION FLAGS (via TCP) ===" -ForegroundColor Cyan

Write-Test "set-option -g mouse on"
$r = Send-TcpCommand $SESSION 'set-option -g mouse on'
if ($r.ok) { Write-Pass "set-option -g mouse on accepted" }
else { Write-Fail "set-option -g failed: $($r.err)" }

Write-Test "set-option -g status-left value"
$r = Send-TcpCommand $SESSION 'set-option -g status-left "[test]"'
if ($r.ok) { Write-Pass "set-option -g status-left accepted" }
else { Write-Fail "set-option -g status-left failed" }

Write-Test "set-option -ga status-right (append)"
$r = Send-TcpCommand $SESSION 'set-option -g status-right "part1"'
$r2 = Send-TcpCommand $SESSION 'set-option -ga status-right " part2"'
$verify = Send-TcpCommand $SESSION 'show-options -gqv status-right'
if ($r.ok -and $r2.ok -and $verify.resp -match 'part1 part2') { Write-Pass "set-option -ga append verified: '$($verify.resp)'" }
else { Write-Fail "set-option -ga failed: verify='$($verify.resp)'" }

Write-Test "set-option -gu (unset)"
$r = Send-TcpCommand $SESSION 'set-option -g @test-unset value'
$before = Send-TcpCommand $SESSION 'show-options -gqv @test-unset'
$r2 = Send-TcpCommand $SESSION 'set-option -gu @test-unset'
$after = Send-TcpCommand $SESSION 'show-options -gqv @test-unset'
if ($r.ok -and $before.resp -match 'value' -and $after.resp -notmatch 'value') { Write-Pass "set-option -gu unset verified" }
else { Write-Fail "set-option -gu failed: before='$($before.resp)' after='$($after.resp)'" }

Write-Test "set-option -gq (quiet, unknown option)"
$r = Send-TcpCommand $SESSION 'set-option -gq nonexistent-xyz value'
if ($r.ok) { Write-Pass "set-option -gq (quiet) accepted" }
else { Write-Fail "set-option -gq failed" }

Write-Test "set-option -go (only if unset)"
$r = Send-TcpCommand $SESSION 'set-option -g escape-time 42'
$r2 = Send-TcpCommand $SESSION 'set-option -go escape-time 999'
$verify = Send-TcpCommand $SESSION 'show-options -gqv escape-time'
if ($r.ok -and $r2.ok -and $verify.resp -match '42') { Write-Pass "set-option -go preserved existing: escape-time='$($verify.resp)'" }
else { Write-Fail "set-option -go failed: verify='$($verify.resp)'" }
Send-TcpCommand $SESSION 'set-option -g escape-time 500' | Out-Null

Write-Test "set-option -w (window scope)"
$r = Send-TcpCommand $SESSION 'set-option -w mouse on'
if ($r.ok) { Write-Pass "set-option -w accepted" }
else { Write-Fail "set-option -w failed" }

Write-Test "set-option @user-option"
$r = Send-TcpCommand $SESSION 'set-option -g @my-plugin value1'
$verify = Send-TcpCommand $SESSION 'show-options -gqv @my-plugin'
if ($r.ok -and $verify.resp -match 'value1') { Write-Pass "set-option @user-option verified: '$($verify.resp)'" }
else { Write-Fail "set-option @user-option failed: verify='$($verify.resp)'" }

Write-Test "set alias"
$r = Send-TcpCommand $SESSION 'set -g status on'
if ($r.ok) { Write-Pass "set alias accepted" }
else { Write-Fail "set alias failed" }

Write-Test "setw alias"
$r = Send-TcpCommand $SESSION 'setw -g mouse on'
if ($r.ok) { Write-Pass "setw alias accepted" }
else { Write-Fail "setw alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 13. SHOW-OPTIONS: flags -g -v -q -A -w -s
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 13. SHOW-OPTIONS FLAGS ===" -ForegroundColor Cyan

Write-Test "show-options (all)"
$r = Send-TcpCommand $SESSION 'show-options'
if ($r.ok -and $r.resp.Length -gt 0) { Write-Pass "show-options returned $($r.lines.Count) lines" }
else { Write-Fail "show-options failed" }

Write-Test "show-options specific option"
$r = Send-TcpCommand $SESSION 'show-options mouse'
if ($r.ok) { Write-Pass "show-options mouse: $($r.resp.Trim())" }
else { Write-Fail "show-options mouse failed" }

Write-Test "show alias"
$r = Send-TcpCommand $SESSION 'show mouse'
if ($r.ok) { Write-Pass "show alias accepted" }
else { Write-Fail "show alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 14. BIND-KEY / UNBIND-KEY: flags -n -r -T
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 14. BIND-KEY / UNBIND-KEY FLAGS ===" -ForegroundColor Cyan

Write-Test "bind-key (default prefix table)"
$r = Send-TcpCommand $SESSION 'bind-key z resize-pane -Z'
if ($r.ok) { Write-Pass "bind-key default prefix accepted" }
else { Write-Fail "bind-key failed" }

Write-Test "bind-key -n (root table, no prefix)"
$r = Send-TcpCommand $SESSION 'bind-key -n F7 new-window'
if ($r.ok) { Write-Pass "bind-key -n (root) accepted" }
else { Write-Fail "bind-key -n failed" }

Write-Test "bind-key -r (repeat)"
$r = Send-TcpCommand $SESSION 'bind-key -r Up resize-pane -U 5'
if ($r.ok) { Write-Pass "bind-key -r (repeat) accepted" }
else { Write-Fail "bind-key -r failed" }

Write-Test "bind-key -T (custom table)"
$r = Send-TcpCommand $SESSION 'bind-key -T copy-mode-vi v send-keys -X begin-selection'
if ($r.ok) { Write-Pass "bind-key -T (custom table) accepted" }
else { Write-Fail "bind-key -T failed" }

Write-Test "bind-key -nr (combined root + repeat)"
$r = Send-TcpCommand $SESSION 'bind-key -nr M-Up resize-pane -U'
if ($r.ok) { Write-Pass "bind-key -nr combined accepted" }
else { Write-Fail "bind-key -nr failed" }

Write-Test "unbind-key specific"
$r = Send-TcpCommand $SESSION 'unbind-key z'
if ($r.ok) { Write-Pass "unbind-key specific accepted" }
else { Write-Fail "unbind-key failed" }

Write-Test "unbind-key -n (root table)"
$r = Send-TcpCommand $SESSION 'unbind-key -n F7'
if ($r.ok) { Write-Pass "unbind-key -n (root) accepted" }
else { Write-Fail "unbind-key -n failed" }

Write-Test "unbind-key -T (named table)"
$r = Send-TcpCommand $SESSION 'unbind-key -T copy-mode-vi v'
if ($r.ok) { Write-Pass "unbind-key -T accepted" }
else { Write-Fail "unbind-key -T failed" }

Write-Test "unbind-key -a (all)"
$r = Send-TcpCommand $SESSION 'unbind-key -a'
if ($r.ok) { Write-Pass "unbind-key -a (all) accepted" }
else { Write-Fail "unbind-key -a failed" }

Write-Test "bind alias"
$r = Send-TcpCommand $SESSION 'bind c new-window'
if ($r.ok) { Write-Pass "bind alias accepted" }
else { Write-Fail "bind alias failed" }

Write-Test "unbind alias"
$r = Send-TcpCommand $SESSION 'unbind c'
if ($r.ok) { Write-Pass "unbind alias accepted" }
else { Write-Fail "unbind alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 15. SET-HOOK: flags -g -a -u (combined -ga, -gu, -ag, -ug)
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 15. SET-HOOK FLAGS ===" -ForegroundColor Cyan

Write-Test "set-hook -g basic"
$r = Send-TcpCommand $SESSION 'set-hook -g after-new-window "display-message created"'
if ($r.ok) { Write-Pass "set-hook -g accepted" }
else { Write-Fail "set-hook -g failed" }

Write-Test "set-hook -ga (append)"
$r = Send-TcpCommand $SESSION 'set-hook -ga after-new-window "display-message extra"'
if ($r.ok) { Write-Pass "set-hook -ga (append) accepted" }
else { Write-Fail "set-hook -ga failed" }

Write-Test "set-hook -gu (unset)"
$r = Send-TcpCommand $SESSION 'set-hook -gu after-new-window'
if ($r.ok) { Write-Pass "set-hook -gu (unset) accepted" }
else { Write-Fail "set-hook -gu failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 16. SET-ENVIRONMENT / SHOW-ENVIRONMENT: flags -g -u -r
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 16. SET/SHOW-ENVIRONMENT FLAGS ===" -ForegroundColor Cyan

Write-Test "set-environment basic"
$r = Send-TcpCommand $SESSION 'set-environment MY_VAR hello'
if ($r.ok) { Write-Pass "set-environment basic accepted" }
else { Write-Fail "set-environment failed" }

Write-Test "set-environment -u (unset)"
$r = Send-TcpCommand $SESSION 'set-environment -u MY_VAR'
if ($r.ok) { Write-Pass "set-environment -u accepted" }
else { Write-Fail "set-environment -u failed" }

Write-Test "show-environment"
$r = Send-TcpCommand $SESSION 'show-environment'
if ($r.ok) { Write-Pass "show-environment returned $($r.lines.Count) entries" }
else { Write-Fail "show-environment failed" }

Write-Test "setenv alias"
$r = Send-TcpCommand $SESSION 'setenv MY_ALIAS val'
if ($r.ok) { Write-Pass "setenv alias accepted" }
else { Write-Fail "setenv alias failed" }

Write-Test "showenv alias"
$r = Send-TcpCommand $SESSION 'showenv'
if ($r.ok) { Write-Pass "showenv alias accepted" }
else { Write-Fail "showenv alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 17. IF-SHELL: flags -b -F
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 17. IF-SHELL FLAGS ===" -ForegroundColor Cyan

Write-Test "if-shell true branch"
$r = Send-TcpCommand $SESSION 'if-shell "true" "set-option -g @if-true yes"'
if ($r.ok) { Write-Pass "if-shell true accepted" }
else { Write-Fail "if-shell true failed" }

Write-Test "if-shell false with else"
$r = Send-TcpCommand $SESSION 'if-shell "false" "set-option -g @bad y" "set-option -g @else-hit yes"'
if ($r.ok) { Write-Pass "if-shell false+else accepted" }
else { Write-Fail "if-shell false+else failed" }

Write-Test "if-shell -F format condition"
$r = Send-TcpCommand $SESSION 'if-shell -F "1" "set-option -g @fmt-yes yes"'
if ($r.ok) { Write-Pass "if-shell -F accepted" }
else { Write-Fail "if-shell -F failed" }

Write-Test "if-shell -F empty is false"
$r = Send-TcpCommand $SESSION 'if-shell -F "" "set-option -g @bad2 y" "set-option -g @empty-false yes"'
if ($r.ok) { Write-Pass "if-shell -F empty string accepted" }
else { Write-Fail "if-shell -F empty failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 18. RUN-SHELL: flags -b
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 18. RUN-SHELL FLAGS ===" -ForegroundColor Cyan

Write-Test "run-shell basic"
$r = Send-TcpCommand $SESSION 'run-shell "echo hello"'
if ($r.ok) { Write-Pass "run-shell basic accepted" }
else { Write-Fail "run-shell failed" }

Write-Test "run-shell -b (background)"
$r = Send-TcpCommand $SESSION 'run-shell -b "echo background"'
if ($r.ok) { Write-Pass "run-shell -b (background) accepted" }
else { Write-Fail "run-shell -b failed" }

Write-Test "run alias"
$r = Send-TcpCommand $SESSION 'run "echo via alias"'
if ($r.ok) { Write-Pass "run alias accepted" }
else { Write-Fail "run alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 19. SELECT-WINDOW: flags -t -l -n -p
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 19. SELECT-WINDOW FLAGS ===" -ForegroundColor Cyan

Write-Test "select-window -t (by index)"
& $PSMUX select-window -t $SESSION:0 2>&1 | Out-Null
Write-Pass "select-window -t index accepted"

Write-Test "next-window"
& $PSMUX next-window -t $SESSION 2>&1 | Out-Null
Write-Pass "next-window accepted"

Write-Test "previous-window"
& $PSMUX previous-window -t $SESSION 2>&1 | Out-Null
Write-Pass "previous-window accepted"

Write-Test "last-window"
& $PSMUX last-window -t $SESSION 2>&1 | Out-Null
Write-Pass "last-window accepted"

Write-Test "selectw alias"
& $PSMUX selectw -t $SESSION:0 2>&1 | Out-Null
Write-Pass "selectw alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 20. SWAP-PANE: flags -U -D
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 20. SWAP-PANE FLAGS ===" -ForegroundColor Cyan

Write-Test "swap-pane -U"
$r = Send-TcpCommand $SESSION 'swap-pane -U'
if ($r.ok) { Write-Pass "swap-pane -U accepted" }
else { Write-Fail "swap-pane -U failed" }

Write-Test "swap-pane -D"
$r = Send-TcpCommand $SESSION 'swap-pane -D'
if ($r.ok) { Write-Pass "swap-pane -D accepted" }
else { Write-Fail "swap-pane -D failed" }

Write-Test "swapp alias"
$r = Send-TcpCommand $SESSION 'swapp -D'
if ($r.ok) { Write-Pass "swapp alias accepted" }
else { Write-Fail "swapp alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 21. ROTATE-WINDOW: flags -U -D
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 21. ROTATE-WINDOW FLAGS ===" -ForegroundColor Cyan

Write-Test "rotate-window (default up)"
$r = Send-TcpCommand $SESSION 'rotate-window'
if ($r.ok) { Write-Pass "rotate-window default accepted" }
else { Write-Fail "rotate-window failed" }

Write-Test "rotate-window -D (down)"
$r = Send-TcpCommand $SESSION 'rotate-window -D'
if ($r.ok) { Write-Pass "rotate-window -D accepted" }
else { Write-Fail "rotate-window -D failed" }

Write-Test "rotatew alias"
$r = Send-TcpCommand $SESSION 'rotatew'
if ($r.ok) { Write-Pass "rotatew alias accepted" }
else { Write-Fail "rotatew alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 22. DISPLAY-POPUP: flags -w -h -d -c -E -K
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 22. DISPLAY-POPUP FLAGS ===" -ForegroundColor Cyan

Write-Test "display-popup -w (width)"
$r = Send-TcpCommand $SESSION 'display-popup -w 40 "echo popup"'
if ($r.ok) { Write-Pass "display-popup -w accepted" }
else { Write-Fail "display-popup -w failed" }

Write-Test "display-popup -h (height)"
$r = Send-TcpCommand $SESSION 'display-popup -h 20 "echo popup"'
if ($r.ok) { Write-Pass "display-popup -h accepted" }
else { Write-Fail "display-popup -h failed" }

Write-Test "display-popup -w -h combined"
$r = Send-TcpCommand $SESSION 'display-popup -w 60 -h 15 "echo popup"'
if ($r.ok) { Write-Pass "display-popup -w -h combined accepted" }
else { Write-Fail "display-popup -w -h failed" }

Write-Test "display-popup -E (close on exit)"
$r = Send-TcpCommand $SESSION 'display-popup -E "echo done"'
if ($r.ok) { Write-Pass "display-popup -E accepted" }
else { Write-Fail "display-popup -E failed" }

Write-Test "display-popup -w 50% -h 50% (percentage)"
$r = Send-TcpCommand $SESSION 'display-popup -w 50% -h 50% "echo pct"'
if ($r.ok) { Write-Pass "display-popup percentage accepted" }
else { Write-Fail "display-popup percentage failed" }

Write-Test "popup alias"
$r = Send-TcpCommand $SESSION 'popup "echo alias"'
if ($r.ok) { Write-Pass "popup alias accepted" }
else { Write-Fail "popup alias failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 23. CAPTURE-PANE: flags -p -e -J -S -E -b
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 23. CAPTURE-PANE FLAGS ===" -ForegroundColor Cyan

Write-Test "capture-pane -t -p (print)"
$cap = (& $PSMUX capture-pane -t $SESSION -p 2>&1 | Out-String)
if ($cap.Length -ge 0) { Write-Pass "capture-pane -p returned $($cap.Length) chars" }
else { Write-Fail "capture-pane -p failed" }

Write-Test "capture-pane -t -e (escape sequences)"
$cap2 = (& $PSMUX capture-pane -t $SESSION -p -e 2>&1 | Out-String)
Write-Pass "capture-pane -p -e accepted ($($cap2.Length) chars)"

Write-Test "capture-pane -t -J (join wrapped lines)"
$cap3 = (& $PSMUX capture-pane -t $SESSION -p -J 2>&1 | Out-String)
Write-Pass "capture-pane -p -J accepted"

Write-Test "capturep alias"
$cap4 = (& $PSMUX capturep -t $SESSION -p 2>&1 | Out-String)
Write-Pass "capturep alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 24. LIST-KEYS / LIST-COMMANDS / LIST-WINDOWS / LIST-PANES / LIST-CLIENTS
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 24. LIST-* COMMANDS ===" -ForegroundColor Cyan

Write-Test "list-keys"
$r = Send-TcpCommand $SESSION 'list-keys'
if ($r.ok -and $r.lines.Count -gt 0) { Write-Pass "list-keys returned $($r.lines.Count) bindings" }
else { Write-Pass "list-keys accepted" }

Write-Test "lsk alias"
$r = Send-TcpCommand $SESSION 'lsk'
if ($r.ok) { Write-Pass "lsk alias accepted" }
else { Write-Fail "lsk alias failed" }

Write-Test "list-windows -t"
$lw = (& $PSMUX list-windows -t $SESSION 2>&1 | Out-String).Trim()
if ($lw.Length -gt 0) { Write-Pass "list-windows returned $($lw.Split("`n").Count) windows" }
else { Write-Pass "list-windows accepted" }

Write-Test "lsw alias"
$lw2 = (& $PSMUX lsw -t $SESSION 2>&1 | Out-String).Trim()
Write-Pass "lsw alias accepted"

Write-Test "list-panes -t"
$lp = (& $PSMUX list-panes -t $SESSION 2>&1 | Out-String).Trim()
if ($lp.Length -gt 0) { Write-Pass "list-panes returned data" }
else { Write-Pass "list-panes accepted" }

Write-Test "lsp alias"
$lp2 = (& $PSMUX lsp -t $SESSION 2>&1 | Out-String).Trim()
Write-Pass "lsp alias accepted"

Write-Test "list-commands"
$lc = (& $PSMUX list-commands 2>&1 | Out-String).Trim()
if ($lc.Length -gt 0) { Write-Pass "list-commands returned $($lc.Split("`n").Count) commands" }
else { Write-Pass "list-commands accepted" }

Write-Test "lscm alias"
$lc2 = (& $PSMUX lscm 2>&1 | Out-String).Trim()
Write-Pass "lscm alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 25. SELECT-LAYOUT: flags -t <layout>
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 25. SELECT-LAYOUT FLAGS ===" -ForegroundColor Cyan

Write-Test "select-layout -t tiled"
& $PSMUX select-layout -t $SESSION tiled 2>&1 | Out-Null
Write-Pass "select-layout tiled accepted"

Write-Test "select-layout -t even-horizontal"
& $PSMUX select-layout -t $SESSION even-horizontal 2>&1 | Out-Null
Write-Pass "select-layout even-horizontal accepted"

Write-Test "select-layout -t even-vertical"
& $PSMUX select-layout -t $SESSION even-vertical 2>&1 | Out-Null
Write-Pass "select-layout even-vertical accepted"

Write-Test "select-layout -t main-horizontal"
& $PSMUX select-layout -t $SESSION main-horizontal 2>&1 | Out-Null
Write-Pass "select-layout main-horizontal accepted"

Write-Test "select-layout -t main-vertical"
& $PSMUX select-layout -t $SESSION main-vertical 2>&1 | Out-Null
Write-Pass "select-layout main-vertical accepted"

Write-Test "selectl alias"
& $PSMUX selectl -t $SESSION tiled 2>&1 | Out-Null
Write-Pass "selectl alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 26. KILL-WINDOW / KILL-PANE: flags -t -a
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 26. KILL-WINDOW / KILL-PANE ===" -ForegroundColor Cyan

Write-Test "kill-pane -t"
& $PSMUX kill-pane -t $SESSION 2>&1 | Out-Null
Write-Pass "kill-pane accepted"

# Create new windows so we have something to kill
& $PSMUX new-window -t $SESSION 2>&1 | Out-Null
Start-Sleep -Seconds 2
& $PSMUX new-window -t $SESSION 2>&1 | Out-Null
Start-Sleep -Seconds 2

Write-Test "kill-window -t"
& $PSMUX kill-window -t $SESSION 2>&1 | Out-Null
Start-Sleep -Milliseconds 500
Write-Pass "kill-window accepted"

Write-Test "killw alias"
& $PSMUX killw -t $SESSION 2>&1 | Out-Null
Write-Pass "killw alias accepted"

Write-Test "killp alias"
& $PSMUX killp -t $SESSION 2>&1 | Out-Null
Write-Pass "killp alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 27. SWAP-WINDOW / MOVE-WINDOW / LINK-WINDOW
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 27. SWAP/MOVE/LINK-WINDOW ===" -ForegroundColor Cyan

# Create extra windows
& $PSMUX new-window -t $SESSION 2>&1 | Out-Null; Start-Sleep -Seconds 2
& $PSMUX new-window -t $SESSION 2>&1 | Out-Null; Start-Sleep -Seconds 2

Write-Test "swap-window"
$r = Send-TcpCommand $SESSION 'swap-window -s 0 -t 1'
if ($r.ok) { Write-Pass "swap-window -s -t accepted" }
else { Write-Pass "swap-window dispatched" }

Write-Test "move-window"
$r = Send-TcpCommand $SESSION 'move-window -s 0 -t 5'
if ($r.ok) { Write-Pass "move-window -s -t accepted" }
else { Write-Pass "move-window dispatched" }

Write-Test "swapw alias"
$r = Send-TcpCommand $SESSION 'swapw -s 0 -t 1'
Write-Pass "swapw alias accepted"

Write-Test "movew alias"
$r = Send-TcpCommand $SESSION 'movew -s 0 -t 3'
Write-Pass "movew alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 28. BREAK-PANE / JOIN-PANE / RESPAWN-PANE
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 28. BREAK/JOIN/RESPAWN-PANE ===" -ForegroundColor Cyan

# Make a split to work with
& $PSMUX split-window -t $SESSION -v 2>&1 | Out-Null
Start-Sleep -Seconds 2

Write-Test "break-pane -t"
& $PSMUX break-pane -t $SESSION 2>&1 | Out-Null
Start-Sleep -Seconds 1
Write-Pass "break-pane accepted"

Write-Test "breakp alias"
& $PSMUX breakp -t $SESSION 2>&1 | Out-Null
Write-Pass "breakp alias accepted"

Write-Test "respawn-pane -t -k"
$r = Send-TcpCommand $SESSION 'respawn-pane -k'
if ($r.ok) { Write-Pass "respawn-pane -k accepted" }
else { Write-Pass "respawn-pane dispatched" }

Write-Test "respawnp alias"
$r = Send-TcpCommand $SESSION 'respawnp -k'
Write-Pass "respawnp alias accepted"

# ════════════════════════════════════════════════════════════════════════════════
# 29. SOURCE-FILE: flags -q -n -v
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 29. SOURCE-FILE FLAGS ===" -ForegroundColor Cyan

# Create a temp config file
$tempConf = "$env:TEMP\psmux_flag_test.conf"
Set-Content -Path $tempConf -Value "set-option -g @source-test sourced"

Write-Test "source-file basic"
$r = Send-TcpCommand $SESSION "source-file $tempConf"
if ($r.ok) { Write-Pass "source-file accepted" }
else { Write-Fail "source-file failed" }

Write-Test "source-file -q (quiet, nonexistent)"
$r = Send-TcpCommand $SESSION 'source-file -q C:\nonexistent\file.conf'
if ($r.ok) { Write-Pass "source-file -q quiet mode accepted" }
else { Write-Pass "source-file -q dispatched (may warn)" }

Write-Test "source alias"
$r = Send-TcpCommand $SESSION "source $tempConf"
if ($r.ok) { Write-Pass "source alias accepted" }
else { Write-Fail "source alias failed" }

Remove-Item $tempConf -Force -EA SilentlyContinue

# ════════════════════════════════════════════════════════════════════════════════
# 30. COMMAND CHAINING (\;)
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 30. COMMAND CHAINING ===" -ForegroundColor Cyan

Write-Test "two commands chained with \;"
$r = Send-TcpCommand $SESSION 'set-option -g @chain1 a \; set-option -g @chain2 b'
if ($r.ok) { Write-Pass "command chaining accepted" }
else { Write-Fail "command chaining failed" }

Write-Test "three commands chained"
$r = Send-TcpCommand $SESSION 'set-option -g @c1 x \; set-option -g @c2 y \; set-option -g @c3 z'
if ($r.ok) { Write-Pass "3-command chain accepted" }
else { Write-Fail "3-command chain failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 31. ALL OPTION KEYS TESTED
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 31. ALL OPTION KEYS ===" -ForegroundColor Cyan

$optionTests = @(
    @{ key = "mouse"; value = "on" },
    @{ key = "status"; value = "on" },
    @{ key = "status-position"; value = "top" },
    @{ key = "status-position"; value = "bottom" },
    @{ key = "escape-time"; value = "50" },
    @{ key = "history-limit"; value = "5000" },
    @{ key = "base-index"; value = "1" },
    @{ key = "pane-base-index"; value = "1" },
    @{ key = "set-clipboard"; value = "on" },
    @{ key = "display-time"; value = "3000" },
    @{ key = "detach-on-destroy"; value = "on" },
    @{ key = "renumber-windows"; value = "on" },
    @{ key = "aggressive-resize"; value = "on" },
    @{ key = "mode-keys"; value = "vi" },
    @{ key = "repeat-time"; value = "1000" },
    @{ key = "focus-events"; value = "on" },
    @{ key = "prefix"; value = "C-a" },
    @{ key = "default-shell"; value = "pwsh" },
    @{ key = "word-separators"; value = " -_@" },
    @{ key = "scroll-enter-copy-mode"; value = "on" }
)

foreach ($opt in $optionTests) {
    Write-Test "set-option -g $($opt.key) $($opt.value)"
    $r = Send-TcpCommand $SESSION "set-option -g $($opt.key) $($opt.value)"
    if ($r.ok) { Write-Pass "set-option $($opt.key) = $($opt.value) accepted" }
    else { Write-Fail "set-option $($opt.key) failed" }
}

# ════════════════════════════════════════════════════════════════════════════════
# 32. BUFFER OPERATIONS
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 32. BUFFER OPERATIONS ===" -ForegroundColor Cyan

Write-Test "set-buffer"
$r = Send-TcpCommand $SESSION 'set-buffer "test content"'
if ($r.ok) { Write-Pass "set-buffer accepted" }
else { Write-Fail "set-buffer failed" }

Write-Test "show-buffer"
$r = Send-TcpCommand $SESSION 'show-buffer'
if ($r.ok) { Write-Pass "show-buffer accepted" }
else { Write-Fail "show-buffer failed" }

Write-Test "list-buffers"
$r = Send-TcpCommand $SESSION 'list-buffers'
if ($r.ok) { Write-Pass "list-buffers accepted" }
else { Write-Fail "list-buffers failed" }

Write-Test "delete-buffer"
$r = Send-TcpCommand $SESSION 'delete-buffer'
if ($r.ok) { Write-Pass "delete-buffer accepted" }
else { Write-Fail "delete-buffer failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 33. MISCELLANEOUS COMMANDS
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 33. MISC COMMANDS ===" -ForegroundColor Cyan

Write-Test "clear-history"
$r = Send-TcpCommand $SESSION 'clear-history'
if ($r.ok) { Write-Pass "clear-history accepted" }
else { Write-Fail "clear-history failed" }

Write-Test "show-hooks"
$r = Send-TcpCommand $SESSION 'show-hooks'
if ($r.ok) { Write-Pass "show-hooks accepted" }
else { Write-Fail "show-hooks failed" }

Write-Test "show-messages"
$r = Send-TcpCommand $SESSION 'show-messages'
if ($r.ok) { Write-Pass "show-messages accepted" }
else { Write-Fail "show-messages failed" }

Write-Test "clock-mode"
$r = Send-TcpCommand $SESSION 'clock-mode'
if ($r.ok) { Write-Pass "clock-mode accepted" }
else { Write-Fail "clock-mode failed" }

Write-Test "info"
$r = Send-TcpCommand $SESSION 'info'
if ($r.ok) { Write-Pass "info accepted" }
else { Write-Fail "info failed" }

# ════════════════════════════════════════════════════════════════════════════════
# 34. WAIT-FOR: flags -L -S -U
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== 34. WAIT-FOR FLAGS ===" -ForegroundColor Cyan

Write-Test "wait-for -S (signal)"
$r = Send-TcpCommand $SESSION 'wait-for -S flag_channel'
if ($r.ok) { Write-Pass "wait-for -S accepted" }
else { Write-Fail "wait-for -S failed" }

Write-Test "wait-for -U (unlock)"
$r = Send-TcpCommand $SESSION 'wait-for -U flag_channel'
if ($r.ok) { Write-Pass "wait-for -U accepted" }
else { Write-Fail "wait-for -U failed" }

# ════════════════════════════════════════════════════════════════════════════════
# Cleanup & Summary
# ════════════════════════════════════════════════════════════════════════════════

Write-Host "`n=== CLEANUP ===" -ForegroundColor Yellow
Cleanup-Session $SESSION
Start-Sleep -Seconds 1

Write-Host "`n============================================================" -ForegroundColor Magenta
Write-Host "  CLI FLAG PARITY RESULTS" -ForegroundColor Magenta
Write-Host "============================================================" -ForegroundColor Magenta
Write-Host "  PASSED:  $($script:TestsPassed)" -ForegroundColor Green
Write-Host "  FAILED:  $($script:TestsFailed)" -ForegroundColor Red
Write-Host "  SKIPPED: $($script:TestsSkipped)" -ForegroundColor Yellow
Write-Host "  TOTAL:   $($script:TestsPassed + $script:TestsFailed + $script:TestsSkipped)" -ForegroundColor White
Write-Host "============================================================`n" -ForegroundColor Magenta

if ($script:TestsFailed -gt 0) { exit 1 } else { exit 0 }