From bf3f230b1bc065143472c959e42b02821eeaa620 Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 13 Aug 2026 00:27:10 +0530 Subject: [PATCH] fix(spec): read the injected seed per call Binding it at module scope bound it to whenever the module was first imported, so a test file that imported the runtime before setting SANDERLING_SEED froze the seed at zero for every file after it. The bundler still replaces the expression with a literal. --- pkg/spec/src/web-runtime.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/spec/src/web-runtime.ts b/pkg/spec/src/web-runtime.ts index 14f4b64..4c38e23 100644 --- a/pkg/spec/src/web-runtime.ts +++ b/pkg/spec/src/web-runtime.ts @@ -70,7 +70,13 @@ function seedBigInt(): bigint { } } -const SEED_HI = seedBigInt(); +// Read on every call rather than once at module scope. The bundler replaces the +// seed expression with a literal, so production reads a constant either way, +// and parsing one decimal string per run costs nothing. Binding it at module +// scope bound it instead to whenever this module was first imported, which made +// the seed depend on test file ordering: a file importing this module before +// the seed was set froze it at zero, and the failure then surfaced in a +// different file that had set it correctly. function noopFormula(): unknown { const formula: Record = { __sanderlingFormula: true }; @@ -553,7 +559,7 @@ function resetTargetCache(): void { const host: Host = { platform: () => "web", - seedHi: () => SEED_HI, + seedHi: () => seedBigInt(), // lo = 0 matches the goja side's rand.NewPCG(seed, 0). seedLo: () => 0n, queryTargets(): TargetElement[] {