Files
Memoh/internal/conversation/flow/capability_policy_test.go
T
Acbox Liu b88ca96064 refactor: provider & models (#277)
* refactor: move client_type to provider, replace model fields with config JSONB

- Move `client_type` from `models` to `llm_providers` table
- Add `icon` field to `llm_providers`
- Replace `dimensions`, `input_modalities`, `supports_reasoning` on `models`
  with a single `config` JSONB column containing `dimensions`,
  `compatibilities` (vision, tool-call, image-output, reasoning),
  and `context_window`
- Auto-imported models default to vision + tool-call + reasoning
- Update all backend consumers (agent, flow resolver, handlers, memory)
- Regenerate sqlc, swagger, and TypeScript SDK
- Update frontend forms, display, and i18n for new schema

* ui: show provider icon avatar in sidebar and detail header, remove icon input

* feat: add built-in provider registry with YAML definitions and enable toggle

- Add `enable` column to llm_providers (default true, backward-compatible)
- Create internal/registry package to load YAML provider/model definitions
  on startup and upsert into database (new providers disabled by default)
- Add conf/providers/ with OpenAI, Anthropic, Google YAML definitions
- Add RegistryConfig to TOML config (providers_dir, default conf/providers)
- Model listing APIs and conversation flow now filter by enabled providers
- Frontend: enable switch in provider form, green status dot in sidebar,
  enabled providers sorted to top

* fix: make 0041 migration idempotent for fresh databases

Guard data migration steps with column-existence checks so the
migration succeeds on databases created from the updated init schema.
2026-03-22 17:24:45 +08:00

78 lines
2.8 KiB
Go

package flow
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRouteAttachmentsByCapability_VisionSupported(t *testing.T) {
compatibilities := []string{"vision", "tool-call"}
attachments := []gatewayAttachment{
{Type: "image", Transport: gatewayTransportInlineDataURL, Payload: "data:image/png;base64,abc"},
{Type: "audio", Transport: gatewayTransportToolFileRef, Payload: "/data/voice.wav"},
}
result := routeAttachmentsByCapability(compatibilities, attachments)
assert.Len(t, result.Native, 1)
assert.Len(t, result.Fallback, 1)
assert.Equal(t, "image", result.Native[0].Type)
assert.Equal(t, "audio", result.Fallback[0].Type)
}
func TestRouteAttachmentsByCapability_NoVision(t *testing.T) {
compatibilities := []string{"tool-call"}
attachments := []gatewayAttachment{
{Type: "image", Transport: gatewayTransportInlineDataURL, Payload: "data:image/png;base64,abc"},
{Type: "video", Transport: gatewayTransportToolFileRef, Payload: "/data/video.mp4"},
}
result := routeAttachmentsByCapability(compatibilities, attachments)
assert.Empty(t, result.Native)
assert.Len(t, result.Fallback, 2)
}
func TestRouteAttachmentsByCapability_ImagePathOnlyFallsBack(t *testing.T) {
compatibilities := []string{"vision"}
attachments := []gatewayAttachment{
{Type: "image", Transport: gatewayTransportToolFileRef, Payload: "/data/image.png"},
}
result := routeAttachmentsByCapability(compatibilities, attachments)
assert.Empty(t, result.Native)
assert.Len(t, result.Fallback, 1)
assert.Equal(t, "image", result.Fallback[0].Type)
}
func TestRouteAttachmentsByCapability_ImageURLIsNative(t *testing.T) {
compatibilities := []string{"vision"}
attachments := []gatewayAttachment{
{Type: "image", Transport: gatewayTransportPublicURL, Payload: "https://example.com/image.png"},
}
result := routeAttachmentsByCapability(compatibilities, attachments)
assert.Len(t, result.Native, 1)
assert.Empty(t, result.Fallback)
}
func TestRouteAttachmentsByCapability_UnknownType(t *testing.T) {
compatibilities := []string{"vision"}
attachments := []gatewayAttachment{
{Type: "hologram", Transport: gatewayTransportToolFileRef, Payload: "/data/holo.dat"},
}
result := routeAttachmentsByCapability(compatibilities, attachments)
assert.Empty(t, result.Native)
assert.Len(t, result.Fallback, 1)
}
func TestRouteAttachmentsByCapability_Empty(t *testing.T) {
result := routeAttachmentsByCapability([]string{"vision"}, nil)
assert.Empty(t, result.Native)
assert.Empty(t, result.Fallback)
}
func TestAttachmentsToAny(t *testing.T) {
atts := []gatewayAttachment{
{Type: "image", Transport: gatewayTransportInlineDataURL, Payload: "data:image/png;base64,abc"},
{Type: "file", Transport: gatewayTransportToolFileRef, Payload: "/data/doc.pdf"},
}
result := attachmentsToAny(atts)
assert.Len(t, result, 2)
}