mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-03 03:27:10 +00:00
feat(testrun): inject seed into web bundle via SANDERLING_SEED define
This commit is contained in:
1 parent
d7c05181b0
commit
6fc1c971c7
1 file changed
+13
-4
@@ -7,6 +7,7 @@ import (
|
|||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/priyanshujain/sanderling/internal/android"
|
"github.com/priyanshujain/sanderling/internal/android"
|
||||||
@@ -53,9 +54,11 @@ func Execute(ctx context.Context, options Options, stdout io.Writer) error {
|
|||||||
aliases["@sanderling/spec/defaults"] = filepath.Join(base, "defaults/index.ts")
|
aliases["@sanderling/spec/defaults"] = filepath.Join(base, "defaults/index.ts")
|
||||||
aliases["@sanderling/spec/defaults/properties"] = filepath.Join(base, "defaults/properties.ts")
|
aliases["@sanderling/spec/defaults/properties"] = filepath.Join(base, "defaults/properties.ts")
|
||||||
}
|
}
|
||||||
|
seed := resolveSeed(options.Seed)
|
||||||
defines := map[string]string{
|
defines := map[string]string{
|
||||||
"SANDERLING_TEST_PHONE": os.Getenv("SANDERLING_TEST_PHONE"),
|
"SANDERLING_TEST_PHONE": os.Getenv("SANDERLING_TEST_PHONE"),
|
||||||
"SANDERLING_TEST_OTP": os.Getenv("SANDERLING_TEST_OTP"),
|
"SANDERLING_TEST_OTP": os.Getenv("SANDERLING_TEST_OTP"),
|
||||||
|
"SANDERLING_SEED": strconv.FormatInt(seed, 10),
|
||||||
}
|
}
|
||||||
bundle, err := bundler.Bundle(bundler.Options{
|
bundle, err := bundler.Bundle(bundler.Options{
|
||||||
EntryFile: options.Spec,
|
EntryFile: options.Spec,
|
||||||
@@ -101,10 +104,6 @@ func Execute(ctx context.Context, options Options, stdout io.Writer) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
seed := options.Seed
|
|
||||||
if seed == 0 {
|
|
||||||
seed = time.Now().UnixNano()
|
|
||||||
}
|
|
||||||
verifierInstance, err := verifier.New(
|
verifierInstance, err := verifier.New(
|
||||||
verifier.WithRand(rand.New(rand.NewPCG(uint64(seed), 0))),
|
verifier.WithRand(rand.New(rand.NewPCG(uint64(seed), 0))),
|
||||||
verifier.WithAppPackage(options.BundleID),
|
verifier.WithAppPackage(options.BundleID),
|
||||||
@@ -173,6 +172,16 @@ func Execute(ctx context.Context, options Options, stdout io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolveSeed returns the configured seed, or a time-derived one when unset.
|
||||||
|
// The same value seeds both the goja PRNG and the web bundle's SANDERLING_SEED
|
||||||
|
// define, so a single run is reproducible across both runtimes.
|
||||||
|
func resolveSeed(configured int64) int64 {
|
||||||
|
if configured != 0 {
|
||||||
|
return configured
|
||||||
|
}
|
||||||
|
return time.Now().UnixNano()
|
||||||
|
}
|
||||||
|
|
||||||
// resolveWebRuntimePath returns the path to pkg/spec/src/web-runtime.ts.
|
// resolveWebRuntimePath returns the path to pkg/spec/src/web-runtime.ts.
|
||||||
// Tries the spec-API checkout first (so monorepo development works without
|
// Tries the spec-API checkout first (so monorepo development works without
|
||||||
// publishing the package), then falls back to a sibling of the resolved
|
// publishing the package), then falls back to a sibling of the resolved
|
||||||
|
|||||||
Reference in new issue
Block a user