diff --git a/packages/lint/src/rules/core.test.ts b/packages/lint/src/rules/core.test.ts index 1bc0a21e8a..d11d9a4b67 100644 --- a/packages/lint/src/rules/core.test.ts +++ b/packages/lint/src/rules/core.test.ts @@ -601,6 +601,25 @@ describe("core rules", () => { }); describe("non_deterministic_code", () => { + it("gives randomness guidance for crypto and clock guidance for wall time", async () => { + const result = await lintHyperframeHtml(` +
+ + `); + const crypto = result.findings.find((finding) => + finding.message.includes("crypto.getRandomValues"), + ); + const clock = result.findings.find((finding) => finding.message.includes("Date.now")); + expect(crypto).toMatchObject({ code: "non_deterministic_code", severity: "error" }); + expect(crypto?.fixHint).toContain("seeded PRNG"); + expect(crypto?.fixHint).not.toContain("time-dependent"); + expect(clock?.fixHint).toContain("wall-clock time"); + }); + it("detects Math.random() in script content", async () => { const html = ` diff --git a/packages/lint/src/rules/core.ts b/packages/lint/src/rules/core.ts index 8d784da2ff..d387a42d53 100644 --- a/packages/lint/src/rules/core.ts +++ b/packages/lint/src/rules/core.ts @@ -478,7 +478,7 @@ export const coreRules: Array<(ctx: LintContext) => HyperframeLintFinding[]> = [ { pattern: /crypto\.getRandomValues\s*\(/, label: "crypto.getRandomValues()", - hint: "Remove time-dependent code. Use a seeded PRNG for deterministic renders.", + hint: "Use a seeded PRNG (e.g. a simple mulberry32) so renders are deterministic across frames.", }, { pattern: /gsap\.utils\.random\s*\(/,