An open source design system that's fully customizable and agent ready
TypeScript
test(interaction-harness): a pool leaves out a run that began too late (#10464)
Christopher Chedeau8484dc4ff413
diff --git a/internal/interaction-harness/README.md b/internal/interaction-harness/README.mdindex c80c36aa92..5a5bc62d60 100644--- a/internal/interaction-harness/README.md+++ b/internal/interaction-harness/README.md@@ -328,8 +328,10 @@ frames over all the runs, the component on every one of them, and in each runits longest stall may be no longer than that run's control's, since a stallbelongs to its run. A run whose control moved on fewer frames than`minRunFrames` (1 by default) is too little to judge: the summary names it,-and the pool leaves it out, so it never counts as a pass. The pool fails with-fewer than `minJudgedRuns` judged runs (half, rounded up). In each judged run,+and the pool leaves it out, so it never counts as a pass. A run whose block+began after its motion had settled is left out the same way: its `runs` entry+is null, and `late` holds its `BusyWindowTooLateError`. The pool fails with+fewer than `minJudgedRuns` judged runs (half of all the runs, rounded up). In each judged run,the component must move on every frame its control moved on, so a freeze failsits run.diff --git a/internal/interaction-harness/src/busy.control.test.ts b/internal/interaction-harness/src/busy.control.test.tsindex 2c6d2db964..debb196d33 100644--- a/internal/interaction-harness/src/busy.control.test.ts+++ b/internal/interaction-harness/src/busy.control.test.ts@@ -17,7 +17,7 @@*/import {describe, expect, it} from 'vitest';-import {busyWindowProof, pooledBusyProof} from './busy';+import {busyWindowProof, BusyWindowTooLateError, pooledBusyProof} from './busy';import type {TrackedFrame} from './frames';const FRAME = 1000 / 60;@@ -303,6 +303,58 @@ describe('pooledBusyProof', () => {);});+ it('leaves out a run whose block began after its motion had settled, and names it', () => {+ const control = asControl(moving());+ // Settled 50 ms before the run's block: nothing in it is left to judge.+ const settled = moving().map(f =>+ f.t < 950+ ? f+ : ({...f, box: {...f.box!, y: 3 * at(950)}} as TrackedFrame),+ );+ const pooled = pooledBusyProof(+ [+ {tracked: settled, control, window: short(1000)},+ {tracked: moving(), control, window: short(1300)},+ {tracked: moving(), control, window: short(1600)},+ ],+ {settledWithin: 2},+ );+ expect(pooled.verdict.failures, pooled.summary).toEqual([]);+ expect(pooled.judged).toEqual([false, true, true]);+ expect(pooled.runs[0]).toBeNull();+ expect(pooled.late[0]).toBeInstanceOf(BusyWindowTooLateError);+ expect(pooled.late.slice(1)).toEqual([null, null]);+ // Only the judged runs' frames count toward the pool's floors.+ expect(pooled.control).toEqual({moved: 6, movedWith: 6});+ expect(pooled.summary).toMatch(+ /^3 runs pooled, 2 judged: .*; run 1: too late to judge: busyWindowProof: /,+ );+ });++ it('fails by name a pool left with fewer judged runs than its minimum, however many began too late', () => {+ const control = asControl(moving());+ const settled = moving().map(f =>+ f.t < 950+ ? f+ : ({...f, box: {...f.box!, y: 3 * at(950)}} as TrackedFrame),+ );+ // One long run passes every floor alone, beside two that began too late.+ const pooled = pooledBusyProof(+ [+ {tracked: settled, control, window: short(1000)},+ {tracked: settled, control, window: short(1000)},+ {tracked: moving(), control, window: {from: 1100, to: 1700}},+ ],+ {settledWithin: 2},+ );+ expect(pooled.verdict.pass).toBe(false);+ expect(pooled.verdict.failures).toEqual([+ '1 of 3 runs judged, under 2: 2 began after the motion had settled, and the compositor presented too little in any other to judge',+ ]);+ expect(pooled.summary).toMatch(/run 1: too late to judge/);+ expect(pooled.summary).toMatch(/run 2: too late to judge/);+ });+it('still fails a component that is frozen in every run while the control moves', () => {const frozen = moving().map(f => ({...f, box: {...f.box!, y: 0}}) as TrackedFrame,diff --git a/internal/interaction-harness/src/busy.ts b/internal/interaction-harness/src/busy.tsindex bfbcb9b4e7..6b5aa0de5c 100644--- a/internal/interaction-harness/src/busy.ts+++ b/internal/interaction-harness/src/busy.ts@@ -1580,10 +1580,17 @@ export interface PooledBusyProof {* Each run judged on its own against its control: read its numbers, not its* verdict (one short run can hold too few frames to judge).*/- readonly runs: readonly BusyProof[];+ readonly runs: readonly (BusyProof | null)[];+ /**+ * For each run, the `BusyWindowTooLateError` its window threw, or null. Such+ * a run's block began after its motion had settled, so its `runs` entry is+ * null: the run holds nothing to judge.+ */+ readonly late: readonly (BusyWindowTooLateError | null)[];/*** Whether each run was judged. A run whose control moved on fewer than- * `minRunFrames` frames is too little to judge, and the pool leaves it out.+ * `minRunFrames` frames is too little to judge, and so is a run that began+ * too late (`late`). The pool leaves both out.*/readonly judged: readonly boolean[];/**@@ -1604,7 +1611,9 @@ export interface PooledBusyProof {* present fewer than `minJudgedFrames` in one run, and one run cannot decide.* A run whose control moved on fewer than `minRunFrames` frames (1 by* default) is too little to judge: the machine starved it. The summary names- * it, and the pool leaves it out, so it never counts as a pass.+ * it, and the pool leaves it out, so it never counts as a pass. A run whose+ * window throws `BusyWindowTooLateError` is left out the same way: its block+ * began after its motion had settled.* The judged runs are judged as one long window is:* - at least `minJudgedRuns` runs are judged (by default, half the runs,* rounded up);@@ -1644,15 +1653,31 @@ export function pooledBusyProof(`pooledBusyProof: minJudgedRuns ${minJudgedRuns} is not between 1 and the ${runs.length} runs`,);}- const proofs = runs.map(run =>- busyWindowProof(run.tracked, run.window, {- ...windowOptions,- control: run.control,- }),+ const late: (BusyWindowTooLateError | null)[] = [];+ const proofs = runs.map(run => {+ try {+ const proof = busyWindowProof(run.tracked, run.window, {+ ...windowOptions,+ control: run.control,+ });+ late.push(null);+ return proof;+ } catch (error) {+ if (!(error instanceof BusyWindowTooLateError)) {+ throw error;+ }+ late.push(error);+ return null;+ }+ });+ const reads = proofs.map(proof =>+ proof == null ? null : (proof.control as BusyControlRead),);- const reads = proofs.map(proof => proof.control as BusyControlRead);- const judged = reads.map(read => read.moved >= minRunFrames);- const judgedReads = reads.filter((_, i) => judged[i]);+ const judged = reads.map(read => read != null && read.moved >= minRunFrames);+ const judgedReads = reads.filter(+ (read, i): read is BusyControlRead => judged[i] && read != null,+ );+ const lateRuns = late.filter(error => error != null).length;const total = (key: 'moved' | 'movedWith' | 'belowStep') =>judgedReads.reduce((sum, read) => sum + read[key], 0);const moved = total('moved');@@ -1664,7 +1689,9 @@ export function pooledBusyProof(const failures: string[] = [];if (judgedReads.length < minJudgedRuns) {failures.push(- `${judgedReads.length} of ${runs.length} runs judged, under ${minJudgedRuns}: the compositor presented too little in the others to judge`,+ lateRuns === 0+ ? `${judgedReads.length} of ${runs.length} runs judged, under ${minJudgedRuns}: the compositor presented too little in the others to judge`+ : `${judgedReads.length} of ${runs.length} runs judged, under ${minJudgedRuns}: ${lateRuns} began after the motion had settled, and the compositor presented too little in any other to judge`,);}if (judgedReads.length > 0 && moved < minJudgedFrames) {@@ -1684,15 +1711,18 @@ export function pooledBusyProof();}proofs.forEach((proof, i) => {+ if (proof == null) {+ return;+ }if (proof.frames > 0 && proof.medianFrameMs > maxMedianFrameMs) {failures.push(`run ${i + 1}: median frame interval ${proof.medianFrameMs.toFixed(1)} ms > ${maxMedianFrameMs} ms`,);}- if (!judged[i]) {+ const read = reads[i];+ if (!judged[i] || read == null) {return;}- const read = reads[i];if (read.movedWith < read.moved) {failures.push(`run ${i + 1}: moved on ${read.movedWith} of the ${read.moved} frames its control moved`,@@ -1712,13 +1742,16 @@ export function pooledBusyProof(`: moved on ${movedWith} of the control's ${moved} frames` +proofs.map((proof, i) =>- judged[i]- ? `; run ${i + 1}: ${proof.summary}`- : `; run ${i + 1}: too little to judge, the control moved on ${reads[i].moved} frames, under ${minRunFrames}: ${proof.summary}`,+ proof == null+ ? `; run ${i + 1}: too late to judge: ${late[i]?.message ?? ''}`+ : judged[i]+ ? `; run ${i + 1}: ${proof.summary}`+ : `; run ${i + 1}: too little to judge, the control moved on ${reads[i]?.moved ?? 0} frames, under ${minRunFrames}: ${proof.summary}`,).join('');return {runs: proofs,+ late,judged,control: {moved, movedWith},verdict: {pass: failures.length === 0, failures},diff --git a/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts b/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.tsindex 297f6f0906..e1bb35c5f5 100644--- a/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts+++ b/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts@@ -1186,11 +1186,11 @@ test('a settle keeps advancing every frame through an 800 ms main-thread block',expect(proof.verdict.failures, proof.summary).toEqual([]);// Each run's own block has to show the settle at a new position.proof.runs.forEach((run, i) => {- const read = run.control;+ const read = run?.control;const settleFrames = (read?.movedWith ?? 0) - (read?.belowStep ?? 0);expect(settleFrames,- `run ${i + 1}: the settle showed a new position on ${settleFrames} frames in its block. ${run.summary}`,+ `run ${i + 1}: the settle showed a new position on ${settleFrames} frames in its block. ${run?.summary ?? proof.late[i]?.message}`,).toBeGreaterThanOrEqual(1);});});