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,87 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"img_infinite_canvas/internal/domain/design"
|
||||
"img_infinite_canvas/internal/infrastructure/memory"
|
||||
)
|
||||
|
||||
func TestProjectRepositoryCachesProjectReads(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
base := memory.NewProjectRepository()
|
||||
store := NewMemoryStore()
|
||||
repo := NewProjectRepository(base, store, time.Minute)
|
||||
|
||||
project := design.Project{
|
||||
ID: "project-1",
|
||||
Title: "Original",
|
||||
Brief: "brief",
|
||||
Status: design.StatusReady,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
if err := base.Save(ctx, project); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
first, err := repo.Get(ctx, project.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
project.Title = "Changed behind cache"
|
||||
if err := base.Save(ctx, project); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
second, err := repo.Get(ctx, project.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if second.Title != first.Title {
|
||||
t.Fatalf("expected cached title %q, got %q", first.Title, second.Title)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectRepositoryInvalidatesListOnSave(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
base := memory.NewProjectRepository()
|
||||
repo := NewProjectRepository(base, NewMemoryStore(), time.Minute)
|
||||
|
||||
if err := repo.Save(ctx, design.Project{
|
||||
ID: "project-1",
|
||||
Title: "First",
|
||||
Brief: "brief",
|
||||
Status: design.StatusReady,
|
||||
UpdatedAt: time.Now(),
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
first, err := repo.List(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(first) != 1 {
|
||||
t.Fatalf("expected first list length 1, got %d", len(first))
|
||||
}
|
||||
|
||||
if err := repo.Save(ctx, design.Project{
|
||||
ID: "project-2",
|
||||
Title: "Second",
|
||||
Brief: "brief",
|
||||
Status: design.StatusReady,
|
||||
UpdatedAt: time.Now(),
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
second, err := repo.List(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(second) != 2 {
|
||||
t.Fatalf("expected invalidated list length 2, got %d", len(second))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user