Files
aego/app/docsview/state_machine_workflow_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

127 lines
3.7 KiB
Go

//go:build aego_editor
package docsview
import (
"encoding/json"
"strings"
"testing"
"aego/app/playground"
"aego/modules/gameplay"
"aego/modules/render2d"
"aego/scene"
)
func TestStateMachineTryRunsHooksTransitionAndReset(t *testing.T) {
p, err := playground.New()
if err != nil {
t.Fatal(err)
}
e, ok := p.Docs().Get("gameplay.StateMachine")
if !ok || e.Demo == nil {
t.Fatal("State Machine contract is absent")
}
code, err := p.TryCode(e.TryScript)
if err != nil {
t.Fatal(err)
}
a := newHeadless(t)
req, err := json.Marshal(map[string]any{"scene": e.Try, "select": e.TrySelect, "code": code, "prefabs": e.TryPrefabs, "artifacts": e.TryArtifacts})
if err != nil {
t.Fatal(err)
}
if r := a.Call("load", req); r.Error != "" {
t.Fatal(r.Error)
}
if err := a.Step(10); err != nil {
t.Fatal(err)
}
state := func() (*gameplay.StateMachine, *render2d.SpriteRenderer) {
t.Helper()
sc := a.session.Controller().Scene()
h := sc.Find(sc.Root(), "State indicator")
machine, ok := scene.Get[gameplay.StateMachine](sc, h)
if !ok {
t.Fatal("state machine is absent")
}
sprite, ok := scene.Get[render2d.SpriteRenderer](sc, h)
if !ok {
t.Fatal("state indicator sprite is absent")
}
return machine, sprite
}
machine, sprite := state()
if machine.Initial != "Idle" || machine.Current != "Idle" {
t.Fatalf("machine did not start in Idle: %+v", machine)
}
idleColor := sprite.Tint
if r := a.Call("set", []byte(`{"component":"gameplay.StateMachine","field":"Initial","value":"Run"}`)); r.Error != "" {
t.Fatal(r.Error)
}
if err := a.Step(10); err != nil {
t.Fatal(err)
}
machine, sprite = state()
if machine.Initial != "Run" || machine.Current != "Run" || sprite.Tint == idleColor {
t.Fatalf("Run state and its Enter hook did not execute: machine=%+v tint=%+v", machine, sprite.Tint)
}
if !machine.Go("Idle") {
t.Fatal("the running machine rejected its Idle transition")
}
if err := a.Step(10); err != nil {
t.Fatal(err)
}
machine, sprite = state()
if machine.Current != "Idle" || machine.Previous != "Run" || sprite.Tint != idleColor {
t.Fatalf("the queued transition did not execute the Idle hook: machine=%+v tint=%+v", machine, sprite.Tint)
}
if r := a.Call("reset", nil); r.Error != "" {
t.Fatal(r.Error)
}
if err := a.Step(10); err != nil {
t.Fatal(err)
}
machine, sprite = state()
if machine.Initial != "Idle" || machine.Current != "Idle" || sprite.Tint != idleColor {
t.Fatalf("Reset did not restore Idle: machine=%+v tint=%+v", machine, sprite.Tint)
}
if messages := errorsOf(a); len(messages) > 0 {
t.Fatalf("State Machine Try runtime errors: %v", messages)
}
}
func TestStateMachineGuideKeepsOriginalMotionExample(t *testing.T) {
p, err := playground.New()
if err != nil {
t.Fatal(err)
}
e, ok := p.Docs().Get("gameplay/statemachine")
if !ok || !strings.Contains(e.Try, "gameplay.Motion2D") || !strings.Contains(e.TryScript, "func UpdateAir") {
t.Fatal("the guide lost its original walking and jumping example")
}
code, err := p.TryCode(e.TryScript)
if err != nil {
t.Fatal(err)
}
a := newHeadless(t)
req, err := json.Marshal(map[string]any{"scene": e.Try, "select": e.TrySelect, "code": code, "prefabs": e.TryPrefabs, "artifacts": e.TryArtifacts})
if err != nil {
t.Fatal(err)
}
if r := a.Call("load", req); r.Error != "" {
t.Fatal(r.Error)
}
if err := a.Step(150); err != nil {
t.Fatal(err)
}
sc := a.session.Controller().Scene()
machine, ok := scene.Get[gameplay.StateMachine](sc, sc.Find(sc.Root(), "Player"))
if !ok || machine.Current == "" {
t.Fatalf("the guide state machine did not start: %+v", machine)
}
if messages := errorsOf(a); len(messages) > 0 {
t.Fatalf("state-machine guide runtime errors: %v", messages)
}
}