1package wailshost23import (4 "context"5 "io"6 "os"7 "path/filepath"8 "reflect"9 "sync"10 "sync/atomic"11 "testing"12)1314func TestAtlasPathsAcceptsOnlyNativeVolumeFiles(t *testing.T) {15 t.Parallel()1617 got := atlasPaths([]string{"/tmp/world.atlas", "/tmp/readme.txt", "/tmp/legacy.zip"})18 want := []string{"/tmp/world.atlas"}19 if !reflect.DeepEqual(got, want) {20 t.Fatalf("atlasPaths = %v, want %v", got, want)21 }22}2324func TestConcurrentNativeFileIntakeIsSerializedAndRefreshesOnce(t *testing.T) {25 dir := t.TempDir()26 paths := []string{filepath.Join(dir, "first.atlas"), filepath.Join(dir, "second.atlas")}27 for _, path := range paths {28 if err := os.WriteFile(path, []byte(filepath.Base(path)), 0o644); err != nil {29 t.Fatal(err)30 }31 }32 started := make(chan struct{})33 release := make(chan struct{})34 var active, maximum, installed, refreshed atomic.Int3235 window := Window{36 install: func(_ string, _ io.Reader) error {37 current := active.Add(1)38 for {39 held := maximum.Load()40 if current <= held || maximum.CompareAndSwap(held, current) {41 break42 }43 }44 if installed.Add(1) == 1 {45 close(started)46 <-release47 }48 active.Add(-1)49 return nil50 },51 refresh: func(context.Context) { refreshed.Add(1) },52 }53 ctx := context.Background()54 window.live.Store(&ctx)55 var calls sync.WaitGroup56 calls.Add(2)57 go func() { defer calls.Done(); window.QueuePaths(paths[:1]) }()58 <-started59 queued := make(chan struct{})60 go func() {61 defer calls.Done()62 window.QueuePaths(paths[1:])63 close(queued)64 }()65 <-queued66 close(release)67 calls.Wait()68 if installed.Load() != 2 || maximum.Load() != 1 || refreshed.Load() != 1 {69 t.Fatalf("installed=%d maximum=%d refreshed=%d", installed.Load(), maximum.Load(), refreshed.Load())70 }71}7273func TestNativeFileIntakeRefreshesTheOpenWindow(t *testing.T) {74 path := filepath.Join(t.TempDir(), "world.atlas")75 if err := os.WriteFile(path, []byte("native volume"), 0o644); err != nil {76 t.Fatal(err)77 }78 installed, refreshed := 0, 079 window := Window{80 install: func(_ string, _ io.Reader) error {81 installed++82 return nil83 },84 refresh: func(context.Context) { refreshed++ },85 }86 ctx := context.Background()87 window.live.Store(&ctx)88 window.QueuePaths([]string{path})89 if installed != 1 || refreshed != 1 {90 t.Fatalf("installed=%d refreshed=%d, want one install and one refresh", installed, refreshed)91 }92}