Skip to content

test(website): keep one framer-motion mock component per tag - #30681

Merged
buluoray merged 1 commit into
mainfrom
test/motion-mock-stable-tags
Nov 5, 2026
Merged

buluoray merged 1 commit into
mainfrom
test/motion-mock-stable-tags

Conversation

@buluoray

@buluoray buluoray commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

Problem / Motivation

Goal: Stop 99 frontend test files from remounting their framer-motion subtrees on every render, and fail CI when a new file reintroduces that mock shape.

These files mock framer-motion with const motion = new Proxy({}, { get: (_t, tag: string) => make(tag) }), and make() returns a new React.forwardRef(...) on each call (origin/main @ 34e8a26, website/src/test/ChatSidebar.arrowNav.test.tsx:26-37). Each motion.div read is a new component type, so every render makes React unmount and remount that subtree with fresh DOM nodes. A test holding a node from before a re-render then acts on a detached element. That already produced the #30081 flake (fixed in one file by #30633) and the earlier #28905 flake (fixed in one file by #29255).

Why it matters

Every one of these files can flake the same way whenever a re-render lands between a query and the action that uses its result. On a loaded CI shard that is a matter of timing, so the failures show up as red shards on unrelated PRs, and each one has so far been fixed one file at a time.

Not a goal

What changed (motivation → approach → change)

  • Symptom: CI-only flakes where a test's held DOM node goes stale before a click or a read.
  • Root cause: the motion Proxy getter returns a new component type per read, so React remounts the subtree on every render.
  • Change: a codemod wrapped the getter in each of the 99 files with a per-file Map, so a tag always yields the same component, matching the shape test(chat-sidebar): keep one motion component per tag in resume-all mock #30633 uses and the files that already cached (ChatSidebar.animCap.test.tsx, ChatSidebar.laneScrollMemory.test.tsx). Across all 99 files the only removed lines are the 99 old getter lines; the added lines are the Map declaration, a one-line comment, and the cached getter (104 hunks: 93 standard getters, 6 inline motion: new Proxy(...) getters, each with the Map declared just above its return {). ChatSidebar.slotRenameFocus.test.tsx already caches inside its make(), so it is unchanged.
  • Guard: website/src/test/framerMotionMockStableTags.test.ts walks website/src, and for every file mentioning framer-motion finds each motion Proxy. It fails with src/<file>:<line> unless the getter checks .has(<key>) itself, or delegates to a function defined earlier in the file that does. A first test pins that rule on inline snippets (uncached standard, inline and direct-forwardRef getters are flagged; a cached getter and a caching make() pass).

Backwards compatibility

Compatible: only test files change; no production code, config or public API is touched.

Removes nothing: the diff only adds a cache around existing test mocks and a new test.

Tests

  • New website/src/test/framerMotionMockStableTags.test.ts (2 tests): the rule on fixtures, and the whole-tree scan.
  • Mutation: restoring the old getter line in ChatSidebar.arrowNav.test.tsx turns the scan red with src/test/ChatSidebar.arrowNav.test.tsx:39; restoring the file turns it green again.
  • All 99 changed files plus the guard, run in one vitest batch at --maxWorkers 4: 100 files passed, 1238 tests passed, 0 failed. The same 99 files on origin/main @ 34e8a26: 99 files and 1236 tests passed, so no test relied on the remounting.
  • act() warnings in that batch: arrowNav went from 160 to 12 and closeRefused from 57 to 13. hideStatusFilter (2) and modelFilter (1) were unchanged. renameFailureRecovery emitted 1 in the batch, but 0 in three solo runs on this branch and three on origin/main, so it is timing-dependent under load.
  • eslint on the 100 files: clean. npx tsc -p tsconfig.app.json: 0 errors (it excludes tests). A scratch tsconfig covering the 99 changed test files gave the same 266 pre-existing errors on this branch and on origin/main; the guard file has 0.
  • scripts/check_file_line_cap.py: 0 failures. ChatSidebar.conductorLane.test.tsx goes from 1750 to 1757 lines; it was already past 1,600 on main.

Proof: not provable -- test-only change

Manual verification

N/A — test-only change; the vitest runs and the mutation above cover it.

Screenshots / video

N/A — only test files change, and pr-policy.yml excludes website/src/**/*.test.ts(x) and website/src/test/** from the screenshot watch.

Related Issues

Fixes #30679
Refs #30081, #30633, #28905, #29255

#30633 owns ChatSidebar.resumeAll.test.tsx and should merge first or independently; neither order reds the other.

Sibling sweep

Swept: a node scan of every website/src file containing framer-motion for motion Proxy getters with no .has(<key>) cache, then a check of each file's make() for its own cache
Sibling: website/src/test/ChatSidebar.resumeAll.test.tsx -- tracked in #30633
Sibling: website/src/test/ChatSidebar.slotRenameFocus.test.tsx -- not affected -- its make() caches one component per tag already

Pattern harvest

Rule candidate: lint
Pattern: a framer-motion mock whose motion Proxy getter builds a new component on every read (now enforced by framerMotionMockStableTags.test.ts)

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

Most frontend test files mock framer-motion with a motion Proxy whose
getter calls make(tag) on every read. Each read returns a new
React.forwardRef component, so every render gives React a new element
type, and React unmounts and remounts that subtree with fresh DOM
nodes. A test holding a node from before a re-render then acts on a
detached element, which surfaces as a CI-only flake.

Wrap the getter in each of the 99 remaining files with a per-file Map
so a tag always yields the same component. Each file keeps its own
make(), since they strip different props. ChatSidebar.resumeAll is
left to its own in-flight fix and is tolerated by the guard in either
state.

Add a guard that scans website/src and fails, naming the file and
line, when a framer-motion mock's motion Proxy getter builds a
component per read without caching it.

Fixes #30679
Refs #30081
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 5, 2026 18:47
@buluoray
buluoray requested a review from bolichen97 November 5, 2026 18:48
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 5, 2026
@buluoray
buluoray enabled auto-merge (squash) November 5, 2026 18:50
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 4b9ada9646ba74657e2eb13f2ab34fc749f002fe ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Does not block merge.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 4b9ada9646ba74657e2eb13f2ab34fc749f002fe — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: this changes only tests, removes nothing, and fixes the actual cause (a new component type on every proxy read). A source scan guards the whole tree against the pattern coming back.

Notes

  • The 99 copies of the mock are the actual source of drift. Tracking a shared framerMotionMock helper as a follow-up would remove both the copies and the regex guard, which is the fragile part of this change.
  • OWNED_ELSEWHERE is an exemption that must be removed by hand. Once test(chat-sidebar): keep one motion component per tag in resume-all mock #30633 lands, drop it or make the scan fail when an exempt file already caches. Otherwise the exemption silently outlives its reason.

[DESIGN-REVIEWED] 4b9ada9

Description read

[DESCRIPTION-READ] 5fce57090c92b487c0115cce76e54f2946c965d79b7cc8ec556f496f90723019

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 4b9ada9646ba74657e2eb13f2ab34fc749f002fe — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check: the diff only changes test files and adds no user-visible control.

[UX-REVIEWED] 4b9ada9

Description read

[DESCRIPTION-READ] fea42acb907e443dc84caf63db02bf537aed942032d7954513662c1e7d834582

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 4b9ada9646ba74657e2eb13f2ab34fc749f002fe — this comment is updated in place on each push.

Review details

Test-only diff with no candidates to falsify.

No findings.

[OPUS-REVIEWED] 4b9ada9

Verdict parsed from the review's SHA-scoped output markers for commit 4b9ada9646ba74657e2eb13f2ab34fc749f002fe.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 4b9ada9646ba74657e2eb13f2ab34fc749f002fe false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4b9ada9646ba74657e2eb13f2ab34fc749f002fe and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4b9ada9

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 4b9ada9646ba74657e2eb13f2ab34fc749f002fe false-positive: <reason, 20 to 500 characters>

@bolichen97 bolichen97 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.

Approving 4b9ada9. I read every file.

  • All 100 changed files are under website/src/test/. In 99 of them the framer-motion mock's motion Proxy getter now caches one component per tag in a Map (byTag) instead of building a new component type on every read, which remounted the subtree and left tests holding detached nodes. I folded the changed lines across the files and checked them: every file makes the same edit, in one of two shapes (multi-line or inline get).
  • The new framerMotionMockStableTags.test.ts scans website/src and fails, naming the file, when a mock's getter does not cache per tag. It skips its own fixtures and ChatSidebar.resumeAll.test.tsx, which #30633 fixes separately.
  • Test files only, no product code. The new scan uses regex, but it is a test file, so it is out of scope for the no-regex rule.

All checks pass on this head; only numbered Backend test shards and PR Readiness are pending. Auto-merge was already enabled by the author, so I left it as is.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 5, 2026
@buluoray
buluoray merged commit e4d1156 into main Nov 5, 2026
97 checks passed
@buluoray
buluoray deleted the test/motion-mock-stable-tags branch November 5, 2026 20:01
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(website): framer-motion mocks remount subtrees on every render

2 participants