File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -601,6 +601,25 @@ describe("core rules", () => {
601601 } ) ;
602602
603603 describe ( "non_deterministic_code" , ( ) => {
604+ it ( "gives randomness guidance for crypto and clock guidance for wall time" , async ( ) => {
605+ const result = await lintHyperframeHtml ( `<html><body>
606+ <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
607+ <script>
608+ crypto.getRandomValues(new Uint32Array(1));
609+ Date.now();
610+ window.__timelines = { c1: gsap.timeline({ paused: true }) };
611+ </script>
612+ </body></html>` ) ;
613+ const crypto = result . findings . find ( ( finding ) =>
614+ finding . message . includes ( "crypto.getRandomValues" ) ,
615+ ) ;
616+ const clock = result . findings . find ( ( finding ) => finding . message . includes ( "Date.now" ) ) ;
617+ expect ( crypto ) . toMatchObject ( { code : "non_deterministic_code" , severity : "error" } ) ;
618+ expect ( crypto ?. fixHint ) . toContain ( "seeded PRNG" ) ;
619+ expect ( crypto ?. fixHint ) . not . toContain ( "time-dependent" ) ;
620+ expect ( clock ?. fixHint ) . toContain ( "wall-clock time" ) ;
621+ } ) ;
622+
604623 it ( "detects Math.random() in script content" , async ( ) => {
605624 const html = `
606625<html><body>
Original file line number Diff line number Diff line change @@ -478,7 +478,7 @@ export const coreRules: Array<(ctx: LintContext) => HyperframeLintFinding[]> = [
478478 {
479479 pattern : / c r y p t o \. g e t R a n d o m V a l u e s \s * \( / ,
480480 label : "crypto.getRandomValues()" ,
481- hint : "Remove time-dependent code. Use a seeded PRNG for deterministic renders." ,
481+ hint : "Use a seeded PRNG (e.g. a simple mulberry32) so renders are deterministic across frames ." ,
482482 } ,
483483 {
484484 pattern : / g s a p \. u t i l s \. r a n d o m \s * \( / ,
You can’t perform that action at this time.
0 commit comments