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,73 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"img_infinite_canvas/internal/domain/design"
|
||||
)
|
||||
|
||||
func TestSaveCanvasPreservesMessages(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repo := NewProjectRepository()
|
||||
project := design.Project{
|
||||
ID: "project-canvas-save",
|
||||
UserID: design.DefaultUserID,
|
||||
Title: "Canvas save",
|
||||
Status: design.StatusReady,
|
||||
Version: "v1",
|
||||
UpdatedAt: time.Now(),
|
||||
Messages: []design.Message{{ID: "message-1", Role: "assistant", Content: "keep me"}},
|
||||
}
|
||||
if err := repo.Save(ctx, project); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
canvasProject := design.Project{
|
||||
ID: project.ID,
|
||||
UserID: project.UserID,
|
||||
Title: project.Title,
|
||||
Status: design.StatusReady,
|
||||
Version: "v2",
|
||||
SnapshotID: "snapshot-2",
|
||||
UpdatedAt: time.Now(),
|
||||
Viewport: design.Viewport{K: 1},
|
||||
Nodes: []design.Node{{ID: "node-1", Type: design.NodeTypeFrame}},
|
||||
}
|
||||
if err := repo.SaveCanvas(ctx, canvasProject, "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
saved, err := repo.Get(ctx, project.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(saved.Messages) != 1 || saved.Messages[0].ID != "message-1" {
|
||||
t.Fatalf("expected existing messages to be preserved, got %#v", saved.Messages)
|
||||
}
|
||||
if len(saved.Nodes) != 1 || saved.Nodes[0].ID != "node-1" {
|
||||
t.Fatalf("expected canvas nodes to update, got %#v", saved.Nodes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveCanvasRejectsStaleVersion(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repo := NewProjectRepository()
|
||||
project := design.Project{
|
||||
ID: "project-stale-canvas-save",
|
||||
UserID: design.DefaultUserID,
|
||||
Title: "Canvas save",
|
||||
Status: design.StatusReady,
|
||||
Version: "v2",
|
||||
}
|
||||
if err := repo.Save(ctx, project); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err := repo.SaveCanvas(ctx, design.Project{ID: project.ID, UserID: project.UserID, Version: "v3"}, "v1")
|
||||
if !errors.Is(err, design.ErrConflict) {
|
||||
t.Fatalf("expected version conflict, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user