55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
|
"gitea.maximumdirect.net/eric/promptkit"
|
|
)
|
|
|
|
func TestExplicitPromptKitProfileValidationUsesConfiguredLocalBackendWithoutGeneration(t *testing.T) {
|
|
var providerCalls atomic.Int32
|
|
server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
|
|
providerCalls.Add(1)
|
|
}))
|
|
defer server.Close()
|
|
|
|
profilePath := filepath.Join(t.TempDir(), "profiles.yml")
|
|
if err := os.WriteFile(profilePath, []byte(`id: local-profile
|
|
backend: local
|
|
model: local-model
|
|
`), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg := config.Default()
|
|
cfg.PromptKit.ProfileFile = profilePath
|
|
cfg.PromptKit.LocalBackend = &config.PromptKitLocalBackendConfig{
|
|
Endpoint: server.URL + "/v1",
|
|
ConcurrencyLimit: 2,
|
|
}
|
|
if err := validateExplicitPromptKitProfiles(context.Background(), cfg, []string{"local-profile"}); err != nil {
|
|
t.Fatalf("validateExplicitPromptKitProfiles() error = %v, want nil", err)
|
|
}
|
|
if providerCalls.Load() != 0 {
|
|
t.Fatalf("provider calls during configured profile validation = %d, want 0", providerCalls.Load())
|
|
}
|
|
|
|
cfg.PromptKit.LocalBackend = nil
|
|
err := validateExplicitPromptKitProfiles(context.Background(), cfg, []string{"local-profile"})
|
|
if err == nil ||
|
|
!strings.Contains(err.Error(), `validate PromptKit profile "local-profile"`) ||
|
|
!strings.Contains(err.Error(), promptkit.BackendLocal) {
|
|
t.Fatalf("validation without registration error = %v, want profile and local backend context", err)
|
|
}
|
|
if providerCalls.Load() != 0 {
|
|
t.Fatalf("provider calls after missing-registration validation = %d, want 0", providerCalls.Load())
|
|
}
|
|
}
|