Files
aego/modules/render2d/editor/art_blank_test.go
sanspie 50be5c04bc
ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Stage 12.5: Art Workspace and asset authoring
Add dockable Art tools, animation and previews, guarded asset workflows,
and the Web Asset Studio built on the shared Art Core. Expand English and
Russian documentation, interactive Try scenes, examples and editor icons.

Add audio waveform navigation, source analysis, guarded previews and a
browser Worker mixer. Preserve source changes and recovery with bounded
checks, and strengthen native, browser and interoperability CI.

Prepare version 0.12.5 and manually built native artifact candidates.
Fix the production site image demo build dependency.
Reuse immutable scene indices when capturing keyframes.
Wait for real Persist save/load completion in component tests.
Stabilize browser Game View captures outside pointer hover.
Aseprite interchange and persistent Audio EDL recovery remain limited;
the artifact workflow does not publish releases or change stable.
2026-11-15 10:37:50 +03:00

220 lines
8.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package editor
import (
"bytes"
stdctx "context"
"errors"
"image"
"os"
"path/filepath"
"testing"
"aego/art"
"aego/asset/importers/artsource"
"aego/asset/pipeline"
"aego/core/log"
"aego/editor/core/artedit"
"aego/editor/core/command"
"aego/editor/core/context"
"aego/editor/core/document"
"aego/editor/core/workspace"
"aego/editor/ext"
"aego/project"
"aego/ui/core"
)
func workspaceBlankTestHost(t *testing.T, p *project.Project, pl *pipeline.Pipeline) (*context.Editor, *workspace.Workspace, *ext.Registry) {
t.Helper()
commands := command.New()
docs := document.NewManager(document.Options{Root: p.Root, SourceWrite: pl.GuardSourceWrite})
ed := &context.Editor{Project: p, Pipeline: pl, Docs: docs, Commands: commands, UI: core.New(nil)}
ws := workspace.New(p.Root, nil)
for _, id := range []string{workspace.Design, workspace.Art} {
if err := ws.RegisterPreset(workspace.Preset{ID: id}); err != nil {
t.Fatal(err)
}
}
registry := ext.New(ext.Deps{Editor: ed, Workspace: ws, Commands: commands})
if err := registry.Run("render2d", imageHooks); err != nil {
t.Fatal(err)
}
ws.LoadLayout()
return ed, ws, registry
}
func workspaceBlankFixture(t *testing.T) (*project.Project, *pipeline.Pipeline, *context.Editor, *workspace.Workspace, *ext.Registry) {
t.Helper()
p, err := project.Create(t.TempDir(), "Blank canvas", false)
if err != nil {
t.Fatal(err)
}
importers := pipeline.NewImporterRegistry()
if err := importers.Register(artsource.New()); err != nil {
t.Fatal(err)
}
if err := importers.Register(artsource.NewTexture()); err != nil {
t.Fatal(err)
}
pl, err := pipeline.Open(p, importers, log.Nop())
if err != nil {
t.Fatal(err)
}
t.Cleanup(pl.Close)
if _, _, err := pl.Scan(); err != nil {
t.Fatal(err)
}
batch, err := pl.ImportAll()
if err != nil || batch == nil || len(batch.Failed) != 0 || len(batch.Retry) != 0 {
t.Fatalf("fixture import failed: batch=%+v, error=%v", batch, err)
}
ed, ws, registry := workspaceBlankTestHost(t, p, pl)
return p, pl, ed, ws, registry
}
func enterBlankArt(t *testing.T, ed *context.Editor, ws *workspace.Workspace, registry *ext.Registry) (*document.AssetDocument, *artedit.Document) {
t.Helper()
if !ws.Switch(workspace.Art) {
t.Fatal("Art workspace is unavailable")
}
registry.RunTicks()
doc := ed.Docs.AssetDocument(artWorkspaceBlankID)
if doc == nil || !doc.Transient {
t.Fatal("entering Art did not open an in-memory drawing")
}
model, ok := doc.Binding.Model.(*artedit.Document)
if !ok || !model.Draft {
t.Fatal("blank canvas did not bind the shared Art model")
}
return doc, model
}
// These tests describe the desired workflow; they are deferred, not evidence
// that this mixed tree has passed UI, CI, or real OS acceptance.
func TestArtWorkspaceBlankDrawSwitchAndSaveAsAsset(t *testing.T) {
_, pl, ed, ws, registry := workspaceBlankFixture(t)
doc, model := enterBlankArt(t, ed, ws, registry)
if doc.Dirty() || model.PendingRecovery || model.Session.Document.Info().Canvas.Width != 32 || model.Session.Document.Info().Canvas.Height != 32 {
t.Fatal("default blank must be a clean editable 32×32 canvas")
}
for _, name := range []string{"assets/drawing.aeart", "assets/drawing.aeart.meta"} {
if got, err := pl.SourceBytes(name); err != nil || got != nil {
t.Fatalf("entering Art created %s: %v", name, err)
}
}
if _, err := model.Execute(stdctx.Background(), art.Operation{Kind: "stroke", Points: []image.Point{{X: 4, Y: 5}}, Brush: art.Brush{Size: 1, Paint: art.Paint{Color: art.Color{R: 255, A: 255}}}}); err != nil {
t.Fatal(err)
}
if !doc.Dirty() || model.History.Cursor() != 1 {
t.Fatal("painting did not use the document's shared dirty state and history")
}
if !ws.Switch(workspace.Design) {
t.Fatal("Design workspace is unavailable")
}
registry.RunTicks()
if !ws.Switch(workspace.Art) {
t.Fatal("could not return to Art")
}
registry.RunTicks()
if ed.Docs.AssetDocument(artWorkspaceBlankID) != doc || doc.Binding.Model != model || !doc.Dirty() || model.History.Cursor() != 1 {
t.Fatal("workspace switching replaced the dirty blank drawing")
}
if ws.Focused() != artHandlerID+"/"+doc.Asset.String() {
t.Fatal("returning to Art did not focus the existing drawing")
}
if err := ed.SaveAsset(doc); !errors.Is(err, document.ErrSavePending) {
t.Fatal("first Save did not wait for a path", err)
}
questions := ed.TakeQuestions()
if len(questions) != 1 || questions[0].Submit == nil {
t.Fatal("first Save did not offer an asset path")
}
questions[0].Submit([]string{"assets/first-drawing.aeart"})
id, ok := pl.Lookup("assets/first-drawing.aeart")
if !ok {
notice, _ := ed.LastNotice()
t.Fatalf("confirmed drawing was not imported: %+v", notice)
}
saved := ed.Docs.AssetDocument(id)
if saved == nil || saved.Transient || saved.Binding.Model != model || model.Draft || saved.Dirty() || model.History.Cursor() != 1 || ed.Docs.AssetDocument(artWorkspaceBlankID) != nil {
t.Fatal("first Save did not transfer the same clean session and history")
}
pixels, _, err := model.Capture(model.Session.Frame, art.Albedo)
if err != nil || pixels.NRGBAAt(4, 5).R != 255 || pixels.NRGBAAt(4, 5).A != 255 {
t.Fatal("the saved drawing lost its pixels", err)
}
if err := model.SessionUndo(); err != nil || !saved.Dirty() {
t.Fatal("Undo after first Save lost its history", err)
}
if err := model.SessionRedo(); err != nil || saved.Dirty() {
t.Fatal("Redo did not return to the saved generation", err)
}
}
func TestArtWorkspaceBlankSaveDoesNotOverwriteExistingFiles(t *testing.T) {
p, _, ed, ws, registry := workspaceBlankFixture(t)
doc, model := enterBlankArt(t, ed, ws, registry)
if _, err := model.Execute(stdctx.Background(), art.Operation{Kind: "stroke", Points: []image.Point{{X: 2, Y: 3}}, Brush: art.Brush{Size: 1, Paint: art.Paint{Color: art.Color{G: 255, A: 255}}}}); err != nil {
t.Fatal(err)
}
if err := ed.SaveAsset(doc); !errors.Is(err, document.ErrSavePending) {
t.Fatal(err)
}
questions := ed.TakeQuestions()
if len(questions) != 1 || questions[0].Submit == nil {
t.Fatal("missing Save prompt")
}
target := filepath.Join(p.Root, "assets", "occupied.aeart")
other := []byte("another person's source")
if err := os.WriteFile(target, other, 0o600); err != nil {
t.Fatal(err)
}
questions[0].Submit([]string{"assets/occupied.aeart"})
if got, err := os.ReadFile(target); err != nil || !bytes.Equal(got, other) {
t.Fatal("Save overwrote an externally created destination", err)
}
if !doc.Dirty() || doc.Binding.Model != model || model.History.Cursor() != 1 {
t.Fatal("a rejected Save lost unsaved pixels or history")
}
if notice, ok := ed.LastNotice(); !ok || notice.Level != context.LevelError {
t.Fatal("the rejected destination was not reported")
}
}
func TestArtWorkspaceBlankRecoveryRequiresExplicitAction(t *testing.T) {
p, pl, ed, ws, registry := workspaceBlankFixture(t)
doc, model := enterBlankArt(t, ed, ws, registry)
if _, err := model.Execute(stdctx.Background(), art.Operation{Kind: "stroke", Points: []image.Point{{X: 3, Y: 6}}, Brush: art.Brush{Size: 1, Paint: art.Paint{Color: art.Color{B: 255, A: 255}}}}); err != nil {
t.Fatal(err)
}
if err := ed.Docs.WriteAssetRecovery(doc); err != nil {
t.Fatal(err)
}
file := filepath.Join(p.Root, document.RecoveryDir, "asset-"+artWorkspaceBlankID.String()+".recovery")
before, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
}
// A fresh manager represents reopening the project after an interruption.
next, nextWS, nextRegistry := workspaceBlankTestHost(t, p, pl)
reopened, recovered := enterBlankArt(t, next, nextWS, nextRegistry)
if !recovered.PendingRecovery || reopened.Dirty() {
t.Fatal("an earlier blank was not offered for explicit recovery")
}
if _, err := recovered.Execute(stdctx.Background(), art.Operation{Kind: "stroke", Points: []image.Point{{X: 0, Y: 0}}, Brush: art.Brush{Size: 1}}); err == nil {
t.Fatal("editing bypassed the unresolved recovery")
}
if got, err := os.ReadFile(file); err != nil || !bytes.Equal(got, before) {
t.Fatal("opening the blank changed the recovery", err)
}
if err := recovered.Recover(); err != nil || !reopened.Dirty() || recovered.PendingRecovery {
t.Fatal("explicit blank recovery failed", err)
}
pixels, _, err := recovered.Capture(recovered.Session.Frame, art.Albedo)
if err != nil || pixels.NRGBAAt(3, 6).B != 255 || pixels.NRGBAAt(3, 6).A != 255 {
t.Fatal("explicit recovery lost the unsaved drawing", err)
}
if got, err := pl.SourceBytes("assets/drawing.aeart"); err != nil || got != nil {
t.Fatal("recovery created a project asset without Save", err)
}
}