Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/lint/src/rules/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`<html><body>
<div data-composition-id="c1" data-width="1920" data-height="1080"></div>
<script>
crypto.getRandomValues(new Uint32Array(1));
Date.now();
window.__timelines = { c1: gsap.timeline({ paused: true }) };
</script>
</body></html>`);
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 = `
<html><body>
Expand Down
2 changes: 1 addition & 1 deletion packages/lint/src/rules/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*\(/,
Expand Down
Loading