263748af4a
Add canva/canda-compatible routes for lightweight project open/save and agent thread history: - POST /canva/project/queryProject, saveProject - POST /canva/agent/queryAgentLastThread, agentThreadList - GET /canda/chat-history, /canda/thread/status Canvas save now accepts a compressed SHAKKERDATA:// snapshot payload, preserves connections, and returns a SaveProject response; blank successful image nodes are backfilled from generated artifacts. Frontend designGateway adopts the new save/query flow. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
88 lines
2.4 KiB
Go
88 lines
2.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"img_infinite_canvas/internal/application"
|
|
"img_infinite_canvas/internal/domain/design"
|
|
"img_infinite_canvas/internal/infrastructure/memory"
|
|
"img_infinite_canvas/internal/svc"
|
|
"img_infinite_canvas/internal/types"
|
|
)
|
|
|
|
func TestSaveCanvasReturnsSaveProjectMetadata(t *testing.T) {
|
|
ctx := context.Background()
|
|
repo := memory.NewProjectRepository()
|
|
service := application.NewDesignService(repo, nil, nil, nil, nil)
|
|
project := design.Project{
|
|
ID: "project-save-metadata",
|
|
Title: "Save metadata",
|
|
Status: design.StatusReady,
|
|
UpdatedAt: time.Unix(100, 0).UTC(),
|
|
Version: "100000",
|
|
SnapshotID: "snapshot-old",
|
|
Viewport: design.Viewport{K: 1},
|
|
}
|
|
if err := repo.Save(ctx, project); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
logic := NewSaveCanvasLogic(ctx, &svc.ServiceContext{DesignService: service})
|
|
resp, err := logic.SaveCanvas(&types.SaveCanvasRequest{
|
|
Id: project.ID,
|
|
Version: project.Version,
|
|
Viewport: types.CanvasViewport{
|
|
K: 1,
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if resp.Code != 0 || resp.Msg != nil {
|
|
t.Fatalf("unexpected wrapper: %#v", resp)
|
|
}
|
|
if resp.Data.ProjectId != project.ID || resp.Data.NewCreated || !resp.Data.ValidProjectId || resp.Data.Version == "" {
|
|
t.Fatalf("unexpected save project data: %#v", resp.Data)
|
|
}
|
|
}
|
|
|
|
func TestSaveProjectReturnsSaveProjectMetadata(t *testing.T) {
|
|
ctx := context.Background()
|
|
repo := memory.NewProjectRepository()
|
|
service := application.NewDesignService(repo, nil, nil, nil, nil)
|
|
project := design.Project{
|
|
ID: "project-lovart-save",
|
|
Title: "Lovart save",
|
|
Status: design.StatusReady,
|
|
UpdatedAt: time.Unix(100, 0).UTC(),
|
|
Version: "100000",
|
|
SnapshotID: "snapshot-old",
|
|
Viewport: design.Viewport{K: 1},
|
|
}
|
|
if err := repo.Save(ctx, project); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
logic := NewSaveProjectLogic(ctx, &svc.ServiceContext{DesignService: service})
|
|
resp, err := logic.SaveProject(&types.SaveProjectRequest{
|
|
ProjectId: project.ID,
|
|
Version: project.Version,
|
|
Viewport: types.CanvasViewport{
|
|
K: 1,
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if resp.Code != 0 || resp.Msg != nil {
|
|
t.Fatalf("unexpected wrapper: %#v", resp)
|
|
}
|
|
if resp.Data.ProjectId != project.ID || resp.Data.NewCreated || !resp.Data.ValidProjectId || resp.Data.Version == "" {
|
|
t.Fatalf("unexpected save project data: %#v", resp.Data)
|
|
}
|
|
}
|