File size: 49,949 Bytes
bf9e111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-

"""
Unit tests for Dynamic Model Resolution System.

Tests 4-layer model resolution architecture:
1. Normalize Name - convert client formats to Kiro format
2. Check Dynamic Cache - models from /ListAvailableModels API
3. Check Hidden Models - manual config for undocumented models
4. Pass-through - unknown models are sent to Kiro
"""

import pytest
from dataclasses import FrozenInstanceError

from kiro.model_resolver import (
    normalize_model_name,
    get_model_id_for_kiro,
    extract_model_family,
    ModelResolver,
    ModelResolution,
)
from kiro.cache import ModelInfoCache


# =============================================================================
# Fixtures
# =============================================================================

@pytest.fixture
def mock_model_cache():
    """
    Creates ModelInfoCache with pre-populated models.
    Simulates data from Kiro /ListAvailableModels API.
    """
    print("Setup: Creating ModelInfoCache with test models...")
    cache = ModelInfoCache()
    # Directly populate cache (without async update)
    cache._cache = {
        "auto": {"modelId": "auto", "modelName": "Auto"},
        "claude-sonnet-4.5": {"modelId": "claude-sonnet-4.5", "modelName": "Claude Sonnet 4.5"},
        "claude-sonnet-4": {"modelId": "claude-sonnet-4", "modelName": "Claude Sonnet 4"},
        "claude-haiku-4.5": {"modelId": "claude-haiku-4.5", "modelName": "Claude Haiku 4.5"},
        "claude-opus-4.5": {"modelId": "claude-opus-4.5", "modelName": "Claude Opus 4.5"},
    }
    return cache


@pytest.fixture
def empty_model_cache():
    """Creates empty ModelInfoCache."""
    print("Setup: Creating empty ModelInfoCache...")
    return ModelInfoCache()


@pytest.fixture
def hidden_models():
    """Hidden models for tests."""
    return {
        "claude-3.7-sonnet": "CLAUDE_3_7_SONNET_20250219_V1_0",
    }


@pytest.fixture
def model_resolver(mock_model_cache, hidden_models):
    """Ready-to-use ModelResolver for tests."""
    print("Setup: Creating ModelResolver with cache and hidden models...")
    return ModelResolver(cache=mock_model_cache, hidden_models=hidden_models)


@pytest.fixture
def resolver_without_hidden(mock_model_cache):
    """ModelResolver without hidden models."""
    print("Setup: Creating ModelResolver without hidden models...")
    return ModelResolver(cache=mock_model_cache, hidden_models={})


# =============================================================================
# TestNormalizeModelName - Tests for model name normalization
# =============================================================================

class TestNormalizeModelName:
    """
    Tests for normalize_model_name() function.
    
    Checks conversion of client formats to Kiro format:
    - Dashes → dots for minor versions
    - Removal of date suffix (20251001)
    - Removal of 'latest' suffix
    - Legacy format (claude-3-7-sonnet)
    """
    
    # === Standard format with minor version ===
    
    def test_normalizes_haiku_dash_to_dot(self):
        """
        What it does: claude-haiku-4-5 → claude-haiku-4.5
        Goal: Check dash-to-dot conversion for Haiku.
        """
        print("Action: Normalizing 'claude-haiku-4-5'...")
        result = normalize_model_name("claude-haiku-4-5")
        
        print(f"Comparing result: Expected 'claude-haiku-4.5', Got '{result}'")
        assert result == "claude-haiku-4.5"
    
    def test_normalizes_sonnet_dash_to_dot(self):
        """
        What it does: claude-sonnet-4-5 → claude-sonnet-4.5
        Goal: Check dash-to-dot conversion for Sonnet.
        """
        print("Action: Normalizing 'claude-sonnet-4-5'...")
        result = normalize_model_name("claude-sonnet-4-5")
        
        print(f"Comparing result: Expected 'claude-sonnet-4.5', Got '{result}'")
        assert result == "claude-sonnet-4.5"
    
    def test_normalizes_opus_dash_to_dot(self):
        """
        What it does: claude-opus-4-5 → claude-opus-4.5
        Goal: Check dash-to-dot conversion for Opus.
        """
        print("Action: Normalizing 'claude-opus-4-5'...")
        result = normalize_model_name("claude-opus-4-5")
        
        print(f"Comparing result: Expected 'claude-opus-4.5', Got '{result}'")
        assert result == "claude-opus-4.5"
    
    # === Removal of date suffix ===
    
    def test_strips_date_suffix_haiku(self):
        """
        What it does: claude-haiku-4-5-20251001 → claude-haiku-4.5
        Goal: Check date suffix removal for Haiku (Claude Code format).
        """
        print("Action: Normalizing 'claude-haiku-4-5-20251001'...")
        result = normalize_model_name("claude-haiku-4-5-20251001")
        
        print(f"Comparing result: Expected 'claude-haiku-4.5', Got '{result}'")
        assert result == "claude-haiku-4.5"
    
    def test_strips_date_suffix_sonnet(self):
        """
        What it does: claude-sonnet-4-5-20250929 → claude-sonnet-4.5
        Goal: Check date suffix removal for Sonnet.
        """
        print("Action: Normalizing 'claude-sonnet-4-5-20250929'...")
        result = normalize_model_name("claude-sonnet-4-5-20250929")
        
        print(f"Comparing result: Expected 'claude-sonnet-4.5', Got '{result}'")
        assert result == "claude-sonnet-4.5"
    
    def test_strips_date_suffix_opus(self):
        """
        What it does: claude-opus-4-5-20251101 → claude-opus-4.5
        Goal: Check date suffix removal for Opus.
        """
        print("Action: Normalizing 'claude-opus-4-5-20251101'...")
        result = normalize_model_name("claude-opus-4-5-20251101")
        
        print(f"Comparing result: Expected 'claude-opus-4.5', Got '{result}'")
        assert result == "claude-opus-4.5"
    
    # === Removal of 'latest' suffix ===
    
    def test_strips_latest_suffix(self):
        """
        What it does: claude-haiku-4-5-latest → claude-haiku-4.5
        Goal: Check 'latest' suffix removal.
        """
        print("Action: Normalizing 'claude-haiku-4-5-latest'...")
        result = normalize_model_name("claude-haiku-4-5-latest")
        
        print(f"Comparing result: Expected 'claude-haiku-4.5', Got '{result}'")
        assert result == "claude-haiku-4.5"
    
    # === Standard format without minor version ===
    
    def test_keeps_model_without_minor(self):
        """
        What it does: claude-sonnet-4 → claude-sonnet-4
        Goal: Check that models without minor version are unchanged.
        """
        print("Action: Normalizing 'claude-sonnet-4'...")
        result = normalize_model_name("claude-sonnet-4")
        
        print(f"Comparing result: Expected 'claude-sonnet-4', Got '{result}'")
        assert result == "claude-sonnet-4"
    
    def test_strips_date_from_model_without_minor(self):
        """
        What it does: claude-sonnet-4-20250514 → claude-sonnet-4
        Goal: Check date suffix removal for model without minor version.
        """
        print("Action: Normalizing 'claude-sonnet-4-20250514'...")
        result = normalize_model_name("claude-sonnet-4-20250514")
        
        print(f"Comparing result: Expected 'claude-sonnet-4', Got '{result}'")
        assert result == "claude-sonnet-4"
    
    # === Legacy format (claude-X-Y-family) ===
    
    def test_normalizes_legacy_format(self):
        """
        What it does: claude-3-7-sonnet → claude-3.7-sonnet
        Goal: Check legacy format normalization.
        """
        print("Action: Normalizing 'claude-3-7-sonnet'...")
        result = normalize_model_name("claude-3-7-sonnet")
        
        print(f"Comparing result: Expected 'claude-3.7-sonnet', Got '{result}'")
        assert result == "claude-3.7-sonnet"
    
    def test_normalizes_legacy_format_with_date(self):
        """
        What it does: claude-3-7-sonnet-20250219 → claude-3.7-sonnet
        Goal: Check legacy format normalization with date suffix.
        """
        print("Action: Normalizing 'claude-3-7-sonnet-20250219'...")
        result = normalize_model_name("claude-3-7-sonnet-20250219")
        
        print(f"Comparing result: Expected 'claude-3.7-sonnet', Got '{result}'")
        assert result == "claude-3.7-sonnet"
    
    def test_normalizes_legacy_haiku(self):
        """
        What it does: claude-3-5-haiku → claude-3.5-haiku
        Goal: Check legacy format normalization for Haiku.
        """
        print("Action: Normalizing 'claude-3-5-haiku'...")
        result = normalize_model_name("claude-3-5-haiku")
        
        print(f"Comparing result: Expected 'claude-3.5-haiku', Got '{result}'")
        assert result == "claude-3.5-haiku"
    
    def test_normalizes_legacy_opus(self):
        """
        What it does: claude-3-0-opus → claude-3.0-opus
        Goal: Check legacy format normalization for Opus.
        """
        print("Action: Normalizing 'claude-3-0-opus'...")
        result = normalize_model_name("claude-3-0-opus")
        
        print(f"Comparing result: Expected 'claude-3.0-opus', Got '{result}'")
        assert result == "claude-3.0-opus"
    
    # === Inverted format with suffix (Pattern 5 - Cursor IDE) ===
    
    def test_inverted_format_with_high_suffix(self):
        """
        What it does: claude-4.5-opus-high → claude-opus-4.5
        Goal: Check inverted format normalization with 'high' suffix (Cursor IDE).
        
        Cursor IDE sends model names in inverted format with priority suffix.
        This is Pattern 5 from PR #49.
        """
        print("Action: Normalizing 'claude-4.5-opus-high'...")
        result = normalize_model_name("claude-4.5-opus-high")
        
        print(f"Comparing result: Expected 'claude-opus-4.5', Got '{result}'")
        assert result == "claude-opus-4.5"
    
    def test_inverted_format_with_low_suffix(self):
        """
        What it does: claude-4.5-sonnet-low → claude-sonnet-4.5
        Goal: Check inverted format normalization with 'low' suffix (Cursor IDE).
        """
        print("Action: Normalizing 'claude-4.5-sonnet-low'...")
        result = normalize_model_name("claude-4.5-sonnet-low")
        
        print(f"Comparing result: Expected 'claude-sonnet-4.5', Got '{result}'")
        assert result == "claude-sonnet-4.5"
    
    def test_inverted_format_with_thinking_suffix(self):
        """
        What it does: claude-4.5-opus-high-thinking → claude-opus-4.5
        Goal: Check inverted format with compound suffix (high-thinking).
        
        The pattern strips ALL suffixes after the family name.
        """
        print("Action: Normalizing 'claude-4.5-opus-high-thinking'...")
        result = normalize_model_name("claude-4.5-opus-high-thinking")
        
        print(f"Comparing result: Expected 'claude-opus-4.5', Got '{result}'")
        assert result == "claude-opus-4.5"
    
    def test_inverted_format_all_families(self):
        """
        What it does: Verifies inverted format works for all families.
        Goal: Check haiku, sonnet, opus all work with inverted format.
        """
        print("Action: Normalizing inverted format for all families...")
        
        print("  Testing haiku...")
        result_haiku = normalize_model_name("claude-4.5-haiku-high")
        print(f"  Comparing: Expected 'claude-haiku-4.5', Got '{result_haiku}'")
        assert result_haiku == "claude-haiku-4.5"
        
        print("  Testing sonnet...")
        result_sonnet = normalize_model_name("claude-4.5-sonnet-low")
        print(f"  Comparing: Expected 'claude-sonnet-4.5', Got '{result_sonnet}'")
        assert result_sonnet == "claude-sonnet-4.5"
        
        print("  Testing opus...")
        result_opus = normalize_model_name("claude-4.5-opus-high")
        print(f"  Comparing: Expected 'claude-opus-4.5', Got '{result_opus}'")
        assert result_opus == "claude-opus-4.5"
    
    def test_inverted_format_requires_suffix(self):
        """
        What it does: Verifies that suffix is required (doesn't match claude-3.7-sonnet).
        Goal: CRITICAL - ensure Pattern 5 doesn't break already-normalized formats.
        
        This is the most important test for Pattern 5. The regex MUST require a suffix
        to avoid matching already-normalized formats like claude-3.7-sonnet.
        """
        print("Action: Normalizing 'claude-3.7-sonnet' (should NOT match Pattern 5)...")
        result = normalize_model_name("claude-3.7-sonnet")
        
        print(f"Comparing result: Expected 'claude-3.7-sonnet' (unchanged), Got '{result}'")
        assert result == "claude-3.7-sonnet"
        
        print("Action: Normalizing 'claude-4.5-sonnet' (should NOT match Pattern 5)...")
        result2 = normalize_model_name("claude-4.5-sonnet")
        
        print(f"Comparing result: Expected 'claude-4.5-sonnet' (unchanged), Got '{result2}'")
        assert result2 == "claude-4.5-sonnet"
    
    def test_inverted_format_case_insensitive(self):
        """
        What it does: CLAUDE-4.5-OPUS-HIGH → claude-opus-4.5
        Goal: Check case insensitivity for inverted format.
        """
        print("Action: Normalizing 'CLAUDE-4.5-OPUS-HIGH'...")
        result = normalize_model_name("CLAUDE-4.5-OPUS-HIGH")
        
        print(f"Comparing result: Expected 'claude-opus-4.5', Got '{result}'")
        assert result == "claude-opus-4.5"
    
    # === Already normalized (passthrough) ===
    
    def test_passthrough_already_normalized_haiku(self):
        """
        What it does: claude-haiku-4.5 → claude-haiku-4.5
        Goal: Check that already normalized models are unchanged.
        """
        print("Action: Normalizing 'claude-haiku-4.5'...")
        result = normalize_model_name("claude-haiku-4.5")
        
        print(f"Comparing result: Expected 'claude-haiku-4.5', Got '{result}'")
        assert result == "claude-haiku-4.5"
    
    def test_passthrough_already_normalized_sonnet(self):
        """
        What it does: claude-sonnet-4.5 → claude-sonnet-4.5
        Goal: Check passthrough for Sonnet.
        """
        print("Action: Normalizing 'claude-sonnet-4.5'...")
        result = normalize_model_name("claude-sonnet-4.5")
        
        print(f"Comparing result: Expected 'claude-sonnet-4.5', Got '{result}'")
        assert result == "claude-sonnet-4.5"
    
    def test_passthrough_auto(self):
        """
        What it does: auto → auto
        Goal: Check passthrough for 'auto'.
        """
        print("Action: Normalizing 'auto'...")
        result = normalize_model_name("auto")
        
        print(f"Comparing result: Expected 'auto', Got '{result}'")
        assert result == "auto"
    
    # === Edge cases ===
    
    def test_handles_empty_string(self):
        """
        What it does: "" → ""
        Goal: Check empty string handling.
        """
        print("Action: Normalizing empty string...")
        result = normalize_model_name("")
        
        print(f"Comparing result: Expected '', Got '{result}'")
        assert result == ""
    
    def test_handles_unknown_format(self):
        """
        What it does: gpt-4 → gpt-4 (passthrough)
        Goal: Check passthrough for unknown formats.
        """
        print("Action: Normalizing 'gpt-4'...")
        result = normalize_model_name("gpt-4")
        
        print(f"Comparing result: Expected 'gpt-4', Got '{result}'")
        assert result == "gpt-4"
    
    def test_handles_random_model_name(self):
        """
        What it does: some-random-model → some-random-model
        Goal: Check passthrough for arbitrary names.
        """
        print("Action: Normalizing 'some-random-model'...")
        result = normalize_model_name("some-random-model")
        
        print(f"Comparing result: Expected 'some-random-model', Got '{result}'")
        assert result == "some-random-model"


# =============================================================================
# TestNormalizeModelNameParametrized - Parametrized tests
# =============================================================================

class TestNormalizeModelNameParametrized:
    """Parametrized tests for complete coverage of scenarios."""
    
    @pytest.mark.parametrize("input_model,expected", [
        # Standard format with minor version
        ("claude-haiku-4-5", "claude-haiku-4.5"),
        ("claude-haiku-4-5-20251001", "claude-haiku-4.5"),
        ("claude-haiku-4-5-latest", "claude-haiku-4.5"),
        ("claude-sonnet-4-5", "claude-sonnet-4.5"),
        ("claude-sonnet-4-5-20250929", "claude-sonnet-4.5"),
        ("claude-opus-4-5", "claude-opus-4.5"),
        ("claude-opus-4-5-20251101", "claude-opus-4.5"),
        # Without minor version
        ("claude-sonnet-4", "claude-sonnet-4"),
        ("claude-sonnet-4-20250514", "claude-sonnet-4"),
        ("claude-haiku-4", "claude-haiku-4"),
        ("claude-opus-4", "claude-opus-4"),
        # Legacy format
        ("claude-3-7-sonnet", "claude-3.7-sonnet"),
        ("claude-3-7-sonnet-20250219", "claude-3.7-sonnet"),
        ("claude-3-5-haiku", "claude-3.5-haiku"),
        ("claude-3-0-opus", "claude-3.0-opus"),
        # Already normalized
        ("claude-haiku-4.5", "claude-haiku-4.5"),
        ("claude-sonnet-4.5", "claude-sonnet-4.5"),
        ("claude-opus-4.5", "claude-opus-4.5"),
        ("claude-3.7-sonnet", "claude-3.7-sonnet"),
        ("auto", "auto"),
        # Passthrough for unknown
        ("gpt-4", "gpt-4"),
        ("gpt-4-turbo", "gpt-4-turbo"),
        ("unknown-model", "unknown-model"),
    ])
    def test_normalize_model_name_all_scenarios(self, input_model, expected):
        """
        What it does: Checks all normalization scenarios.
        Goal: Complete coverage of scenario table.
        """
        print(f"Action: Normalizing '{input_model}'...")
        result = normalize_model_name(input_model)
        
        print(f"Comparing result: Expected '{expected}', Got '{result}'")
        assert result == expected


# =============================================================================
# TestExtractModelFamily - Tests for model family extraction
# =============================================================================

class TestExtractModelFamily:
    """
    Tests for extract_model_family() function.
    
    Checks extraction of model family (haiku, sonnet, opus) from name.
    """
    
    def test_extracts_haiku_from_standard_format(self):
        """
        What it does: claude-haiku-4.5 → haiku
        Goal: Check Haiku family extraction.
        """
        print("Action: Extracting family from 'claude-haiku-4.5'...")
        result = extract_model_family("claude-haiku-4.5")
        
        print(f"Comparing result: Expected 'haiku', Got '{result}'")
        assert result == "haiku"
    
    def test_extracts_sonnet_from_standard_format(self):
        """
        What it does: claude-sonnet-4.5 → sonnet
        Goal: Check Sonnet family extraction.
        """
        print("Action: Extracting family from 'claude-sonnet-4.5'...")
        result = extract_model_family("claude-sonnet-4.5")
        
        print(f"Comparing result: Expected 'sonnet', Got '{result}'")
        assert result == "sonnet"
    
    def test_extracts_opus_from_standard_format(self):
        """
        What it does: claude-opus-4.5 → opus
        Goal: Check Opus family extraction.
        """
        print("Action: Extracting family from 'claude-opus-4.5'...")
        result = extract_model_family("claude-opus-4.5")
        
        print(f"Comparing result: Expected 'opus', Got '{result}'")
        assert result == "opus"
    
    def test_extracts_sonnet_from_legacy_format(self):
        """
        What it does: claude-3.7-sonnet → sonnet
        Goal: Check family extraction from legacy format.
        """
        print("Action: Extracting family from 'claude-3.7-sonnet'...")
        result = extract_model_family("claude-3.7-sonnet")
        
        print(f"Comparing result: Expected 'sonnet', Got '{result}'")
        assert result == "sonnet"
    
    def test_extracts_haiku_from_unnormalized(self):
        """
        What it does: claude-haiku-4-5-20251001 → haiku
        Goal: Check family extraction from unnormalized name.
        """
        print("Action: Extracting family from 'claude-haiku-4-5-20251001'...")
        result = extract_model_family("claude-haiku-4-5-20251001")
        
        print(f"Comparing result: Expected 'haiku', Got '{result}'")
        assert result == "haiku"
    
    def test_returns_none_for_non_claude(self):
        """
        What it does: gpt-4 → None
        Goal: Check None return for non-Claude models.
        """
        print("Action: Extracting family from 'gpt-4'...")
        result = extract_model_family("gpt-4")
        
        print(f"Comparing result: Expected None, Got {result}")
        assert result is None
    
    def test_returns_none_for_auto(self):
        """
        What it does: auto → None
        Goal: Check None return for 'auto'.
        """
        print("Action: Extracting family from 'auto'...")
        result = extract_model_family("auto")
        
        print(f"Comparing result: Expected None, Got {result}")
        assert result is None
    
    def test_case_insensitive(self):
        """
        What it does: CLAUDE-HAIKU-4.5 → haiku
        Goal: Check case insensitivity.
        """
        print("Action: Extracting family from 'CLAUDE-HAIKU-4.5'...")
        result = extract_model_family("CLAUDE-HAIKU-4.5")
        
        print(f"Comparing result: Expected 'haiku', Got '{result}'")
        assert result == "haiku"


# =============================================================================
# TestGetModelIdForKiro - Tests for converter helper
# =============================================================================

class TestGetModelIdForKiro:
    """
    Tests for get_model_id_for_kiro() function.
    
    Checks getting model ID for sending to Kiro API.
    """
    
    def test_normalizes_without_hidden_models(self):
        """
        What it does: Normalizes model without hidden models.
        Goal: Check basic normalization.
        """
        print("Action: get_model_id_for_kiro('claude-haiku-4-5-20251001', {})...")
        result = get_model_id_for_kiro("claude-haiku-4-5-20251001", {})
        
        print(f"Comparing result: Expected 'claude-haiku-4.5', Got '{result}'")
        assert result == "claude-haiku-4.5"
    
    def test_returns_internal_id_for_hidden_model(self):
        """
        What it does: Returns internal ID for hidden model.
        Goal: Check hidden model resolution.
        """
        hidden = {"claude-3.7-sonnet": "CLAUDE_3_7_SONNET_20250219_V1_0"}
        
        print("Action: get_model_id_for_kiro('claude-3.7-sonnet', hidden)...")
        result = get_model_id_for_kiro("claude-3.7-sonnet", hidden)
        
        print(f"Comparing result: Expected 'CLAUDE_3_7_SONNET_20250219_V1_0', Got '{result}'")
        assert result == "CLAUDE_3_7_SONNET_20250219_V1_0"
    
    def test_normalizes_then_checks_hidden(self):
        """
        What it does: Normalizes first, then checks hidden.
        Goal: Check operation order.
        """
        hidden = {"claude-3.7-sonnet": "CLAUDE_3_7_SONNET_20250219_V1_0"}
        
        print("Action: get_model_id_for_kiro('claude-3-7-sonnet', hidden)...")
        result = get_model_id_for_kiro("claude-3-7-sonnet", hidden)
        
        print(f"Comparing result: Expected 'CLAUDE_3_7_SONNET_20250219_V1_0', Got '{result}'")
        assert result == "CLAUDE_3_7_SONNET_20250219_V1_0"
    
    def test_normalizes_with_date_then_checks_hidden(self):
        """
        What it does: Normalizes with date suffix, then checks hidden.
        Goal: Check full normalization chain.
        """
        hidden = {"claude-3.7-sonnet": "CLAUDE_3_7_SONNET_20250219_V1_0"}
        
        print("Action: get_model_id_for_kiro('claude-3-7-sonnet-20250219', hidden)...")
        result = get_model_id_for_kiro("claude-3-7-sonnet-20250219", hidden)
        
        print(f"Comparing result: Expected 'CLAUDE_3_7_SONNET_20250219_V1_0', Got '{result}'")
        assert result == "CLAUDE_3_7_SONNET_20250219_V1_0"
    
    def test_passthrough_unknown_model(self):
        """
        What it does: Passthrough for unknown models.
        Goal: Check that unknown models pass through normalized.
        """
        print("Action: get_model_id_for_kiro('claude-unknown-model', {})...")
        result = get_model_id_for_kiro("claude-unknown-model", {})
        
        print(f"Comparing result: Expected 'claude-unknown-model', Got '{result}'")
        assert result == "claude-unknown-model"


# =============================================================================
# TestModelResolver - Tests for ModelResolver class
# =============================================================================

class TestModelResolverInitialization:
    """Tests for ModelResolver initialization."""
    
    def test_init_with_cache_and_hidden_models(self, mock_model_cache, hidden_models):
        """
        What it does: Creates ModelResolver with cache and hidden models.
        Goal: Check correct initialization.
        """
        print("Action: Creating ModelResolver...")
        resolver = ModelResolver(cache=mock_model_cache, hidden_models=hidden_models)
        
        print("Check: Attributes set correctly...")
        assert resolver.cache is mock_model_cache
        assert resolver.hidden_models == hidden_models
    
    def test_init_with_empty_hidden_models(self, mock_model_cache):
        """
        What it does: Creates ModelResolver without hidden models.
        Goal: Check work with empty dict.
        """
        print("Action: Creating ModelResolver without hidden models...")
        resolver = ModelResolver(cache=mock_model_cache, hidden_models={})
        
        print("Check: hidden_models is empty...")
        assert resolver.hidden_models == {}
    
    def test_init_with_none_hidden_models(self, mock_model_cache):
        """
        What it does: Creates ModelResolver with hidden_models=None.
        Goal: Check default value.
        """
        print("Action: Creating ModelResolver with hidden_models=None...")
        resolver = ModelResolver(cache=mock_model_cache, hidden_models=None)
        
        print("Check: hidden_models initialized as empty dict...")
        assert resolver.hidden_models == {}


class TestModelResolverResolve:
    """Tests for resolve() method of ModelResolver class."""
    
    def test_resolve_finds_model_in_cache(self, model_resolver):
        """
        What it does: Finds model in cache.
        Goal: Check Layer 2 (Dynamic Cache).
        """
        print("Action: Resolving 'claude-haiku-4-5'...")
        result = model_resolver.resolve("claude-haiku-4-5")
        
        print(f"Check result: {result}")
        print(f"Comparing internal_id: Expected 'claude-haiku-4.5', Got '{result.internal_id}'")
        assert result.internal_id == "claude-haiku-4.5"
        
        print(f"Comparing source: Expected 'cache', Got '{result.source}'")
        assert result.source == "cache"
        
        print(f"Comparing is_verified: Expected True, Got {result.is_verified}")
        assert result.is_verified is True
        
        print(f"Comparing normalized: Expected 'claude-haiku-4.5', Got '{result.normalized}'")
        assert result.normalized == "claude-haiku-4.5"
        
        print(f"Comparing original_request: Expected 'claude-haiku-4-5', Got '{result.original_request}'")
        assert result.original_request == "claude-haiku-4-5"
    
    def test_resolve_finds_model_in_hidden(self, model_resolver):
        """
        What it does: Finds model in hidden models.
        Goal: Check Layer 3 (Hidden Models).
        """
        print("Action: Resolving 'claude-3-7-sonnet'...")
        result = model_resolver.resolve("claude-3-7-sonnet")
        
        print(f"Check result: {result}")
        print(f"Comparing internal_id: Expected 'CLAUDE_3_7_SONNET_20250219_V1_0', Got '{result.internal_id}'")
        assert result.internal_id == "CLAUDE_3_7_SONNET_20250219_V1_0"
        
        print(f"Comparing source: Expected 'hidden', Got '{result.source}'")
        assert result.source == "hidden"
        
        print(f"Comparing is_verified: Expected True, Got {result.is_verified}")
        assert result.is_verified is True
    
    def test_resolve_passthrough_for_unknown(self, model_resolver):
        """
        What it does: Passthrough for unknown model.
        Goal: Check Layer 4 (Pass-through).
        """
        print("Action: Resolving 'claude-haiku-4-6' (does not exist)...")
        result = model_resolver.resolve("claude-haiku-4-6")
        
        print(f"Check result: {result}")
        print(f"Comparing internal_id: Expected 'claude-haiku-4.6', Got '{result.internal_id}'")
        assert result.internal_id == "claude-haiku-4.6"
        
        print(f"Comparing source: Expected 'passthrough', Got '{result.source}'")
        assert result.source == "passthrough"
        
        print(f"Comparing is_verified: Expected False, Got {result.is_verified}")
        assert result.is_verified is False
    
    def test_resolve_normalizes_before_lookup(self, model_resolver):
        """
        What it does: Normalizes name before cache lookup.
        Goal: Check Layer 1 (Normalize Name).
        """
        print("Action: Resolving 'claude-haiku-4-5-20251001'...")
        result = model_resolver.resolve("claude-haiku-4-5-20251001")
        
        print(f"Comparing normalized: Expected 'claude-haiku-4.5', Got '{result.normalized}'")
        assert result.normalized == "claude-haiku-4.5"
        
        print(f"Comparing source: Expected 'cache', Got '{result.source}'")
        assert result.source == "cache"
    
    def test_resolve_never_raises(self, model_resolver):
        """
        What it does: Never raises exception.
        Goal: Check that resolve() always returns ModelResolution.
        """
        print("Action: Resolving strange input data...")
        
        # Empty string
        result1 = model_resolver.resolve("")
        print(f"Empty string: {result1}")
        assert isinstance(result1, ModelResolution)
        
        # Special characters
        result2 = model_resolver.resolve("!@#$%^&*()")
        print(f"Special characters: {result2}")
        assert isinstance(result2, ModelResolution)
        
        # Very long name
        result3 = model_resolver.resolve("a" * 1000)
        print(f"Long name: source={result3.source}")
        assert isinstance(result3, ModelResolution)
    
    def test_resolve_auto_model(self, model_resolver):
        """
        What it does: Resolves 'auto' model.
        Goal: Check that 'auto' is in cache.
        """
        print("Action: Resolving 'auto'...")
        result = model_resolver.resolve("auto")
        
        print(f"Comparing internal_id: Expected 'auto', Got '{result.internal_id}'")
        assert result.internal_id == "auto"
        
        print(f"Comparing source: Expected 'cache', Got '{result.source}'")
        assert result.source == "cache"
    
    def test_resolve_with_empty_cache(self, empty_model_cache, hidden_models):
        """
        What it does: Resolves model with empty cache.
        Goal: Check work with only hidden models.
        """
        print("Setup: Creating resolver with empty cache...")
        resolver = ModelResolver(cache=empty_model_cache, hidden_models=hidden_models)
        
        print("Action: Resolving 'claude-3.7-sonnet'...")
        result = resolver.resolve("claude-3.7-sonnet")
        
        print(f"Comparing source: Expected 'hidden', Got '{result.source}'")
        assert result.source == "hidden"
        
        print("Action: Resolving 'claude-haiku-4.5' (not in cache)...")
        result2 = resolver.resolve("claude-haiku-4.5")
        
        print(f"Comparing source: Expected 'passthrough', Got '{result2.source}'")
        assert result2.source == "passthrough"


class TestModelResolverGetAvailableModels:
    """Tests for get_available_models() method."""
    
    def test_get_available_models_combines_cache_and_hidden(self, model_resolver):
        """
        What it does: Returns models from cache and hidden.
        Goal: Check combining sources.
        """
        print("Action: Getting list of available models...")
        models = model_resolver.get_available_models()
        
        print(f"Received models: {models}")
        
        # Check cache models
        print("Check: Cache models present...")
        assert "claude-haiku-4.5" in models
        assert "claude-sonnet-4.5" in models
        assert "claude-opus-4.5" in models
        assert "auto" in models
        
        # Check hidden models
        print("Check: Hidden models present...")
        assert "claude-3.7-sonnet" in models
    
    def test_get_available_models_returns_sorted_list(self, model_resolver):
        """
        What it does: Returns sorted list.
        Goal: Check sorting.
        """
        print("Action: Getting list of available models...")
        models = model_resolver.get_available_models()
        
        print(f"Received models: {models}")
        print(f"Sorted: {sorted(models)}")
        
        assert models == sorted(models)
    
    def test_get_available_models_no_duplicates(self, mock_model_cache):
        """
        What it does: Does not return duplicates.
        Goal: Check uniqueness.
        """
        # Add hidden model that already exists in cache
        hidden = {"claude-haiku-4.5": "SOME_INTERNAL_ID"}
        resolver = ModelResolver(cache=mock_model_cache, hidden_models=hidden)
        
        print("Action: Getting list with potential duplicate...")
        models = resolver.get_available_models()
        
        print(f"Received models: {models}")
        
        # Check uniqueness
        assert len(models) == len(set(models))


class TestModelResolverGetModelsByFamily:
    """Tests for get_models_by_family() method."""
    
    def test_get_models_by_family_haiku(self, model_resolver):
        """
        What it does: Returns only Haiku models.
        Goal: Check filtering by family.
        """
        print("Action: Getting Haiku models...")
        models = model_resolver.get_models_by_family("haiku")
        
        print(f"Received models: {models}")
        
        assert "claude-haiku-4.5" in models
        assert "claude-sonnet-4.5" not in models
        assert "claude-opus-4.5" not in models
    
    def test_get_models_by_family_sonnet(self, model_resolver):
        """
        What it does: Returns only Sonnet models.
        Goal: Check Sonnet filtering.
        """
        print("Action: Getting Sonnet models...")
        models = model_resolver.get_models_by_family("sonnet")
        
        print(f"Received models: {models}")
        
        assert "claude-sonnet-4.5" in models
        assert "claude-sonnet-4" in models
        assert "claude-3.7-sonnet" in models  # Hidden model
        assert "claude-haiku-4.5" not in models
    
    def test_get_models_by_family_opus(self, model_resolver):
        """
        What it does: Returns only Opus models.
        Goal: Check Opus filtering.
        """
        print("Action: Getting Opus models...")
        models = model_resolver.get_models_by_family("opus")
        
        print(f"Received models: {models}")
        
        assert "claude-opus-4.5" in models
        assert "claude-sonnet-4.5" not in models
    
    def test_get_models_by_family_case_insensitive(self, model_resolver):
        """
        What it does: Filtering is case insensitive.
        Goal: Check case-insensitivity.
        """
        print("Action: Getting HAIKU models (uppercase)...")
        models = model_resolver.get_models_by_family("HAIKU")
        
        print(f"Received models: {models}")
        
        assert "claude-haiku-4.5" in models


class TestModelResolverGetSuggestionsForModel:
    """Tests for get_suggestions_for_model() method."""
    
    def test_get_suggestions_returns_same_family(self, model_resolver):
        """
        What it does: Returns models of same family.
        Goal: Check that suggestions are from same family.
        """
        print("Action: Getting suggestions for 'claude-haiku-4-6'...")
        suggestions = model_resolver.get_suggestions_for_model("claude-haiku-4-6")
        
        print(f"Received suggestions: {suggestions}")
        
        # All suggestions should be Haiku
        for s in suggestions:
            print(f"Check: '{s}' contains 'haiku'...")
            assert "haiku" in s.lower()
    
    def test_get_suggestions_no_cross_family(self, model_resolver):
        """
        What it does: NEVER suggests models from other family.
        Goal: Critical check - Opus never becomes Sonnet!
        """
        print("Action: Getting suggestions for 'claude-opus-5'...")
        suggestions = model_resolver.get_suggestions_for_model("claude-opus-5")
        
        print(f"Received suggestions: {suggestions}")
        
        # Should NOT be Sonnet or Haiku
        for s in suggestions:
            print(f"Check: '{s}' does NOT contain 'sonnet' or 'haiku'...")
            assert "sonnet" not in s.lower()
            assert "haiku" not in s.lower()
    
    def test_get_suggestions_returns_all_for_unknown_family(self, model_resolver):
        """
        What it does: Returns all models for unknown family.
        Goal: Check fallback for non-Claude models.
        """
        print("Action: Getting suggestions for 'gpt-4'...")
        suggestions = model_resolver.get_suggestions_for_model("gpt-4")
        
        print(f"Received suggestions: {suggestions}")
        
        # Should be all models
        all_models = model_resolver.get_available_models()
        assert set(suggestions) == set(all_models)


# =============================================================================
# TestModelResolution - Tests for ModelResolution dataclass
# =============================================================================

class TestModelResolution:
    """Tests for ModelResolution dataclass."""
    
    def test_model_resolution_fields(self):
        """
        What it does: Checks all ModelResolution fields.
        Goal: Ensure correct structure.
        """
        print("Action: Creating ModelResolution...")
        resolution = ModelResolution(
            internal_id="claude-haiku-4.5",
            source="cache",
            original_request="claude-haiku-4-5",
            normalized="claude-haiku-4.5",
            is_verified=True
        )
        
        print(f"Check fields: {resolution}")
        assert resolution.internal_id == "claude-haiku-4.5"
        assert resolution.source == "cache"
        assert resolution.original_request == "claude-haiku-4-5"
        assert resolution.normalized == "claude-haiku-4.5"
        assert resolution.is_verified is True
    
    def test_model_resolution_is_frozen(self):
        """
        What it does: Checks that ModelResolution is immutable.
        Goal: Ensure immutability (frozen=True).
        """
        print("Action: Creating ModelResolution...")
        resolution = ModelResolution(
            internal_id="test",
            source="cache",
            original_request="test",
            normalized="test",
            is_verified=True
        )
        
        print("Check: Attempt to modify field should raise error...")
        with pytest.raises(FrozenInstanceError):
            resolution.internal_id = "changed"
    
    def test_model_resolution_equality(self):
        """
        What it does: Checks comparison of two ModelResolution objects.
        Goal: Ensure correct __eq__ implementation.
        """
        print("Action: Creating two identical ModelResolution objects...")
        resolution1 = ModelResolution(
            internal_id="test",
            source="cache",
            original_request="test",
            normalized="test",
            is_verified=True
        )
        resolution2 = ModelResolution(
            internal_id="test",
            source="cache",
            original_request="test",
            normalized="test",
            is_verified=True
        )
        
        print(f"Comparing: {resolution1} == {resolution2}")
        assert resolution1 == resolution2
    
    def test_model_resolution_inequality(self):
        """
        What it does: Checks inequality of different ModelResolution objects.
        Goal: Ensure correct __eq__ implementation.
        """
        print("Action: Creating two different ModelResolution objects...")
        resolution1 = ModelResolution(
            internal_id="test1",
            source="cache",
            original_request="test",
            normalized="test",
            is_verified=True
        )
        resolution2 = ModelResolution(
            internal_id="test2",
            source="hidden",
            original_request="test",
            normalized="test",
            is_verified=True
        )
        
        print(f"Comparing: {resolution1} != {resolution2}")
        assert resolution1 != resolution2


# =============================================================================
# TestModelInfoCacheNewMethods - Tests for new cache methods
# =============================================================================

class TestModelInfoCacheIsValidModel:
    """Tests for is_valid_model() method in ModelInfoCache."""
    
    @pytest.mark.asyncio
    async def test_is_valid_model_returns_true_for_cached(self):
        """
        What it does: Returns True for model in cache.
        Goal: Check basic functionality.
        """
        print("Setup: Creating and populating cache...")
        cache = ModelInfoCache()
        await cache.update([{"modelId": "claude-sonnet-4.5"}])
        
        print("Action: Checking is_valid_model('claude-sonnet-4.5')...")
        result = cache.is_valid_model("claude-sonnet-4.5")
        
        print(f"Comparing result: Expected True, Got {result}")
        assert result is True
    
    @pytest.mark.asyncio
    async def test_is_valid_model_returns_false_for_unknown(self):
        """
        What it does: Returns False for unknown model.
        Goal: Check negative case.
        """
        print("Setup: Creating and populating cache...")
        cache = ModelInfoCache()
        await cache.update([{"modelId": "claude-sonnet-4.5"}])
        
        print("Action: Checking is_valid_model('unknown-model')...")
        result = cache.is_valid_model("unknown-model")
        
        print(f"Comparing result: Expected False, Got {result}")
        assert result is False
    
    def test_is_valid_model_on_empty_cache(self):
        """
        What it does: Returns False for empty cache.
        Goal: Check edge case.
        """
        print("Setup: Creating empty cache...")
        cache = ModelInfoCache()
        
        print("Action: Checking is_valid_model('any-model')...")
        result = cache.is_valid_model("any-model")
        
        print(f"Comparing result: Expected False, Got {result}")
        assert result is False


class TestModelInfoCacheAddHiddenModel:
    """Tests for add_hidden_model() method in ModelInfoCache."""
    
    def test_add_hidden_model_adds_to_cache(self):
        """
        What it does: Adds hidden model to cache.
        Goal: Check basic functionality.
        """
        print("Setup: Creating empty cache...")
        cache = ModelInfoCache()
        
        print("Action: Adding hidden model...")
        cache.add_hidden_model("claude-3.7-sonnet", "CLAUDE_3_7_SONNET_20250219_V1_0")
        
        print("Check: Model added to cache...")
        assert cache.is_valid_model("claude-3.7-sonnet") is True
    
    def test_add_hidden_model_stores_internal_id(self):
        """
        What it does: Stores internal ID in _internal_id field.
        Goal: Check data structure.
        """
        print("Setup: Creating empty cache...")
        cache = ModelInfoCache()
        
        print("Action: Adding hidden model...")
        cache.add_hidden_model("claude-3.7-sonnet", "CLAUDE_3_7_SONNET_20250219_V1_0")
        
        print("Check: _internal_id saved...")
        model_info = cache.get("claude-3.7-sonnet")
        print(f"model_info: {model_info}")
        
        assert model_info["_internal_id"] == "CLAUDE_3_7_SONNET_20250219_V1_0"
        assert model_info["_is_hidden"] is True
    
    def test_add_hidden_model_sets_model_id(self):
        """
        What it does: Sets modelId equal to display_name.
        Goal: Check data consistency.
        """
        print("Setup: Creating empty cache...")
        cache = ModelInfoCache()
        
        print("Action: Adding hidden model...")
        cache.add_hidden_model("claude-3.7-sonnet", "INTERNAL_ID")
        
        print("Check: modelId set...")
        model_info = cache.get("claude-3.7-sonnet")
        
        assert model_info["modelId"] == "claude-3.7-sonnet"
        assert model_info["modelName"] == "claude-3.7-sonnet"
    
    @pytest.mark.asyncio
    async def test_add_hidden_model_does_not_overwrite_existing(self):
        """
        What it does: Does not overwrite existing model.
        Goal: Check protection from overwriting.
        """
        print("Setup: Creating cache with model...")
        cache = ModelInfoCache()
        await cache.update([{
            "modelId": "claude-3.7-sonnet",
            "modelName": "Original Name",
            "tokenLimits": {"maxInputTokens": 200000}
        }])
        
        print("Action: Attempting to add hidden model with same ID...")
        cache.add_hidden_model("claude-3.7-sonnet", "NEW_INTERNAL_ID")
        
        print("Check: Original data preserved...")
        model_info = cache.get("claude-3.7-sonnet")
        
        assert model_info["modelName"] == "Original Name"
        assert "_internal_id" not in model_info  # Should not be added
    
    def test_add_hidden_model_appears_in_get_all_model_ids(self):
        """
        What it does: Hidden model appears in list of all models.
        Goal: Check integration with get_all_model_ids().
        """
        print("Setup: Creating empty cache...")
        cache = ModelInfoCache()
        
        print("Action: Adding hidden model...")
        cache.add_hidden_model("claude-3.7-sonnet", "INTERNAL_ID")
        
        print("Check: Model in list...")
        model_ids = cache.get_all_model_ids()
        
        assert "claude-3.7-sonnet" in model_ids


# =============================================================================
# TestCriticalSafetyPrinciple - Critical security tests
# =============================================================================

class TestCriticalSafetyPrinciple:
    """
    Critical security tests: Family Isolation.
    
    IMPORTANT: Resolver MUST NEVER cross model family boundaries!
    """
    
    def test_opus_never_becomes_sonnet(self, model_resolver):
        """
        What it does: Opus request NEVER becomes Sonnet.
        Goal: Critical check for Family Isolation.
        """
        print("Action: Resolving non-existent Opus model...")
        result = model_resolver.resolve("claude-opus-5")
        
        print(f"Result: {result}")
        
        # Should be passthrough, NOT fallback to Sonnet
        print("Check: Does NOT contain 'sonnet'...")
        assert "sonnet" not in result.internal_id.lower()
        
        print("Check: Does NOT contain 'haiku'...")
        assert "haiku" not in result.internal_id.lower()
    
    def test_haiku_never_becomes_opus(self, model_resolver):
        """
        What it does: Haiku request NEVER becomes Opus.
        Goal: Critical check for Family Isolation.
        """
        print("Action: Resolving non-existent Haiku model...")
        result = model_resolver.resolve("claude-haiku-5")
        
        print(f"Result: {result}")
        
        # Should be passthrough, NOT fallback to Opus
        print("Check: Does NOT contain 'opus'...")
        assert "opus" not in result.internal_id.lower()
        
        print("Check: Does NOT contain 'sonnet'...")
        assert "sonnet" not in result.internal_id.lower()
    
    def test_sonnet_never_becomes_haiku(self, model_resolver):
        """
        What it does: Sonnet request NEVER becomes Haiku.
        Goal: Critical check for Family Isolation.
        """
        print("Action: Resolving non-existent Sonnet model...")
        result = model_resolver.resolve("claude-sonnet-5")
        
        print(f"Result: {result}")
        
        # Should be passthrough, NOT fallback to Haiku
        print("Check: Does NOT contain 'haiku'...")
        assert "haiku" not in result.internal_id.lower()
        
        print("Check: Does NOT contain 'opus'...")
        assert "opus" not in result.internal_id.lower()
    
    def test_suggestions_respect_family_boundaries(self, model_resolver):
        """
        What it does: Suggestions only from same family.
        Goal: Check that get_suggestions_for_model() respects boundaries.
        """
        families = ["haiku", "sonnet", "opus"]
        
        for family in families:
            print(f"Check family: {family}...")
            suggestions = model_resolver.get_suggestions_for_model(f"claude-{family}-99")
            
            for suggestion in suggestions:
                print(f"  Suggestion: {suggestion}")
                # Each suggestion must contain same family
                assert family in suggestion.lower(), \
                    f"Suggestion '{suggestion}' not from family '{family}'!"