选择性整合 #547,保留主分支节点与工具条设计。新增默认折叠的节点、资产、任务和历史面板,风格与预设保留在节点内,移除重复入口。 补齐工具权限、提示词解析、资源引用保护及数据库迁移,修复提示词清空和连续编辑后的生成配置同步。 验证:前端全量 1925 项测试、构建、类型检查及 lint 通过;后端 go test ./... 通过。真实模型、PostgreSQL 实库与登录态页面验收仍待进行。 Refs #547 Co-authored-by: bensharp <bensharp@qq.com>
67 lines
2.1 KiB
Go
67 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"infinite-canvas/backend/internal/model"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestToolPreviewOwnershipAndResourceDeletionGuard(t *testing.T) {
|
|
svc, db, _ := newResourceDeletionTestService(t)
|
|
resource := model.Resource{ID: "tool-preview", UserID: "alice", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "preview.png"}
|
|
if err := db.Create(&resource).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
req := ToolMutationRequest{Type: "style", Label: "style", Prompt: "film", Cover: "/api/resources/tool-preview/file", Visibility: "private"}
|
|
if _, err := svc.CreateTool("bob", req); err == nil {
|
|
t.Fatal("foreign resource accepted")
|
|
}
|
|
req.Visibility = "public"
|
|
if _, err := svc.CreateTool("alice", req); err == nil {
|
|
t.Fatal("private resource exposed publicly")
|
|
}
|
|
req.Visibility = "private"
|
|
tool, err := svc.CreateTool("alice", req)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
snapshot, err := svc.repo.ResourceReferenceSnapshot("alice", "", []string{resource.ID})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
found := false
|
|
for _, doc := range snapshot.Documents {
|
|
if doc.Kind == "工具" && documentReferencesResources(doc.PrimaryJSON, map[string]struct{}{resource.ID: {}}) {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("tool preview not protected from resource deletion")
|
|
}
|
|
if err := svc.DeleteTool("alice", tool.ID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var count int64
|
|
if err := db.Model(&model.Resource{}).Where("id = ?", resource.ID).Count(&count).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 1 {
|
|
t.Fatal("deleting tool deleted preview resource")
|
|
}
|
|
}
|
|
|
|
func TestToolAdmissionRejectsBeforeQueueing(t *testing.T) {
|
|
svc, db, _ := newResourceDeletionTestService(t)
|
|
_, err := svc.CreateTask("alice", CreateTaskRequest{Type: "canvas_image", Prompt: "@[tool:style:999:x:X]", Input: map[string]any{"mode": "image", "prompt": "@[tool:style:999:x:X]"}})
|
|
if err == nil || !strings.Contains(err.Error(), "工具") {
|
|
t.Fatalf("unexpected admission result: %v", err)
|
|
}
|
|
var count int64
|
|
if err := db.Model(&model.Task{}).Count(&count).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 0 {
|
|
t.Fatal("invalid tool was queued")
|
|
}
|
|
}
|