6d14cc3536
Introduce resource://<handle> as the stable application identity for stored objects, decoupling API responses, persisted rich text, and LLM prompts from physical storage paths. Adds a resource catalog service (register/resolve/bind, revocable expiring access grants), a request-local alias registry that compacts resource references while in the LLM context and restores them (including across streaming chunks), plus router, IM, chat-pipeline, and multimodal integration. Includes schema migrations (resources, resource_bindings, resource_access_grants) for sqlite, and hardens URL/output security handling.
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package llmresource
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Tencent/WeKnora/internal/models/chat"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRegistryRoundTripAndDeduplicate(t *testing.T) {
|
|
r := NewRegistry()
|
|
ref := "resource://AbCdEfGhIjKlMnOpQrStUv"
|
|
encoded := r.EncodeText(" and " + ref)
|
|
require.Equal(t, " and res:0001", encoded)
|
|
require.Equal(t, " and "+ref, r.DecodeText(encoded))
|
|
}
|
|
|
|
func TestRegistryAliasesLegacyPhysicalReferencesDuringRollout(t *testing.T) {
|
|
r := NewRegistry()
|
|
ref := "storage://c0d93536-702c-4977-aa5e-fe670073c3cb/local://10000/exports/image.png"
|
|
encoded := r.EncodeText("")
|
|
require.Equal(t, "", encoded)
|
|
require.Equal(t, "", r.DecodeText(encoded))
|
|
}
|
|
|
|
func TestRegistryEncodesMessageCopies(t *testing.T) {
|
|
r := NewRegistry()
|
|
ref := "resource://AbCdEfGhIjKlMnOpQrStUv"
|
|
original := []chat.Message{{Role: "tool", Content: ref}}
|
|
encoded := r.EncodeMessages(original)
|
|
require.Equal(t, ref, original[0].Content)
|
|
require.Equal(t, "res:0001", encoded[0].Content)
|
|
}
|
|
|
|
func TestStreamDecoderRestoresSplitAlias(t *testing.T) {
|
|
r := NewRegistry()
|
|
ref := "resource://AbCdEfGhIjKlMnOpQrStUv"
|
|
require.Equal(t, "res:0001", r.EncodeText(ref))
|
|
d := NewStreamDecoder(r)
|
|
require.Equal(t, "before ", d.Feed("before res:0"))
|
|
require.Equal(t, ref+" afte", d.Feed("001 after"))
|
|
require.Equal(t, "r", d.Flush())
|
|
}
|