Files
aego/tests/integration/restart_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

120 lines
3.6 KiB
Go

package integration
import (
"math"
"os"
"path/filepath"
"testing"
"aego/app/run"
"aego/core/log"
"aego/scene"
)
func TestRestartStatePreservesTheScene(t *testing.T) {
const frameTime = 1.0 / 60
const frames = 60
const speed = 1.5 // the speed in rotatorScene
p := newRotatorProject(t)
scenePath := filepath.Join(p.ScenesDir(), "main.aescene")
app, err := run.Open(p, run.Config{Headless: true, FrameTime: frameTime, Logger: log.Nop(), ScenePath: scenePath}, rotatorModule{})
if err != nil {
t.Fatal(err)
}
appOpen := true
defer func() {
if appOpen {
app.Close()
}
}()
player := app.Scene.Find(app.Scene.Root(), "Player")
if player.IsZero() {
t.Fatal("player missing before the snapshot")
}
rotator, ok := scene.Get[Rotator](app.Scene, player)
if !ok || rotator.Speed != speed {
t.Fatalf("rotator before the snapshot = %v, want speed %v", rotator, speed)
}
before := app.Scene.Local(player).Rotation
if before != 0 {
t.Fatalf("initial rotation = %v, want 0", before)
}
playerID := app.Scene.ID(player)
driver := app.Driver()
for i := 0; i < frames; i++ {
if !app.Engine.Step(driver) {
t.Fatalf("engine stopped at frame %d: %v", i, app.Engine.Err())
}
}
advanced := app.Scene.Local(player).Rotation
if advanced == 0 {
t.Fatal("rotation did not advance before the snapshot")
}
// The first engine frame has zero delta; all the others use frameTime.
wantAdvanced := float64(before) + (frames-1)*speed*frameTime
if !(math.Abs(float64(advanced)-wantAdvanced) <= 1e-5) {
t.Fatalf("rotation before snapshot = %v, want %v", advanced, wantAdvanced)
}
statePath := run.StatePath(p.Root)
app.SaveStateAndQuit(statePath)
if app.Engine.Step(driver) {
t.Fatal("engine kept running after SaveStateAndQuit")
}
app.Close()
appOpen = false
if _, err := os.Stat(statePath); err != nil {
t.Fatalf("state file was not written: %v", err)
}
restored, err := run.Open(p, run.Config{Headless: true, FrameTime: frameTime, Logger: log.Nop(), ScenePath: statePath}, rotatorModule{})
if err != nil {
t.Fatal(err)
}
defer restored.Close()
rp := restored.Scene.Find(restored.Scene.Root(), "Player")
if rp.IsZero() {
t.Fatal("player missing after restore")
}
if got := restored.Scene.Local(rp).Rotation; got != advanced {
t.Fatalf("restored rotation %v, want the snapshot's %v", got, advanced)
}
if restored.Scene.ID(rp) != playerID {
t.Fatal("node ids changed across the restart")
}
rotator, ok = scene.Get[Rotator](restored.Scene, rp)
if !ok || rotator.Speed != speed {
t.Fatalf("rotator after restart = %v, want speed %v", rotator, speed)
}
restoredDriver := restored.Driver()
for i := 0; i < 2; i++ {
if !restored.Engine.Step(restoredDriver) {
t.Fatalf("restored engine stopped at frame %d: %v", i, restored.Engine.Err())
}
}
wantContinued := float64(advanced) + speed*frameTime
if got := float64(restored.Scene.Local(rp).Rotation); !(math.Abs(got-wantContinued) <= 1e-5) {
t.Fatalf("rotation after restart and two frames = %v, want %v", got, wantContinued)
}
}
func TestRestartStateKeepsUnknownComponents(t *testing.T) {
p := newRotatorProject(t)
scenePath := filepath.Join(p.ScenesDir(), "main.aescene")
app, err := run.Open(p, run.Config{Headless: true, Logger: log.Nop(), ScenePath: scenePath})
if err != nil {
t.Fatal(err)
}
statePath := run.StatePath(p.Root)
app.SaveStateAndQuit(statePath)
app.Close()
data, err := os.ReadFile(statePath)
if err != nil {
t.Fatal(err)
}
if !containsString(string(data), "game.Rotator") || !containsString(string(data), "speed=1.5") {
t.Fatalf("a component from a removed module did not survive the restart:\n%s", data)
}
}