chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/langgenius/dify/dify-agent-runtime/internal/agentcli"
|
||||
)
|
||||
|
||||
func TestKnowledgeProtocolNeedsNoEnvironment(t *testing.T) {
|
||||
t.Setenv(agentcli.EnvAPIBaseURL, "")
|
||||
t.Setenv(agentcli.EnvAuthJWE, "")
|
||||
if output := executeHelp(t, "knowledge", "--protocol-version"); output != "1\n" {
|
||||
t.Fatalf("unexpected protocol: %q", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKnowledgeCommandsSerializeOnlyAllowedArguments(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var payload map[string]any
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if payload["command"] == "grep" && payload["query"] != "text" {
|
||||
t.Fatal("query lost")
|
||||
}
|
||||
if _, found := payload["url"]; found {
|
||||
t.Fatal("routing authority exposed")
|
||||
}
|
||||
if images, found := payload["image_file_ids"]; found {
|
||||
if values := images.([]any); len(values) != 1 || values[0] != "00000000-0000-4000-8000-000000000001" {
|
||||
t.Fatal("canonical input reference was not translated into an upload identity")
|
||||
}
|
||||
}
|
||||
payload["status"] = "ok"
|
||||
_ = json.NewEncoder(w).Encode(payload)
|
||||
}))
|
||||
defer server.Close()
|
||||
t.Setenv(agentcli.EnvAPIBaseURL, server.URL)
|
||||
t.Setenv(agentcli.EnvAuthJWE, "jwe")
|
||||
for _, args := range [][]string{
|
||||
{"spaces"}, {"capabilities", "--space", "docs"}, {"search", "--space", "docs", "--query", "text"},
|
||||
{"search", "--space", "docs", "--image-file-id", "dify-file-ref:" + base64.URLEncoding.EncodeToString([]byte(`{"record_id":"00000000-0000-4000-8000-000000000001"}`))},
|
||||
{"ls", "--space", "docs"}, {"tree", "--space", "docs"}, {"find", "--space", "docs", "--query", "text"},
|
||||
{"grep", "--space", "docs", "--query", "text"}, {"cat", "--space", "docs", "--path", "/knowledge/a"}, {"stat", "--space", "docs"},
|
||||
{"diff", "--space", "docs", "--old-path", "/knowledge/a", "--new-path", "/knowledge/b"},
|
||||
{"open", "--space", "docs", "--node-id", "00000000-0000-4000-8000-000000000001"},
|
||||
{"images", "--space", "docs", "--receipt", "receipt"}, {"image", "--space", "docs", "--receipt", "receipt", "--item-id", "image"},
|
||||
} {
|
||||
t.Run(args[0], func(t *testing.T) {
|
||||
output := executeHelp(t, append([]string{"knowledge"}, args...)...)
|
||||
if !json.Valid(bytes.TrimSpace([]byte(output))) {
|
||||
t.Fatal(output)
|
||||
}
|
||||
})
|
||||
}
|
||||
root := newRootCommand()
|
||||
root.SetArgs([]string{"knowledge", "search", "--url", "http://other"})
|
||||
if err := root.Execute(); err == nil {
|
||||
t.Fatal("arbitrary URL flag accepted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user