Repository navigation
test(storybook): make the Charts stories' sample data deterministic - #12549
Conversation
The stock, scatter and heatmap sample data now come from a small seeded pseudo-random generator instead of Math.random, so Dot/Scatter, both Candlestick stories and the WebGL scatter and heatmap stories draw the same geometry on every load. WebGL/Streaming starts from 60 seeded samples with a fixed window and still streams live by default. Pause, Step and Reset give a fixed frame for captures. No story id changes.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Approved pending CI: the required checks are still running on this head (the first CI run was refused for lack of capacity), so let them finish before merging.
The seven Charts stories now render the same data on every load. Two loads of each story on this head give identical frames, where two loads on the base differ in every story, and the seeded values match an independent implementation. No package code, story id or public API changes.
Claims and files checked
Review mode: full; reason: no-earlier-review
Claims:
- Seven Charts stories (Dot / Scatter, both Candlestick stories, four WebGL stories) drew
Math.randomdata: verified (base_data.tsstock, scatter and heatmap data; baseWebGL.stories.tsx:118). - Every load rendered different data, so two captures never matched: verified (two base loads differ in 7 of 7 stories).
- Only the two story files change, with no package code: verified (diff).
- Story ids, export names and args are unchanged; the index keeps 3124 entries, 43 under
charts-: verified (base and head story index). - Every other dataset in
_data.ts,monthlyDataincluded, is unchanged: verified (the diff touches only the stock, scatter and heatmap data). - WebGL / Streaming still streams live by default: verified (the window slides while live).
- A module-private mulberry32 generator with seeds 1, 2 and 3 replaces
Math.random, with unchanged formulas: verified (_data.ts:13-22,:86-124). createStreamSamples(seed 4) yields the same noisy sine wave formula as before: verified (_data.ts:28-36).- Streaming starts from 60 samples in a 0–60 window and pushes one sample every 200 ms: verified (
WebGL.stories.tsx:112-121,:183-191). - Pause/Resume, Step (enabled only while paused) and Reset behave as described: verified in the browser; Step is
aria-disabledwhile live, and each Step moves the window by one sample. - The push handle can attach after the story's first effects, so the handle ref replays the samples on every attach: verified (the chart renders its series only after it measures its width, and the seeded line is on the canvas at load with no clicks;
WebGL.stories.tsx:145-159). - Two head loads give identical frames: verified at desktop width in light mode for 7 of 7 stories; phone and dark were not re-run.
- Oracle values for Dot point 0, Candlestick day 1 and the heatmap extremes: verified with an independent implementation; the lightest heatmap value (1) is shared by Sat 20h and Sun 18h.
- The before captures came from an earlier main: verified that both story files are identical there and on the current base.
- The seeding red-arm variant fails without the handle-ref replay: not reproduced; consistent with when the chart mounts its stream mark.
- Prettier and strict ESLint pass on both files: verified.
- Typecheck passes: verified for the changed story files.
- Story play guard, RTL audit, story-tree test, pre-review and changeset checks pass: not re-run; the stories they name read only datasets this change leaves untouched, and a story-only change needs no changeset.
- No workflow or CI script changes: verified.
- Public text carries no internal context: verified.
Files:
apps/storybook/stories/charts/WebGL.stories.tsx: clear.apps/storybook/stories/charts/_data.ts: clear.
Maintainer impact
Seven Charts stories build their sample data with
Math.random:Every load renders different data. Two captures of the same story never match, so a maintainer reviewing a chart change sees noise instead of a diff, and no visual or geometry regression check can compare two renders of these stories.
Intended invariant
apps/storybook/stories/charts/_data.tsandapps/storybook/stories/charts/WebGL.stories.tsxchange.index.jsonhas the same 3124 entries before and after._data.tsis byte-for-byte unchanged. That includesmonthlyData, which the Tooltip stories and their play assertions read.Change
_data.tsgets a small module-private seeded generator (mulberry32).Math.random. Their formulas don't change.createStreamSamples(seed = 4)returns the next sample of the streaming story's noisy sine wave, with the same formula as before.clear(), thenpush) each time a handle attaches. The initial samples reach the canvas, and a remounted canvas is filled again.This is maintenance: it changes story fixtures only, not the charts package or any public API.
Evidence
Setup. Headless Chrome 157, with Figtree and JetBrains Mono installed.
2ff1afc9f8(main before this change).6424b7e5b8(this pull request's head).&globals=colorMode:dark.ltr), loaded fonts, DPR and viewport width were asserted, with 0 violations.Oracle. Expected values come from an independent Python implementation of mulberry32 and the dataset formulas, not from the story code.
Failure before the change
Two fresh loads differ in viewport pixels, for each story across the 4 combinations (desktop/phone × light/dark):
Success after the change
Determinism. 27 of 28 load pairs (7 stories × 4 combinations) have 0 differing viewport pixels and identical SVG geometry.
Oracle checks (desktop, light):
WebGL / Streaming still advances when not paused. This sequence ran on one page, never reloaded:
aria-disabledwhile the stream was live.Seeding red arm. The check loads the story with no clicks and pauses virtual time for one read. It asks whether the seeded initial samples are on the canvas.
useEffectinstead of the handle ref: 0/18, in 3 of 3 runs.Product/runtime behavior verified unchanged
apps/storybook/stories/charts/change. No package source changes.charts-).charts-chrome-tooltip--modal-layeringpasses.charts-chart--playground(legendPosition: 'start'): LTR 48 < 590; RTL 1052 > 510.charts-chrome-legend--default: LTR 48 < 186; RTL 1052 > 914.core-powersearch--near-full-token-row,core-powersearch--near-full-token-row-rtl, andcore-layer--taller-than-the-viewport(desktop and phone). They fail the same way on the main build in the same setup.CI impact
None. No workflow, action or CI script changes.
Scope
Components: Storybook stories only (Charts: Dot, Candlestick, dotGL, dotGLInteractive, heatmapGL, streamGL)
Testing
All of these ran at
6424b7e5b8:pnpm exec prettier --checkandASTRYX_STRICT_LINT=1 pnpm exec eslint --max-warnings=0on the 2 changed files: passnode .github/scripts/build-packages-and-storybook.mjs, thenpnpm typecheck: pass, 0 errorspnpm exec vitest run --project node apps/storybook/.storybook/story-tree.test.tsagainst the built index: 5/5 passpnpm specs:for --diff origin/main: no record links to the changed pathspnpm review:pre: 0 findingspnpm check:changesets: pass. This is a story-only change, so it has no changeset.node .github/scripts/story-play-guard.js --storybook-dir apps/storybook/dist:charts-chrome-tooltip--modal-layeringpasses. The unrelated failures are listed above.node apps/storybook/rtl-audit/rtl-audit.mjs --storybook-dir dist --curated-only --filter charts/Chart,charts/ChartLegend: D2 passes for both2ff1afc9f8(before) and6424b7e5b8(after), as described above. The red-arm variant was injected into this head.