Files

1 line
8.5 KiB
JSON

{"repo": "chenyang-zz/cove", "files": {"internal/transport/http/validation_error_test.go": {"9a7f5c67892908928a39df2f4962fc1d4a495527": {"t": 1785746066.0070364, "n": 2724, "h": "50d9c12085e53079", "c": "package http_test\n\nimport (\n\t\"encoding/json\"\n\t\"net/http\"\n\t\"net/http/httptest\"\n\t\"strings\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/boxify/api-go/internal/infrastructure/security\"\n\t\"github.com/google/uuid\"\n)\n\nfunc TestCreateModelConfigValidationErrorsIncludeFieldDetails(t *testing.T) {\n\trouter := newTestRouter(t)\n\ttoken, err := security.NewTokenIssuer(\"test-secret\", time.Hour).IssueAccessToken(uuid.New())\n\tif err != nil {\n\t\tt.Fatalf(\"issue access token: %v\", err)\n\t}\n\n\ttests := []struct {\n\t\tname string\n\t\tbody string\n\t\twantField string\n\t\twantTag string\n\t}{\n\t\t{\n\t\t\tname: \"missing api key\",\n\t\t\tbody: `{\"type\":\"chat\",\"provider\":\"deepseek\",\"name\":\"DeepSeek Chat\",\"model_name\":\"deepseek-chat\",\"base_url\":\"https://api.deepseek.com\"}`,\n\t\t\twantField: \"api_key\",\n\t\t\twantTag: \"required\",\n\t\t},\n\t\t{\n\t\t\tname: \"invalid provider\",\n\t\t\tbody: `{\"type\":\"chat\",\"provider\":\"bad-provider\",\"name\":\"DeepSeek Chat\",\"model_name\":\"deepseek-chat\",\"base_url\":\"https://api.deepseek.com\",\"api_key\":\"sk-secret\"}`,\n\t\t\twantField: \"provider\",\n\t\t\twantTag: \"oneof\",\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\trec := httptest.NewRecorder()\n\t\t\treq := httptest.NewRequest(http.MethodPost, \"/api/model-configs/create\", strings.NewReader(tt.body))\n\t\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t\t\treq.Header.Set(\"Authorization\", \"Bearer \"+token)\n\t\t\trouter.ServeHTTP(rec, req)\n\n\t\t\tif rec.Code != http.StatusBadRequest {\n\t\t\t\tt.Fatalf(\"status = %d body=%s\", rec.Code, rec.Body.String())\n\t\t\t}\n\t\t\tvar got struct {\n\t\t\t\tCode int `json:\"code\"`\n\t\t\t\tMessage string `json:\"message\"`\n\t\t\t\tErrors []struct {\n\t\t\t\t\tField string `json:\"field\"`\n\t\t\t\t\tTag string `json:\"tag\"`\n\t\t\t\t\tParam string `json:\"param\"`\n\t\t\t\t\tMessage string `json:\"message\"`\n\t\t\t\t} `json:\"errors\"`\n\t\t\t}\n\t\t\tif err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {\n\t\t\t\tt.Fatalf(\"Unmarshal response: %v\", err)\n\t\t\t}\n\t\t\tif got.Code != 40001 || got.Message != \"请求参数错误\" {\n\t\t\t\tt.Fatalf(\"response = %+v, want validation envelope\", got)\n\t\t\t}\n\t\t\tif !hasValidationError(got.Errors, tt.wantField, tt.wantTag) {\n\t\t\t\tt.Fatalf(\"errors = %+v, want %s/%s\", got.Errors, tt.wantField, tt.wantTag)\n\t\t\t}\n\t\t\tif strings.Contains(rec.Body.String(), \"Key:\") || strings.Contains(rec.Body.String(), \"Error:Field validation\") {\n\t\t\t\tt.Fatalf(\"response leaked raw validator error: %s\", rec.Body.String())\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc hasValidationError(errors []struct {\n\tField string `json:\"field\"`\n\tTag string `json:\"tag\"`\n\tParam string `json:\"param\"`\n\tMessage string `json:\"message\"`\n}, field, tag string) bool {\n\tfor _, item := range errors {\n\t\tif item.Field == field && item.Tag == tag && item.Message != \"\" {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n"}, "af736609c77d129f861f37ac1ede9d271acf13c9": {"t": 1785759423.3529928, "n": 2724, "h": "50d9c12085e53079", "c": "package http_test\n\nimport (\n\t\"encoding/json\"\n\t\"net/http\"\n\t\"net/http/httptest\"\n\t\"strings\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/boxify/api-go/internal/infrastructure/security\"\n\t\"github.com/google/uuid\"\n)\n\nfunc TestCreateModelConfigValidationErrorsIncludeFieldDetails(t *testing.T) {\n\trouter := newTestRouter(t)\n\ttoken, err := security.NewTokenIssuer(\"test-secret\", time.Hour).IssueAccessToken(uuid.New())\n\tif err != nil {\n\t\tt.Fatalf(\"issue access token: %v\", err)\n\t}\n\n\ttests := []struct {\n\t\tname string\n\t\tbody string\n\t\twantField string\n\t\twantTag string\n\t}{\n\t\t{\n\t\t\tname: \"missing api key\",\n\t\t\tbody: `{\"type\":\"chat\",\"provider\":\"deepseek\",\"name\":\"DeepSeek Chat\",\"model_name\":\"deepseek-chat\",\"base_url\":\"https://api.deepseek.com\"}`,\n\t\t\twantField: \"api_key\",\n\t\t\twantTag: \"required\",\n\t\t},\n\t\t{\n\t\t\tname: \"invalid provider\",\n\t\t\tbody: `{\"type\":\"chat\",\"provider\":\"bad-provider\",\"name\":\"DeepSeek Chat\",\"model_name\":\"deepseek-chat\",\"base_url\":\"https://api.deepseek.com\",\"api_key\":\"sk-secret\"}`,\n\t\t\twantField: \"provider\",\n\t\t\twantTag: \"oneof\",\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\trec := httptest.NewRecorder()\n\t\t\treq := httptest.NewRequest(http.MethodPost, \"/api/model-configs/create\", strings.NewReader(tt.body))\n\t\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t\t\treq.Header.Set(\"Authorization\", \"Bearer \"+token)\n\t\t\trouter.ServeHTTP(rec, req)\n\n\t\t\tif rec.Code != http.StatusBadRequest {\n\t\t\t\tt.Fatalf(\"status = %d body=%s\", rec.Code, rec.Body.String())\n\t\t\t}\n\t\t\tvar got struct {\n\t\t\t\tCode int `json:\"code\"`\n\t\t\t\tMessage string `json:\"message\"`\n\t\t\t\tErrors []struct {\n\t\t\t\t\tField string `json:\"field\"`\n\t\t\t\t\tTag string `json:\"tag\"`\n\t\t\t\t\tParam string `json:\"param\"`\n\t\t\t\t\tMessage string `json:\"message\"`\n\t\t\t\t} `json:\"errors\"`\n\t\t\t}\n\t\t\tif err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {\n\t\t\t\tt.Fatalf(\"Unmarshal response: %v\", err)\n\t\t\t}\n\t\t\tif got.Code != 40001 || got.Message != \"请求参数错误\" {\n\t\t\t\tt.Fatalf(\"response = %+v, want validation envelope\", got)\n\t\t\t}\n\t\t\tif !hasValidationError(got.Errors, tt.wantField, tt.wantTag) {\n\t\t\t\tt.Fatalf(\"errors = %+v, want %s/%s\", got.Errors, tt.wantField, tt.wantTag)\n\t\t\t}\n\t\t\tif strings.Contains(rec.Body.String(), \"Key:\") || strings.Contains(rec.Body.String(), \"Error:Field validation\") {\n\t\t\t\tt.Fatalf(\"response leaked raw validator error: %s\", rec.Body.String())\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc hasValidationError(errors []struct {\n\tField string `json:\"field\"`\n\tTag string `json:\"tag\"`\n\tParam string `json:\"param\"`\n\tMessage string `json:\"message\"`\n}, field, tag string) bool {\n\tfor _, item := range errors {\n\t\tif item.Field == field && item.Tag == tag && item.Message != \"\" {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n"}}, "internal/infrastructure/llm/openai_internal_test.go": {"9a7f5c67892908928a39df2f4962fc1d4a495527": {"t": 1785746077.3704965, "n": 841, "h": "8a778363129bc9de", "c": "package llm\n\nimport \"testing\"\n\nfunc TestNormalizeOpenAIBaseURLAddsVersionForOfficialHost(t *testing.T) {\n\tif got := normalizeOpenAIBaseURL(\" https://api.openai.com/ \"); got != \"https://api.openai.com/v1\" {\n\t\tt.Fatalf(\"normalizeOpenAIBaseURL = %q, want official /v1 URL\", got)\n\t}\n\tif got := normalizeOpenAIBaseURL(\"https://api.openai.com/v1/\"); got != \"https://api.openai.com/v1\" {\n\t\tt.Fatalf(\"normalizeOpenAIBaseURL = %q, want trimmed official /v1 URL\", got)\n\t}\n}\n\nfunc TestNormalizeOpenAIBaseURLPreservesCompatibleProviderPaths(t *testing.T) {\n\tcases := []string{\n\t\t\"https://api.deepseek.com\",\n\t\t\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n\t\t\"http://127.0.0.1:8080\",\n\t}\n\tfor _, tc := range cases {\n\t\tif got := normalizeOpenAIBaseURL(tc); got != tc {\n\t\t\tt.Fatalf(\"normalizeOpenAIBaseURL(%q) = %q, want unchanged\", tc, got)\n\t\t}\n\t}\n}\n"}, "c9cd4b9f016f7a4d69e462d7f6b46bc5ec97a026": {"t": 1785759423.5496137, "n": 841, "h": "8a778363129bc9de", "c": "package llm\n\nimport \"testing\"\n\nfunc TestNormalizeOpenAIBaseURLAddsVersionForOfficialHost(t *testing.T) {\n\tif got := normalizeOpenAIBaseURL(\" https://api.openai.com/ \"); got != \"https://api.openai.com/v1\" {\n\t\tt.Fatalf(\"normalizeOpenAIBaseURL = %q, want official /v1 URL\", got)\n\t}\n\tif got := normalizeOpenAIBaseURL(\"https://api.openai.com/v1/\"); got != \"https://api.openai.com/v1\" {\n\t\tt.Fatalf(\"normalizeOpenAIBaseURL = %q, want trimmed official /v1 URL\", got)\n\t}\n}\n\nfunc TestNormalizeOpenAIBaseURLPreservesCompatibleProviderPaths(t *testing.T) {\n\tcases := []string{\n\t\t\"https://api.deepseek.com\",\n\t\t\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n\t\t\"http://127.0.0.1:8080\",\n\t}\n\tfor _, tc := range cases {\n\t\tif got := normalizeOpenAIBaseURL(tc); got != tc {\n\t\t\tt.Fatalf(\"normalizeOpenAIBaseURL(%q) = %q, want unchanged\", tc, got)\n\t\t}\n\t}\n}\n"}}}}