Initial commit: img-infinite-canvas AI design workbench MVP
Moteva-style AI design workbench replica. Home prompt creates a project; the project page provides an infinite canvas with node drag, zoom/pan, a design chat panel, history replay, image asset upload, and project save/regenerate. - Backend: go-zero, DDD layering, sqlc/pgx, optional PostgreSQL; memory or Redis cache; asynq job queue; MinIO/S3/R2/OSS object storage; sky-valley/pi agent runtime adapter. - Frontend: Next.js App Router + Vite artifact build, TypeScript, i18n, shadcn/ui components, auth (OTP/Turnstile/Google/WeChat). - Deploy: Docker Compose and k3s manifests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"img_infinite_canvas/internal/domain/design"
|
||||
"img_infinite_canvas/internal/infrastructure/memory"
|
||||
)
|
||||
|
||||
func TestAgentThreadsOnlyListsAgentConversationThreads(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repo := memory.NewProjectRepository()
|
||||
service := NewDesignService(repo, nil, nil, nil, nil)
|
||||
now := time.Now()
|
||||
project := design.Project{
|
||||
ID: "project-agent-history",
|
||||
Title: "Agent history",
|
||||
Status: design.StatusReady,
|
||||
LastThreadID: "thread-remove-background",
|
||||
UpdatedAt: now,
|
||||
Messages: []design.Message{
|
||||
{ID: "agent-user", Role: "user", Type: "user", Content: "官网设计", ThreadID: "thread-agent", CreatedAt: now.Add(-5 * time.Minute)},
|
||||
{ID: "agent-assistant", Role: "assistant", Type: "assistant", Content: "可以继续设计。", ThreadID: "thread-agent", CreatedAt: now.Add(-4 * time.Minute)},
|
||||
{ID: "remove-user", Role: "user", Type: "user", Content: "一键移除背景,保留主体完整边缘", ThreadID: "thread-remove-background", Name: "canvas_action", ToolHint: "canvas_action", CreatedAt: now.Add(-3 * time.Minute)},
|
||||
{ID: "mockup-tool", Role: "tool", Type: "tool", Content: "生成 mockup 模型", ThreadID: "thread-mockup", Name: "mockup_model", ToolHint: "mockup_model", CreatedAt: now.Add(-2 * time.Minute)},
|
||||
{ID: "text-tool", Role: "tool", Type: textExtractionResultMessageType, Content: "文字识别完成", ThreadID: "thread-text", Name: "text_extraction", CreatedAt: now.Add(-time.Minute)},
|
||||
},
|
||||
}
|
||||
if err := repo.Save(ctx, project); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
threads, err := service.AgentThreads(ctx, project.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(threads) != 1 {
|
||||
t.Fatalf("expected only one agent thread, got %#v", threads)
|
||||
}
|
||||
if threads[0].AgentThreadID != "thread-agent" || threads[0].Text != "官网设计" {
|
||||
t.Fatalf("expected agent thread summary, got %#v", threads[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectScopedToAgentThreadKeepsOnlyCurrentConversationContext(t *testing.T) {
|
||||
now := time.Now()
|
||||
project := design.Project{
|
||||
ID: "project-agent-context",
|
||||
Messages: []design.Message{
|
||||
{ID: "old-user", Role: "user", Content: "旧对话", ThreadID: "thread-old", CreatedAt: now.Add(-3 * time.Minute)},
|
||||
{ID: "current-user", Role: "user", Content: "当前对话", ThreadID: "thread-current", CreatedAt: now.Add(-2 * time.Minute)},
|
||||
{ID: "current-action", Role: "user", Content: "一键移除背景", ThreadID: "thread-current", Name: "canvas_action", ToolHint: "canvas_action", CreatedAt: now.Add(-time.Minute)},
|
||||
},
|
||||
}
|
||||
|
||||
scoped := projectScopedToAgentThread(project, "thread-current")
|
||||
if len(scoped.Messages) != 1 {
|
||||
t.Fatalf("expected only current agent message, got %#v", scoped.Messages)
|
||||
}
|
||||
if scoped.Messages[0].ID != "current-user" {
|
||||
t.Fatalf("expected current conversation message, got %#v", scoped.Messages[0])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user