File size: 3,397 Bytes
f606b10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package diff

import (
	"testing"

	"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
)

func TestSummarizeExcludedModels_NormalizesAndDedupes(t *testing.T) {
	summary := SummarizeExcludedModels([]string{"A", " a ", "B", "b"})
	if summary.count != 2 {
		t.Fatalf("expected 2 unique entries, got %d", summary.count)
	}
	if summary.hash == "" {
		t.Fatal("expected non-empty hash")
	}
	if empty := SummarizeExcludedModels(nil); empty.count != 0 || empty.hash != "" {
		t.Fatalf("expected empty summary for nil input, got %+v", empty)
	}
}

func TestDiffOAuthExcludedModelChanges(t *testing.T) {
	oldMap := map[string][]string{
		"ProviderA": {"model-1", "model-2"},
		"providerB": {"x"},
	}
	newMap := map[string][]string{
		"providerA": {"model-1", "model-3"},
		"providerC": {"y"},
	}

	changes, affected := DiffOAuthExcludedModelChanges(oldMap, newMap)
	expectContains(t, changes, "oauth-excluded-models[providera]: updated (2 -> 2 entries)")
	expectContains(t, changes, "oauth-excluded-models[providerb]: removed")
	expectContains(t, changes, "oauth-excluded-models[providerc]: added (1 entries)")

	if len(affected) != 3 {
		t.Fatalf("expected 3 affected providers, got %d", len(affected))
	}
}

func TestSummarizeAmpModelMappings(t *testing.T) {
	summary := SummarizeAmpModelMappings([]config.AmpModelMapping{
		{From: "a", To: "A"},
		{From: "b", To: "B"},
		{From: " ", To: " "}, // ignored
	})
	if summary.count != 2 {
		t.Fatalf("expected 2 entries, got %d", summary.count)
	}
	if summary.hash == "" {
		t.Fatal("expected non-empty hash")
	}
	if empty := SummarizeAmpModelMappings(nil); empty.count != 0 || empty.hash != "" {
		t.Fatalf("expected empty summary for nil input, got %+v", empty)
	}
	if blank := SummarizeAmpModelMappings([]config.AmpModelMapping{{From: " ", To: " "}}); blank.count != 0 || blank.hash != "" {
		t.Fatalf("expected blank mappings ignored, got %+v", blank)
	}
}

func TestSummarizeOAuthExcludedModels_NormalizesKeys(t *testing.T) {
	out := SummarizeOAuthExcludedModels(map[string][]string{
		"ProvA": {"X"},
		"":      {"ignored"},
	})
	if len(out) != 1 {
		t.Fatalf("expected only non-empty key summary, got %d", len(out))
	}
	if _, ok := out["prova"]; !ok {
		t.Fatalf("expected normalized key 'prova', got keys %v", out)
	}
	if out["prova"].count != 1 || out["prova"].hash == "" {
		t.Fatalf("unexpected summary %+v", out["prova"])
	}
	if outEmpty := SummarizeOAuthExcludedModels(nil); outEmpty != nil {
		t.Fatalf("expected nil map for nil input, got %v", outEmpty)
	}
}

func TestSummarizeVertexModels(t *testing.T) {
	summary := SummarizeVertexModels([]config.VertexCompatModel{
		{Name: "m1"},
		{Name: " ", Alias: "alias"},
		{}, // ignored
	})
	if summary.count != 2 {
		t.Fatalf("expected 2 vertex models, got %d", summary.count)
	}
	if summary.hash == "" {
		t.Fatal("expected non-empty hash")
	}
	if empty := SummarizeVertexModels(nil); empty.count != 0 || empty.hash != "" {
		t.Fatalf("expected empty summary for nil input, got %+v", empty)
	}
	if blank := SummarizeVertexModels([]config.VertexCompatModel{{Name: " "}}); blank.count != 0 || blank.hash != "" {
		t.Fatalf("expected blank model ignored, got %+v", blank)
	}
}

func expectContains(t *testing.T, list []string, target string) {
	t.Helper()
	for _, entry := range list {
		if entry == target {
			return
		}
	}
	t.Fatalf("expected list to contain %q, got %#v", target, list)
}