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
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
|
"""Tests for the audio.cpp backend setup module (backends/audiocpp.py)."""
import argparse
import io
import json
import sys
import tempfile
import threading
import unittest
from contextlib import redirect_stdout
from pathlib import Path
from unittest.mock import MagicMock, patch
from converter import config
from backends import audiocpp as make_server
import os
from backends import common, servers
from ui import taskview
from ui import tui
FAKE_CONFIG = (
'LANGUAGE = "English"\n'
"\n"
'AUDIOCPP_API_URL = "http://127.0.0.1:9999" # audio.cpp audiocpp_server\n'
"\n"
"CHUNK_SIZE = 250\n"
)
FAKE_CONFIG_WITH_MODEL_IDS = (
'AUDIOCPP_API_URL = "http://127.0.0.1:9999" # audio.cpp audiocpp_server\n'
"\n"
'AUDIOCPP_MODEL_ID = "qwen" # server entry for speaker mode\n'
'AUDIOCPP_CLONE_MODEL_ID = "qwen-clone"\n'
)
def _write_spec(checkout: Path, family: str, *, display_name=None,
tasks=("tts", "clone"), languages=("en",), packages=None,
category="tts"):
"""Write a minimal model_specs/<family>.json into a fake checkout."""
specs = checkout / "model_specs"
specs.mkdir(parents=True, exist_ok=True)
if packages is None:
packages = [{
"id": f"{family}_q8_0", "default": True, "format": "gguf",
"target_directory": f"{family}-GGUF",
}]
spec = {
"family": family,
"display_name": display_name or family,
"category": category,
"tasks": list(tasks),
"languages": list(languages),
"packages": packages,
}
(specs / f"{family}.json").write_text(json.dumps(spec), encoding="utf-8")
return spec
def _make_checkout(tmp: Path) -> Path:
"""Create a fake audio.cpp checkout with a realistic model_specs set."""
checkout = tmp / "audio.cpp"
checkout.mkdir()
_write_spec(checkout, "qwen3_tts", display_name="Qwen3-TTS",
tasks=("tts", "clone", "design"),
languages=("zh", "en", "ja"),
packages=[
{"id": "qwen3_tts_1_7b_base_q8_0", "default": True,
"format": "gguf",
"target_directory": "Qwen3-TTS-12Hz-1.7B-Base-GGUF"},
{"id": "qwen3_tts_1_7b_customvoice_q8_0",
"format": "gguf",
"target_directory": "Qwen3-TTS-12Hz-1.7B-CustomVoice-GGUF"},
{"id": "qwen3_tts_1_7b_voicedesign_q8_0",
"format": "gguf",
"target_directory": "Qwen3-TTS-12Hz-1.7B-VoiceDesign-GGUF"},
])
_write_spec(checkout, "higgs_audio_tts", display_name="Higgs Audio v3 TTS 4B",
languages=("auto",),
packages=[{
"id": "higgs_audio_tts_4b_q8_0", "default": True,
"format": "gguf",
"target_directory": "Higgs-Audio-v3-TTS-4B-GGUF",
}])
_write_spec(checkout, "voxcpm2", display_name="VoxCPM2-2B",
languages=("en", "zh"),
packages=[{
"id": "voxcpm2_q8_0", "default": True, "format": "gguf",
"target_directory": "VoxCPM2-GGUF",
}])
_write_spec(checkout, "index_tts2", display_name="IndexTTS-2",
languages=("zh", "en"),
packages=[{
"id": "index_tts2_q8_0", "default": True, "format": "gguf",
"target_directory": "IndexTTS2-GGUF",
}])
_write_spec(checkout, "pocket_tts", display_name="PocketTTS-100M",
tasks=("tts", "clone"), languages=("en", "de"),
packages=[{
"id": "pocket_tts_q8_0", "default": True, "format": "gguf",
"target_directory": "PocketTTS-GGUF",
}])
_write_spec(checkout, "supertonic", display_name="Supertonic 3",
tasks=("tts",), languages=("en", "ko"),
packages=[{
"id": "supertonic_q8_0", "default": True, "format": "gguf",
"target_directory": "Supertonic-GGUF",
}])
# An ASR family that must be filtered out.
_write_spec(checkout, "qwen3_asr", display_name="Qwen3-ASR",
tasks=("asr",), category="asr")
# A TTS family with no installable packages (must be skipped).
_write_spec(checkout, "empty_tts", display_name="Empty TTS",
tasks=("tts",), packages=[])
return checkout
class FindWavFilesTests(unittest.TestCase):
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.folder = Path(self._tmp.name)
def tearDown(self):
self._tmp.cleanup()
def _touch(self, name):
path = self.folder / name
path.write_bytes(b"x")
return path
def test_finds_only_wavs_case_insensitive(self):
self._touch("b.wav")
self._touch("a.WAV")
self._touch("notes.txt")
(self.folder / "sub").mkdir()
(self.folder / "sub" / "c.wav").write_bytes(b"x")
names = [path.name for path in common.find_wav_files(self.folder)]
self.assertEqual(names, ["a.WAV", "b.wav"])
def test_sorted_alphabetically_case_insensitive(self):
for name in ("Zed.wav", "alpha.wav", "Beta.wav"):
self._touch(name)
names = [path.name for path in common.find_wav_files(self.folder)]
self.assertEqual(names, ["alpha.wav", "Beta.wav", "Zed.wav"])
def test_empty_directory_returns_empty_list(self):
self.assertEqual(common.find_wav_files(self.folder), [])
class DetectWavDirTests(unittest.TestCase):
"""Shallow .wav-directory discovery across the two checkout roots."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.root = Path(self._td.name)
self.audiocpp = self.root / "audio.cpp"
self.tts_root = self.root / "tts-audiobook-generator"
self.audiocpp.mkdir()
self.tts_root.mkdir()
def tearDown(self):
self._td.cleanup()
def _wav_dir(self, where, name="voices"):
directory = where / name
directory.mkdir(parents=True, exist_ok=True)
(directory / "voice.wav").write_bytes(b"x")
return directory
def test_unique_wav_dir_in_tts_root_returned(self):
found = self._wav_dir(self.tts_root, "voices")
self.assertEqual(common.detect_wav_dir(self.audiocpp,
self.tts_root),
found)
def test_unique_wav_dir_in_audiocpp_root_returned(self):
found = self._wav_dir(self.audiocpp, "reference")
self.assertEqual(common.detect_wav_dir(self.audiocpp,
self.tts_root),
found)
def test_root_itself_containing_wavs_returned(self):
(self.tts_root / "direct.wav").write_bytes(b"x")
self.assertEqual(common.detect_wav_dir(self.audiocpp,
self.tts_root),
self.tts_root)
def test_multiple_wav_dirs_returns_none(self):
self._wav_dir(self.tts_root, "one")
self._wav_dir(self.audiocpp, "two")
self.assertIsNone(common.detect_wav_dir(self.audiocpp,
self.tts_root))
def test_output_dir_of_tts_root_excluded(self):
self._wav_dir(self.tts_root, "output")
self.assertIsNone(common.detect_wav_dir(self.audiocpp,
self.tts_root))
def test_no_wavs_returns_none(self):
self.assertIsNone(common.detect_wav_dir(self.audiocpp,
self.tts_root))
def test_nested_wav_dir_not_seen(self):
nested = self.tts_root / "outer" / "inner"
nested.mkdir(parents=True)
(nested / "voice.wav").write_bytes(b"x")
self.assertIsNone(common.detect_wav_dir(self.audiocpp,
self.tts_root))
class ConfigPortTests(unittest.TestCase):
def test_port_parsed_from_config_url(self):
with patch.object(config, "AUDIOCPP_API_URL",
"http://127.0.0.1:8080"):
self.assertEqual(make_server.configsync.config_port(), 8080)
def test_missing_port_falls_back(self):
with patch.object(config, "AUDIOCPP_API_URL", "http://127.0.0.1"):
self.assertEqual(make_server.configsync.config_port(),
make_server.FALLBACK_PORT)
def test_invalid_url_falls_back(self):
with patch.object(config, "AUDIOCPP_API_URL", "not a url"):
self.assertEqual(make_server.configsync.config_port(),
make_server.FALLBACK_PORT)
def test_url_with_port_replaces_port(self):
# audiocpp reuses the shared helper (backends.common.url_with_port).
self.assertEqual(
common.url_with_port("http://127.0.0.1:8080", 9000),
"http://127.0.0.1:9000")
def test_url_without_port_adds_port(self):
self.assertEqual(
common.url_with_port("http://localhost", 8080),
"http://localhost:8080")
class UpdateConfigPortTests(unittest.TestCase):
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.config_path = Path(self._tmp.name) / "config.py"
self.config_path.write_text(FAKE_CONFIG, encoding="utf-8")
# The shared helper also mirrors values onto converter.config.
self._saved_url = config.AUDIOCPP_API_URL
def tearDown(self):
config.AUDIOCPP_API_URL = self._saved_url
self._tmp.cleanup()
def test_rewrites_port_preserving_comment(self):
changed = make_server.configsync.update_config_api_url_port(
8080, config_path=self.config_path)
self.assertTrue(changed)
text = self.config_path.read_text(encoding="utf-8")
self.assertIn(
'AUDIOCPP_API_URL = "http://127.0.0.1:8080" # audio.cpp audiocpp_server',
text)
self.assertIn('LANGUAGE = "English"', text)
self.assertIn("CHUNK_SIZE = 250", text)
def test_returns_false_when_no_url_line(self):
path = Path(self._tmp.name) / "other.py"
path.write_text('CHUNK_SIZE = 250\n', encoding="utf-8")
self.assertFalse(make_server.configsync.update_config_api_url_port(
8080, config_path=path))
def test_port_unchanged_is_a_success_noop(self):
# The file already holds the port: success, nothing rewritten.
self.assertTrue(make_server.configsync.update_config_api_url_port(
9999, config_path=self.config_path))
self.assertEqual(self.config_path.read_text(encoding="utf-8"),
FAKE_CONFIG)
def test_returns_false_when_file_missing(self):
self.assertFalse(make_server.configsync.update_config_api_url_port(
8080, config_path=Path(self._tmp.name) / "nope.py"))
class UpdateConfigModelIdsTests(unittest.TestCase):
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.config_path = Path(self._tmp.name) / "config.py"
self.config_path.write_text(FAKE_CONFIG_WITH_MODEL_IDS,
encoding="utf-8")
# The shared helper also mirrors values onto converter.config.
self._saved_ids = (config.AUDIOCPP_MODEL_ID,
config.AUDIOCPP_CLONE_MODEL_ID)
def tearDown(self):
(config.AUDIOCPP_MODEL_ID,
config.AUDIOCPP_CLONE_MODEL_ID) = self._saved_ids
self._tmp.cleanup()
def test_rewrites_both_ids_preserving_lines(self):
changed = make_server.configsync.update_config_model_ids(
"higgs", "higgs", config_path=self.config_path)
self.assertTrue(changed)
text = self.config_path.read_text(encoding="utf-8")
self.assertIn('AUDIOCPP_MODEL_ID = "higgs" # server entry for speaker mode',
text)
self.assertIn('AUDIOCPP_CLONE_MODEL_ID = "higgs"', text)
self.assertIn('AUDIOCPP_API_URL = "http://127.0.0.1:9999"', text)
def test_clone_id_optional(self):
changed = make_server.configsync.update_config_model_ids(
"voxcpm2", config_path=self.config_path)
self.assertTrue(changed)
text = self.config_path.read_text(encoding="utf-8")
self.assertIn('AUDIOCPP_MODEL_ID = "voxcpm2"', text)
self.assertIn('AUDIOCPP_CLONE_MODEL_ID = "qwen-clone"', text)
def test_ids_unchanged_is_a_success_noop(self):
# Both ids already hold their values: success, nothing rewritten.
changed = make_server.configsync.update_config_model_ids(
"qwen", "qwen-clone", config_path=self.config_path)
self.assertTrue(changed)
self.assertEqual(self.config_path.read_text(encoding="utf-8"),
FAKE_CONFIG_WITH_MODEL_IDS)
def test_returns_false_when_lines_missing(self):
path = Path(self._tmp.name) / "other.py"
path.write_text('CHUNK_SIZE = 250\n', encoding="utf-8")
self.assertFalse(make_server.configsync.update_config_model_ids(
"higgs", "higgs", config_path=path))
def test_returns_false_when_file_missing(self):
self.assertFalse(make_server.configsync.update_config_model_ids(
"higgs", "higgs",
config_path=Path(self._tmp.name) / "nope.py"))
class ResolveWavDirArgTests(unittest.TestCase):
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.folder = Path(self._tmp.name)
def tearDown(self):
self._tmp.cleanup()
def test_resolves_to_absolute(self):
self.assertEqual(common.resolve_wav_dir_arg(str(self.folder)),
self.folder.resolve())
def test_strips_surrounding_quotes(self):
quoted = f'"{self.folder}"'
self.assertEqual(common.resolve_wav_dir_arg(quoted),
self.folder.resolve())
def test_strips_single_quotes(self):
quoted = f"'{self.folder}'"
self.assertEqual(common.resolve_wav_dir_arg(quoted),
self.folder.resolve())
def test_strips_whitespace(self):
self.assertEqual(common.resolve_wav_dir_arg(f" {self.folder} "),
self.folder.resolve())
def test_expands_tilde(self):
with patch.object(os.path, "expanduser",
return_value=str(self.folder)) as mock_expand:
result = common.resolve_wav_dir_arg("~/voices")
mock_expand.assert_called_once_with("~/voices")
self.assertEqual(result, self.folder.resolve())
def test_trailing_slash_preserved_as_dir(self):
self.assertEqual(common.resolve_wav_dir_arg(f"{self.folder}/"),
self.folder.resolve())
class NormalizeDirArgTests(unittest.TestCase):
"""Path normalization for user-supplied directory arguments."""
def test_expands_tilde_and_resolves(self):
with patch.object(common.os.path, "expanduser",
return_value="/home/u/audio.cpp") as mock_expand:
result = common.normalize_dir_arg("~/audio.cpp")
mock_expand.assert_called_once_with("~/audio.cpp")
self.assertEqual(result, Path("/home/u/audio.cpp").resolve())
def test_strips_quotes_and_whitespace(self):
with patch.object(common.os.path, "expanduser",
side_effect=lambda s: s):
result = common.normalize_dir_arg(' "/tmp/foo" ')
self.assertEqual(result, Path("/tmp/foo").resolve())
class FindLocalCheckoutTests(unittest.TestCase):
"""find_local_checkout resolves ./app/audio.cpp and nothing else."""
def test_none_when_no_checkout_in_app_dir(self):
with tempfile.TemporaryDirectory() as td, \
patch.object(make_server.build, "APP_DIR", Path(td)):
self.assertIsNone(make_server.build.find_local_checkout())
def test_returns_the_managed_checkout(self):
with tempfile.TemporaryDirectory() as td, \
patch.object(make_server.build, "APP_DIR", Path(td)):
checkout = _make_checkout(Path(td))
self.assertEqual(make_server.build.find_local_checkout(), checkout)
def test_none_when_checkout_lacks_model_specs(self):
with tempfile.TemporaryDirectory() as td, \
patch.object(make_server.build, "APP_DIR", Path(td)):
(Path(td) / "audio.cpp").mkdir()
self.assertIsNone(make_server.build.find_local_checkout())
def _add_options_to_spec(checkout: Path, family: str, *,
options=None) -> None:
"""Rewrite one family spec with an (optional) options block."""
path = checkout / "model_specs" / f"{family}.json"
spec = json.loads(path.read_text(encoding="utf-8"))
if options is not None:
spec["options"] = options
elif "options" in spec:
del spec["options"]
path.write_text(json.dumps(spec), encoding="utf-8")
class LoadModelCatalogTests(unittest.TestCase):
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.checkout = _make_checkout(Path(self._td.name))
def tearDown(self):
self._td.cleanup()
def test_includes_tts_families_excludes_asr(self):
catalog = make_server.catalog.load_model_catalog(self.checkout)
families = [entry["family"] for entry in catalog]
self.assertIn("qwen3_tts", families)
self.assertIn("higgs_audio_tts", families)
self.assertIn("pocket_tts", families)
self.assertIn("supertonic", families)
self.assertNotIn("qwen3_asr", families)
def test_skips_families_with_no_packages(self):
catalog = make_server.catalog.load_model_catalog(self.checkout)
self.assertNotIn("empty_tts",
[entry["family"] for entry in catalog])
def test_families_sorted_alphabetically_by_display_name(self):
catalog = make_server.catalog.load_model_catalog(self.checkout)
names = [entry["display_name"].lower() for entry in catalog]
self.assertEqual(names, sorted(names))
self.assertNotIn("tested", catalog[0])
self.assertNotIn("TESTED_FAMILIES", dir(make_server))
def test_default_package_and_target_directory_resolved(self):
catalog = make_server.catalog.load_model_catalog(self.checkout)
by_family = {entry["family"]: entry for entry in catalog}
higgs = by_family["higgs_audio_tts"]
self.assertEqual(higgs["install_id"], "higgs_audio_tts_4b_q8_0")
self.assertEqual(higgs["default_path"],
"models/Higgs-Audio-v3-TTS-4B-GGUF")
def test_picks_first_gguf_when_no_default_flag(self):
_write_spec(self.checkout, "voxcpm2", display_name="VoxCPM2-2B",
packages=[
{"id": "voxcpm2_bf16", "format": "gguf",
"target_directory": "VoxCPM2-GGUF"},
{"id": "voxcpm2_q8_0", "format": "gguf",
"target_directory": "VoxCPM2-GGUF"},
])
catalog = make_server.catalog.load_model_catalog(self.checkout)
by_family = {entry["family"]: entry for entry in catalog}
self.assertEqual(by_family["voxcpm2"]["install_id"], "voxcpm2_bf16")
def test_clone_capability_from_tasks(self):
catalog = make_server.catalog.load_model_catalog(self.checkout)
by_family = {entry["family"]: entry for entry in catalog}
self.assertTrue(by_family["higgs_audio_tts"]["clone_capable"])
self.assertFalse(by_family["supertonic"]["clone_capable"])
def test_missing_model_specs_dir_raises(self):
empty = Path(self._td.name) / "empty"
empty.mkdir()
with self.assertRaises(NotADirectoryError):
make_server.catalog.load_model_catalog(empty)
class RequestOptionsFamiliesTests(unittest.TestCase):
"""request_options_families: which specs declare request options."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.checkout = _make_checkout(Path(self._td.name))
_add_options_to_spec(
self.checkout, "higgs_audio_tts",
options={"request": [{"id": "temperature", "default": 0.8},
{"id": "speed"}]})
def tearDown(self):
self._td.cleanup()
def test_family_with_request_options_listed_with_display_name(self):
families = make_server.request_options_families(self.checkout)
self.assertEqual(families.get("higgs_audio_tts"),
{"display_name": "Higgs Audio v3 TTS 4B"})
def test_family_without_options_block_absent(self):
families = make_server.request_options_families(self.checkout)
self.assertNotIn("qwen3_tts", families)
self.assertNotIn("voxcpm2", families)
def test_empty_request_list_does_not_count_as_support(self):
_add_options_to_spec(self.checkout, "supertonic",
options={"request": []})
families = make_server.request_options_families(self.checkout)
self.assertNotIn("supertonic", families)
def test_missing_specs_dir_yields_empty_map(self):
self.assertEqual(make_server.request_options_families(
Path(self._td.name)), {})
def test_unparsable_spec_skipped(self):
(self.checkout / "model_specs" / "broken.json").write_text(
"{not json", encoding="utf-8")
families = make_server.request_options_families(self.checkout)
self.assertNotIn("broken", families)
self.assertIn("higgs_audio_tts", families)
class SupportsRequestOptionsTests(unittest.TestCase):
"""supports_request_options: True / False / unknown tri-state."""
FAMILIES = {"higgs_audio_tts": {"display_name": "Higgs"}}
def test_true_only_for_a_listed_family(self):
self.assertTrue(make_server.supports_request_options(
self.FAMILIES, "higgs_audio_tts"))
def test_false_for_a_read_but_unlisted_family(self):
self.assertFalse(make_server.supports_request_options(
self.FAMILIES, "qwen3_tts"))
def test_none_when_no_local_specs_exist(self):
self.assertIsNone(make_server.supports_request_options({}, "any"))
# An entry with no family at all is unclassifiable too.
self.assertIsNone(make_server.supports_request_options({}, ""))
class DetectBackendTests(unittest.TestCase):
"""Backend detection from audio.cpp build directory names."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.checkout = Path(self._td.name) / "audio.cpp"
self.checkout.mkdir()
def tearDown(self):
self._td.cleanup()
def _build(self, name, binary="audiocpp_server"):
build_dir = self.checkout / "build" / name
bin_dir = build_dir / "bin"
bin_dir.mkdir(parents=True)
(bin_dir / binary).write_bytes(b"x")
return build_dir
def test_no_build_dir_returns_none(self):
self.assertIsNone(make_server.catalog.detect_backend(self.checkout))
def test_unique_linux_backend_detected(self):
self._build("linux-cuda-release")
self.assertEqual(make_server.catalog.detect_backend(self.checkout), "cuda")
def test_windows_exe_backend_detected(self):
self._build("windows-vulkan-debug", binary="audiocpp_server.exe")
self.assertEqual(make_server.catalog.detect_backend(self.checkout), "vulkan")
def test_hip_backend_detected(self):
self._build("linux-hip-release")
self.assertEqual(make_server.catalog.detect_backend(self.checkout), "hip")
def test_cpu_backend_detected(self):
self._build("linux-cpu-release")
self.assertEqual(make_server.catalog.detect_backend(self.checkout), "cpu")
def test_metal_maps_to_cpu(self):
self._build("macos-metal-release")
self.assertEqual(make_server.catalog.detect_backend(self.checkout), "cpu")
def test_multiple_backends_returns_none(self):
self._build("linux-cuda-release")
self._build("linux-cpu-release")
self.assertIsNone(make_server.catalog.detect_backend(self.checkout))
def test_multiple_builds_same_backend_detected(self):
self._build("linux-cuda-release")
self._build("windows-cuda-debug")
self.assertEqual(make_server.catalog.detect_backend(self.checkout), "cuda")
def test_build_dir_without_binary_ignored(self):
(self.checkout / "build" / "linux-cuda-release").mkdir(parents=True)
self.assertIsNone(make_server.catalog.detect_backend(self.checkout))
def test_non_matching_build_dir_name_ignored(self):
self._build("linux-mybuild-release")
self.assertIsNone(make_server.catalog.detect_backend(self.checkout))
class BackendOptionsTests(unittest.TestCase):
"""Aligned backend menu labels and the [auto-detected] default."""
def test_options_have_aligned_dashes(self):
options, default_index = make_server.catalog._backend_options()
dash_columns = {label.index(" - ") for label, _ in options}
self.assertEqual(len(dash_columns), 1)
self.assertEqual(default_index, 0)
def test_detected_backend_marked_and_defaulted(self):
options, default_index = make_server.catalog._backend_options("vulkan")
labels = [label for label, _ in options]
self.assertEqual(default_index, labels.index(next(
label for label, value in options
if value == "vulkan" and label.endswith("[auto-detected]"))))
self.assertTrue(labels[default_index].endswith("[auto-detected]"))
self.assertEqual(options[default_index][1], "vulkan")
def test_unknown_detected_backend_is_ignored(self):
options, default_index = make_server.catalog._backend_options("opencl")
self.assertEqual(default_index, 0)
self.assertFalse(any("[auto-detected]" in label
for label, _ in options))
def test_labels_keep_backend_values(self):
options, _ = make_server.catalog._backend_options()
self.assertEqual([value for _, value in options],
list(make_server.BACKENDS))
class BuildServerConfigTests(unittest.TestCase):
def test_single_entry_without_voice_dir(self):
entry = make_server.catalog.build_model_entry(
"higgs_audio_tts", "higgs", "models/Higgs-GGUF")
cfg = make_server.catalog.build_server_config(
"127.0.0.1", 8080, "cuda", False, [entry])
self.assertEqual(cfg["host"], "127.0.0.1")
self.assertEqual(cfg["port"], 8080)
self.assertEqual(cfg["backend"], "cuda")
self.assertFalse(cfg["lazy_load"])
self.assertEqual(cfg["models"], [entry])
self.assertNotIn("voice_dir", cfg)
def test_voice_dir_added_when_given(self):
entry = make_server.catalog.build_model_entry("voxcpm2", "voxcpm2", "models/V")
cfg = make_server.catalog.build_server_config(
"0.0.0.0", 9000, "cpu", True, [entry],
voice_dir="/abs/voices")
self.assertTrue(cfg["lazy_load"])
self.assertEqual(cfg["voice_dir"], "/abs/voices")
def test_model_entry_shape(self):
entry = make_server.catalog.build_model_entry("index_tts2", "indextts2", "p")
self.assertEqual(entry["id"], "indextts2")
self.assertEqual(entry["family"], "index_tts2")
self.assertEqual(entry["path"], "p")
self.assertEqual(entry["task"], "tts")
self.assertEqual(entry["mode"], "offline")
def test_model_entry_design_task(self):
entry = make_server.catalog.build_model_entry(
"qwen3_tts", "qwen-design", "p", task="vdes")
self.assertEqual(entry["task"], "vdes")
self.assertEqual(entry["mode"], "offline")
class InstallModelsTests(unittest.TestCase):
"""Printing or auto-running the model install commands."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.checkout = Path(self._td.name) / "audio.cpp"
self.checkout.mkdir()
self.manager = self.checkout / "tools" / "model_manager_v2.py"
self.manager.parent.mkdir()
self.manager.write_text("#!/usr/bin/env python3\n", encoding="utf-8")
self.guidance = [("Higgs Audio v3 TTS 4B", "higgs_audio_tts_4b_q8_0"),
("Qwen3-TTS", "qwen3_tts_1_7b_base_q8_0"),
("Qwen3-TTS", "qwen3_tts_1_7b_base_q8_0")]
def tearDown(self):
self._td.cleanup()
def test_declined_download_prints_commands_deduped(self):
buf = io.StringIO()
with redirect_stdout(buf), \
patch.object(common,
"run_console_subprocess") as run:
make_server.models._install_models(self.checkout, self.guidance,
download=False)
out = buf.getvalue()
self.assertEqual(out.count("install higgs_audio_tts_4b_q8_0"), 1)
self.assertEqual(out.count("install qwen3_tts_1_7b_base_q8_0"), 1)
run.assert_not_called()
def test_accepted_download_runs_each_command(self):
with patch.object(common,
"run_console_subprocess", return_value=0) as run:
make_server.models._install_models(self.checkout, self.guidance,
download=True)
self.assertEqual(run.call_count, 2)
commands = [call[0][0] for call in run.call_args_list]
self.assertEqual(commands[0],
[sys.executable, str(self.manager), "install",
"higgs_audio_tts_4b_q8_0"])
self.assertEqual(commands[1],
[sys.executable, str(self.manager), "install",
"qwen3_tts_1_7b_base_q8_0"])
for call in run.call_args_list:
self.assertEqual(call[1]["cwd"], str(self.checkout))
def test_missing_manager_falls_back_to_printing(self):
self.manager.unlink()
buf = io.StringIO()
with redirect_stdout(buf), \
patch.object(common,
"run_console_subprocess") as run:
make_server.models._install_models(self.checkout, self.guidance,
download=True)
self.assertIn("install higgs_audio_tts_4b_q8_0", buf.getvalue())
run.assert_not_called()
def test_failed_install_reports_warning_and_continues(self):
results = iter([1, 0])
buf = io.StringIO()
with redirect_stdout(buf), \
patch.object(common, "run_console_subprocess",
side_effect=lambda *a, **k: next(results)) as run:
make_server.models._install_models(self.checkout, self.guidance,
download=True)
self.assertEqual(run.call_count, 2)
self.assertIn("exited with code 1", buf.getvalue())
def _entry_paths(self):
return [{"path": "models/higgs"}, {"path": "models/qwen"}]
def test_installed_model_prints_no_command_for_it(self):
# Mixed selection: qwen is on disk, higgs is not. The print path
# reports the installed one without a python command, explains
# that setup downloads automatically, then lists the rest.
(self.checkout / "models" / "qwen").mkdir(parents=True)
(self.checkout / "models" / "qwen" / "f.bin").write_bytes(b"x")
buf = io.StringIO()
with redirect_stdout(buf), \
patch.object(common,
"run_console_subprocess") as run:
make_server.models._install_models(
self.checkout,
[("Higgs Audio v3 TTS 4B", "higgs_audio_tts_4b_q8_0"),
("Qwen3-TTS", "qwen3_tts_1_7b_base_q8_0")],
download=False,
model_entries=self._entry_paths())
out = buf.getvalue()
self.assertIn("[OK] Qwen3-TTS is already installed.", out)
self.assertIn("downloaded automatically", out)
self.assertIn("python {} install higgs_audio_tts_4b_q8_0".format(
self.manager), out)
self.assertNotIn("install qwen3_tts_1_7b_base_q8_0", out)
run.assert_not_called()
def test_all_models_present_prints_no_commands(self):
for name in ("higgs", "qwen"):
target = self.checkout / "models" / name
target.mkdir(parents=True)
(target / "f.bin").write_bytes(b"x")
buf = io.StringIO()
with redirect_stdout(buf), \
patch.object(common,
"run_console_subprocess") as run:
rc = make_server.models._install_models(
self.checkout,
[("Higgs Audio v3 TTS 4B", "higgs_audio_tts_4b_q8_0"),
("Qwen3-TTS", "qwen3_tts_1_7b_base_q8_0")],
download=False,
model_entries=self._entry_paths())
out = buf.getvalue()
self.assertEqual(rc, 0)
self.assertIn("All selected models are already installed.", out)
self.assertNotIn("model_manager_v2.py install", out)
run.assert_not_called()
def test_download_skips_installed_models(self):
(self.checkout / "models" / "qwen").mkdir(parents=True)
(self.checkout / "models" / "qwen" / "f.bin").write_bytes(b"x")
with redirect_stdout(io.StringIO()), \
patch.object(common,
"run_console_subprocess",
return_value=0) as run:
make_server.models._install_models(
self.checkout,
[("Higgs Audio v3 TTS 4B", "higgs_audio_tts_4b_q8_0"),
("Qwen3-TTS", "qwen3_tts_1_7b_base_q8_0")],
download=True,
model_entries=self._entry_paths())
self.assertEqual(run.call_count, 1)
self.assertEqual(run.call_args[0][0][3], "higgs_audio_tts_4b_q8_0")
def test_entries_without_guidance_do_not_filter(self):
# A length mismatch means no filtering is possible: every model
# is treated as missing (the pre-change behavior).
buf = io.StringIO()
with redirect_stdout(buf):
make_server.models._install_models(
self.checkout, self.guidance, download=False,
model_entries=[{"path": "models/qwen"}])
out = buf.getvalue()
self.assertIn("higgs_audio_tts_4b_q8_0", out)
self.assertIn("qwen3_tts_1_7b_base_q8_0", out)
def test_download_applicable_false_without_manager(self):
self.manager.unlink()
self.assertFalse(
make_server.models.download_applicable(self.checkout, []))
def test_download_applicable_when_manager_present(self):
self.assertTrue(
make_server.models.download_applicable(self.checkout, []))
def test_download_applicable_skipped_when_all_models_present(self):
target = self.checkout / "models" / "higgs"
target.mkdir(parents=True)
(target / "model.gguf").write_bytes(b"x")
self.assertFalse(make_server.models.download_applicable(
self.checkout, [{"path": "models/higgs"}]))
def test_download_applicable_when_a_model_is_missing(self):
target = self.checkout / "models" / "higgs"
target.mkdir(parents=True)
(target / "model.gguf").write_bytes(b"x")
self.assertTrue(make_server.models.download_applicable(
self.checkout,
[{"path": "models/higgs"}, {"path": "models/absent"}]))
def test_all_models_present_true_when_all_paths_hold_files(self):
target = self.checkout / "models" / "higgs"
target.mkdir(parents=True)
(target / "model.gguf").write_bytes(b"x")
self.assertTrue(make_server.models._all_models_present(
self.checkout, [{"path": "models/higgs"}]))
def test_all_models_present_false_when_one_missing(self):
target = self.checkout / "models" / "higgs"
target.mkdir(parents=True)
(target / "model.gguf").write_bytes(b"x")
self.assertFalse(make_server.models._all_models_present(
self.checkout,
[{"path": "models/higgs"}, {"path": "models/absent"}]))
def test_all_models_present_false_for_empty_selection(self):
self.assertFalse(make_server.models._all_models_present(self.checkout, []))
def test_all_models_present_honors_absolute_paths(self):
target = self.checkout / "models" / "higgs"
target.mkdir(parents=True)
(target / "model.gguf").write_bytes(b"x")
self.assertTrue(make_server.models._all_models_present(
self.checkout, [{"path": str(target)}]))
def test_all_models_present_false_for_empty_dir(self):
(self.checkout / "models" / "higgs").mkdir(parents=True)
self.assertFalse(make_server.models._all_models_present(
self.checkout, [{"path": "models/higgs"}]))
class ConfigFormTranscriptionToggleTests(unittest.TestCase):
"""The combined form's Voice transcripts row: one fixed two-way toggle.
The row is always visible whenever a clone-capable family is hosted
(it must not hide itself just because the picked wav directory has no
.wavs yet), and the plan it produces follows the toggled mode.
"""
def _checkout(self):
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
return _make_checkout(Path(tmp.name))
def _empty_dir(self):
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
return Path(tmp.name)
def _run(self, checkout, voices_dir, picked_family=None, override=None):
"""Drive _wizard on CHECKOUT; return (form call capture, settings)."""
catalog = make_server.catalog.load_model_catalog(checkout)
family = picked_family or "qwen3_tts"
index = next(i for i, entry in enumerate(catalog)
if entry["family"] == family)
target = catalog[index]["packages"][0]["target_directory"]
captured = {}
def fake_form(stdscr, title, fields, **kwargs):
captured.update(kwargs)
captured["fields"] = fields
result = {f["key"]: f["value"] for f in fields}
if override:
result.update(override)
return result
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree",
return_value=[(index, target)]), \
patch.object(tui, "form", side_effect=fake_form), \
patch.object(make_server.wizard, "VOICES_DIR", voices_dir):
settings = make_server.wizard._wizard(
None, make_server.wizard.build_parser().parse_args([]),
make_server.wizard.build_parser())
return captured, settings
def test_row_is_a_fixed_toggle_defaulting_to_new_voices(self):
checkout = self._checkout()
captured, _settings = self._run(checkout, self._empty_dir())
by_key = {f["key"]: f for f in captured["fields"]}
row = by_key["transcription"]
self.assertEqual(row["kind"], "toggle")
self.assertEqual(row["value"], "missing")
self.assertEqual(
row["choices"],
[("Transcribe new voices", "missing"),
("Re-transcribe all voices", "all")])
def test_row_always_visible_when_clone_capable(self):
# Regression: the row used to hide itself until the wav directory
# contained .wavs; a clone-capable pick must always offer it.
checkout = self._checkout()
voices = self._empty_dir()
captured, _settings = self._run(checkout, voices)
by_key = {f["key"]: f for f in captured["fields"]}
self.assertTrue(by_key["transcription"]["visible"](captured["fields"]))
self.assertEqual(_settings["plan"]["mode"], "missing")
self.assertEqual(_settings["plan"]["missing"], [])
def test_row_hidden_without_a_clone_capable_pick(self):
checkout = self._checkout()
captured, _settings = self._run(checkout, self._empty_dir(),
picked_family="supertonic")
by_key = {f["key"]: f for f in captured["fields"]}
self.assertFalse(by_key["transcription"]["visible"](captured["fields"]))
self.assertIsNone(_settings["plan"])
def test_form_opens_on_the_continue_button(self):
checkout = self._checkout()
captured, _settings = self._run(checkout, self._empty_dir())
self.assertTrue(captured.get("start_on_buttons"))
def test_new_voices_plan_carries_only_untranscribed_wavs(self):
checkout = self._checkout()
voices = self._empty_dir()
(voices / "extra.wav").write_bytes(b"x")
(voices / "narrator.wav").write_bytes(b"x")
common.write_prompt_text(voices, {"narrator": "Old words."})
_captured, settings = self._run(checkout, voices)
self.assertEqual(settings["plan"]["mode"], "missing")
self.assertEqual([w.name for w in settings["plan"]["missing"]],
["extra.wav"])
self.assertEqual(settings["plan"]["existing"],
{"narrator": "Old words."})
def test_toggled_all_retranscribes_everything(self):
checkout = self._checkout()
voices = self._empty_dir()
(voices / "narrator.wav").write_bytes(b"x")
common.write_prompt_text(voices, {"narrator": "Old words."})
_captured, settings = self._run(checkout, voices,
override={"transcription": "all"})
self.assertEqual(settings["plan"]["mode"], "all")
class TranscribeWavDirTests(unittest.TestCase):
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.folder = Path(self._td.name)
self.narrator = self.folder / "narrator.wav"
self.narrator.write_bytes(b"x")
self.other = self.folder / "other.wav"
self.other.write_bytes(b"x")
def tearDown(self):
self._td.cleanup()
def test_transcribes_to_stem_map_with_absolute_paths(self):
transcripts = {str(self.narrator): ("First.", "ok"),
str(self.other): ("Second.", "ok")}
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
side_effect=lambda path, model_name="base":
transcripts[path]):
result = make_server.voices.transcribe_wav_dir(
[self.narrator, self.other], "base")
self.assertEqual(list(result), ["narrator", "other"])
self.assertEqual(result["narrator"], "First.")
def test_failed_transcription_keeps_empty_string(self):
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=(None, "no speech detected")):
result = make_server.voices.transcribe_wav_dir([self.narrator], "base")
self.assertEqual(result["narrator"], "")
def test_failed_transcription_prints_the_reason(self):
buffer = io.StringIO()
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=(None, "faster_whisper heard no speech")), \
redirect_stdout(buffer):
make_server.voices.transcribe_wav_dir([self.narrator], "base")
output = buffer.getvalue()
self.assertIn("No transcript for 'narrator'", output)
self.assertIn("faster_whisper heard no speech", output)
def test_whisper_model_name_passed_through(self):
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=("text", "ok")) as mock_transcribe:
make_server.voices.transcribe_wav_dir([self.narrator], "large-v3")
self.assertEqual(mock_transcribe.call_args.kwargs["model_name"],
"large-v3")
def test_write_prompt_text_format(self):
path = common.write_prompt_text(
self.folder, {"narrator": "Hello.", "other": "World."})
self.assertEqual(path, self.folder / common.PROMPT_TEXT_FILENAME)
text = path.read_text(encoding="utf-8")
self.assertIn("narrator|Hello.", text)
self.assertIn("other|World.", text)
class TranscribePlanTests(unittest.TestCase):
"""_transcribe: plan application and transcript wipe protection."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.folder = Path(self._td.name)
self.narrator = self.folder / "narrator.wav"
self.narrator.write_bytes(b"x")
self.args = argparse.Namespace(input_dir=self.folder,
whisper_model="base")
def tearDown(self):
self._td.cleanup()
def test_all_mode_retranscribes_everything(self):
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=("New words.", "ok")):
transcripts, write = make_server.voices._transcribe(
self.args, {"mode": "all", "missing": [], "existing": {}})
self.assertTrue(write)
self.assertEqual(transcripts, {"narrator": "New words."})
def test_empty_retranscription_keeps_existing_transcript(self):
# A failed re-transcription must never overwrite known-good text
# with a blank: a blank prompt_text entry makes the server reject
# every clone request for that voice.
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=(None, "backend broken")), \
redirect_stdout(io.StringIO()) as buffer:
transcripts, write = make_server.voices._transcribe(
self.args, {"mode": "all", "missing": [],
"existing": {"narrator": "Good words."}})
self.assertTrue(write)
self.assertEqual(transcripts, {"narrator": "Good words."})
self.assertIn("Kept the existing transcript for 'narrator'",
buffer.getvalue())
def test_missing_mode_merges_new_with_existing(self):
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=("Fresh text.", "ok")):
transcripts, _write = make_server.voices._transcribe(
self.args, {"mode": "missing", "missing": [self.narrator],
"existing": {}})
self.assertEqual(transcripts, {"narrator": "Fresh text."})
def test_unusable_backend_warns_with_the_reason(self):
buffer = io.StringIO()
with patch.object(make_server.voices, "whisper_backend_problem",
return_value="faster_whisper is installed but "
"failed to import: boom"), \
patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=("text", "ok")), \
redirect_stdout(buffer):
make_server.voices._transcribe(
self.args, {"mode": "all", "missing": [], "existing": {}})
output = buffer.getvalue()
self.assertIn("No usable Whisper backend", output)
self.assertIn("failed to import: boom", output)
class WizardTranscribeStepTests(unittest.TestCase):
"""The setup lane's transcribe step: rc reflects unusable transcripts."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.folder = Path(self._td.name)
(self.folder / "narrator.wav").write_bytes(b"x")
self.args = argparse.Namespace(input_dir=None, whisper_model="base")
self.settings = {
"audiocpp_dir": self.folder,
"wav_dir": self.folder,
"include_clone": True,
"plan": {"mode": "all", "missing": [], "existing": {}},
"build": None,
"model_entries": [],
}
def tearDown(self):
self._td.cleanup()
def _transcribe_step(self):
lanes = make_server.wizard._execute_lanes(self.settings, self.args)
return lanes[0].steps[0]
def test_blank_transcripts_fail_the_step(self):
step = self._transcribe_step()
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=(None, "broken backend")), \
redirect_stdout(io.StringIO()) as buffer:
rc = step.work(None, None)
self.assertEqual(rc, 1)
self.assertIn("No transcript for: narrator", buffer.getvalue())
def test_good_transcripts_pass_the_step(self):
step = self._transcribe_step()
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
return_value=("Words.", "ok")), \
redirect_stdout(io.StringIO()):
self.assertEqual(step.work(None, None), 0)
def test_no_clone_families_passes_without_transcribing(self):
self.settings["include_clone"] = False
self.settings["plan"] = None
step = self._transcribe_step()
with patch.object(make_server.voices,
"transcribe_reference_audio_detailed") as mock_transcribe:
self.assertEqual(step.work(None, None), 0)
mock_transcribe.assert_not_called()
class DesignPackageTests(unittest.TestCase):
"""Voice-design package detection."""
def test_detects_voicedesign_in_id(self):
self.assertTrue(make_server.catalog.is_design_package(
{"id": "qwen3_tts_1_7b_voicedesign_q8_0"}))
def test_detects_voicedesign_in_directory(self):
self.assertTrue(make_server.catalog.is_design_package(
{"target_directory": "Foo-VoiceDesign-GGUF"}))
def test_detects_separated_voice_design(self):
self.assertTrue(make_server.catalog.is_design_package(
{"display_name": "Voice Design Q8_0"}))
def test_ignores_other_packages(self):
self.assertFalse(make_server.catalog.is_design_package(
{"id": "higgs_audio_tts_4b_q8_0"}))
self.assertFalse(make_server.catalog.is_design_package({}))
class PackageDirOptionsTests(unittest.TestCase):
"""Grouping a family's packages into distinct target directories."""
def test_groups_precisions_and_marks_recommended(self):
entry = {
"family": "qwen3_tts",
"packages": [
{"id": "base_q8", "default": True, "format": "gguf",
"target_directory": "Base-GGUF"},
{"id": "base_bf16", "format": "gguf",
"target_directory": "Base-GGUF"},
{"id": "voicedesign_q8", "format": "gguf",
"target_directory": "VoiceDesign-GGUF"},
],
}
options = make_server.catalog.package_dir_options(entry)
self.assertEqual([o["target_directory"] for o in options],
["Base-GGUF", "VoiceDesign-GGUF"])
self.assertTrue(options[0]["recommended"])
self.assertFalse(options[0]["design"])
self.assertFalse(options[1]["recommended"])
self.assertTrue(options[1]["design"])
self.assertEqual(options[0]["install_id"], "base_q8")
def test_recommended_comes_first_even_if_listed_later(self):
entry = {
"family": "demo_tts",
"packages": [
{"id": "demo_other", "format": "gguf",
"target_directory": "Other-GGUF"},
{"id": "demo_default", "default": True, "format": "gguf",
"target_directory": "Default-GGUF"},
],
}
options = make_server.catalog.package_dir_options(entry)
self.assertEqual([o["target_directory"] for o in options],
["Default-GGUF", "Other-GGUF"])
class FindAudiocppServerBinTests(unittest.TestCase):
"""Locating the built audiocpp_server binary."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.checkout = Path(self._td.name) / "audio.cpp"
self.checkout.mkdir()
def tearDown(self):
self._td.cleanup()
def _build(self, name, binary="audiocpp_server"):
bin_dir = self.checkout / "build" / name / "bin"
bin_dir.mkdir(parents=True)
(bin_dir / binary).write_bytes(b"x")
def test_no_build_dir_returns_none(self):
self.assertIsNone(make_server.build.find_audiocpp_server_bin(self.checkout))
def test_finds_built_binary(self):
self._build("linux-cuda-release")
self.assertEqual(
make_server.build.find_audiocpp_server_bin(self.checkout),
self.checkout / "build" / "linux-cuda-release" / "bin"
/ "audiocpp_server")
def test_finds_windows_exe(self):
self._build("windows-vulkan-debug", binary="audiocpp_server.exe")
self.assertEqual(
make_server.build.find_audiocpp_server_bin(self.checkout).name,
"audiocpp_server.exe")
def test_build_dir_without_binary_returns_none(self):
(self.checkout / "build" / "linux-cuda-release" / "bin").mkdir(
parents=True)
self.assertIsNone(make_server.build.find_audiocpp_server_bin(self.checkout))
class BuiltServerBinaryTests(unittest.TestCase):
"""built_server_binary: locating a specific backend's build."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.checkout = Path(self._td.name) / "audio.cpp"
self.checkout.mkdir()
def tearDown(self):
self._td.cleanup()
def _build(self, name, binary="audiocpp_server"):
bin_dir = self.checkout / "build" / name / "bin"
bin_dir.mkdir(parents=True)
(bin_dir / binary).write_bytes(b"x")
def test_returns_the_matching_backend_binary(self):
self._build("linux-cuda-release")
self._build("linux-cpu-release")
self.assertEqual(
make_server.build.built_server_binary(self.checkout, "cpu"),
self.checkout / "build" / "linux-cpu-release" / "bin"
/ "audiocpp_server")
def test_returns_none_for_unbuilt_backend(self):
self._build("linux-cuda-release")
self.assertIsNone(
make_server.build.built_server_binary(self.checkout, "vulkan"))
def test_metal_counts_as_cpu(self):
self._build("macos-metal-release")
self.assertEqual(
make_server.build.built_server_binary(self.checkout, "cpu"),
self.checkout / "build" / "macos-metal-release" / "bin"
/ "audiocpp_server")
def test_no_build_dir_returns_none(self):
self.assertIsNone(make_server.build.built_server_binary(self.checkout, "cpu"))
class BuildAudiocppTests(unittest.TestCase):
"""Running the audio.cpp build helper script."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.checkout = Path(self._td.name) / "audio.cpp"
self.checkout.mkdir()
self.scripts = self.checkout / "scripts"
self.scripts.mkdir()
(self.scripts / "build_linux.sh").write_text("#!/bin/sh\n",
encoding="utf-8")
self.log_dir = Path(self._td.name) / "logs"
self.addCleanup(common.drain_post_tui_notices)
def tearDown(self):
self._td.cleanup()
def _emit(self):
lines = []
def emit(line):
lines.append(line)
return lines, emit
def _log_files(self):
return sorted(self.log_dir.glob("audiocpp_build_*.log"))
def test_runs_build_script_with_backend_and_target(self):
with patch.object(common, "run_console_subprocess",
return_value=0) as run:
rc = make_server.build.build_audiocpp(self.checkout, "cuda")
self.assertEqual(rc, 0)
argv = run.call_args[0][0]
self.assertEqual(argv[:3], ["sh", str(self.scripts / "build_linux.sh"),
"--backend"])
self.assertIn("cuda", argv)
self.assertIn("--target", argv)
self.assertIn("audiocpp_server", argv)
self.assertIn("--deployment-build", argv)
self.assertEqual(run.call_args[1]["cwd"], self.checkout)
def test_missing_script_returns_nonzero(self):
for f in self.scripts.iterdir():
f.unlink()
rc = make_server.build.build_audiocpp(self.checkout, "cuda")
self.assertNotEqual(rc, 0)
def test_console_path_writes_no_log_and_no_notice(self):
with patch.object(common, "LOG_DIR", self.log_dir), \
patch.object(common, "run_console_subprocess",
return_value=0):
rc = make_server.build.build_audiocpp(self.checkout, "cuda")
self.assertEqual(rc, 0)
self.assertEqual(self._log_files(), [])
self.assertEqual(common.drain_post_tui_notices(), [])
def test_tui_success_writes_log_and_no_notice(self):
emitted, emit = self._emit()
with patch.object(common, "LOG_DIR", self.log_dir), \
patch.object(common, "run_console_subprocess",
return_value=0):
rc = make_server.build.build_audiocpp(self.checkout, "cuda",
emit=emit)
self.assertEqual(rc, 0)
self.assertEqual(len(self._log_files()), 1)
log_text = self._log_files()[0].read_text(encoding="utf-8")
self.assertIn("[INFO] Building audiocpp_server", log_text)
self.assertIn("--backend cuda", log_text)
self.assertTrue(emitted)
self.assertEqual(common.drain_post_tui_notices(), [])
def test_tui_failure_writes_log_and_records_notice(self):
emitted, emit = self._emit()
with patch.object(common, "LOG_DIR", self.log_dir), \
patch.object(common, "run_console_subprocess",
return_value=3):
rc = make_server.build.build_audiocpp(self.checkout, "cuda",
emit=emit)
self.assertEqual(rc, 3)
logs = self._log_files()
self.assertEqual(len(logs), 1)
log_text = logs[0].read_text(encoding="utf-8")
self.assertIn("failed (exit code 3)", log_text)
notices = common.drain_post_tui_notices()
self.assertEqual(len(notices), 1)
notice = notices[0]
self.assertIn("failed (exit code 3)", notice)
self.assertIn(f"Build log: {logs[0]}", notice)
command = (f"cd {self.checkout} && sh "
f"{self.scripts / 'build_linux.sh'} --backend cuda "
"--target audiocpp_server --deployment-build")
self.assertIn(command, notice)
self.assertIn("Troubleshoot by re-running this command", notice)
self.assertTrue(any("failed (exit code 3)" in line
for line in emitted))
def test_tui_cancel_suppresses_notice_but_writes_log(self):
emitted, emit = self._emit()
cancel = threading.Event()
cancel.set()
with patch.object(common, "LOG_DIR", self.log_dir), \
patch.object(common, "run_console_subprocess",
return_value=130):
rc = make_server.build.build_audiocpp(self.checkout, "cuda",
emit=emit, cancel=cancel)
self.assertEqual(rc, 130)
self.assertEqual(len(self._log_files()), 1)
self.assertEqual(common.drain_post_tui_notices(), [])
def test_tui_missing_script_records_guidance_notice(self):
for f in self.scripts.iterdir():
f.unlink()
emitted, emit = self._emit()
with patch.object(common, "LOG_DIR", self.log_dir):
rc = make_server.build.build_audiocpp(self.checkout, "cuda",
emit=emit)
self.assertNotEqual(rc, 0)
self.assertEqual(self._log_files(), [])
notices = common.drain_post_tui_notices()
self.assertEqual(len(notices), 1)
self.assertIn("No build script found", notices[0])
class AudiocppUpdateTests(unittest.TestCase):
"""update: stop the server, refresh the checkout, rebuild when stale.
The rebuild fires when the checkout moved OR the on-disk binary is
missing/older than HEAD's commit time (an interrupted earlier build).
"""
COMMIT_TIME = 1_000_000
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.checkout = Path(self._td.name) / "audio.cpp"
self.checkout.mkdir()
self.addCleanup(common.drain_post_tui_notices)
def tearDown(self):
self._td.cleanup()
def _make_binary(self, backend="cuda"):
bin_dir = self.checkout / "build" / f"linux-{backend}-release" / "bin"
bin_dir.mkdir(parents=True, exist_ok=True)
binary = bin_dir / "audiocpp_server"
binary.write_bytes(b"x")
return binary
def _patch_decision(self, heads, binary, *, commit_time=COMMIT_TIME):
"""Patch git state + a built binary for BACKEND ("cuda" default).
Returns the (mocks) (build, git_update) pair for assertions.
BINARY None means no binary on disk (a present binary is stamped
newer than COMMIT_TIME — stamp it differently after calling this
to simulate staleness); COMMIT_TIME None means the commit-time
probe cannot be answered.
"""
if binary is not None and commit_time is not None:
os.utime(binary, (commit_time + 100,) * 2)
return patch.object(common, "git_head", side_effect=heads), \
patch.object(common, "git_commit_time",
return_value=commit_time), \
patch.object(make_server.build, "load_server_config",
return_value={"backend": "cuda"})
def test_no_checkout_is_a_reported_noop(self):
with patch.object(make_server.build, "find_local_checkout",
return_value=None), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patch.object(common, "git_update") as mk_git:
rc = make_server.build.update()
self.assertEqual(rc, 0)
mk_git.assert_not_called()
def test_stops_server_then_skips_rebuild_for_a_fresh_binary(self):
binary = self._make_binary()
patches = self._patch_decision(["a", "a"], binary)
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=1234), \
patch.object(make_server.build.servers, "stop") as mk_stop, \
patches[0], patches[1], patches[2], \
patch.object(common, "git_update",
return_value=0) as mk_git, \
patch.object(make_server.build, "build_audiocpp") as mk_build:
rc = make_server.build.update(emit="EMIT")
self.assertEqual(rc, 0)
mk_stop.assert_called_once_with("audiocpp")
mk_git.assert_called_once_with(self.checkout, emit="EMIT",
cancel=None)
# HEAD did not move and the binary is newer than HEAD's commit:
# the binary still matches the sources.
mk_build.assert_not_called()
def test_moved_head_rebuilds_even_with_a_fresh_binary(self):
binary = self._make_binary()
patches = self._patch_decision(["a", "b"], binary)
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patches[0], patches[1], patches[2], \
patch.object(common, "git_update", return_value=0), \
patch.object(make_server.build, "build_audiocpp",
return_value=0) as mk_build:
rc = make_server.build.update(emit="EMIT")
self.assertEqual(rc, 0)
mk_build.assert_called_once_with(self.checkout, "cuda",
emit="EMIT", cancel=None)
def test_moved_head_falls_back_to_the_detected_backend(self):
patches = self._patch_decision(["a", "b"], None)
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patches[0], patches[1], \
patch.object(make_server.build, "load_server_config",
return_value={}), \
patch.object(make_server.build, "detect_backend",
return_value="vulkan"), \
patch.object(common, "git_update", return_value=0), \
patch.object(make_server.build, "build_audiocpp",
return_value=0) as mk_build:
rc = make_server.build.update()
self.assertEqual(rc, 0)
mk_build.assert_called_once_with(self.checkout, "vulkan",
emit=None, cancel=None)
def test_no_known_backend_skips_the_rebuild(self):
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patch.object(common, "git_head", side_effect=["a", "b"]), \
patch.object(common, "git_update", return_value=0), \
patch.object(make_server.build, "load_server_config",
return_value={}), \
patch.object(make_server.build, "detect_backend",
return_value=None), \
patch.object(make_server.build, "build_audiocpp") as mk_build:
rc = make_server.build.update()
self.assertEqual(rc, 0)
mk_build.assert_not_called()
def test_stale_binary_rebuilds_without_head_movement(self):
# The cancelled-rebuild scenario: sources already at HEAD, the old
# binary predates the new commit → the next update rebuilds.
binary = self._make_binary()
patches = self._patch_decision(["a", "a"], binary)
os.utime(binary, (self.COMMIT_TIME - 100,) * 2)
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patches[0], patches[1], patches[2], \
patch.object(common, "git_update", return_value=0), \
patch.object(make_server.build, "build_audiocpp",
return_value=0) as mk_build:
rc = make_server.build.update()
self.assertEqual(rc, 0)
mk_build.assert_called_once_with(self.checkout, "cuda",
emit=None, cancel=None)
def test_missing_binary_rebuilds_without_head_movement(self):
patches = self._patch_decision(["a", "a"], None)
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patches[0], patches[1], patches[2], \
patch.object(common, "git_update", return_value=0), \
patch.object(make_server.build, "build_audiocpp",
return_value=0) as mk_build:
rc = make_server.build.update()
self.assertEqual(rc, 0)
mk_build.assert_called_once_with(self.checkout, "cuda",
emit=None, cancel=None)
def test_unknown_commit_time_rebuilds_without_head_movement(self):
binary = self._make_binary()
patches = self._patch_decision(["a", "a"], binary, commit_time=None)
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patches[0], patches[1], patches[2], \
patch.object(common, "git_update", return_value=0), \
patch.object(make_server.build, "build_audiocpp",
return_value=0) as mk_build:
rc = make_server.build.update()
self.assertEqual(rc, 0)
mk_build.assert_called_once_with(self.checkout, "cuda",
emit=None, cancel=None)
def test_checkout_failure_skips_the_rebuild(self):
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patch.object(common, "git_update",
return_value=128) as mk_git, \
patch.object(make_server.build, "build_audiocpp") as mk_build:
rc = make_server.build.update()
self.assertEqual(rc, 128)
mk_git.assert_called_once()
mk_build.assert_not_called()
def test_rebuild_failure_propagates_the_exit_code(self):
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patch.object(common, "git_head", side_effect=["a", "b"]), \
patch.object(common, "git_update", return_value=0), \
patch.object(make_server.build, "load_server_config",
return_value={"backend": "cuda"}), \
patch.object(make_server.build, "build_audiocpp",
return_value=2):
rc = make_server.build.update()
self.assertEqual(rc, 2)
def test_cancel_before_the_update_skips_everything_after_stopping(self):
cancel = threading.Event()
cancel.set()
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=1234), \
patch.object(make_server.build.servers, "stop") as mk_stop, \
patch.object(common, "git_update") as mk_git:
rc = make_server.build.update(cancel=cancel)
self.assertEqual(rc, 130)
mk_stop.assert_called_once_with("audiocpp")
mk_git.assert_not_called()
def test_cancel_after_the_checkout_skips_the_rebuild(self):
cancel = threading.Event()
cancel.set()
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build.servers, "pid_for",
return_value=None), \
patch.object(common, "git_head", side_effect=["a", "b"]), \
patch.object(common, "git_update", return_value=0), \
patch.object(make_server.build, "build_audiocpp") as mk_build:
rc = make_server.build.update(cancel=cancel)
self.assertEqual(rc, 130)
mk_build.assert_not_called()
class AudiocppDetectTests(unittest.TestCase):
"""backends.audiocpp.detect() status reporting."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.root = Path(self._td.name)
self.checkout = _make_checkout(self.root)
def tearDown(self):
self._td.cleanup()
def test_not_cloned(self):
with patch.object(make_server.build, "find_local_checkout", return_value=None):
status = make_server.status.detect()
self.assertFalse(status.installed)
self.assertFalse(status.configured)
self.assertIn("not cloned", status.details[0])
def test_cloned_not_built_not_configured(self):
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout), \
patch.object(make_server.build, "find_audiocpp_server_bin",
return_value=None):
status = make_server.status.detect()
self.assertFalse(status.installed)
self.assertFalse(status.configured)
self.assertEqual(status.launch_hint, "")
self.assertEqual(status.partial, "downloaded (not built)")
def test_built_and_configured_ready(self):
binary = self.checkout / "build" / "linux-cuda-release" / "bin" \
/ "audiocpp_server"
binary.parent.mkdir(parents=True)
binary.write_bytes(b"x")
server_json = self.checkout / "server.json"
server_json.write_text('{"models":[]}', encoding="utf-8")
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout):
status = make_server.status.detect()
self.assertTrue(status.installed)
self.assertTrue(status.configured)
self.assertIn(str(binary), status.launch_hint)
self.assertIn(str(server_json), status.launch_hint)
self.assertEqual(status.partial, "")
def test_built_not_configured(self):
binary = self.checkout / "build" / "linux-cuda-release" / "bin" \
/ "audiocpp_server"
binary.parent.mkdir(parents=True)
binary.write_bytes(b"x")
with patch.object(make_server.build, "find_local_checkout",
return_value=self.checkout):
status = make_server.status.detect()
self.assertTrue(status.installed)
self.assertFalse(status.configured)
self.assertEqual(status.partial, "built (not configured)")
class NonInteractiveMainTests(unittest.TestCase):
"""The flag-only (non-TUI) path through main(), end to end."""
def setUp(self):
self._td = tempfile.TemporaryDirectory()
self.root = Path(self._td.name)
self.folder = self.root / "wavs"
self.folder.mkdir()
self.output = self.root / "server.json"
self.checkout = _make_checkout(self.root)
# Isolate config.py rewrites so no test touches the real one.
self.fake_config = self.root / "config.py"
self.fake_config.write_text(FAKE_CONFIG, encoding="utf-8")
patcher = patch.object(make_server.configsync, "CONFIG_PATH", self.fake_config)
patcher.start()
self.addCleanup(patcher.stop)
# Tests run without a tty -> main() takes the non-interactive path.
patcher = patch.object(make_server.wizard, "_interactive", return_value=False)
patcher.start()
self.addCleanup(patcher.stop)
def tearDown(self):
self._td.cleanup()
def _run(self, argv, transcribe=None, whisper="faster_whisper",
no_checkout=False):
argv = ["backends/audiocpp.py"] + argv
transcribe_effect = transcribe if transcribe is not None \
else MagicMock()
def detailed(path, model_name="base"):
result = transcribe_effect(path, model_name=model_name)
if isinstance(result, tuple):
return result
return (result, "ok" if result
else "faster_whisper is not installed (test stub)")
with patch.object(sys, "argv", argv), \
patch.object(make_server.build, "find_local_checkout",
return_value=None if no_checkout
else self.checkout), \
patch.object(make_server.voices,
"transcribe_reference_audio_detailed",
side_effect=detailed), \
patch.object(make_server.voices, "whisper_backend_problem",
return_value=None if whisper else
"faster_whisper is not installed"):
return make_server.wizard.main()
def _args(self, *extra):
return ["--wavs", str(self.folder), "--output", str(self.output)] \
+ list(extra)
def test_default_run_hosts_recommended_entry(self):
exit_code = self._run(
self._args("--families", "higgs_audio_tts", "--no-sync-model-ids"))
self.assertEqual(exit_code, 0)
data = json.loads(self.output.read_text(encoding="utf-8"))
self.assertEqual(data["host"], "127.0.0.1")
self.assertEqual(data["port"], make_server.configsync.config_port())
self.assertEqual(data["backend"], "cuda")
self.assertTrue(data["lazy_load"])
self.assertEqual([m["id"] for m in data["models"]],
["Higgs-Audio-v3-TTS-4B-GGUF"])
self.assertNotIn("voice_dir", data)
def test_port_comes_from_config_and_leaves_config_alone(self):
# Ports are not a wizard question anymore: server.json always
# records the port in AUDIOCPP_API_URL (edited in Settings), and
# app/converter/config.py itself is never rewritten by setup.
with patch.object(config, "AUDIOCPP_API_URL",
"http://127.0.0.1:9999"):
exit_code = self._run(
self._args("--families", "higgs_audio_tts",
"--no-sync-model-ids"))
self.assertEqual(exit_code, 0)
self.assertIn('"http://127.0.0.1:9999"',
self.fake_config.read_text(encoding="utf-8"))
data = json.loads(self.output.read_text(encoding="utf-8"))
self.assertEqual(data["port"], 9999)
def test_host_port_sync_flags_removed(self):
# No bind-host or port questions anywhere: 127.0.0.1 is fixed and
# the port follows Settings, so their flags are gone.
parser = make_server.wizard.build_parser()
for flag in ("--host", "--port", "--no-sync-port"):
with self.assertRaises(SystemExit):
parser.parse_args([flag, "x"])
def test_model_id_sync_accepted_updates_config(self):
self.fake_config.write_text(FAKE_CONFIG_WITH_MODEL_IDS,
encoding="utf-8")
exit_code = self._run(self._args("--families", "higgs_audio_tts"))
self.assertEqual(exit_code, 0)
text = self.fake_config.read_text(encoding="utf-8")
self.assertIn('AUDIOCPP_MODEL_ID = "Higgs-Audio-v3-TTS-4B-GGUF"', text)
self.assertIn('AUDIOCPP_CLONE_MODEL_ID = "Higgs-Audio-v3-TTS-4B-GGUF"',
text)
def test_multi_family_lazy_with_voice_dir(self):
(self.folder / "narrator.wav").write_bytes(b"x")
exit_code = self._run(
self._args("--families", "qwen3_tts,higgs_audio_tts",
"--no-sync-model-ids"),
transcribe=lambda path, model_name="base": "a transcript")
self.assertEqual(exit_code, 0)
data = json.loads(self.output.read_text(encoding="utf-8"))
self.assertEqual([m["id"] for m in data["models"]],
["Qwen3-TTS-12Hz-1.7B-Base-GGUF",
"Higgs-Audio-v3-TTS-4B-GGUF"])
self.assertTrue(data["lazy_load"])
self.assertEqual(data["voice_dir"], str(self.folder.resolve()))
prompt = (self.folder / common.PROMPT_TEXT_FILENAME).read_text(
encoding="utf-8")
self.assertIn("narrator|a transcript", prompt)
def test_force_overwrites_existing_output(self):
self.output.write_text('{"old": true}', encoding="utf-8")
exit_code = self._run(
self._args("--families", "higgs_audio_tts", "--force",
"--no-sync-model-ids"))
self.assertEqual(exit_code, 0)
data = json.loads(self.output.read_text(encoding="utf-8"))
self.assertEqual(len(data["models"]), 1)
def test_existing_output_declined_keeps_file(self):
self.output.write_text('{"old": true}', encoding="utf-8")
exit_code = self._run(
self._args("--families", "higgs_audio_tts", "--no-sync-model-ids"))
self.assertEqual(exit_code, 1)
self.assertEqual(json.loads(self.output.read_text(encoding="utf-8")),
{"old": True})
def test_all_packages_hosts_design_as_vdes(self):
exit_code = self._run(
self._args("--families", "qwen3_tts", "--all-packages",
"--no-sync-model-ids"))
self.assertEqual(exit_code, 0)
data = json.loads(self.output.read_text(encoding="utf-8"))
by_id = {m["id"]: m for m in data["models"]}
self.assertIn("Qwen3-TTS-12Hz-1.7B-VoiceDesign-GGUF", by_id)
self.assertEqual(by_id["Qwen3-TTS-12Hz-1.7B-VoiceDesign-GGUF"]["task"],
"vdes")
# The non-design packages are hosted with task "tts".
self.assertEqual(by_id["Qwen3-TTS-12Hz-1.7B-Base-GGUF"]["task"], "tts")
self.assertEqual(by_id["Qwen3-TTS-12Hz-1.7B-CustomVoice-GGUF"]["task"],
"tts")
def test_unknown_family_rejected(self):
with self.assertRaises(SystemExit) as ctx:
self._run(self._args("--families", "not_a_family",
"--no-sync-model-ids"))
self.assertEqual(ctx.exception.code, 2)
def test_missing_checkout_rejected(self):
with self.assertRaises(SystemExit) as ctx:
self._run(["--families", "higgs_audio_tts", "--output",
str(self.output), "--no-sync-model-ids"],
no_checkout=True)
self.assertEqual(ctx.exception.code, 2)
def test_missing_wav_dir_rejected(self):
missing = self.root / "nope"
with self.assertRaises(SystemExit) as ctx:
self._run(["--wavs", str(missing), "--output", str(self.output),
"--families", "higgs_audio_tts", "--no-sync-model-ids"])
self.assertEqual(ctx.exception.code, 2)
def test_families_required_in_noninteractive_run(self):
with self.assertRaises(SystemExit) as ctx:
self._run(self._args("--no-sync-model-ids"))
self.assertEqual(ctx.exception.code, 2)
class FetchServerEndpointsTests(unittest.TestCase):
"""fetch_server_models / fetch_server_voices: live queries against a
running audiocpp_server (urlopen mocked)."""
@staticmethod
def _urlopen_responding(bodies, errors=None):
"""A urlopen stub returning successive BODIES (bytes) or raising
successive ERRORS; records every requested URL."""
calls = []
def fake_urlopen(url, timeout=10):
calls.append(url)
if errors:
raise errors.pop(0)
body = bodies.pop(0)
context = MagicMock()
context.__enter__.return_value = context
context.__exit__.return_value = False
context.read.return_value = body
return context
return fake_urlopen, calls
def test_fetch_models_parses_id_family_task(self):
urlopen, calls = self._urlopen_responding([json.dumps({
"data": [{"id": "qwen", "family": "qwen3_tts", "task": "tts"},
{"id": "legacy"}],
}).encode("utf-8")])
with patch("urllib.request.urlopen", urlopen):
models = make_server.remote.fetch_server_models("http://127.0.0.1:8080")
# Missing fields mirror the converter's client: empty strings.
self.assertEqual(models, [
{"id": "qwen", "family": "qwen3_tts", "task": "tts"},
{"id": "legacy", "family": "", "task": ""},
])
self.assertEqual(calls, ["http://127.0.0.1:8080/v1/models"])
def test_fetch_models_trailing_slash_url(self):
urlopen, calls = self._urlopen_responding(
[b'{"data": [{"id": "m"}]}'])
with patch("urllib.request.urlopen", urlopen):
make_server.remote.fetch_server_models("http://host:8080/")
self.assertEqual(calls, ["http://host:8080/v1/models"])
def test_fetch_models_connection_error_returns_none(self):
import urllib.error
urlopen, _ = self._urlopen_responding(
[], errors=[urllib.error.URLError("Connection refused")])
with patch("urllib.request.urlopen", urlopen):
self.assertIsNone(
make_server.remote.fetch_server_models("http://127.0.0.1:8080"))
def test_fetch_models_non_json_body_returns_none(self):
# A port answering TCP but not speaking audiocpp_server JSON.
urlopen, _ = self._urlopen_responding([b"<html>not json</html>"])
with patch("urllib.request.urlopen", urlopen):
self.assertIsNone(
make_server.remote.fetch_server_models("http://127.0.0.1:8080"))
def test_fetch_models_unexpected_document_yields_empty_list(self):
urlopen, _ = self._urlopen_responding([b'{"foo": 1}'])
with patch("urllib.request.urlopen", urlopen):
self.assertEqual(
make_server.remote.fetch_server_models("http://127.0.0.1:8080"), [])
def test_fetch_voices_parses_names_and_encodes_model(self):
urlopen, calls = self._urlopen_responding(
[b'{"voices": ["narrator", "obama"]}'])
with patch("urllib.request.urlopen", urlopen):
voices = make_server.remote.fetch_server_voices(
"http://127.0.0.1:8080", "qwen")
self.assertEqual(voices, ["narrator", "obama"])
self.assertEqual(calls,
["http://127.0.0.1:8080/v1/audio/voices?model=qwen"])
def test_fetch_voices_error_returns_none(self):
import urllib.error
urlopen, _ = self._urlopen_responding(
[], errors=[urllib.error.URLError("boom")])
with patch("urllib.request.urlopen", urlopen):
self.assertIsNone(
make_server.remote.fetch_server_voices("http://h", "qwen"))
def test_fetch_voices_non_list_shape_returns_none(self):
urlopen, _ = self._urlopen_responding([b'{"voices": 5}'])
with patch("urllib.request.urlopen", urlopen):
self.assertIsNone(
make_server.remote.fetch_server_voices("http://h", "qwen"))
class MissingModelEntriesTests(unittest.TestCase):
"""missing_model_entries: server.json paths vs. files on disk."""
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.dir = Path(self._tmp.name)
def tearDown(self):
self._tmp.cleanup()
def _server_json(self, models):
path = self.dir / "server.json"
path.write_text(json.dumps({"models": models}), encoding="utf-8")
return path
def test_relative_path_resolves_against_config_dir(self):
(self.dir / "models" / "present").mkdir(parents=True)
(self.dir / "models" / "present" / "m.gguf").write_bytes(b"x")
path = self._server_json([
{"id": "a", "path": "models/present"},
{"id": "b", "path": "models/absent"},
])
missing = make_server.models.missing_model_entries(path)
self.assertEqual([m["id"] for m in missing], ["b"])
def test_empty_directory_counts_as_missing(self):
(self.dir / "models" / "empty").mkdir(parents=True)
path = self._server_json([{"id": "a", "path": "models/empty"}])
self.assertEqual(len(make_server.models.missing_model_entries(path)), 1)
def test_absolute_paths_honored(self):
target = self.dir / "absolute"
target.mkdir()
(target / "m.gguf").write_bytes(b"x")
path = self._server_json([{"id": "a", "path": str(target)}])
self.assertEqual(make_server.models.missing_model_entries(path), [])
def test_unreadable_json_returns_empty(self):
path = self.dir / "server.json"
path.write_text("not json", encoding="utf-8")
self.assertEqual(make_server.models.missing_model_entries(path), [])
def test_no_models_returns_empty(self):
path = self._server_json([])
self.assertEqual(make_server.models.missing_model_entries(path), [])
class ModelInstallHintsTests(unittest.TestCase):
"""model_install_hints: maps missing paths to the install command."""
def test_maps_path_to_install_id_via_catalog(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
checkout = Path(td)
specs = checkout / "model_specs"
specs.mkdir()
(specs / "qwen3_tts.json").write_text(json.dumps({
"family": "qwen3_tts", "category": "tts",
"tasks": ["tts"],
"packages": [{
"id": "qwen3_tts_0_6b_base_q8_0", "format": "gguf",
"target_directory": "Qwen3-TTS-12Hz-0.6B-Base-GGUF",
}],
}), encoding="utf-8")
missing = [{"id": "qwen", "rel": "models/Qwen3-TTS-12Hz-0.6B-Base-GGUF"}]
hints = make_server.models.model_install_hints(checkout, missing)
self.assertEqual(len(hints), 1)
self.assertIn("qwen3_tts_0_6b_base_q8_0", hints[0])
def test_unmapped_path_names_the_path(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
checkout = Path(td)
(checkout / "model_specs").mkdir()
hints = make_server.models.model_install_hints(
checkout, [{"id": "x", "rel": "models/nope"}])
self.assertIn("models/nope", hints[0])
self.assertNotIn("install", hints[0])
class DetectServerSpecTests(unittest.TestCase):
"""detect(): the server spec carries the checkout cwd + identity."""
def _checkout(self):
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
checkout = Path(tmp.name)
(checkout / "model_specs").mkdir()
build = checkout / "build" / "linux-cuda-release" / "bin"
build.mkdir(parents=True)
(build / "audiocpp_server").write_bytes(b"x")
(checkout / "server.json").write_text(json.dumps({
"models": [{"id": "qwen", "family": "qwen3_tts",
"path": "models/Qwen3-TTS-12Hz-0.6B-Base-GGUF"}],
}), encoding="utf-8")
return checkout
def test_spec_has_cwd_and_identity(self):
checkout = self._checkout()
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(make_server.status, "_detect_remote",
return_value=(False, {})):
status = make_server.status.detect()
self.assertEqual(len(status.servers), 1)
spec = status.servers[0]
self.assertEqual(spec.cwd, checkout)
self.assertEqual(spec.identity, "audiocpp")
self.assertIn("--config", spec.argv)
def test_models_missing_flag_and_details(self):
checkout = self._checkout()
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(make_server.status, "_detect_remote",
return_value=(False, {})):
status = make_server.status.detect()
self.assertTrue(status.models_missing)
self.assertTrue(any("not downloaded" in line
for line in status.details))
class InstalledModelEntriesTests(unittest.TestCase):
"""installed_model_entries: the complement of missing_model_entries."""
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.dir = Path(self._tmp.name)
def tearDown(self):
self._tmp.cleanup()
def _server_json(self, models):
path = self.dir / "server.json"
path.write_text(json.dumps({"models": models}), encoding="utf-8")
return path
def test_lists_entries_whose_files_are_on_disk(self):
(self.dir / "models" / "present").mkdir(parents=True)
(self.dir / "models" / "present" / "m.gguf").write_bytes(b"x")
path = self._server_json([
{"id": "a", "path": "models/present"},
{"id": "b", "path": "models/absent"},
])
installed = make_server.models.installed_model_entries(path)
self.assertEqual([m["id"] for m in installed], ["a"])
def test_unreadable_json_returns_empty(self):
path = self.dir / "server.json"
path.write_text("not json", encoding="utf-8")
self.assertEqual(make_server.models.installed_model_entries(path), [])
class MissingModelInstallGuidanceTests(unittest.TestCase):
"""missing_model_install_guidance: missing paths -> (id, install_id)."""
def test_maps_paths_and_skips_unmapped(self):
with tempfile.TemporaryDirectory() as td:
checkout = Path(td)
specs = checkout / "model_specs"
specs.mkdir()
(specs / "qwen3_tts.json").write_text(json.dumps({
"family": "qwen3_tts", "category": "tts",
"tasks": ["tts"],
"packages": [{
"id": "qwen3_tts_0_6b_base_q8_0", "format": "gguf",
"target_directory": "Qwen3-TTS-12Hz-0.6B-Base-GGUF",
}],
}), encoding="utf-8")
missing = [
{"id": "qwen", "rel": "models/Qwen3-TTS-12Hz-0.6B-Base-GGUF"},
{"id": "x", "rel": "models/nope"},
]
guidance = make_server.models.missing_model_install_guidance(
checkout, missing)
self.assertEqual(guidance,
[("qwen", "qwen3_tts_0_6b_base_q8_0")])
class LoadServerConfigTests(unittest.TestCase):
"""load_server_config: read server.json, or None when unusable."""
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.dir = Path(self._tmp.name)
def tearDown(self):
self._tmp.cleanup()
def test_reads_dict_document(self):
path = self.dir / "server.json"
path.write_text(json.dumps({"host": "0.0.0.0", "models": []}),
encoding="utf-8")
self.assertEqual(make_server.catalog.load_server_config(path),
{"host": "0.0.0.0", "models": []})
def test_missing_file_returns_none(self):
self.assertIsNone(make_server.catalog.load_server_config(
self.dir / "nope.json"))
def test_unreadable_json_returns_none(self):
path = self.dir / "server.json"
path.write_text("not json", encoding="utf-8")
self.assertIsNone(make_server.catalog.load_server_config(path))
def test_non_dict_document_returns_none(self):
path = self.dir / "server.json"
path.write_text("[1, 2, 3]", encoding="utf-8")
self.assertIsNone(make_server.catalog.load_server_config(path))
class ServerConfigSelectionsTests(unittest.TestCase):
"""server_config_selections: map server.json models back to the catalog."""
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.checkout = _make_checkout(Path(self._tmp.name))
self.catalog = make_server.catalog.load_model_catalog(self.checkout)
def tearDown(self):
self._tmp.cleanup()
def test_maps_paths_to_family_dirs_and_tasks(self):
config = {"models": [
{"id": "qwen", "family": "qwen3_tts",
"path": "models/Qwen3-TTS-12Hz-1.7B-Base-GGUF", "task": "tts"},
{"id": "qwen-design", "family": "qwen3_tts",
"path": "models/Qwen3-TTS-12Hz-1.7B-VoiceDesign-GGUF",
"task": "vdes"},
{"id": "higgs", "family": "higgs_audio_tts",
"path": "models/Higgs-Audio-v3-TTS-4B-GGUF", "task": "tts"},
]}
selected, tasks = make_server.catalog.server_config_selections(config,
self.catalog)
self.assertEqual(selected["qwen3_tts"],
["Qwen3-TTS-12Hz-1.7B-Base-GGUF",
"Qwen3-TTS-12Hz-1.7B-VoiceDesign-GGUF"])
self.assertEqual(selected["higgs_audio_tts"],
["Higgs-Audio-v3-TTS-4B-GGUF"])
self.assertEqual(tasks[("qwen3_tts",
"Qwen3-TTS-12Hz-1.7B-VoiceDesign-GGUF")],
"vdes")
self.assertEqual(tasks[("qwen3_tts",
"Qwen3-TTS-12Hz-1.7B-Base-GGUF")], "tts")
def test_unknown_family_ignored(self):
config = {"models": [
{"id": "x", "family": "not_a_family", "path": "models/x"},
]}
selected, tasks = make_server.catalog.server_config_selections(config,
self.catalog)
self.assertEqual(selected, {})
self.assertEqual(tasks, {})
def test_absolute_and_unprefixed_paths_kept_as_targets(self):
config = {"models": [
{"id": "qwen", "family": "qwen3_tts",
"path": "/abs/Qwen3-TTS-12Hz-1.7B-Base-GGUF", "task": "tts"},
]}
selected, tasks = make_server.catalog.server_config_selections(config,
self.catalog)
self.assertEqual(selected["qwen3_tts"],
["/abs/Qwen3-TTS-12Hz-1.7B-Base-GGUF"])
def test_empty_models_yield_empty_selections(self):
selected, tasks = make_server.catalog.server_config_selections({"models": []},
self.catalog)
self.assertEqual(selected, {})
self.assertEqual(tasks, {})
class UnusedInstalledEntriesTests(unittest.TestCase):
"""unused_installed_entries: installed models dropped by a new selection."""
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.dir = Path(self._tmp.name)
(self.dir / "models" / "kept").mkdir(parents=True)
(self.dir / "models" / "kept" / "m.gguf").write_bytes(b"x")
(self.dir / "models" / "dropped").mkdir()
(self.dir / "models" / "dropped" / "m.gguf").write_bytes(b"x")
(self.dir / "models" / "missing").mkdir() # empty: not installed
def tearDown(self):
self._tmp.cleanup()
def _server_json(self, models):
path = self.dir / "server.json"
path.write_text(json.dumps({"models": models}), encoding="utf-8")
return path
def test_returns_installed_entries_not_in_new_paths(self):
path = self._server_json([
{"id": "kept", "path": "models/kept"},
{"id": "dropped", "path": "models/dropped"},
{"id": "missing", "path": "models/missing"},
])
unused = make_server.models.unused_installed_entries(
path, {"models/kept"})
self.assertEqual([entry["id"] for entry in unused], ["dropped"])
def test_nothing_unused_when_all_kept(self):
path = self._server_json([
{"id": "kept", "path": "models/kept"},
])
unused = make_server.models.unused_installed_entries(
path, {"models/kept"})
self.assertEqual(unused, [])
class DeleteModelFilesTests(unittest.TestCase):
"""delete_model_files: remove on-disk model files for {id, rel} entries."""
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.dir = Path(self._tmp.name)
(self.dir / "models" / "a").mkdir(parents=True)
(self.dir / "models" / "a" / "m.gguf").write_bytes(b"x")
(self.dir / "models" / "b").mkdir()
(self.dir / "models" / "b" / "m.gguf").write_bytes(b"x")
(self.dir / "models" / "c").mkdir(parents=True)
self.server_json = self.dir / "server.json"
self.server_json.write_text(json.dumps({
"models": [
{"id": "a", "path": "models/a"},
{"id": "b", "path": "models/b"},
{"id": "c", "path": "models/c"},
],
}), encoding="utf-8")
def tearDown(self):
self._tmp.cleanup()
def test_removes_dirs_and_counts(self):
removed = make_server.models.delete_model_files(
self.server_json,
[{"id": "a", "rel": "models/a"}, {"id": "b", "rel": "models/b"}])
self.assertEqual(removed, 2)
self.assertFalse((self.dir / "models" / "a").exists())
self.assertFalse((self.dir / "models" / "b").exists())
self.assertTrue((self.dir / "models" / "c").exists())
def test_missing_paths_ignored(self):
removed = make_server.models.delete_model_files(
self.server_json, [{"id": "ghost", "rel": "models/ghost"}])
self.assertEqual(removed, 0)
def test_removes_single_file(self):
file_path = self.dir / "models" / "single.gguf"
file_path.write_bytes(b"x")
removed = make_server.models.delete_model_files(
self.server_json, [{"id": "s", "rel": "models/single.gguf"}])
self.assertEqual(removed, 1)
self.assertFalse(file_path.exists())
def test_absolute_rel_path_honored(self):
target = self.dir / "absolute"
target.mkdir()
(target / "m.gguf").write_bytes(b"x")
removed = make_server.models.delete_model_files(
self.server_json, [{"id": "a", "rel": str(target)}])
self.assertEqual(removed, 1)
self.assertFalse(target.exists())
class InstallModelsApiTests(unittest.TestCase):
"""install_models: runs the install helper with download=True."""
def test_downloads_delegating_to_install_models(self):
with tempfile.TemporaryDirectory() as td:
checkout = Path(td)
guidance = [("qwen", "qwen3_tts_0_6b_base_q8_0")]
with patch.object(make_server.models, "_install_models") as mk:
make_server.models.install_models(checkout, guidance)
mk.assert_called_once_with(checkout, guidance, download=True,
emit=None, cancel=None)
class HandInstallGuidanceTests(unittest.TestCase):
"""hand_install_guidance: explains how to install models by hand."""
def test_lists_each_model_and_its_path(self):
with tempfile.TemporaryDirectory() as td:
checkout = Path(td)
message = make_server.models.hand_install_guidance(checkout, [
{"id": "qwen", "rel": "models/Qwen3-TTS-12Hz-0.6B-Base-GGUF"},
{"id": "higgs", "rel": "models/Higgs-Audio-4B-GGUF"},
])
self.assertIn("qwen", message)
self.assertIn("models/Qwen3-TTS-12Hz-0.6B-Base-GGUF", message)
self.assertIn("higgs", message)
self.assertIn("models/Higgs-Audio-4B-GGUF", message)
self.assertIn("download", message.lower())
class WizardNavigationTests(unittest.TestCase):
"""Esc in the audio.cpp wizard goes back one screen (via tui.Wizard)."""
def _args(self):
return make_server.wizard.build_parser().parse_args([])
def _checkout(self):
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
return _make_checkout(Path(tmp.name))
def test_esc_on_first_screen_aborts(self):
# Configure audio.cpp (modify flow): the families tree is the first
# screen, so Esc on it must abort the wizard — not re-show itself.
checkout = self._checkout()
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree",
return_value=make_server.wizard._GO_BACK):
settings = make_server.wizard._wizard(None, self._args(),
make_server.wizard.build_parser())
self.assertIsNone(settings)
def test_modify_flow_offers_build_when_not_built(self):
# A server.json recording "vulkan" exists, but nothing is built: the
# combined config form must still ask the backend (pre-selecting
# vulkan) and offer the build — instead of silently skipping it
# because the existing server.json already records a backend.
checkout = self._checkout()
(checkout / "server.json").write_text(
json.dumps({"models": [], "backend": "vulkan"}),
encoding="utf-8")
catalog = make_server.catalog.load_model_catalog(checkout)
supertonic = next(i for i, entry in enumerate(catalog)
if entry["family"] == "supertonic")
def fake_tree(*args, **kwargs):
return [(supertonic, "Supertonic-GGUF")]
captured = {}
def fake_form(stdscr, title, fields, **kwargs):
captured["title"] = title
captured["keys"] = [f["key"] for f in fields]
by_key = {f["key"]: f for f in fields}
return {f["key"]: f["value"] for f in fields} | {
"backend": by_key["backend"]["value"],
"build": False, # decline the build
}
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree", side_effect=fake_tree), \
patch.object(tui, "form", side_effect=fake_form):
settings = make_server.wizard._wizard(None, self._args(),
make_server.wizard.build_parser())
self.assertIsNotNone(settings)
self.assertEqual(settings["backend"], "vulkan")
self.assertFalse(settings["build"])
# The config screen is one combined form (not one question per
# screen) that includes both the backend pick and the build offer.
self.assertEqual(captured["title"], "Configure audio.cpp")
self.assertIn("backend", captured["keys"])
self.assertIn("build", captured["keys"])
def test_esc_on_config_form_returns_to_families_tree(self):
# Esc on the combined config form must fall back to the model-family
# tree; re-selecting then proceeds through the rest of the wizard.
checkout = self._checkout()
catalog = make_server.catalog.load_model_catalog(checkout)
supertonic = next(i for i, entry in enumerate(catalog)
if entry["family"] == "supertonic")
tree_calls = []
form_calls = []
def fake_tree(*args, **kwargs):
tree_calls.append(1)
return [(supertonic, "Supertonic-GGUF")]
def fake_form(stdscr, title, fields, **kwargs):
form_calls.append(title)
if len(form_calls) == 1:
return tui.Wizard.BACK # Esc on the config form
return {f["key"]: f["value"] for f in fields}
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree",
side_effect=fake_tree), \
patch.object(tui, "form",
side_effect=fake_form):
settings = make_server.wizard._wizard(None, self._args(),
make_server.wizard.build_parser())
self.assertIsNotNone(settings)
# The tree was re-shown after the form's Esc.
self.assertEqual(len(tree_calls), 2)
self.assertEqual(form_calls,
["Configure audio.cpp", "Configure audio.cpp"])
self.assertEqual([m["id"] for m in settings["model_entries"]],
["Supertonic-GGUF"])
def test_combined_form_defaults_and_fixed_host_port(self):
# One screen collects everything: the form value defaults produce a
# complete settings dict whose host/port never came from questions.
checkout = self._checkout()
catalog = make_server.catalog.load_model_catalog(checkout)
supertonic = next(i for i, entry in enumerate(catalog)
if entry["family"] == "supertonic")
def fake_tree(*args, **kwargs):
return [(supertonic, "Supertonic-GGUF")]
def fake_form(stdscr, title, fields, **kwargs):
return {f["key"]: f["value"] for f in fields}
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree", side_effect=fake_tree), \
patch.object(tui, "form", side_effect=fake_form):
settings = make_server.wizard._wizard(None, self._args(),
make_server.wizard.build_parser())
self.assertIsNotNone(settings)
self.assertEqual(settings["host"], "127.0.0.1")
self.assertEqual(settings["port"],
make_server.configsync.config_port())
self.assertEqual(settings["backend"], "cuda") # default choice
self.assertTrue(settings["build"]) # not built yet → offered (default Yes)
self.assertFalse(settings["download"]) # no manager script here
self.assertTrue(settings["sync_model_ids"])
def test_tree_screen_starts_on_confirm(self):
# The model-tree screen opens with focus on Confirm so Enter
# accepts the seeded/checked selection immediately.
checkout = self._checkout()
catalog = make_server.catalog.load_model_catalog(checkout)
qwen3 = next(i for i, entry in enumerate(catalog)
if entry["family"] == "qwen3_tts")
captured = {}
def fake_tree(*args, **kwargs):
captured.update(kwargs)
return [(qwen3, "Qwen3-TTS-12Hz-1.7B-Base-GGUF")]
def fake_form(stdscr, title, fields, **kwargs):
return {f["key"]: f["value"] for f in fields}
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree",
side_effect=fake_tree), \
patch.object(tui, "form", side_effect=fake_form):
make_server.wizard._wizard(None, self._args(),
make_server.wizard.build_parser())
self.assertTrue(captured.get("start_on_buttons"))
def test_wav_dir_seeded_from_existing_voice_dir(self):
# A modify run loads the Voice clone .wav directory from the
# server.json being configured instead of starting blank.
checkout = self._checkout()
recorded_voices = checkout.parent / "recorded-voices"
(checkout / "server.json").write_text(json.dumps({
"host": "127.0.0.1", "port": 8080, "backend": "cuda",
"models": [], "voice_dir": str(recorded_voices),
}), encoding="utf-8")
catalog = make_server.catalog.load_model_catalog(checkout)
qwen3 = next(i for i, entry in enumerate(catalog)
if entry["family"] == "qwen3_tts")
def fake_tree(*args, **kwargs):
return [(qwen3, "Qwen3-TTS-12Hz-1.7B-Base-GGUF")]
def fake_form(stdscr, title, fields, **kwargs):
by_key = {f["key"]: f for f in fields}
self.assertEqual(by_key["wav_dir"]["value"],
Path(recorded_voices))
return {f["key"]: f["value"] for f in fields}
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree",
side_effect=fake_tree), \
patch.object(tui, "form", side_effect=fake_form):
make_server.wizard._wizard(None, self._args(),
make_server.wizard.build_parser())
def test_wav_dir_defaults_to_project_voices_when_unconfigured(self):
# Without a voice_dir in server.json the field starts on the
# project's voices/ directory — never blank.
checkout = self._checkout()
(checkout / "server.json").write_text(
json.dumps({"models": []}), encoding="utf-8")
catalog = make_server.catalog.load_model_catalog(checkout)
qwen3 = next(i for i, entry in enumerate(catalog)
if entry["family"] == "qwen3_tts")
def fake_tree(*args, **kwargs):
return [(qwen3, "Qwen3-TTS-12Hz-1.7B-Base-GGUF")]
def fake_form(stdscr, title, fields, **kwargs):
by_key = {f["key"]: f for f in fields}
self.assertEqual(by_key["wav_dir"]["value"], common.VOICES_DIR)
return {f["key"]: f["value"] for f in fields}
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree",
side_effect=fake_tree), \
patch.object(tui, "form", side_effect=fake_form):
make_server.wizard._wizard(None, self._args(),
make_server.wizard.build_parser())
def test_build_offer_hidden_when_backend_already_built(self):
# A checkout with a built binary for the chosen backend must not
# show (or honor) a build offer.
checkout = self._checkout()
catalog = make_server.catalog.load_model_catalog(checkout)
supertonic = next(i for i, entry in enumerate(catalog)
if entry["family"] == "supertonic")
binary = checkout / "build" / "linux-cuda-release" / "bin" \
/ "audiocpp_server"
binary.parent.mkdir(parents=True)
binary.write_bytes(b"x")
def fake_tree(*args, **kwargs):
return [(supertonic, "Supertonic-GGUF")]
def fake_form(stdscr, title, fields, **kwargs):
keys = [f["key"] for f in fields]
self.assertNotIn("build", keys)
self.assertNotIn("backend", keys)
return {f["key"]: f["value"] for f in fields}
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(tui, "checkbox_tree", side_effect=fake_tree), \
patch.object(tui, "form", side_effect=fake_form):
settings = make_server.wizard._wizard(None, self._args(),
make_server.wizard.build_parser())
self.assertIsNotNone(settings)
self.assertFalse(settings["build"])
self.assertEqual(settings["backend"], "cuda")
class UninstallTests(unittest.TestCase):
"""uninstall: stop the server and remove the checkout."""
def test_removes_checkout(self):
with tempfile.TemporaryDirectory() as td:
checkout = Path(td) / "audio.cpp"
checkout.mkdir()
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(servers, "pid_for",
return_value=1234), \
patch.object(servers, "stop") as mk_stop:
rc = make_server.build.uninstall()
self.assertEqual(rc, 0)
self.assertFalse(checkout.exists())
mk_stop.assert_called_once_with("audiocpp")
def test_skips_stop_without_a_pid_file(self):
# No pid file: the server was never started by this tool, so
# stop (and its "stop it manually" noise) is skipped.
with patch.object(make_server.build, "find_local_checkout",
return_value=None), \
patch.object(servers, "pid_for",
return_value=None), \
patch.object(servers, "stop") as mk_stop:
rc = make_server.build.uninstall()
self.assertEqual(rc, 0)
mk_stop.assert_not_called()
def test_accepts_task_view_kwargs_for_registry_symmetry(self):
# The hub calls uninstall(emit=..., cancel=...); emit is unused here
# (no subprocess phase) and cancel=None behaves like the plain call.
with tempfile.TemporaryDirectory() as td:
checkout = Path(td) / "audio.cpp"
checkout.mkdir()
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(servers, "pid_for",
return_value=1234), \
patch.object(servers, "stop"):
rc = make_server.build.uninstall(emit=lambda line: None,
cancel=None)
self.assertEqual(rc, 0)
self.assertFalse(checkout.exists())
def test_cancel_before_delete_keeps_checkout(self):
# Cancel is honored between phases only: once the server is stopped
# and cancellation is pending, the checkout deletion never starts.
with tempfile.TemporaryDirectory() as td:
checkout = Path(td) / "audio.cpp"
checkout.mkdir()
cancel = threading.Event()
cancel.set()
with patch.object(make_server.build, "find_local_checkout",
return_value=checkout), \
patch.object(servers, "pid_for",
return_value=1234), \
patch.object(servers, "stop"):
rc = make_server.build.uninstall(cancel=cancel)
self.assertEqual(rc, 130)
self.assertTrue(checkout.exists())
if __name__ == "__main__":
unittest.main()
class SetupScreenTests(unittest.TestCase):
"""setup_screen: the wizard run on the hub's screen, setup tail via the
in-TUI task view (two parallel lanes on a fresh install)."""
def test_abort_returns_one_without_executing(self):
with patch.object(make_server.wizard, "_wizard", return_value=None) as mk_wizard, \
patch.object(make_server.wizard, "_execute_lanes") as mk_lanes:
rc = make_server.wizard.setup_screen(None)
self.assertEqual(rc, 1)
mk_wizard.assert_called_once()
mk_lanes.assert_not_called()
def test_success_runs_the_tail_in_the_task_view(self):
settings = {"audiocpp_dir": Path("/x")}
lanes = [taskview.TaskLane(
"Build", [taskview.TaskStep("t", lambda emit, cancel: 0)])]
with patch.object(make_server.wizard, "_wizard", return_value=settings), \
patch.object(make_server.wizard, "_execute_lanes",
return_value=lanes) as mk_lanes, \
patch.object(taskview, "run_lanes",
return_value=0) as mk_run:
rc = make_server.wizard.setup_screen(None)
self.assertEqual(rc, 0)
mk_lanes.assert_called_once()
self.assertIs(mk_lanes.call_args[0][0], settings)
mk_run.assert_called_once()
self.assertEqual(mk_run.call_args[0][2], lanes)
class ExecuteLanesTests(unittest.TestCase):
"""_execute_lanes: two lanes (build + configure/download) and the
flattened console order."""
def _settings(self, **overrides):
settings = {
"audiocpp_dir": Path("/x"),
"backend": "cuda",
"build": True,
"download": True,
"include_clone": False,
"wav_dir": None,
"plan": None,
"sync_port": None,
"sync_model_ids": None,
"delete_unused": False,
"unused_entries": [],
"model_entries": [],
"entry_ids": [],
"install_guidance": [],
"output_path": Path("/x/server.json"),
"host": "127.0.0.1",
"port": 8080,
"lazy_load": True,
}
settings.update(overrides)
return settings
def test_two_lanes_when_building(self):
args = make_server.wizard.build_parser().parse_args([])
lanes = make_server.wizard._execute_lanes(self._settings(), args)
self.assertEqual([lane.title for lane in lanes],
["Build", "Configure & download"])
self.assertEqual([s.title for s in lanes[0].steps],
["Build audiocpp_server (cuda)"])
self.assertEqual([s.title for s in lanes[1].steps],
["Transcribe reference voices",
"Write server.json & sync config",
"Download models"])
def test_single_lane_when_not_building(self):
args = make_server.wizard.build_parser().parse_args([])
lanes = make_server.wizard._execute_lanes(
self._settings(build=False), args)
self.assertEqual([lane.title for lane in lanes],
["Configure & download"])
def test_flattened_console_steps_keep_the_build_first(self):
args = make_server.wizard.build_parser().parse_args([])
steps = make_server.wizard._execute_steps(self._settings(), args)
self.assertEqual([s.title for s in steps],
["Build audiocpp_server (cuda)",
"Transcribe reference voices",
"Write server.json & sync config",
"Download models"])
def test_download_step_prints_the_launch_hint(self):
args = make_server.wizard.build_parser().parse_args([])
lanes = make_server.wizard._execute_lanes(self._settings(), args)
install_step = lanes[1].steps[2]
with patch.object(make_server.models, "_install_models"), \
patch.object(make_server.build, "_print_launch_hint") as mk_hint:
install_step.work(lambda line: None, threading.Event())
mk_hint.assert_called_once_with(Path("/x"), Path("/x/server.json"))
class LaunchHintTests(unittest.TestCase):
"""_print_launch_hint: silent when built, remediation when not."""
def _capture(self, audiocpp_dir, output_path, binary=None):
buf = io.StringIO()
with redirect_stdout(buf), \
patch.object(make_server.build, "find_audiocpp_server_bin",
return_value=binary):
make_server.build._print_launch_hint(audiocpp_dir, output_path)
return buf.getvalue()
def test_built_server_prints_nothing(self):
# The hub starts/stops the server itself; no manual instructions.
out = self._capture(Path("/tmp/acpp"), Path("/tmp/acpp/server.json"),
binary=Path("/tmp/acpp/build/x/bin/audiocpp_server"))
self.assertEqual(out, "")
def test_missing_binary_gives_build_remediation(self):
out = self._capture(Path("/tmp/acpp"), Path("/tmp/acpp/server.json"))
self.assertIn("Build it first", out)
self.assertNotIn("Start the server with:", out)
|