Skip to content

test(interaction): deterministic storyboards - #8348

Merged
cixzhang merged 69 commits into
meta:mainfrom
vjeux:uikit/f3-storyboards
Oct 26, 2026
Merged

cixzhang merged 69 commits into
meta:mainfrom
vjeux:uikit/f3-storyboards

Conversation

@vjeux

@vjeux vjeux commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #8505.

Maintainer impact

A reviewer can't see an animation frame by frame. A screen recording depends on machine load and frame timing, so two runs of the same motion differ, and nothing in it can be asserted.

Intended invariant

No product change. A storyboard is reproducible: its frames come from seeking held animations or stepping scripted input, never from wall-clock capture, and the spec asserts on its trace.

Change

  • storyboard.ts:
    • animationStoryboard films held animations by seeking them. By default it runs from the earliest start to the latest curve end among the animations that end, on a 16.7 ms grid plus the exact end, each animation at its own offset. So a spinner that started earlier doesn't pin the animation under test to its start, and a later animation is filmed to its end.
    • touchStoryboard takes a frame per scripted touch event. Event timestamps keep the script's times; a handler reading the clock sees one event per photograph.
    • Each writes a PNG contact sheet and the JSON trace the spec asserts.
    • An endless animation doesn't set the default length; with nothing else to film, the spec passes times.
  • output.ts: evidence goes to the gitignored test-results/interaction-evidence and the test report.
  • story.ts: a timer gate (installTimerGate, freezeTimers, thawTimers) holds the component's own timers and frame callbacks while frames are taken. The page can still cancel a held callback, a held frame callback gets the time it actually runs, and the harness's own frame waits (and the animation recorder) keep the page's real requestAnimationFrame.
  • pnpm storyboards runs the tests tagged @storyboard.
  • scripts/webkit-container.mjs (from test(interaction): real touch input for browser interaction proofs #8043): WebKit in the official Playwright image for hosts with older libraries.

Stacked on #8505 (the animation-state waits, on main with #8044's curve sampling); #8045 and #8423 follow. Review this pull request's own commits.

Evidence

  • Failure before the change: no reproducible frame-by-frame record of an animation exists.
  • Success after the change, in Chromium and WebKit:
    • A filmstrip's trace follows its curve, and a touch filmstrip photographs every scripted event.
    • A filmstrip runs from the earliest start to the latest end among the animations that end.
    • An endless animation alone asks for its times.
    • The timer gate holds a component timer through a filmstrip, drops callbacks the page cancels, and stamps a held frame with the time it runs.
  • Product/runtime behavior verified unchanged: no package source changes.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • At 8082d27 (merges main through test(interaction): curve oracles for animation proofs #8462, and test(interaction): curve sampling #8044's 432ef44): pnpm test:interaction --project chromium internal/interaction-harness: 34 passed; the .github/scripts duration and interaction guards: 32 passed; harness unit tests: 25 passed.
  • pnpm test:interaction --project chromium (harness): 30 passed; pnpm storyboards --list: 9 tests per engine.
  • The recapture self-test (a capture that fails once with Chromium's "Unable to capture screenshot"): the previous Storyboard.capture failed it 3 of 3 times in Chromium and in WebKit; now 10/10 in each.
  • WebKit 26.5 through node internal/interaction-harness/scripts/webkit-container.mjs: 27 passed, 3 skipped (native fling; partial lift; the handler-clock test is Chromium-only).
  • pnpm exec vitest run .github/scripts internal/interaction-harness: 1,298 passed.
  • Harness typecheck, eslint, prettier and the pre-commit repo checks: clean.

vjeux added 10 commits October 24, 2026 14:37
Adds internal/interaction-harness (@astryxdesign/interaction-harness) and
playwright.interaction.config.ts: phone-sized touch projects in Chromium and
WebKit for *.interaction.browser.spec.ts specs.

Touch scripts are data (tap, drag with hold and rest, flick with an exact
release velocity and velocity profiles, hold-then-drag, pinch, rotate, any
path, a second finger mid-gesture), played as real engine input: CDP
Input.dispatchTouchEvent with scripted timestamps in Chromium, WebKit's own
input command in WebKit. The harness's self-test proves the timestamps, a
native fling and multi-touch delivery; a pr-interaction CI job runs the
proofs against each PR's Storybook build, and a container script runs the
WebKit project where host libraries are missing.
… Chromium

The Chromium driver sent a lift of one finger of several as a touchMove
listing the fingers still down, assuming CDP releases a point a move
omits. It does not: the lifted finger stayed down. A touchEnd that lists
the lifting fingers releases exactly those while the others keep moving,
so the driver sends that, and a self-test lifts one of two fingers and
checks the release, the other finger's moves and the touchend's
remaining touches.

Playwright's WebKit sends that touchend with no remaining touches, which
iOS never does. The harness does not work around it: drivers expose
partialLifts, and PARTIAL_LIFT_SKIP is the reason a proof cites when it
skips; the README lists it with the other engine limits.
… lift profiled flicks at their velocity

- pr-interaction now always reports and the `test` join requires its
  success (AST-030 FR7, FR11), shaped like test-native-swift: a Linux
  interaction-scope job decides, with the base's scope helper and failing
  closed, whether the harness, a component, Storybook, internal/a11y-spec,
  the workflow, package.json or pnpm-lock.yaml changed. Only then do the
  proofs take a 4-core runner; otherwise, and in merge groups (as with
  pr-a11y), the job passes without work.
- A profiled flick's last move runs at velocity times profile(1), so the
  finger lifts at the documented velocity, and releaseVelocity reads the
  last move instead of a 100 ms window mean.
- Docs: drop the /math subpath this package does not export yet; scripted
  timestamps arrive to 0.1 ms; the job comment describes the self-test it
  runs.
…ed its previous position

A sample that repeats a position is not a move: frames that merge() inserts
for another finger, where this finger did not move, made the last move look
shorter, so a 10 Hz drag merged with a tap read 375 px/s instead of 300 and a
60 Hz drag whose other finger lifted 5 ms before its last move read about
3.6x too fast. The previous sample is now the first one at the previous
position, as the page sees it, with a merged case in scripts.test.ts.
Pause every Web Animation, seek it to a time and read the presented
transform and opacity, then compare the curve with oracles that share no
code with the motion under test: cubic-bezier, the SwiftUI spring
(response, dampingFraction, initial velocity), UIScrollView deceleration
and UIKit's rubber band. Storyboards photograph seeked animations at
t = 0, 16.7, 33.3 ... ms or each step of a scripted touch, and write a PNG
contact sheet plus the JSON trace a spec asserts, under the gitignored
test-results/interaction-evidence. A timer gate holds a component's own
timers while a filmstrip is taken. pnpm storyboards runs the tagged tests.
…sented values

An animation that keeps its end value in a run of identical final
keyframes (held so a later interruption can read it) reported its whole
duration as the curve: storyboards filmed the hold, waitForAnimation's
interval reached past the landing, and waitForRest, which also required
every animation to leave the running state and read only transform, timed
out. The curve now ends where that run starts (HeldAnimation.curveEndMs,
waitForAnimation's to, the default storyboard times), and rest is no
animation pending or before its curve's end plus the presented transform,
translate, rotate, scale and opacity (and ::backdrop opacity) still for 3
frames, whatever the playState. sampleCurve composes translate, rotate and
scale with transform, so curves of the individual properties are sampled.
…film no endless curve, let the page cancel gated callbacks

- holdAnimations holds only running document-timeline animations: a
  finished fill animation keeps its end value, an animation the page paused
  stays paused (release resumes only what was held), and a scroll-driven one
  is not seeked. Each held animation keeps its offset from the earliest
  start, so staggered starts stay staggered.
- A sample or storyboard frame at or past an end reports the time it was
  read at (presentedAt, half a millisecond inside the end), and curveOf
  reads oracles there.
- An animation that repeats forever no longer sets a storyboard's default
  length (it ran the worker out of memory); with nothing else to film,
  animationStoryboard asks for times.
- The timer gate queues held callbacks by id, so the page's clearTimeout
  and cancelAnimationFrame still cancel them; a held frame callback gets
  the time it runs; frames(), waitForRest and touchStoryboard use the real
  requestAnimationFrame, so they resolve while frozen.
- The storyboard self-tests carry the @Storyboard tag that
  `pnpm storyboards` selects.
…s from the element's own animations, resume endless ones

- animationStoryboard's default times run from the earliest start to the
  latest curve end among the animations that end, each seek at
  origin + t: beside a spinner that started earlier the animation under
  test no longer shows its start in every frame, and a second animation
  that starts later is filmed to its end.
- A sample's presentedAt (per channel: transform, opacity) comes from the
  sampled element's own animations, by keyframe property, not from any
  animation on the page.
- releaseAnimations({finish: true}) resumes an animation that repeats
  forever instead of finishing it (which throws), and always clears the
  held set.
- The interaction proofs' scope includes packages/themes/*/src/.
…before it looked

waitForAnimation polled getAnimations() after the action, so an entrance
shorter than the first look (a cold page answers its first evaluate late)
had already finished: "no animation started".

The page now records every animation from the first call into curves.ts
on it, and on every later document: a frame loop on its own
requestAnimationFrame, the CSS animation and transition events, and
Element.animate as it is called, pending animations included (WebKit can
start and finish a short script animation between two frames of a fresh
page). waitForAnimation also reports an animation that started after the
last waitForRest or waitForAnimation and has finished, with finishedAt.
watchAnimations(locator) arms the record before an action that may be the
page's first contact with the harness.
…uest

This pull request keeps the curve-sampling instruments: holding and seeking
animations, sampling presented values, the oracles, waiting for an
animation and for rest. The storyboards (storyboard.ts, the evidence
output, the timer gate and the `pnpm storyboards` script) and their tests
move to a pull request stacked on this one.
@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 26, 2026 3:39pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 26, 2026, 3:53 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 25, 2026
vjeux added 2 commits October 24, 2026 21:21
`holdAnimations` replaced the held set on each call, so a second hold left
the first set paused after `releaseAnimations` (it resumed only the newest
set), and `waitForRest` then reported the frozen frame as rest. A later hold
now adds to the set: everything held stays held until the release, and
offsets count from the earliest start of all of it. The self-test holds two
elements in turn, releases, and checks the first runs to its end; on the
old code it stays frozen 50 px into a 300 px move.

The self-test's header and the `curves.ts` SYNC line no longer describe the
storyboard and timer-gate layer, which moved to its own pull request.
animationStoryboard films held animations by seeking them (t = 0, 16.7,
33.3 … ms, from the earliest start to the latest curve end among the
animations that end, each at its own offset); touchStoryboard takes a
frame per scripted touch event. Each writes a PNG contact sheet and a JSON
trace of its measurements to the evidence directory and attaches them to
the report; the spec asserts on the trace.

The timer gate (installTimerGate, freezeTimers, thawTimers) holds the
page's timers and frame callbacks while a storyboard photographs, so a
component that finishes an animation from a timer cannot do it behind the
held animation's back; the page can still cancel a held callback, and the
harness's own frame waits (and the animation recorder) keep the page's
real requestAnimationFrame. `pnpm storyboards` runs only the tests tagged
@Storyboard.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the storyboard layer passes its own Chromium self-tests, but this pull request still carries #8043 and #8044 whole, and one documented guarantee of touchStoryboard does not hold.

  • Land #8043 and #8044 first and rebase, so the diff is this pull request's own 822-line commit rather than 4,298 authored lines.
  • touchStoryboard says velocity-dependent behavior is unchanged in Chromium, but a component that times a release with performance.now() or Date.now() (Item's and Toast's swipes) sees the storyboard's slower pacing, so a flick that dismisses a SwipeCommit row when played settles back when filmed; please document that limit or drive the page clock to the scripted times, and cover it with a self-test.

[Automated review]

Comment on lines +300 to +301
* after every event. In Chromium the page still sees the scripted timestamps,
* so velocity-dependent behavior is unchanged; in WebKit the page sees the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This holds only for velocity read from event.timeStamp (BottomSheet). Item's swipe (useSwipeAction.ts, performance.now()) and Toast's (useToastGesture.ts, Date.now()) read the handler clock, and here each event arrives only after two frames, measure and a screenshot: on core-item--swipe-commit, a 150 px flick at 1,500 px/s that dismisses the row under driver.play settles back under touchStoryboard (handler clock 100 ms between the last two moves instead of 33 ms). Please state that limit here and in the README, or drive the page clock to the scripted times while filming.

`touchStoryboard` said velocity-dependent behavior is unchanged in
Chromium. That holds for velocity read from event timestamps, which keep
their scripted times, but a handler that reads `performance.now()` or
`Date.now()` (Item's and Toast's swipes) sees one event per photograph,
about 100 ms apart, so a flick that dismisses when played can settle back
when filmed. The doc and the README now state that limit and point such
gestures at a screencast, and a self-test shows both clocks: scripted
16.7 ms gaps in `timeStamp`, more than two frames in the handler's clock.
@vjeux
vjeux force-pushed the uikit/f3-storyboards branch from 21c9295 to eec2404 Compare October 25, 2026 04:29
@vjeux

vjeux commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. The guarantee is restated and proven in eec2404:

  • touchStoryboard's doc and the README now say what holds and what doesn't. Event timeStamps keep the scripted times in Chromium, so velocity read from events is unchanged. A handler that reads performance.now() or Date.now() (Item's and Toast's swipes) sees one event per photograph, about 100 ms apart, so a clock-timed release flings slower when filmed than when played. Such a gesture should be filmed from a screencast (startScreencast, castStoryboard).
  • A self-test, "a touch filmstrip keeps the scripted event times, and a handler clock sees its pacing", records both clocks during a filmed 60 Hz drag. timeStamp gaps are 16.7 ms; the handler's clock gaps are over two frames.

On scope: this depends on #8043 and #8044, which can't be its base from a fork, so it carries their commits until they merge; then I'll rebase onto main. Its own commits are 4a6dfbe and eec2404.

Retargeting a CSS transition cancels it. If that happened while it was
held, `seekAnimations` and `sampleCurve` set its time again, which revived
it over the page's own new transition, and `releaseAnimations` replayed it
from the start. Seeking, sampling and releasing now drop an `idle` animation
from the held set first, and times count from a fixed origin (the earliest
start held until the release), so dropping one never moves the others. The
self-test retargets a held transition, seeks, releases and waits for rest:
the cancelled transition stays idle and the box ends where the page sent
it. On the old code the cancelled transition is still held after the seek.
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
meta#8117 brings meta#8082 c2fd1bb (with meta#8076 b4e0adb, main with meta#8348's
harness), which clears meta#8118's conflict with main, and its FR11 profiles.
Both behaviors stay: a cell waits the content-touch delay only inside a
scroll view, as a control does (spec:AST-094 FR11), and a control releases
on UIButton's clock under a coarse primary pointer. The tests keep both:
the fixed-bar and cell FR11 cases beside the coarse and fine release
clocks. The story describes both.
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
meta#8076 now carries meta#8446 2931530 and main with meta#8348; this pull request's dependencies arrive as one commit, so its compare link shows only its own change.
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
F1's foundation on main with the meta#8348 harness and cixzhang's meta#8056 fold.
No conflicts.
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
… harness) into uikit/c09-search-table
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 26, 2026
cixzhang added a commit that referenced this pull request Oct 30, 2026
…tion record and the long-task log (#8548)

Stacked on #8045 (frame evidence), which is stacked on #8348. Until those land, this diff includes them; this pull request's own change is its single commit.

## What it adds

Chromium-only instruments for interaction proofs, split out of #8045 for scope (the code is unchanged):

- `traceRendering(page, body)` counts the main thread's rendering work (Layout, Paint, UpdateLayoutTree, PrePaint, …) between two marks, and `countBetween` reads an animation's steady middle: the "no Layout / Paint during a transform animation" proof.
- `startCompositorTrace(page)` records when the compositor presented each frame, which `busyWindowProof` takes as `presented` so a frame the screencast skipped is not mistaken for a stall.
- `installLongTaskLog` / `readLongTasks` record the page's own long tasks. Harness reads mark themselves (`console.timeStamp('harness-read')`), so a trace reports them in `devtoolsTasks`, apart from the page's `longTasks`.

## Who it helps

Authors of interaction proofs: a proof can show that an animation costs the main thread nothing per frame, and the busy-main-thread verdict stays correct on a loaded machine.

## Testing

- Harness self-tests in Chromium (`harness.interaction.browser.spec.ts`): the trace counts no Layout for a transform animation and one per frame for `top`; the long-task log records the page's own long task but not a DevTools evaluate; a harness read inside a trace is not a page long task; screencast-skipped frames the compositor presented are not a stall, and a frozen animation still fails. 49 tests × 2 repeats pass.
- `busy.test.ts` (29 pass), including the recorded skip fixture.
- Test-harness only (`internal/`), nothing published: no changeset.

Co-authored with vjeux.
vjeux pushed a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux pushed a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
# Conflicts:
#	internal/interaction-harness/src/curves.ts
#	internal/interaction-harness/src/harness.interaction.browser.spec.ts
vjeux pushed a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
…o the frame evidence

# Conflicts:
#	internal/interaction-harness/scripts/webkit-container.mjs
vjeux pushed a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux pushed a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux pushed a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
# Conflicts:
#	internal/interaction-harness/README.md
#	internal/interaction-harness/package.json
#	internal/interaction-harness/src/harness.interaction.browser.spec.ts
#	internal/interaction-harness/src/story.ts

This branch was successfully deployed

1 active deployment
Preview — 38ea7d9c Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants