summaryrefslogtreecommitdiff
path: root/internal/adminapi/model_page_test.go
blob: eac6d7d6fdd7758e2beddb2f507979a1c85e5333 (plain)
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
package adminapi

import (
	"strings"
	"testing"
	"time"

	"aigw/internal/controlplane"
)

func TestBuildPublicModelPageDataUsesSupportedProtocolsWithoutInternalRouting(t *testing.T) {
	released := time.Date(2026, time.August, 1, 0, 0, 0, 0, time.UTC)
	model := controlplane.PublicModel{
		PublicID: "openai/text-embedding-3-small", DisplayName: "Text Embedding 3 Small",
		Description: "Embeddings for search.", OwnedBy: "OpenAI", InputModalities: []string{"text"},
		OutputModalities: []string{"embedding"}, Capabilities: []string{"embeddings"}, Regions: []string{"global"},
		Lifecycle: "active", ReleasedAt: &released, PriceCurrency: "usd", InputPriceMicrosPerMillion: 20_000,
		ContextWindow: 8192, SupportedWireAPIs: []string{"embeddings"}, ProviderCount: 2,
		AvailableProviderCount: 1, HealthStatus: "degraded",
	}
	data := buildPublicModelPageData(model, "https://console.example.test/admin/", "https://api.example.test/", "/admin", true)
	if data.CanonicalURL != "https://console.example.test/admin/models/openai/text-embedding-3-small" {
		t.Fatalf("canonical=%q", data.CanonicalURL)
	}
	if data.CSSURL != "/admin/models.css" || data.CatalogURL != "/admin/models" {
		t.Fatalf("cross-origin static URL: css=%q catalog=%q", data.CSSURL, data.CatalogURL)
	}
	if len(data.Examples) != 1 || data.Examples[0].Endpoint != "/v1/embeddings" {
		t.Fatalf("examples=%+v", data.Examples)
	}
	if !strings.Contains(data.Examples[0].Code, `"model":"openai/text-embedding-3-small"`) ||
		strings.Contains(data.Examples[0].Code, "provider") || strings.Contains(data.Examples[0].Code, "upstream") {
		t.Fatalf("unexpected public example: %s", data.Examples[0].Code)
	}
	if data.HealthLabel != "1/2 routes" || data.InputPrice != "USD 0.02" || data.ContextWindow != "8,192" {
		t.Fatalf("unexpected page projection: %+v", data)
	}
}

func TestEscapeModelPathPreservesHierarchyAndEscapesSegments(t *testing.T) {
	if got := escapeModelPath("owner/model name"); got != "owner/model%20name" {
		t.Fatalf("escapeModelPath=%q", got)
	}
}