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
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.
189 lines
5.7 KiB
Go
189 lines
5.7 KiB
Go
package scripteditor
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
|
|
"aego/editor/core/code"
|
|
"aego/editor/core/document"
|
|
"aego/script/langsvc"
|
|
"aego/script/workspace"
|
|
)
|
|
|
|
// queuedAnalysisJobs lets a real language analysis finish while delaying its
|
|
// owner-thread callback until after the document has been reloaded or reset.
|
|
type queuedAnalysisJobs struct {
|
|
work []func()
|
|
main []func()
|
|
}
|
|
|
|
func TestPanelRejectsLateCompletionAfterDocumentReset(t *testing.T) {
|
|
const source = "package c\nscript Mover {\n\tfunc Update(dt float) {\n\t\tyield \n\t}\n}\n"
|
|
cursor := strings.Index(source, "yield ") + len("yield ")
|
|
for _, tc := range []struct {
|
|
name string
|
|
replace, rename, reset bool
|
|
}{
|
|
{"same document reset", false, false, true},
|
|
{"replacement then reset", true, false, true},
|
|
{"replacement before reset", true, false, false},
|
|
{"rename before reset", false, true, false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
ws, err := workspace.Open(workspace.Config{Root: t.TempDir(), Module: "game"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
jobs := &queuedAnalysisJobs{}
|
|
host := NewHost(langsvc.New(ws, jobs))
|
|
doc := &document.ScriptDocument{Path: "scripts/test.aes", Code: code.New([]byte(source))}
|
|
doc.Code.SetCursor(cursor, false)
|
|
panel := newPanel(host, doc)
|
|
defer panel.releaseDoc()
|
|
panel.requestCompletion(nil)
|
|
jobs.completeWork(t)
|
|
jobs.deliver(t)
|
|
if !panel.comp.open {
|
|
t.Fatal("fixture did not produce a real completion")
|
|
}
|
|
panel.requestCompletion(nil)
|
|
jobs.completeWork(t)
|
|
// The earlier successful result must not be mistaken for a late one.
|
|
panel.comp.open = false
|
|
if tc.replace {
|
|
old := doc.Code
|
|
doc.Code = code.New([]byte(source + "\n// replacement\n"))
|
|
doc.Code.SetCursor(cursor, false)
|
|
if doc.Code.Rev() != old.Rev() {
|
|
t.Fatal("fixture did not produce overlapping document revisions")
|
|
}
|
|
}
|
|
if tc.rename {
|
|
doc.Path = "scripts/renamed.aes"
|
|
}
|
|
if tc.reset {
|
|
panel.resync()
|
|
}
|
|
jobs.deliver(t)
|
|
if panel.comp.open {
|
|
t.Fatal("late completion from before reset was published")
|
|
}
|
|
panel.requestCompletion(nil)
|
|
jobs.completeWork(t)
|
|
jobs.deliver(t)
|
|
if !panel.comp.open {
|
|
t.Fatal("fresh completion after reset was not published")
|
|
}
|
|
file, ok := ws.FileID(doc.Path)
|
|
snap := host.lang.Latest()
|
|
if !ok || snap == nil || !bytes.Equal(snap.Sources.Source(file), doc.Code.Bytes()) {
|
|
t.Fatal("fresh completion used old document bytes")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func (j *queuedAnalysisJobs) Submit(fn func()) { j.work = append(j.work, fn) }
|
|
func (j *queuedAnalysisJobs) OnMain(fn func()) { j.main = append(j.main, fn) }
|
|
|
|
func (j *queuedAnalysisJobs) completeWork(t *testing.T) {
|
|
t.Helper()
|
|
if len(j.work) != 1 {
|
|
t.Fatalf("expected one analysis job, got %d", len(j.work))
|
|
}
|
|
fn := j.work[0]
|
|
j.work = nil
|
|
fn()
|
|
}
|
|
|
|
func (j *queuedAnalysisJobs) deliver(t *testing.T) {
|
|
t.Helper()
|
|
if len(j.main) != 1 {
|
|
t.Fatalf("expected one owner-thread result, got %d", len(j.main))
|
|
}
|
|
fn := j.main[0]
|
|
j.main = nil
|
|
fn()
|
|
}
|
|
|
|
func TestPanelRejectsLateAnalysisAfterDocumentReset(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
replace, reset bool
|
|
}{
|
|
{"same document reset", false, true},
|
|
{"replacement then reset", true, true},
|
|
{"replacement before reset", true, false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
ws, err := workspace.Open(workspace.Config{Root: t.TempDir(), Module: "game"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
jobs := &queuedAnalysisJobs{}
|
|
host := NewHost(langsvc.New(ws, jobs))
|
|
doc := &document.ScriptDocument{Path: "scripts/test.aes", Code: code.New([]byte("var old = 1\n"))}
|
|
panel := newPanel(host, doc)
|
|
defer panel.releaseDoc()
|
|
panel.ask(1)
|
|
jobs.completeWork(t)
|
|
if tc.replace {
|
|
old := doc.Code
|
|
doc.Code = code.New([]byte("var different = 2\n"))
|
|
if doc.Code.Rev() != old.Rev() {
|
|
t.Fatal("fixture did not produce overlapping document revisions")
|
|
}
|
|
}
|
|
if tc.reset {
|
|
panel.resync()
|
|
}
|
|
jobs.deliver(t)
|
|
if panel.snap != nil || panel.synced() || host.liveSnap != nil {
|
|
t.Fatal("late analysis from before reset was published")
|
|
}
|
|
panel.ask(2)
|
|
jobs.completeWork(t)
|
|
jobs.deliver(t)
|
|
if panel.snap == nil || !panel.synced() || host.liveSnap != panel.snap {
|
|
t.Fatal("fresh analysis after reset was not published")
|
|
}
|
|
file, ok := ws.FileID(doc.Path)
|
|
if !ok || !bytes.Equal(panel.snap.Sources.Source(file), doc.Code.Bytes()) {
|
|
t.Fatal("fresh analysis used old document bytes")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPanelRetainsAnalysisAcrossEditsToSameDocument(t *testing.T) {
|
|
ws, err := workspace.Open(workspace.Config{Root: t.TempDir(), Module: "game"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
jobs := &queuedAnalysisJobs{}
|
|
host := NewHost(langsvc.New(ws, jobs))
|
|
doc := &document.ScriptDocument{Path: "scripts/test.aes", Code: code.New([]byte("var old = 1\n"))}
|
|
panel := newPanel(host, doc)
|
|
defer panel.releaseDoc()
|
|
panel.ask(1)
|
|
jobs.completeWork(t)
|
|
revision := doc.Code.Rev()
|
|
doc.Code.Replace(doc.Code.Len(), 0, "\n")
|
|
jobs.deliver(t)
|
|
if panel.snap == nil || panel.snapRev != revision || panel.synced() || host.liveSnap != panel.snap {
|
|
t.Fatal("analysis for an earlier revision of the same document was discarded or marked current")
|
|
}
|
|
}
|
|
|
|
func TestPanelResetClearsStaleHover(t *testing.T) {
|
|
doc := &document.ScriptDocument{Path: "scripts/test.aes", Code: code.New([]byte("saved\n"))}
|
|
panel := newPanel(&Host{}, doc)
|
|
defer panel.releaseDoc()
|
|
panel.hover = hoverState{off: 3, since: 1, done: true, ok: true, hasDiag: true, builtin: true}
|
|
panel.resync()
|
|
if panel.hover.off != -1 || panel.hover.done || panel.hover.ok || panel.hover.hasDiag || panel.hover.builtin {
|
|
t.Fatal("reset retained stale hover state")
|
|
}
|
|
}
|