mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-30 16:01:58 +08:00
## Summary
This PR re-enables the Go test steps in CI that were previously
commented out, and fixes all compilation errors that have accumulated in
`internal/entity/models/` since the `ListModels` return type was changed
from `[]string` to `[]ListModelResponse`.
## Changes
### CI (`.github/workflows/tests.yml`)
- Re-enable **Prepare test resources** step (clones resource repo with
WordNet data)
- Re-enable **Test Go packages** step (runs `go test ./internal/...`)
- Fix resource path race condition by using
`/tmp/resource-${GITHUB_RUN_ID}` instead of `/tmp/resource`
- Exclude `/cli` package from Go tests (contains `main` redeclarations)
### Test fixes (16 model provider test files)
All errors were caused by the upstream change from `[]string` to
`[]ListModelResponse` in the `ListModels` interface:
- Add `joinModelNames` test helper to extract `.Name` from
`[]ListModelResponse` slices
- `strings.Join(models, ",")` → `joinModelNames(models, ",")` (11 files)
- `ids[i] != "..."` → `ids[i].Name != "..."` (cometapi, mistral)
- `got[i] != want[i]` → `got[i].Name != want[i]` (bedrock)
- `[]string` return types → `[]ListModelResponse` (google)
### Pre-existing bugs in model_test.go
Bugs introduced by the upstream `entity/` → `entity/models/` directory
rename:
- Add missing `pm := GetProviderManager()` calls in 3 test functions
- Fix `InitProviderManager` signature (`_, err :=` → `err :=`)
- Fix `MaxTokens` `*int` dereference (6 comparisons)
- Fix `readProviderConfig` relative path (3 levels up instead of 2)
### model.go
- Add `findRepoRoot()` to make `conf/all_models.json` resolution work
from any CWD, fixing `TestSiliconFlowProviderConfigLoadsLatestProModels`
### Test validation
```bash
go build ./internal/... # ✅
go test ./internal/entity/models/... -count=1 # ✅ all pass
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
111 lines
3.1 KiB
Go
111 lines
3.1 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func newVolcEngineServer(t *testing.T, handler func(t *testing.T, r *http.Request, w http.ResponseWriter)) *httptest.Server {
|
|
t.Helper()
|
|
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
handler(t, r, w)
|
|
}))
|
|
}
|
|
|
|
func newVolcEngineForTest(baseURL string) *VolcEngine {
|
|
return NewVolcEngine(
|
|
map[string]string{"default": baseURL},
|
|
URLSuffix{
|
|
Chat: "chat/completions",
|
|
Files: "files",
|
|
Embedding: "embeddings/multimodal",
|
|
Models: "/models",
|
|
},
|
|
)
|
|
}
|
|
|
|
func TestVolcEngineConfigDeclaresModelsSuffix(t *testing.T) {
|
|
var provider struct {
|
|
URLSuffix URLSuffix `json:"url_suffix"`
|
|
}
|
|
|
|
for _, candidate := range []string{
|
|
filepath.Join("..", "..", "..", "conf", "models", "volcengine.json"),
|
|
filepath.Join("conf", "models", "volcengine.json"),
|
|
} {
|
|
data, err := os.ReadFile(candidate)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if err := json.Unmarshal(data, &provider); err != nil {
|
|
t.Fatalf("unmarshal %s: %v", candidate, err)
|
|
}
|
|
if provider.URLSuffix.Models != "models" {
|
|
t.Fatalf("models suffix=%q, want models", provider.URLSuffix.Models)
|
|
}
|
|
return
|
|
}
|
|
|
|
t.Fatal("could not locate conf/models/volcengine.json")
|
|
}
|
|
|
|
func TestVolcEngineListModelsHappyPath(t *testing.T) {
|
|
srv := newVolcEngineServer(t, func(t *testing.T, r *http.Request, w http.ResponseWriter) {
|
|
if r.Method != http.MethodGet {
|
|
t.Errorf("method=%s", r.Method)
|
|
}
|
|
if r.URL.Path != "/models" {
|
|
t.Errorf("path=%s", r.URL.Path)
|
|
}
|
|
if got := r.Header.Get("Authorization"); got != "Bearer test-key" {
|
|
t.Errorf("Authorization=%q", got)
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, _ = w.Write([]byte(`{
|
|
"object": "list",
|
|
"data": [
|
|
{"id": "doubao-seed-2-0-pro-260215", "owned_by": "volcengine"},
|
|
{"id": "doubao-embedding-vision-251215"}
|
|
]
|
|
}`))
|
|
})
|
|
defer srv.Close()
|
|
|
|
apiKey := "test-key"
|
|
models, err := newVolcEngineForTest(srv.URL).ListModels(&APIConfig{ApiKey: &apiKey})
|
|
if err != nil {
|
|
t.Fatalf("ListModels: %v", err)
|
|
}
|
|
if joinModelNames(models, ",") != "doubao-seed-2-0-pro-260215@volcengine,doubao-embedding-vision-251215" {
|
|
t.Errorf("models=%v", models)
|
|
}
|
|
}
|
|
|
|
func TestVolcEngineListModelsRejectsProviderError(t *testing.T) {
|
|
srv := newVolcEngineServer(t, func(t *testing.T, r *http.Request, w http.ResponseWriter) {
|
|
http.Error(w, "bad key", http.StatusUnauthorized)
|
|
})
|
|
defer srv.Close()
|
|
|
|
apiKey := "test-key"
|
|
_, err := newVolcEngineForTest(srv.URL).ListModels(&APIConfig{ApiKey: &apiKey})
|
|
if err == nil || !strings.Contains(err.Error(), "401 Unauthorized") || !strings.Contains(err.Error(), "bad key") {
|
|
t.Fatalf("expected provider error with status and body, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestVolcEngineListModelsRequiresModelsSuffix(t *testing.T) {
|
|
apiKey := "test-key"
|
|
model := NewVolcEngine(map[string]string{"default": "http://unused"}, URLSuffix{})
|
|
|
|
_, err := model.ListModels(&APIConfig{ApiKey: &apiKey})
|
|
if err == nil || !strings.Contains(err.Error(), "models URL suffix is not configured") {
|
|
t.Fatalf("expected missing models suffix error, got %v", err)
|
|
}
|
|
}
|