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.
198 lines
6.7 KiB
Go
198 lines
6.7 KiB
Go
package audio
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"crypto/sha256"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"aego/asset"
|
|
"aego/asset/audiosidecar"
|
|
audioimport "aego/asset/importers/audio"
|
|
"aego/asset/pipeline"
|
|
"aego/audio/codec/wav"
|
|
"aego/audio/edit"
|
|
"aego/core/log"
|
|
"aego/project"
|
|
)
|
|
|
|
func TestUnsupportedEditedSidecarCannotPublishThroughCurrentImporter(t *testing.T) {
|
|
for _, initial := range []bool{false, true} {
|
|
name := "guarded-publication"
|
|
if initial {
|
|
name = "fresh-project-scan"
|
|
}
|
|
t.Run(name, func(t *testing.T) {
|
|
pj, err := project.Create(t.TempDir(), "UnsupportedAudioEdit", false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
const rel = "assets/tone.wav"
|
|
file := filepath.Join(pj.Root, filepath.FromSlash(rel))
|
|
source := wav.Encode([]float32{.1, .2, .3, .4}, 8000, 1, wav.EncodeOptions{Float: true})
|
|
digest := sha256.Sum256(source)
|
|
imp := audioimport.New()
|
|
meta := asset.NewSourceMeta(imp.ID(), imp.Version(), imp.Defaults())
|
|
before := asset.MarshalSourceMeta(meta)
|
|
doc, err := audioedit.New(audioedit.Source{AssetID: meta.ID.String(), Path: rel, SHA256: fmt.Sprintf("%x", digest),
|
|
Codec: "wav", SampleRate: 8000, Channels: 1, Frames: 4})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
doc.Operations = []audioedit.Operation{{Kind: audioedit.Gain, Region: audioedit.Range{Start: 0, End: 4}, Value: .5}}
|
|
after, err := audiosidecar.Encode(before, rel, doc)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(file, source, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
onDisk := before
|
|
if initial {
|
|
onDisk = after
|
|
}
|
|
if err := os.WriteFile(file+asset.MetaSuffix, onDisk, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
registry := pipeline.NewImporterRegistry()
|
|
if err := registry.Register(imp); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pl, err := pipeline.Open(pj, registry, log.Nop())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer 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("initial scan/import: %+v %v", batch, err)
|
|
}
|
|
if initial {
|
|
if len(batch.Imported) != 0 {
|
|
t.Fatal("fresh scan imported an unsupported edited source")
|
|
}
|
|
if _, ok := pl.Lookup(rel); ok || pl.VerifyCurrent(meta.ID) == nil {
|
|
t.Fatal("fresh scan exposed an unsupported edit as a current asset")
|
|
}
|
|
} else {
|
|
if len(batch.Imported) != 1 {
|
|
t.Fatal("fixture did not import its original source")
|
|
}
|
|
guard, err := pl.FingerprintSource(context.Background(), rel, pipeline.MaxSourceFingerprintBytes)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
edits := []pipeline.SourceEdit{{Path: rel, ReadOnlyGuard: true, Fingerprint: &guard},
|
|
{Path: rel + asset.MetaSuffix, Before: before, After: after}}
|
|
if batch, err := pl.ApplySources(edits, false); err == nil {
|
|
t.Fatalf("published an edit without importer support: %+v", batch)
|
|
}
|
|
if status, err := pipeline.SourceRecoveryStatus(pj); err != nil || status != nil {
|
|
t.Fatalf("fully rolled-back candidate left recovery: %+v %v", status, err)
|
|
}
|
|
}
|
|
if data, err := os.ReadFile(file); err != nil || sha256.Sum256(data) != digest {
|
|
t.Fatal("safety check changed source bytes", err)
|
|
}
|
|
if data, err := os.ReadFile(file + asset.MetaSuffix); err != nil || !bytes.Equal(data, onDisk) {
|
|
t.Fatal("safety check changed the metadata preimage", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestOpenPipelineRejectsExternallyPublishedEditedSidecar(t *testing.T) {
|
|
for _, changedSource := range []bool{false, true} {
|
|
name := "unchanged-source"
|
|
if changedSource {
|
|
name = "changed-source"
|
|
}
|
|
t.Run(name, func(t *testing.T) {
|
|
pj, err := project.Create(t.TempDir(), "CachedAudioMetadata", false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
const rel = "assets/tone.wav"
|
|
file := filepath.Join(pj.Root, filepath.FromSlash(rel))
|
|
original := wav.Encode([]float32{.1, .2, .3, .4}, 8000, 1, wav.EncodeOptions{Float: true})
|
|
external := wav.Encode([]float32{.4, .3, .2, .1}, 8000, 1, wav.EncodeOptions{Float: true})
|
|
imp := audioimport.New()
|
|
meta := asset.NewSourceMeta(imp.ID(), imp.Version(), imp.Defaults())
|
|
before := asset.MarshalSourceMeta(meta)
|
|
doc, err := audioedit.New(audioedit.Source{AssetID: meta.ID.String(), Path: rel,
|
|
SHA256: fmt.Sprintf("%x", sha256.Sum256(original)), Codec: "wav", SampleRate: 8000, Channels: 1, Frames: 4})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
doc.Operations = []audioedit.Operation{{Kind: audioedit.Gain, Region: audioedit.Range{Start: 0, End: 4}, Value: .5}}
|
|
edited, err := audiosidecar.Encode(before, rel, doc)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(file, original, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(file+asset.MetaSuffix, before, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
registry := pipeline.NewImporterRegistry()
|
|
if err := registry.Register(imp); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pl, err := pipeline.Open(pj, registry, log.Nop())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer pl.Close()
|
|
if _, _, err := pl.Scan(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
batch, err := pl.ImportAll()
|
|
if err != nil || batch == nil || len(batch.Imported) != 1 || len(batch.Failed) != 0 || len(batch.Retry) != 0 {
|
|
t.Fatalf("initial import: %+v %v", batch, err)
|
|
}
|
|
artifact, ok := pl.PrimaryArtifact(meta.ID)
|
|
if !ok {
|
|
t.Fatal("initial audio artifact is missing")
|
|
}
|
|
artifactPath := filepath.Join(pj.CacheDir(), "artifacts", filepath.Base(artifact.Path))
|
|
artifactBefore, err := os.ReadFile(artifactPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(file+asset.MetaSuffix, edited, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wantSource := original
|
|
if changedSource {
|
|
if err := os.WriteFile(file, external, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wantSource = external
|
|
}
|
|
batch, err = pl.Import(meta.ID)
|
|
if err != nil || batch == nil || batch.Failed[meta.ID] == nil || len(batch.Imported) != 0 || len(batch.Retry) != 0 {
|
|
t.Fatalf("open pipeline accepted unsupported edited metadata: %+v %v", batch, err)
|
|
}
|
|
if err := pl.VerifyCurrent(meta.ID); err == nil {
|
|
t.Fatal("strict verification accepted unsupported edited metadata")
|
|
}
|
|
if got, err := os.ReadFile(artifactPath); err != nil || !bytes.Equal(got, artifactBefore) {
|
|
t.Fatal("stale import replaced the last audio artifact", err)
|
|
}
|
|
if got, err := os.ReadFile(file); err != nil || !bytes.Equal(got, wantSource) {
|
|
t.Fatal("stale import changed source bytes", err)
|
|
}
|
|
if got, err := os.ReadFile(file + asset.MetaSuffix); err != nil || !bytes.Equal(got, edited) {
|
|
t.Fatal("stale import changed the external metadata", err)
|
|
}
|
|
})
|
|
}
|
|
}
|